From 1af75329396cfb66b12fa6d57386e05b8d918442 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20Vissy?= Date: Mon, 12 Jun 2017 22:38:35 +0200 Subject: [PATCH] #354 - fixed - Cost recalculated for solution after jobs added (also a copy is made from the solution) --- .../core/algorithm/VehicleRoutingAlgorithm.java | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/VehicleRoutingAlgorithm.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/VehicleRoutingAlgorithm.java index cea9975b..b60fae9f 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/VehicleRoutingAlgorithm.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/VehicleRoutingAlgorithm.java @@ -142,6 +142,8 @@ public class VehicleRoutingAlgorithm { * @param solution the solution to be added */ public void addInitialSolution(VehicleRoutingProblemSolution solution) { + // We will make changes so let's make a copy + solution = VehicleRoutingProblemSolution.copyOf(solution); verify(solution); initialSolutions.add(solution); } @@ -164,19 +166,7 @@ public class VehicleRoutingAlgorithm { } solution.getUnassignedJobs().addAll(allJobs); - - // Doesn't work - // for (Vehicle v : problem.getVehicles()) { - // boolean found = false; - // for (VehicleRoute vr : solution.getRoutes()) - // if (vr.getVehicle().getId().equals(v.getId())) { - // found = true; - // break; - // } - // if (!found) { - // solution.getRoutes().add(VehicleRoute.Builder.newInstance(v).build()); - // } - // } + solution.setCost(getObjectiveFunction().getCosts(solution)); // if (nuJobs != problem.getJobs().values().size()) { // logger.warn("number of jobs in initial solution ({}) is not equal nuJobs in vehicle routing problem ({})" +