diff --git a/jsprit-core/src/main/java/algorithms/StateUpdates.java b/jsprit-core/src/main/java/algorithms/StateUpdates.java index ed3e85a8..7bd07b42 100644 --- a/jsprit-core/src/main/java/algorithms/StateUpdates.java +++ b/jsprit-core/src/main/java/algorithms/StateUpdates.java @@ -212,7 +212,7 @@ class StateUpdates { totalOperationCost += transportCost; totalOperationCost += actCost; - totalOperationCost += getFixCosts(); +// totalOperationCost += getFixCosts(); states.putRouteState(vehicleRoute, StateTypes.COSTS, new StateImpl(totalOperationCost)); diff --git a/jsprit-core/src/main/java/algorithms/VehicleRoutingAlgorithms.java b/jsprit-core/src/main/java/algorithms/VehicleRoutingAlgorithms.java index b86be126..6f891a0d 100644 --- a/jsprit-core/src/main/java/algorithms/VehicleRoutingAlgorithms.java +++ b/jsprit-core/src/main/java/algorithms/VehicleRoutingAlgorithms.java @@ -69,6 +69,7 @@ import basics.algo.VehicleRoutingAlgorithmListeners.PrioritizedVRAListener; import basics.algo.VehicleRoutingAlgorithmListeners.Priority; import basics.io.AlgorithmConfig; import basics.io.AlgorithmConfigXmlReader; +import basics.route.Vehicle; import basics.route.VehicleRoute; @@ -536,10 +537,16 @@ public class VehicleRoutingAlgorithms { public void calculateCosts(VehicleRoutingProblemSolution solution) { double costs = 0.0; for(VehicleRoute route : solution.getRoutes()){ - costs += stateManager.getRouteState(route, StateTypes.COSTS).toDouble(); + costs += stateManager.getRouteState(route, StateTypes.COSTS).toDouble() + getFixedCosts(route.getVehicle()); } solution.setCost(costs); } + + private double getFixedCosts(Vehicle vehicle) { + if(vehicle == null) return 0.0; + if(vehicle.getType() == null) return 0.0; + return vehicle.getType().getVehicleCostParams().fix; + } }; return calc; } diff --git a/jsprit-core/src/test/java/algorithms/GendreauPostOptTest.java b/jsprit-core/src/test/java/algorithms/GendreauPostOptTest.java index f8234d6e..c130af57 100644 --- a/jsprit-core/src/test/java/algorithms/GendreauPostOptTest.java +++ b/jsprit-core/src/test/java/algorithms/GendreauPostOptTest.java @@ -186,8 +186,8 @@ public class GendreauPostOptTest { routes.add(route); // routes.add(new VehicleRoute(getEmptyTour(),getDriver(),getNoVehicle())); // routes.add(new VehicleRoute(getEmptyTour(),getDriver(),getNoVehicle())); - - VehicleRoutingProblemSolution sol = new VehicleRoutingProblemSolution(routes, states.getRouteState(route, StateTypes.COSTS).toDouble()); + + VehicleRoutingProblemSolution sol = new VehicleRoutingProblemSolution(routes, states.getRouteState(route, StateTypes.COSTS).toDouble() + getFixedCosts(routes)); assertEquals(110.0, sol.getCost(), 0.5); @@ -209,10 +209,16 @@ public class GendreauPostOptTest { assertEquals(80.0,newSolution.getCost(),0.5); } + private double getFixedCosts(Collection routes) { + double c = 0.0; + for(VehicleRoute r : routes){ c += r.getVehicle().getType().getVehicleCostParams().fix; } + return c; + } + private double getCosts(VehicleRoutingProblemSolution newSolution, StateManagerImpl states) { double c = 0.0; for(VehicleRoute r : newSolution.getRoutes()){ - c += states.getRouteState(r, StateTypes.COSTS).toDouble(); + c += states.getRouteState(r, StateTypes.COSTS).toDouble() + r.getVehicle().getType().getVehicleCostParams().fix; } return c; }