From 36d0b644a065ea3ad85659dec15fee1dfa44788f Mon Sep 17 00:00:00 2001 From: Michal Maciejewski Date: Tue, 14 Nov 2017 11:10:48 +0100 Subject: [PATCH] updated job indexing: lower indices for unplanned jobs, higher for jobs in initial routes --- .../core/problem/VehicleRoutingProblem.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/VehicleRoutingProblem.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/VehicleRoutingProblem.java index 99a1788e..913c5eea 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/VehicleRoutingProblem.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/VehicleRoutingProblem.java @@ -116,8 +116,6 @@ public class VehicleRoutingProblem { }; - private int jobIndexCounter = 1; - private int vehicleIndexCounter = 1; private int activityIndexCounter = 1; @@ -132,10 +130,6 @@ public class VehicleRoutingProblem { private final DefaultTourActivityFactory serviceActivityFactory = new DefaultTourActivityFactory(); - private void incJobIndexCounter() { - jobIndexCounter++; - } - private void incActivityIndexCounter() { activityIndexCounter++; } @@ -235,8 +229,6 @@ public class VehicleRoutingProblem { throw new IllegalArgumentException("vehicle routing problem already contains a service or shipment with id " + job.getId() + ". make sure you use unique ids for all services and shipments"); if (!(job instanceof Service || job instanceof Shipment)) throw new IllegalArgumentException("job must be either a service or a shipment"); - job.setIndex(jobIndexCounter); - incJobIndexCounter(); tentativeJobs.put(job.getId(), job); addLocationToTentativeLocations(job); return this; @@ -441,6 +433,15 @@ public class VehicleRoutingProblem { addJobToFinalJobMapAndCreateActivities(job); } } + + int jobIndexCounter = 1; + for (Job job : jobs.values()) { + ((AbstractJob)job).setIndex(jobIndexCounter++); + } + for (String jobId : jobsInInitialRoutes) { + ((AbstractJob)tentativeJobs.get(jobId)).setIndex(jobIndexCounter++); + } + boolean hasBreaks = addBreaksToActivityMap(); if (hasBreaks && fleetSize.equals(FleetSize.INFINITE)) throw new UnsupportedOperationException("breaks are not yet supported when dealing with infinite fleet. either set it to finite or omit breaks.");