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 27574a3f..c54ed687 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 @@ -81,7 +81,7 @@ public class VehicleRoutingProblem { private Map tentativeJobs = new LinkedHashMap(); - private Set jobsInInitialRoutes = new HashSet(); + private Map jobsInInitialRoutes = new HashMap<>(); private Map tentative_coordinates = new HashMap(); @@ -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("The vehicle routing problem already contains a service or shipment with id " + job.getId() + ". Please 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; @@ -317,7 +309,7 @@ public class VehicleRoutingProblem { incActivityIndexCounter(); if (act instanceof TourActivity.JobActivity) { Job job = ((TourActivity.JobActivity) act).getJob(); - jobsInInitialRoutes.add(job.getId()); + jobsInInitialRoutes.put(job.getId(), job); addLocationToTentativeLocations(job); registerJobAndActivity(abstractAct, job); } @@ -443,10 +435,19 @@ public class VehicleRoutingProblem { transportCosts = new CrowFlyCosts(getLocations()); } for (Job job : tentativeJobs.values()) { - if (!jobsInInitialRoutes.contains(job.getId())) { + if (!jobsInInitialRoutes.containsKey(job.getId())) { addJobToFinalJobMapAndCreateActivities(job); } } + + int jobIndexCounter = 1; + for (Job job : jobs.values()) { + ((AbstractJob)job).setIndex(jobIndexCounter++); + } + for (Job job : jobsInInitialRoutes.values()) { + ((AbstractJob)job).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."); @@ -599,7 +600,8 @@ public class VehicleRoutingProblem { this.activityMap = builder.activityMap; this.nuActivities = builder.activityIndexCounter; this.allLocations = builder.allLocations; - this.allJobs = builder.tentativeJobs; + this.allJobs = new HashMap<>(jobs); + this.allJobs.putAll(builder.jobsInInitialRoutes); logger.info("setup problem: {}", this); } diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/job/Delivery.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/job/Delivery.java index f31b25ef..40b70a75 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/job/Delivery.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/job/Delivery.java @@ -43,7 +43,7 @@ public class Delivery extends Service { public Builder setMaxTimeInVehicle(double maxTimeInVehicle){ - if(maxTimeInVehicle < 0) throw new IllegalArgumentException("maxTimeInVehicle should be positive"); + if(maxTimeInVehicle < 0) throw new IllegalArgumentException("maxTimeInVehicle should not be negative"); this.maxTimeInVehicle = maxTimeInVehicle; return this; } diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/solution/route/VehicleRoute.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/solution/route/VehicleRoute.java index 7dd0c17d..40fe5907 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/solution/route/VehicleRoute.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/solution/route/VehicleRoute.java @@ -115,15 +115,15 @@ public class VehicleRoute { private End end; - private TourActivities tourActivities = new TourActivities(); + private final TourActivities tourActivities = new TourActivities(); - private TourActivityFactory serviceActivityFactory = new DefaultTourActivityFactory(); - - private TourShipmentActivityFactory shipmentActivityFactory = new DefaultShipmentActivityFactory(); - - private Set openShipments = new HashSet(); + private final Set openShipments = new HashSet(); private JobActivityFactory jobActivityFactory = new JobActivityFactory() { + + private final TourShipmentActivityFactory shipmentActivityFactory = new DefaultShipmentActivityFactory(); + + private final TourActivityFactory serviceActivityFactory = new DefaultTourActivityFactory(); @Override public List createActivities(Job job) {