mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
make service time dependent on vehicle - #199
This commit is contained in:
commit
627c2184ce
38 changed files with 236 additions and 366 deletions
|
|
@ -93,7 +93,7 @@ public class PrettyAlgorithmBuilder {
|
|||
constraintManager.addConstraint(new SwitchNotFeasible(stateManager));
|
||||
stateManager.updateLoadStates();
|
||||
stateManager.updateTimeWindowStates();
|
||||
UpdateVehicleDependentPracticalTimeWindows twUpdater = new UpdateVehicleDependentPracticalTimeWindows(stateManager, vrp.getTransportCosts());
|
||||
UpdateVehicleDependentPracticalTimeWindows twUpdater = new UpdateVehicleDependentPracticalTimeWindows(stateManager, vrp.getTransportCosts(), vrp.getActivityCosts());
|
||||
twUpdater.setVehiclesToUpdate(new UpdateVehicleDependentPracticalTimeWindows.VehiclesToUpdate() {
|
||||
|
||||
Map<VehicleTypeKey, Vehicle> uniqueTypes = new HashMap<VehicleTypeKey, Vehicle>();
|
||||
|
|
@ -116,7 +116,7 @@ public class PrettyAlgorithmBuilder {
|
|||
stateManager.addStateUpdater(twUpdater);
|
||||
stateManager.updateSkillStates();
|
||||
stateManager.addStateUpdater(new UpdateEndLocationIfRouteIsOpen());
|
||||
stateManager.addStateUpdater(new UpdateActivityTimes(vrp.getTransportCosts(), ActivityTimeTracker.ActivityPolicy.AS_SOON_AS_TIME_WINDOW_OPENS));
|
||||
stateManager.addStateUpdater(new UpdateActivityTimes(vrp.getTransportCosts(), ActivityTimeTracker.ActivityPolicy.AS_SOON_AS_TIME_WINDOW_OPENS, vrp.getActivityCosts()));
|
||||
stateManager.addStateUpdater(new UpdateVariableCosts(vrp.getActivityCosts(), vrp.getTransportCosts(), stateManager));
|
||||
stateManager.addStateUpdater(new UpdateFutureWaitingTimes(stateManager, vrp.getTransportCosts()));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -542,7 +542,7 @@ public class VehicleRoutingAlgorithms {
|
|||
} else switchAllowed = true;
|
||||
ActivityTimeTracker.ActivityPolicy activityPolicy;
|
||||
if (stateManager.timeWindowUpdateIsActivated()) {
|
||||
UpdateVehicleDependentPracticalTimeWindows timeWindowUpdater = new UpdateVehicleDependentPracticalTimeWindows(stateManager, vrp.getTransportCosts());
|
||||
UpdateVehicleDependentPracticalTimeWindows timeWindowUpdater = new UpdateVehicleDependentPracticalTimeWindows(stateManager, vrp.getTransportCosts(), vrp.getActivityCosts());
|
||||
timeWindowUpdater.setVehiclesToUpdate(new UpdateVehicleDependentPracticalTimeWindows.VehiclesToUpdate() {
|
||||
Map<VehicleTypeKey, Vehicle> uniqueTypes = new HashMap<VehicleTypeKey, Vehicle>();
|
||||
|
||||
|
|
@ -565,7 +565,7 @@ public class VehicleRoutingAlgorithms {
|
|||
} else {
|
||||
activityPolicy = ActivityTimeTracker.ActivityPolicy.AS_SOON_AS_ARRIVED;
|
||||
}
|
||||
stateManager.addStateUpdater(new UpdateActivityTimes(vrp.getTransportCosts(), activityPolicy));
|
||||
stateManager.addStateUpdater(new UpdateActivityTimes(vrp.getTransportCosts(), activityPolicy, vrp.getActivityCosts()));
|
||||
stateManager.addStateUpdater(new UpdateVariableCosts(vrp.getActivityCosts(), vrp.getTransportCosts(), stateManager, activityPolicy));
|
||||
|
||||
final SolutionCostCalculator costCalculator;
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ final class AuxilliaryCostCalculator {
|
|||
double transportTime = routingCosts.getTransportTime(prevAct.getLocation(), act.getLocation(), departureTimePrevAct, driver, vehicle);
|
||||
cost += transportCost;
|
||||
double actStartTime = departureTimePrevAct + transportTime;
|
||||
departureTimePrevAct = Math.max(actStartTime, act.getTheoreticalEarliestOperationStartTime()) + act.getOperationTime();
|
||||
departureTimePrevAct = Math.max(actStartTime, act.getTheoreticalEarliestOperationStartTime()) + activityCosts.getActivityDuration(act,actStartTime,driver,vehicle);
|
||||
cost += activityCosts.getActivityCost(act, actStartTime, driver, vehicle);
|
||||
prevAct = act;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ import java.util.Iterator;
|
|||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Calculator that calculates the best insertion position for a {@link com.graphhopper.jsprit.core.problem.job.Service}.
|
||||
* Calculator that calculates the best insertion position for a {@link jsprit.core.problem.job.Service}.
|
||||
*
|
||||
* @author schroeder
|
||||
*/
|
||||
|
|
@ -58,15 +58,18 @@ final class BreakInsertionCalculator implements JobInsertionCostsCalculator {
|
|||
|
||||
private VehicleRoutingTransportCosts transportCosts;
|
||||
|
||||
private final VehicleRoutingActivityCosts activityCosts;
|
||||
|
||||
private ActivityInsertionCostsCalculator additionalTransportCostsCalculator;
|
||||
|
||||
private JobActivityFactory activityFactory;
|
||||
|
||||
private AdditionalAccessEgressCalculator additionalAccessEgressCalculator;
|
||||
|
||||
public BreakInsertionCalculator(VehicleRoutingTransportCosts routingCosts, ActivityInsertionCostsCalculator additionalTransportCostsCalculator, ConstraintManager constraintManager) {
|
||||
public BreakInsertionCalculator(VehicleRoutingTransportCosts routingCosts, VehicleRoutingActivityCosts activityCosts, ActivityInsertionCostsCalculator additionalTransportCostsCalculator, ConstraintManager constraintManager) {
|
||||
super();
|
||||
this.transportCosts = routingCosts;
|
||||
this.activityCosts = activityCosts;
|
||||
hardRouteLevelConstraint = constraintManager;
|
||||
hardActivityLevelConstraint = constraintManager;
|
||||
softActivityConstraint = constraintManager;
|
||||
|
|
@ -161,7 +164,7 @@ final class BreakInsertionCalculator implements JobInsertionCostsCalculator {
|
|||
}
|
||||
}
|
||||
double nextActArrTime = prevActStartTime + transportCosts.getTransportTime(prevAct.getLocation(), nextAct.getLocation(), prevActStartTime, newDriver, newVehicle);
|
||||
prevActStartTime = CalculationUtils.getActivityEndTime(nextActArrTime, nextAct);
|
||||
prevActStartTime = Math.max(nextActArrTime, nextAct.getTheoreticalEarliestOperationStartTime()) + activityCosts.getActivityDuration(nextAct,nextActArrTime,newDriver,newVehicle);
|
||||
prevAct = nextAct;
|
||||
actIndex++;
|
||||
if (breakThis) break;
|
||||
|
|
|
|||
|
|
@ -286,12 +286,12 @@ public class JobInsertionCostsCalculatorBuilder {
|
|||
}
|
||||
|
||||
};
|
||||
ShipmentInsertionCalculator shipmentInsertion = new ShipmentInsertionCalculator(vrp.getTransportCosts(), actInsertionCalc, constraintManager);
|
||||
ShipmentInsertionCalculator shipmentInsertion = new ShipmentInsertionCalculator(vrp.getTransportCosts(), vrp.getActivityCosts(), actInsertionCalc, constraintManager);
|
||||
shipmentInsertion.setJobActivityFactory(activityFactory);
|
||||
ServiceInsertionCalculator serviceInsertion = new ServiceInsertionCalculator(vrp.getTransportCosts(), actInsertionCalc, constraintManager);
|
||||
ServiceInsertionCalculator serviceInsertion = new ServiceInsertionCalculator(vrp.getTransportCosts(), vrp.getActivityCosts(), actInsertionCalc, constraintManager);
|
||||
serviceInsertion.setJobActivityFactory(activityFactory);
|
||||
|
||||
BreakInsertionCalculator breakInsertionCalculator = new BreakInsertionCalculator(vrp.getTransportCosts(), actInsertionCalc, constraintManager);
|
||||
BreakInsertionCalculator breakInsertionCalculator = new BreakInsertionCalculator(vrp.getTransportCosts(), vrp.getActivityCosts(), actInsertionCalc, constraintManager);
|
||||
breakInsertionCalculator.setJobActivityFactory(activityFactory);
|
||||
|
||||
JobCalculatorSwitcher switcher = new JobCalculatorSwitcher();
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ import com.graphhopper.jsprit.core.problem.solution.route.activity.End;
|
|||
import com.graphhopper.jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import com.graphhopper.jsprit.core.problem.solution.route.state.RouteAndActivityStateGetter;
|
||||
import com.graphhopper.jsprit.core.problem.vehicle.Vehicle;
|
||||
import com.graphhopper.jsprit.core.util.CalculationUtils;
|
||||
|
||||
/**
|
||||
* Calculates activity insertion costs locally, i.e. by comparing the additional costs of insertion the new activity k between
|
||||
|
|
@ -61,7 +60,7 @@ class LocalActivityInsertionCostsCalculator implements ActivityInsertionCostsCal
|
|||
double tp_costs_prevAct_newAct = routingCosts.getTransportCost(prevAct.getLocation(), newAct.getLocation(), depTimeAtPrevAct, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
double tp_time_prevAct_newAct = routingCosts.getTransportTime(prevAct.getLocation(), newAct.getLocation(), depTimeAtPrevAct, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
double newAct_arrTime = depTimeAtPrevAct + tp_time_prevAct_newAct;
|
||||
double newAct_endTime = CalculationUtils.getActivityEndTime(newAct_arrTime, newAct);
|
||||
double newAct_endTime = Math.max(newAct_arrTime, newAct.getTheoreticalEarliestOperationStartTime()) + activityCosts.getActivityDuration(newAct, newAct_arrTime, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
|
||||
double act_costs_newAct = activityCosts.getActivityCost(newAct, newAct_arrTime, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
|
||||
|
|
@ -70,7 +69,7 @@ class LocalActivityInsertionCostsCalculator implements ActivityInsertionCostsCal
|
|||
double tp_costs_newAct_nextAct = routingCosts.getTransportCost(newAct.getLocation(), nextAct.getLocation(), newAct_endTime, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
double tp_time_newAct_nextAct = routingCosts.getTransportTime(newAct.getLocation(), nextAct.getLocation(), newAct_endTime, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
double nextAct_arrTime = newAct_endTime + tp_time_newAct_nextAct;
|
||||
double endTime_nextAct_new = CalculationUtils.getActivityEndTime(nextAct_arrTime, nextAct);
|
||||
double endTime_nextAct_new = Math.max(nextAct_arrTime, nextAct.getTheoreticalEarliestOperationStartTime()) + activityCosts.getActivityDuration(nextAct, newAct_arrTime, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
double act_costs_nextAct = activityCosts.getActivityCost(nextAct, nextAct_arrTime, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
|
||||
double totalCosts = tp_costs_prevAct_newAct + tp_costs_newAct_nextAct + solutionCompletenessRatio * activityCostsWeight * (act_costs_newAct + act_costs_nextAct);
|
||||
|
|
@ -82,7 +81,7 @@ class LocalActivityInsertionCostsCalculator implements ActivityInsertionCostsCal
|
|||
} else {
|
||||
double tp_costs_prevAct_nextAct = routingCosts.getTransportCost(prevAct.getLocation(), nextAct.getLocation(), prevAct.getEndTime(), iFacts.getRoute().getDriver(), iFacts.getRoute().getVehicle());
|
||||
double arrTime_nextAct = depTimeAtPrevAct + routingCosts.getTransportTime(prevAct.getLocation(), nextAct.getLocation(), prevAct.getEndTime(), iFacts.getRoute().getDriver(), iFacts.getRoute().getVehicle());
|
||||
double endTime_nextAct_old = CalculationUtils.getActivityEndTime(arrTime_nextAct, nextAct);
|
||||
double endTime_nextAct_old = Math.max(arrTime_nextAct, nextAct.getTheoreticalEarliestOperationStartTime()) + activityCosts.getActivityDuration(nextAct, nextAct_arrTime, iFacts.getRoute().getDriver(),iFacts.getRoute().getVehicle());
|
||||
double actCost_nextAct = activityCosts.getActivityCost(nextAct, arrTime_nextAct, iFacts.getRoute().getDriver(), iFacts.getRoute().getVehicle());
|
||||
|
||||
double endTimeDelay_nextAct = Math.max(0, endTime_nextAct_new - endTime_nextAct_old);
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ package com.graphhopper.jsprit.core.algorithm.recreate;
|
|||
import com.graphhopper.jsprit.core.problem.JobActivityFactory;
|
||||
import com.graphhopper.jsprit.core.problem.constraint.*;
|
||||
import com.graphhopper.jsprit.core.problem.constraint.HardActivityConstraint.ConstraintsStatus;
|
||||
import com.graphhopper.jsprit.core.problem.cost.VehicleRoutingActivityCosts;
|
||||
import com.graphhopper.jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
||||
import com.graphhopper.jsprit.core.problem.driver.Driver;
|
||||
import com.graphhopper.jsprit.core.problem.job.Job;
|
||||
|
|
@ -31,14 +32,13 @@ import com.graphhopper.jsprit.core.problem.solution.route.activity.Start;
|
|||
import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindow;
|
||||
import com.graphhopper.jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import com.graphhopper.jsprit.core.problem.vehicle.Vehicle;
|
||||
import com.graphhopper.jsprit.core.util.CalculationUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* Calculator that calculates the best insertion position for a {@link com.graphhopper.jsprit.core.problem.job.Service}.
|
||||
* Calculator that calculates the best insertion position for a {@link Service}.
|
||||
*
|
||||
* @author schroeder
|
||||
*/
|
||||
|
|
@ -56,15 +56,18 @@ final class ServiceInsertionCalculator implements JobInsertionCostsCalculator {
|
|||
|
||||
private VehicleRoutingTransportCosts transportCosts;
|
||||
|
||||
private final VehicleRoutingActivityCosts activityCosts;
|
||||
|
||||
private ActivityInsertionCostsCalculator additionalTransportCostsCalculator;
|
||||
|
||||
private JobActivityFactory activityFactory;
|
||||
|
||||
private AdditionalAccessEgressCalculator additionalAccessEgressCalculator;
|
||||
|
||||
public ServiceInsertionCalculator(VehicleRoutingTransportCosts routingCosts, ActivityInsertionCostsCalculator additionalTransportCostsCalculator, ConstraintManager constraintManager) {
|
||||
public ServiceInsertionCalculator(VehicleRoutingTransportCosts routingCosts, VehicleRoutingActivityCosts activityCosts, ActivityInsertionCostsCalculator additionalTransportCostsCalculator, ConstraintManager constraintManager) {
|
||||
super();
|
||||
this.transportCosts = routingCosts;
|
||||
this.activityCosts = activityCosts;
|
||||
hardRouteLevelConstraint = constraintManager;
|
||||
hardActivityLevelConstraint = constraintManager;
|
||||
softActivityConstraint = constraintManager;
|
||||
|
|
@ -154,7 +157,7 @@ final class ServiceInsertionCalculator implements JobInsertionCostsCalculator {
|
|||
}
|
||||
if(not_fulfilled_break) break;
|
||||
double nextActArrTime = prevActStartTime + transportCosts.getTransportTime(prevAct.getLocation(), nextAct.getLocation(), prevActStartTime, newDriver, newVehicle);
|
||||
prevActStartTime = CalculationUtils.getActivityEndTime(nextActArrTime, nextAct);
|
||||
prevActStartTime = Math.max(nextActArrTime, nextAct.getTheoreticalEarliestOperationStartTime()) + activityCosts.getActivityDuration(nextAct,nextActArrTime,newDriver,newVehicle);
|
||||
prevAct = nextAct;
|
||||
actIndex++;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -203,7 +203,7 @@ final class ServiceInsertionOnRouteLevelCalculator implements JobInsertionCostsC
|
|||
/**
|
||||
* departure time at nextAct with new vehicle
|
||||
*/
|
||||
double depTime_nextAct_newVehicle = Math.max(arrTime_nextAct_newVehicle, nextAct.getTheoreticalEarliestOperationStartTime()) + nextAct.getOperationTime();
|
||||
double depTime_nextAct_newVehicle = Math.max(arrTime_nextAct_newVehicle, nextAct.getTheoreticalEarliestOperationStartTime()) + activityCosts.getActivityDuration(nextAct, arrTime_nextAct_newVehicle,newDriver,newVehicle);
|
||||
|
||||
/**
|
||||
* set previous to next
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
package com.graphhopper.jsprit.core.algorithm.recreate;
|
||||
|
||||
import com.graphhopper.jsprit.core.problem.constraint.SoftActivityConstraint;
|
||||
import com.graphhopper.jsprit.core.problem.cost.VehicleRoutingActivityCosts;
|
||||
import com.graphhopper.jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
||||
import com.graphhopper.jsprit.core.problem.misc.JobInsertionContext;
|
||||
import com.graphhopper.jsprit.core.problem.solution.route.activity.End;
|
||||
|
|
@ -25,11 +26,14 @@ import com.graphhopper.jsprit.core.util.CalculationUtils;
|
|||
|
||||
public class VariableTransportCostCalculator implements SoftActivityConstraint {
|
||||
|
||||
private VehicleRoutingTransportCosts routingCosts;
|
||||
private final VehicleRoutingTransportCosts routingCosts;
|
||||
|
||||
public VariableTransportCostCalculator(VehicleRoutingTransportCosts routingCosts) {
|
||||
private final VehicleRoutingActivityCosts activityCosts;
|
||||
|
||||
public VariableTransportCostCalculator(VehicleRoutingTransportCosts routingCosts, VehicleRoutingActivityCosts activityCosts) {
|
||||
super();
|
||||
this.routingCosts = routingCosts;
|
||||
this.activityCosts = activityCosts;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -38,7 +42,7 @@ public class VariableTransportCostCalculator implements SoftActivityConstraint {
|
|||
double tp_time_prevAct_newAct = routingCosts.getTransportTime(prevAct.getLocation(), newAct.getLocation(), depTimeAtPrevAct, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
|
||||
double newAct_arrTime = depTimeAtPrevAct + tp_time_prevAct_newAct;
|
||||
double newAct_endTime = CalculationUtils.getActivityEndTime(newAct_arrTime, newAct);
|
||||
double newAct_endTime = Math.max(newAct_arrTime, newAct.getTheoreticalEarliestOperationStartTime()) + activityCosts.getActivityDuration(newAct,newAct_arrTime,iFacts.getNewDriver(),iFacts.getNewVehicle());
|
||||
|
||||
//open routes
|
||||
if (nextAct instanceof End) {
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
package com.graphhopper.jsprit.core.algorithm.state;
|
||||
|
||||
import com.graphhopper.jsprit.core.problem.cost.ForwardTransportTime;
|
||||
import com.graphhopper.jsprit.core.problem.cost.VehicleRoutingActivityCosts;
|
||||
import com.graphhopper.jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import com.graphhopper.jsprit.core.problem.solution.route.activity.ActivityVisitor;
|
||||
import com.graphhopper.jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
|
|
@ -45,13 +46,13 @@ public class UpdateActivityTimes implements ActivityVisitor, StateUpdater {
|
|||
* <code>activity.getArrTime()</code> and
|
||||
* <code>activity.getEndTime()</code>
|
||||
*/
|
||||
public UpdateActivityTimes(ForwardTransportTime transportTime) {
|
||||
public UpdateActivityTimes(ForwardTransportTime transportTime, VehicleRoutingActivityCosts activityCosts) {
|
||||
super();
|
||||
timeTracker = new ActivityTimeTracker(transportTime);
|
||||
timeTracker = new ActivityTimeTracker(transportTime,activityCosts );
|
||||
}
|
||||
|
||||
public UpdateActivityTimes(ForwardTransportTime transportTime, ActivityTimeTracker.ActivityPolicy activityPolicy) {
|
||||
timeTracker = new ActivityTimeTracker(transportTime, activityPolicy);
|
||||
public UpdateActivityTimes(ForwardTransportTime transportTime, ActivityTimeTracker.ActivityPolicy activityPolicy, VehicleRoutingActivityCosts activityCosts) {
|
||||
timeTracker = new ActivityTimeTracker(transportTime, activityPolicy, activityCosts);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
******************************************************************************/
|
||||
package com.graphhopper.jsprit.core.algorithm.state;
|
||||
|
||||
import com.graphhopper.jsprit.core.problem.cost.VehicleRoutingActivityCosts;
|
||||
import com.graphhopper.jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
||||
import com.graphhopper.jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import com.graphhopper.jsprit.core.problem.solution.route.activity.ReverseActivityVisitor;
|
||||
|
|
@ -34,14 +35,17 @@ class UpdatePracticalTimeWindows implements ReverseActivityVisitor, StateUpdater
|
|||
|
||||
private VehicleRoutingTransportCosts transportCosts;
|
||||
|
||||
private VehicleRoutingActivityCosts activityCosts;
|
||||
|
||||
private double latestArrTimeAtPrevAct;
|
||||
|
||||
private TourActivity prevAct;
|
||||
|
||||
public UpdatePracticalTimeWindows(StateManager states, VehicleRoutingTransportCosts tpCosts) {
|
||||
public UpdatePracticalTimeWindows(StateManager states, VehicleRoutingTransportCosts tpCosts, VehicleRoutingActivityCosts activityCosts) {
|
||||
super();
|
||||
this.states = states;
|
||||
this.transportCosts = tpCosts;
|
||||
this.activityCosts = activityCosts;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -53,7 +57,7 @@ class UpdatePracticalTimeWindows implements ReverseActivityVisitor, StateUpdater
|
|||
|
||||
@Override
|
||||
public void visit(TourActivity activity) {
|
||||
double potentialLatestArrivalTimeAtCurrAct = latestArrTimeAtPrevAct - transportCosts.getBackwardTransportTime(activity.getLocation(), prevAct.getLocation(), latestArrTimeAtPrevAct, route.getDriver(), route.getVehicle()) - activity.getOperationTime();
|
||||
double potentialLatestArrivalTimeAtCurrAct = latestArrTimeAtPrevAct - transportCosts.getBackwardTransportTime(activity.getLocation(), prevAct.getLocation(), latestArrTimeAtPrevAct, route.getDriver(), route.getVehicle()) - activityCosts.getActivityDuration(activity,latestArrTimeAtPrevAct,route.getDriver(),route.getVehicle());
|
||||
double latestArrivalTime = Math.min(activity.getTheoreticalLatestOperationStartTime(), potentialLatestArrivalTimeAtCurrAct);
|
||||
|
||||
states.putInternalTypedActivityState(activity, InternalStates.LATEST_OPERATION_START_TIME, latestArrivalTime);
|
||||
|
|
|
|||
|
|
@ -64,14 +64,14 @@ public class UpdateVariableCosts implements ActivityVisitor, StateUpdater {
|
|||
this.activityCost = activityCost;
|
||||
this.transportCost = transportCost;
|
||||
this.states = states;
|
||||
timeTracker = new ActivityTimeTracker(transportCost);
|
||||
timeTracker = new ActivityTimeTracker(transportCost, activityCost);
|
||||
}
|
||||
|
||||
public UpdateVariableCosts(VehicleRoutingActivityCosts activityCosts, VehicleRoutingTransportCosts transportCosts, StateManager stateManager, ActivityTimeTracker.ActivityPolicy activityPolicy) {
|
||||
this.activityCost = activityCosts;
|
||||
this.transportCost = transportCosts;
|
||||
this.states = stateManager;
|
||||
timeTracker = new ActivityTimeTracker(transportCosts, activityPolicy);
|
||||
timeTracker = new ActivityTimeTracker(transportCosts, activityPolicy, activityCosts);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -59,6 +59,8 @@ public class UpdateVehicleDependentPracticalTimeWindows implements RouteVisitor,
|
|||
|
||||
private final VehicleRoutingTransportCosts transportCosts;
|
||||
|
||||
private final VehicleRoutingActivityCosts activityCosts;
|
||||
|
||||
private VehicleRoute route;
|
||||
|
||||
private double[] latest_arrTimes_at_prevAct;
|
||||
|
|
@ -67,10 +69,11 @@ public class UpdateVehicleDependentPracticalTimeWindows implements RouteVisitor,
|
|||
|
||||
private Collection<Vehicle> vehicles;
|
||||
|
||||
public UpdateVehicleDependentPracticalTimeWindows(StateManager stateManager, VehicleRoutingTransportCosts tpCosts) {
|
||||
public UpdateVehicleDependentPracticalTimeWindows(StateManager stateManager, VehicleRoutingTransportCosts tpCosts, VehicleRoutingActivityCosts activityCosts) {
|
||||
super();
|
||||
this.stateManager = stateManager;
|
||||
this.transportCosts = tpCosts;
|
||||
this.activityCosts = activityCosts;
|
||||
latest_arrTimes_at_prevAct = new double[stateManager.getMaxIndexOfVehicleTypeIdentifiers() + 1];
|
||||
location_of_prevAct = new Location[stateManager.getMaxIndexOfVehicleTypeIdentifiers() + 1];
|
||||
}
|
||||
|
|
@ -95,9 +98,8 @@ public class UpdateVehicleDependentPracticalTimeWindows implements RouteVisitor,
|
|||
double latestArrTimeAtPrevAct = latest_arrTimes_at_prevAct[vehicle.getVehicleTypeIdentifier().getIndex()];
|
||||
Location prevLocation = location_of_prevAct[vehicle.getVehicleTypeIdentifier().getIndex()];
|
||||
double potentialLatestArrivalTimeAtCurrAct = latestArrTimeAtPrevAct - transportCosts.getBackwardTransportTime(activity.getLocation(), prevLocation,
|
||||
latestArrTimeAtPrevAct, route.getDriver(), vehicle) - activity.getOperationTime();
|
||||
latestArrTimeAtPrevAct, route.getDriver(), vehicle) - activityCosts.getActivityDuration(activity, latestArrTimeAtPrevAct, route.getDriver(), route.getVehicle());
|
||||
double latestArrivalTime = Math.min(activity.getTheoreticalLatestOperationStartTime(), potentialLatestArrivalTimeAtCurrAct);
|
||||
// getLatestArrivalTime(activity.getTimeWindows(), potentialLatestArrivalTimeAtCurrAct);
|
||||
if (latestArrivalTime < activity.getTheoreticalEarliestOperationStartTime()) {
|
||||
stateManager.putTypedInternalRouteState(route, vehicle, InternalStates.SWITCH_NOT_FEASIBLE, true);
|
||||
}
|
||||
|
|
@ -108,8 +110,8 @@ public class UpdateVehicleDependentPracticalTimeWindows implements RouteVisitor,
|
|||
}
|
||||
|
||||
|
||||
public void finish() {}
|
||||
|
||||
public void finish() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -231,6 +231,8 @@ public class SolutionAnalyser {
|
|||
|
||||
private StateManager stateManager;
|
||||
|
||||
private final VehicleRoutingActivityCosts activityCosts;
|
||||
|
||||
private ActivityTimeTracker.ActivityPolicy activityPolicy;
|
||||
|
||||
private VehicleRoute route;
|
||||
|
|
@ -245,13 +247,14 @@ public class SolutionAnalyser {
|
|||
|
||||
double prevActDeparture;
|
||||
|
||||
private SumUpActivityTimes(StateId waiting_time_id, StateId transport_time_id, StateId service_time_id, StateId too_late_id, StateManager stateManager, ActivityTimeTracker.ActivityPolicy activityPolicy) {
|
||||
private SumUpActivityTimes(StateId waiting_time_id, StateId transport_time_id, StateId service_time_id, StateId too_late_id, StateManager stateManager, ActivityTimeTracker.ActivityPolicy activityPolicy, VehicleRoutingActivityCosts activityCosts) {
|
||||
this.waiting_time_id = waiting_time_id;
|
||||
this.transport_time_id = transport_time_id;
|
||||
this.service_time_id = service_time_id;
|
||||
this.too_late_id = too_late_id;
|
||||
this.stateManager = stateManager;
|
||||
this.activityPolicy = activityPolicy;
|
||||
this.activityCosts = activityCosts;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -280,7 +283,7 @@ public class SolutionAnalyser {
|
|||
sum_transport_time += transportTime;
|
||||
prevActDeparture = activity.getEndTime();
|
||||
//service time
|
||||
sum_service_time += activity.getOperationTime();
|
||||
sum_service_time += activityCosts.getActivityDuration(activity,activity.getArrTime(),route.getDriver(),route.getVehicle());
|
||||
|
||||
stateManager.putActivityState(activity, transport_time_id, sum_transport_time);
|
||||
|
||||
|
|
@ -547,7 +550,7 @@ public class SolutionAnalyser {
|
|||
this.stateManager.updateLoadStates();
|
||||
this.stateManager.updateSkillStates();
|
||||
activityPolicy = ActivityTimeTracker.ActivityPolicy.AS_SOON_AS_TIME_WINDOW_OPENS;
|
||||
this.stateManager.addStateUpdater(new UpdateActivityTimes(vrp.getTransportCosts(), activityPolicy));
|
||||
this.stateManager.addStateUpdater(new UpdateActivityTimes(vrp.getTransportCosts(), activityPolicy, vrp.getActivityCosts()));
|
||||
this.stateManager.addStateUpdater(new UpdateVariableCosts(vrp.getActivityCosts(), vrp.getTransportCosts(), stateManager));
|
||||
waiting_time_id = stateManager.createStateId("waiting-time");
|
||||
transport_time_id = stateManager.createStateId("transport-time");
|
||||
|
|
@ -561,7 +564,7 @@ public class SolutionAnalyser {
|
|||
last_transport_distance_id = stateManager.createStateId("last-transport-distance");
|
||||
last_transport_time_id = stateManager.createStateId("last-transport-time");
|
||||
|
||||
stateManager.addStateUpdater(new SumUpActivityTimes(waiting_time_id, transport_time_id, service_time_id, too_late_id, stateManager, activityPolicy));
|
||||
stateManager.addStateUpdater(new SumUpActivityTimes(waiting_time_id, transport_time_id, service_time_id, too_late_id, stateManager, activityPolicy, vrp.getActivityCosts()));
|
||||
stateManager.addStateUpdater(new DistanceUpdater(distance_id, stateManager, distanceCalculator));
|
||||
stateManager.addStateUpdater(new BackhaulAndShipmentUpdater(backhaul_id, shipment_id, stateManager));
|
||||
stateManager.addStateUpdater(new SkillUpdater(stateManager, skill_id));
|
||||
|
|
|
|||
|
|
@ -31,6 +31,8 @@ class AdditionalTransportationCosts implements SoftActivityConstraint {
|
|||
|
||||
private VehicleRoutingTransportCosts routingCosts;
|
||||
|
||||
private VehicleRoutingActivityCosts activityCosts;
|
||||
|
||||
/**
|
||||
* Constructs the calculator that calculates additional transportation costs induced by inserting new activity.
|
||||
* <p/>
|
||||
|
|
@ -38,10 +40,12 @@ class AdditionalTransportationCosts implements SoftActivityConstraint {
|
|||
* <p>If newVehicle.isReturnToDepot == false then the additional costs of inserting act_new between act_i and end is c(act_i,act_new) [since act_new is then the new end-of-route]
|
||||
*
|
||||
* @param routingCosts
|
||||
* @param activityCosts
|
||||
*/
|
||||
public AdditionalTransportationCosts(VehicleRoutingTransportCosts routingCosts) {
|
||||
public AdditionalTransportationCosts(VehicleRoutingTransportCosts routingCosts, VehicleRoutingActivityCosts activityCosts) {
|
||||
super();
|
||||
this.routingCosts = routingCosts;
|
||||
this.activityCosts = activityCosts;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -56,7 +60,7 @@ class AdditionalTransportationCosts implements SoftActivityConstraint {
|
|||
double tp_time_prevAct_newAct = routingCosts.getTransportTime(prevAct.getLocation(), newAct.getLocation(), depTimeAtPrevAct, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
|
||||
double newAct_arrTime = depTimeAtPrevAct + tp_time_prevAct_newAct;
|
||||
double newAct_endTime = CalculationUtils.getActivityEndTime(newAct_arrTime, newAct);
|
||||
double newAct_endTime = Math.max(newAct_arrTime, newAct.getTheoreticalEarliestOperationStartTime()) + activityCosts.getActivityDuration(newAct,newAct_arrTime,iFacts.getNewDriver(),iFacts.getNewVehicle());
|
||||
|
||||
//open routes
|
||||
if (nextAct instanceof End) {
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ public class ConstraintManager implements HardActivityConstraint, HardRouteConst
|
|||
|
||||
public void addTimeWindowConstraint() {
|
||||
if (!timeWindowConstraintsSet) {
|
||||
addConstraint(new VehicleDependentTimeWindowConstraints(stateManager, vrp.getTransportCosts()), Priority.HIGH);
|
||||
addConstraint(new VehicleDependentTimeWindowConstraints(stateManager, vrp.getTransportCosts(), vrp.getActivityCosts()), Priority.HIGH);
|
||||
timeWindowConstraintsSet = true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,142 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (C) 2014 Stefan Schroeder
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
package com.graphhopper.jsprit.core.problem.constraint;
|
||||
|
||||
import com.graphhopper.jsprit.core.algorithm.state.InternalStates;
|
||||
import com.graphhopper.jsprit.core.problem.Location;
|
||||
import com.graphhopper.jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
||||
import com.graphhopper.jsprit.core.problem.misc.JobInsertionContext;
|
||||
import com.graphhopper.jsprit.core.problem.solution.route.activity.End;
|
||||
import com.graphhopper.jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import com.graphhopper.jsprit.core.problem.solution.route.state.RouteAndActivityStateGetter;
|
||||
import com.graphhopper.jsprit.core.util.CalculationUtils;
|
||||
|
||||
|
||||
/**
|
||||
* @author stefan
|
||||
*/
|
||||
class TimeWindowConstraint implements HardActivityConstraint {
|
||||
|
||||
private RouteAndActivityStateGetter states;
|
||||
|
||||
private VehicleRoutingTransportCosts routingCosts;
|
||||
|
||||
public TimeWindowConstraint(RouteAndActivityStateGetter states, VehicleRoutingTransportCosts routingCosts) {
|
||||
super();
|
||||
this.states = states;
|
||||
this.routingCosts = routingCosts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConstraintsStatus fulfilled(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) {
|
||||
double latestVehicleArrival = iFacts.getNewVehicle().getLatestArrival();
|
||||
Double latestArrTimeAtNextAct;
|
||||
Location nextActLocation;
|
||||
if (nextAct instanceof End) {
|
||||
latestArrTimeAtNextAct = latestVehicleArrival;
|
||||
nextActLocation = iFacts.getNewVehicle().getEndLocation();
|
||||
if (!iFacts.getNewVehicle().isReturnToDepot()) {
|
||||
nextActLocation = newAct.getLocation();
|
||||
}
|
||||
} else {
|
||||
latestArrTimeAtNextAct = states.getActivityState(nextAct, InternalStates.LATEST_OPERATION_START_TIME, Double.class);
|
||||
if (latestArrTimeAtNextAct == null)
|
||||
latestArrTimeAtNextAct = nextAct.getTheoreticalLatestOperationStartTime();
|
||||
nextActLocation = nextAct.getLocation();
|
||||
}
|
||||
|
||||
/*
|
||||
* if latest arrival of vehicle (at its end) is smaller than earliest operation start times of activities,
|
||||
* then vehicle can never conduct activities.
|
||||
*
|
||||
* |--- vehicle's operation time ---|
|
||||
* |--- prevAct or newAct or nextAct ---|
|
||||
*/
|
||||
if (latestVehicleArrival < prevAct.getTheoreticalEarliestOperationStartTime() ||
|
||||
latestVehicleArrival < newAct.getTheoreticalEarliestOperationStartTime() ||
|
||||
latestVehicleArrival < nextAct.getTheoreticalEarliestOperationStartTime()) {
|
||||
return ConstraintsStatus.NOT_FULFILLED_BREAK;
|
||||
}
|
||||
/*
|
||||
* if the latest operation start-time of new activity is smaller than the earliest start of prev. activity,
|
||||
* then
|
||||
*
|
||||
* |--- prevAct ---|
|
||||
* |--- newAct ---|
|
||||
*/
|
||||
if (newAct.getTheoreticalLatestOperationStartTime() < prevAct.getTheoreticalEarliestOperationStartTime()) {
|
||||
return ConstraintsStatus.NOT_FULFILLED_BREAK;
|
||||
}
|
||||
|
||||
/*
|
||||
* |--- prevAct ---|
|
||||
* |- earliest arrival of vehicle
|
||||
* |--- nextAct ---|
|
||||
*/
|
||||
double arrTimeAtNextOnDirectRouteWithNewVehicle = prevActDepTime + routingCosts.getTransportTime(prevAct.getLocation(), nextAct.getLocation(), prevActDepTime, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
if (arrTimeAtNextOnDirectRouteWithNewVehicle > nextAct.getTheoreticalLatestOperationStartTime()) {
|
||||
return ConstraintsStatus.NOT_FULFILLED_BREAK;
|
||||
}
|
||||
/*
|
||||
* |--- newAct ---|
|
||||
* |--- nextAct ---|
|
||||
*/
|
||||
if (newAct.getTheoreticalEarliestOperationStartTime() > nextAct.getTheoreticalLatestOperationStartTime()) {
|
||||
return ConstraintsStatus.NOT_FULFILLED;
|
||||
}
|
||||
// log.info("check insertion of " + newAct + " between " + prevAct + " and " + nextAct + ". prevActDepTime=" + prevActDepTime);
|
||||
// double latestArrTimeAtNextAct = states.getActivityState(nextAct, StateFactory.LATEST_OPERATION_START_TIME, Double.class);
|
||||
double arrTimeAtNewAct = prevActDepTime + routingCosts.getTransportTime(prevAct.getLocation(), newAct.getLocation(), prevActDepTime, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
|
||||
|
||||
double latestArrTimeAtNewAct = Math.min(newAct.getTheoreticalLatestOperationStartTime(), latestArrTimeAtNextAct -
|
||||
routingCosts.getBackwardTransportTime(nextActLocation, newAct.getLocation(), latestArrTimeAtNextAct, iFacts.getNewDriver(),
|
||||
iFacts.getNewVehicle()) - newAct.getOperationTime());
|
||||
/*
|
||||
* |--- prevAct ---|
|
||||
* |--- vehicle's arrival @newAct
|
||||
* latest arrival of vehicle @newAct ---|
|
||||
*/
|
||||
if (arrTimeAtNewAct > latestArrTimeAtNewAct) {
|
||||
return ConstraintsStatus.NOT_FULFILLED;
|
||||
}
|
||||
|
||||
if (nextAct instanceof End) {
|
||||
if (!iFacts.getNewVehicle().isReturnToDepot()) {
|
||||
return ConstraintsStatus.FULFILLED;
|
||||
}
|
||||
}
|
||||
// log.info(newAct + " arrTime=" + arrTimeAtNewAct);
|
||||
double endTimeAtNewAct = CalculationUtils.getActivityEndTime(arrTimeAtNewAct, newAct);
|
||||
double arrTimeAtNextAct = endTimeAtNewAct + routingCosts.getTransportTime(newAct.getLocation(), nextAct.getLocation(), endTimeAtNewAct, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
|
||||
/*
|
||||
* |--- newAct ---|
|
||||
* |--- vehicle's arrival @nextAct
|
||||
* latest arrival of vehicle @nextAct ---|
|
||||
*/
|
||||
if (arrTimeAtNextAct > latestArrTimeAtNextAct) {
|
||||
return ConstraintsStatus.NOT_FULFILLED;
|
||||
}
|
||||
|
||||
// if vehicle cannot even manage direct-route - break
|
||||
if (arrTimeAtNextOnDirectRouteWithNewVehicle > latestArrTimeAtNextAct) {
|
||||
return ConstraintsStatus.NOT_FULFILLED_BREAK;
|
||||
}
|
||||
return ConstraintsStatus.FULFILLED;
|
||||
}
|
||||
}
|
||||
|
|
@ -36,10 +36,13 @@ public class VehicleDependentTimeWindowConstraints implements HardActivityConstr
|
|||
|
||||
private VehicleRoutingTransportCosts routingCosts;
|
||||
|
||||
public VehicleDependentTimeWindowConstraints(RouteAndActivityStateGetter states, VehicleRoutingTransportCosts routingCosts) {
|
||||
private VehicleRoutingActivityCosts activityCosts;
|
||||
|
||||
public VehicleDependentTimeWindowConstraints(RouteAndActivityStateGetter states, VehicleRoutingTransportCosts routingCosts, VehicleRoutingActivityCosts activityCosts) {
|
||||
super();
|
||||
this.states = states;
|
||||
this.routingCosts = routingCosts;
|
||||
this.activityCosts = activityCosts;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -82,9 +85,7 @@ public class VehicleDependentTimeWindowConstraints implements HardActivityConstr
|
|||
* |--- prevAct ---|
|
||||
* |--- newAct ---|
|
||||
*/
|
||||
double newAct_theoreticalLatestOperationStartTime = newAct.getTheoreticalLatestOperationStartTime();
|
||||
|
||||
if (newAct_theoreticalLatestOperationStartTime < prevAct.getTheoreticalEarliestOperationStartTime()) {
|
||||
if (newAct.getTheoreticalLatestOperationStartTime() < prevAct.getTheoreticalEarliestOperationStartTime()) {
|
||||
return ConstraintsStatus.NOT_FULFILLED_BREAK;
|
||||
}
|
||||
|
||||
|
|
@ -102,17 +103,17 @@ public class VehicleDependentTimeWindowConstraints implements HardActivityConstr
|
|||
* |--- newAct ---|
|
||||
* |--- nextAct ---|
|
||||
*/
|
||||
if(newAct_theoreticalEarliestOperationStartTime > nextAct.getTheoreticalLatestOperationStartTime()){
|
||||
if (newAct.getTheoreticalEarliestOperationStartTime() > nextAct.getTheoreticalLatestOperationStartTime()) {
|
||||
return ConstraintsStatus.NOT_FULFILLED;
|
||||
}
|
||||
// log.info("check insertion of " + newAct + " between " + prevAct + " and " + nextAct + ". prevActDepTime=" + prevActDepTime);
|
||||
double arrTimeAtNewAct = prevActDepTime + routingCosts.getTransportTime(prevAct.getLocation(), newAct.getLocation(), prevActDepTime, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
double endTimeAtNewAct = CalculationUtils.getActivityEndTime(arrTimeAtNewAct, newAct);
|
||||
double endTimeAtNewAct = Math.max(arrTimeAtNewAct, newAct.getTheoreticalEarliestOperationStartTime()) + activityCosts.getActivityDuration(newAct, arrTimeAtNewAct,iFacts.getNewDriver(),iFacts.getNewVehicle());
|
||||
double latestArrTimeAtNewAct =
|
||||
Math.min(newAct_theoreticalLatestOperationStartTime,
|
||||
Math.min(newAct.getTheoreticalLatestOperationStartTime(),
|
||||
latestArrTimeAtNextAct -
|
||||
routingCosts.getBackwardTransportTime(newAct.getLocation(),nextActLocation,latestArrTimeAtNextAct,iFacts.getNewDriver(),iFacts.getNewVehicle())
|
||||
- newAct.getOperationTime()
|
||||
routingCosts.getBackwardTransportTime(newAct.getLocation(), nextActLocation, latestArrTimeAtNextAct, iFacts.getNewDriver(), iFacts.getNewVehicle())
|
||||
- activityCosts.getActivityDuration(newAct, arrTimeAtNewAct, iFacts.getNewDriver(), iFacts.getNewVehicle())
|
||||
);
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -58,5 +58,6 @@ public interface VehicleRoutingActivityCosts {
|
|||
*/
|
||||
public double getActivityCost(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle);
|
||||
|
||||
public double getActivityDuration(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,10 +13,15 @@ public class WaitingTimeCosts implements VehicleRoutingActivityCosts {
|
|||
public double getActivityCost(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) {
|
||||
if (vehicle != null) {
|
||||
double waiting = vehicle.getType().getVehicleCostParams().perWaitingTimeUnit * Math.max(0., tourAct.getTheoreticalEarliestOperationStartTime() - arrivalTime);
|
||||
double servicing = vehicle.getType().getVehicleCostParams().perServiceTimeUnit * tourAct.getOperationTime();
|
||||
double servicing = vehicle.getType().getVehicleCostParams().perServiceTimeUnit * getActivityDuration(tourAct,arrivalTime,driver,vehicle);
|
||||
return waiting + servicing;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getActivityDuration(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) {
|
||||
return tourAct.getOperationTime();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
package com.graphhopper.jsprit.core.util;
|
||||
|
||||
import com.graphhopper.jsprit.core.problem.cost.ForwardTransportTime;
|
||||
import com.graphhopper.jsprit.core.problem.cost.VehicleRoutingActivityCosts;
|
||||
import com.graphhopper.jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import com.graphhopper.jsprit.core.problem.solution.route.activity.*;
|
||||
|
||||
|
|
@ -28,7 +29,9 @@ public class ActivityTimeTracker implements ActivityVisitor {
|
|||
|
||||
}
|
||||
|
||||
private ForwardTransportTime transportTime;
|
||||
private final ForwardTransportTime transportTime;
|
||||
|
||||
private final VehicleRoutingActivityCosts activityCosts;
|
||||
|
||||
private TourActivity prevAct = null;
|
||||
|
||||
|
|
@ -42,27 +45,19 @@ public class ActivityTimeTracker implements ActivityVisitor {
|
|||
|
||||
private double actEndTime;
|
||||
|
||||
private ActivityStartStrategy startStrategy;
|
||||
private ActivityPolicy activityPolicy = ActivityPolicy.AS_SOON_AS_TIME_WINDOW_OPENS;
|
||||
|
||||
public ActivityTimeTracker(ForwardTransportTime transportTime) {
|
||||
super();
|
||||
this.transportTime = transportTime;
|
||||
this.startStrategy = new ActivityStartsAsSoonAsTimeWindowOpens();
|
||||
}
|
||||
|
||||
public ActivityTimeTracker(ForwardTransportTime transportTime, ActivityPolicy activityPolicy) {
|
||||
public ActivityTimeTracker(ForwardTransportTime transportTime, VehicleRoutingActivityCosts activityCosts) {
|
||||
super();
|
||||
this.transportTime = transportTime;
|
||||
if(activityPolicy.equals(ActivityPolicy.AS_SOON_AS_ARRIVED)){
|
||||
this.startStrategy = new ActivityStartAsSoonAsArrived();
|
||||
}
|
||||
else this.startStrategy = new ActivityStartsAsSoonAsTimeWindowOpens();
|
||||
this.activityCosts = activityCosts;
|
||||
}
|
||||
|
||||
public ActivityTimeTracker(ForwardTransportTime transportTime, ActivityStartStrategy startStrategy) {
|
||||
public ActivityTimeTracker(ForwardTransportTime transportTime, ActivityPolicy activityPolicy, VehicleRoutingActivityCosts activityCosts) {
|
||||
super();
|
||||
this.transportTime = transportTime;
|
||||
this.startStrategy = startStrategy;
|
||||
this.activityPolicy = activityPolicy;
|
||||
this.activityCosts = activityCosts;
|
||||
}
|
||||
|
||||
public double getActArrTime() {
|
||||
|
|
@ -84,22 +79,36 @@ public class ActivityTimeTracker implements ActivityVisitor {
|
|||
|
||||
@Override
|
||||
public void visit(TourActivity activity) {
|
||||
if(!beginFirst) throw new IllegalStateException("never called begin. this however is essential here");
|
||||
if (!beginFirst) throw new IllegalStateException("never called begin. this however is essential here");
|
||||
double transportTime = this.transportTime.getTransportTime(prevAct.getLocation(), activity.getLocation(), startAtPrevAct, route.getDriver(), route.getVehicle());
|
||||
double arrivalTimeAtCurrAct = startAtPrevAct + transportTime;
|
||||
|
||||
actArrTime = arrivalTimeAtCurrAct;
|
||||
double operationEndTime = startStrategy.getActivityStartTime(activity,arrivalTimeAtCurrAct) + activity.getOperationTime();
|
||||
double operationStartTime;
|
||||
|
||||
if (activityPolicy.equals(ActivityPolicy.AS_SOON_AS_TIME_WINDOW_OPENS)) {
|
||||
operationStartTime = Math.max(activity.getTheoreticalEarliestOperationStartTime(), arrivalTimeAtCurrAct);
|
||||
} else if (activityPolicy.equals(ActivityPolicy.AS_SOON_AS_ARRIVED)) {
|
||||
operationStartTime = actArrTime;
|
||||
} else operationStartTime = actArrTime;
|
||||
|
||||
double operationEndTime = operationStartTime + activityCosts.getActivityDuration(activity,actArrTime,route.getDriver(),route.getVehicle());
|
||||
|
||||
actEndTime = operationEndTime;
|
||||
|
||||
prevAct = activity;
|
||||
startAtPrevAct = operationEndTime;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finish() {
|
||||
double transportTime = this.transportTime.getTransportTime(prevAct.getLocation(), route.getEnd().getLocation(), startAtPrevAct, route.getDriver(), route.getVehicle());
|
||||
double arrivalTimeAtCurrAct = startAtPrevAct + transportTime;
|
||||
|
||||
actArrTime = arrivalTimeAtCurrAct;
|
||||
actEndTime = arrivalTimeAtCurrAct;
|
||||
|
||||
beginFirst = false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ package com.graphhopper.jsprit.core.util;
|
|||
|
||||
import com.graphhopper.jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
|
||||
@Deprecated
|
||||
public class CalculationUtils {
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,111 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (C) 2014 Stefan Schroeder
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
package com.graphhopper.jsprit.core.util;
|
||||
|
||||
import com.graphhopper.jsprit.core.algorithm.state.UpdateActivityTimes;
|
||||
import com.graphhopper.jsprit.core.problem.cost.TransportTime;
|
||||
import com.graphhopper.jsprit.core.problem.driver.DriverImpl;
|
||||
import com.graphhopper.jsprit.core.problem.job.Job;
|
||||
import com.graphhopper.jsprit.core.problem.job.Service;
|
||||
import com.graphhopper.jsprit.core.problem.solution.route.RouteActivityVisitor;
|
||||
import com.graphhopper.jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import com.graphhopper.jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@Deprecated
|
||||
public class RouteUtils {
|
||||
|
||||
/**
|
||||
* Returns total service time, i.e. sum of service time of each job.
|
||||
*
|
||||
* @param routes
|
||||
* @return
|
||||
*/
|
||||
public static double calculateServiceTime(Collection<VehicleRoute> routes) {
|
||||
double serviceTime = 0.;
|
||||
for (VehicleRoute r : routes) {
|
||||
for (Job j : r.getTourActivities().getJobs()) {
|
||||
serviceTime += ((Service) j).getServiceDuration();
|
||||
}
|
||||
}
|
||||
return serviceTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns total transport time.
|
||||
*
|
||||
* @param routes
|
||||
* @param transportTimes
|
||||
* @return
|
||||
*/
|
||||
public static double calculateTransportTime(Collection<VehicleRoute> routes, TransportTime transportTimes) {
|
||||
double tpTime = 0.;
|
||||
for (VehicleRoute r : routes) {
|
||||
TourActivity lastact = r.getStart();
|
||||
double lastActDepTime = r.getDepartureTime();
|
||||
for (TourActivity act : r.getActivities()) {
|
||||
tpTime += transportTimes.getTransportTime(lastact.getLocation(), act.getLocation(), lastActDepTime, DriverImpl.noDriver(), r.getVehicle());
|
||||
lastact = act;
|
||||
lastActDepTime = act.getEndTime();
|
||||
}
|
||||
tpTime += transportTimes.getTransportTime(lastact.getLocation(), r.getEnd().getLocation(), lastActDepTime, DriverImpl.noDriver(), r.getVehicle());
|
||||
}
|
||||
return tpTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns total waiting time.
|
||||
*
|
||||
* @param routes
|
||||
* @return
|
||||
*/
|
||||
public static double calculateWaitingTime(Collection<VehicleRoute> routes) {
|
||||
double waitingTime = 0.;
|
||||
for (VehicleRoute r : routes) {
|
||||
for (TourActivity act : r.getActivities()) {
|
||||
waitingTime += Math.max(0., act.getTheoreticalEarliestOperationStartTime() - act.getArrTime());
|
||||
}
|
||||
}
|
||||
return waitingTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns total operation time.
|
||||
*
|
||||
* @param routes
|
||||
* @return
|
||||
*/
|
||||
public static double calulateOperationTime(Collection<VehicleRoute> routes) {
|
||||
double opTime = 0.;
|
||||
for (VehicleRoute r : routes) {
|
||||
opTime += r.getEnd().getArrTime() - r.getDepartureTime();
|
||||
}
|
||||
return opTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates activity arrival/end-times of activities in specified route.
|
||||
*
|
||||
* @param route
|
||||
* @param transportTimes
|
||||
*/
|
||||
public static void updateActivityTimes(VehicleRoute route, TransportTime transportTimes) {
|
||||
new RouteActivityVisitor().addActivityVisitor(new UpdateActivityTimes(transportTimes)).visit(route);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue