-
Notifications
You must be signed in to change notification settings - Fork 10
Home
Departure time opt considering maximum driver operation time (works with v1.3.0):
This is still experimental, as long as it is located here, copy the following files to your local machine (click on the file and then right click 'raw' --> save):
UpdateDepartureTimeAndPracticalTimeWindows
TimeWindowConstraintWithDriverTime
and modify your code as follows:
VehicleRoutingProblem problem = vrpBuilder.build();
//set the maximum driver operation time
double maxDriverTime = 600.;
VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(problem, "yourAlgo.xml");
vraBuilder.addDefaultCostCalculators();
StateManager stateManager = new StateManager(problem.getTransportCosts());
//adds core load/capacity constraints
stateManager.updateLoadStates();
//replaces the default twUpdater and updates departureTime and practical time windows
stateManager.addStateUpdater(new UpdateDepartureTimeAndPracticalTimeWindows(stateManager, problem.getTransportCosts(), maxDriverTime));
ConstraintManager constraintManager = new ConstraintManager(problem, stateManager);
constraintManager.addLoadConstraint();
//replaces the default twConstraint to consider departureTime and driver's working hour as well
constraintManager.addConstraint(new TimeWindowConstraintWithDriverTime(stateManager, problem.getTransportCosts(), maxDriverTime),Priority.CRITICAL);
vraBuilder.setStateAndConstraintManager(stateManager, constraintManager);
VehicleRoutingAlgorithm algorithm = vraBuilder.build();
//finally re-schedules the departure time of vehicles to avoid waiting times at first activity
algorithm.addListener(new DepartureTimeReScheduler());
In the example above a maximum working time of drivers of 600. time units is considered. Additionally, the algorithm optimizes departure times at the depot such that waiting times at the first activity of a route are avoided, i.e. the vehicle starts at the depot such that it just arrives at the earliestOperationStartTime of the first activity, i.e. actualDepartureTime = max(earliestStartOfVehicle, firstActivity.earliestOperationStart - tpTime(start,firstActivity)). If the vehicle departs later, it can also arrive at its endLocation later as long as actualArrival@depot <= latestArrivalOfVehicle and actualArrival@depot - actualDepartureTime <= driverOperationTime hold.
Code examples:
It might be helpful to know that
VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(routingProblem, "yourAlgorithmConfig");
is equivalent to
VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(routingProblem, "yourAlgorithmConfig");
vraBuilder.addCoreConstraints();
vraBuilder.addDefaultCostCalculators();
VehicleRoutingAlgorithm vra = vraBuilder.build();
which is in turn equivalent to
VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(routingProblem, "yourAlgorithmConfig");
StateManager stateManager = new StateManager(problem.getTransportCosts());
stateManager.updateLoadStates();
stateManager.updateTimeWindowStates();
ConstraintManager constraintManager = new ConstraintManager(problem, stateManager);
constraintManager.addLoadConstraint();
constraintManager.addTimeWindowConstraint();
vraBuilder.setStateAndConstraintManager(stateManager, constraintManager);
vraBuilder.addDefaultCostCalculators();
VehicleRoutingAlgorithm vra = vraBuilder.build();