Hi,
VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(routingProblem, "yourAlgorithmConfig");
is equivalent to (Skill is not present because, I guess, it was not implemented at the time of those posts)
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();
I have not found any similar statement about the Jsprit algorithm, so my question is:
is
VehicleRoutingAlgorithm algorithm = Jsprit.createAlgorithm(problem);
equivalent to the following (Skill is also not present)?
Jsprit.Builder algorithmBuilder = Jsprit.Builder.newInstance(problem);
algorithmBuilder.addCoreStateAndConstraintStuff(false);
StateManager stateManager = new StateManager(problem);
ConstraintManager constraintManager = new ConstraintManager(problem, stateManager);
constraintManager.addLoadConstraint();
stateManager.updateLoadStates();
constraintManager.addTimeWindowConstraint();
stateManager.updateTimeWindowStates();
UpdateVehicleDependentPracticalTimeWindows vra = new UpdateVehicleDependentPracticalTimeWindows(stateManager, problem.getTransportCosts());
vra.setVehiclesToUpdate(new UpdateVehicleDependentPracticalTimeWindows.VehiclesToUpdate() {
Map<VehicleTypeKey, Vehicle> uniqueTypes = new HashMap();
public Collection<Vehicle> get(VehicleRoute vehicleRoute) {
if (uniqueTypes.isEmpty()) {
Iterator vehicles = problem.getVehicles().iterator();
while (vehicles.hasNext()) {
Vehicle v = (Vehicle) vehicles.next();
if (!uniqueTypes.containsKey(v.getVehicleTypeIdentifier())) {
uniqueTypes.put(v.getVehicleTypeIdentifier(), v);
ArrayList vehicles1 = new ArrayList();
vehicles1.addAll(uniqueTypes.values());
stateManager.addStateUpdater(vra);
stateManager.addStateUpdater(new UpdateEndLocationIfRouteIsOpen());
stateManager.addStateUpdater(new UpdateActivityTimes(problem.getTransportCosts(), ActivityTimeTracker.ActivityPolicy.AS_SOON_AS_TIME_WINDOW_OPENS));
stateManager.addStateUpdater(new UpdateVariableCosts(problem.getActivityCosts(), problem.getTransportCosts(), stateManager));
algorithmBuilder.setStateAndConstraintManager(stateManager, constraintManager);
algorithmBuilder.setObjectiveFunction(new SolutionCostCalculator() {
public double getCosts(VehicleRoutingProblemSolution solution) {
for (VehicleRoute r : solution.getRoutes()) {
c += (stateManager.getRouteState(r, InternalStates.COSTS, Double.class)).doubleValue();
c += r.getVehicle().getType().getVehicleCostParams().fix;
c += solution.getUnassignedJobs().size() * c * .1;
algorithm = algorithmBuilder.buildAlgorithm();
I have conducted tests on Solomon C1 instances and the results show that they are not equivalent, as they return different results for instances C102, C106 and C108.
inst |
runs |
res* |
veh* |
Jsprit.createAlgorithm(problem) |
Jsprit (second implementation)
|
|
|
|
|
iterations |
totalDistance |
numRoutes |
iterations |
totalDistance |
numRoutes |
C101 |
1 |
828.94 |
10 |
10000 |
828.94 |
10 |
10000 |
828.94 |
10 |
C102 |
1 |
828.94 |
10 |
10000 |
829.7 |
10 |
10000 |
828.94 |
10 |
C103 |
1 |
828.06 |
10 |
10000 |
831.07 |
10 |
10000 |
831.07 |
10 |
C104 |
1 |
824.78 |
10 |
10000 |
848.44 |
10 |
10000 |
848.44 |
10 |
C105 |
1 |
828.94 |
10 |
10000 |
828.94 |
10 |
10000 |
828.94 |
10 |
C106 |
1 |
828.94 |
10 |
10000 |
828.94 |
10 |
10000 |
829.38 |
10 |
C107 |
1 |
828.94 |
10 |
10000 |
828.94 |
10 |
10000 |
828.94 |
10 |
C108 |
1 |
828.94 |
10 |
10000 |
829.7 |
10 |
10000 |
828.94 |
10 |
C109 |
1 |
828.94 |
10 |
10000 |
828.94 |
10 |
10000 |
828.94 |
10 |
What am I missing in the second implementation?
Best regards,
He