1
0
Fork 0
mirror of https://github.com/graphhopper/jsprit.git synced 2020-01-24 07:45:05 +01:00

Merge pull request #392 from michalmac/master

bugfixing initial routes
This commit is contained in:
Stefan Schröder 2018-09-27 09:15:33 +02:00 committed by GitHub
commit 410cedb0e9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 19 deletions

View file

@ -81,7 +81,7 @@ public class VehicleRoutingProblem {
private Map<String, Job> tentativeJobs = new LinkedHashMap<String, Job>();
private Set<String> jobsInInitialRoutes = new HashSet<String>();
private Map<String, Job> jobsInInitialRoutes = new HashMap<>();
private Map<String, Coordinate> tentative_coordinates = new HashMap<String, Coordinate>();
@ -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);
}

View file

@ -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;
}

View file

@ -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<Shipment> openShipments = new HashSet<Shipment>();
private final Set<Shipment> openShipments = new HashSet<Shipment>();
private JobActivityFactory jobActivityFactory = new JobActivityFactory() {
private final TourShipmentActivityFactory shipmentActivityFactory = new DefaultShipmentActivityFactory();
private final TourActivityFactory serviceActivityFactory = new DefaultTourActivityFactory();
@Override
public List<AbstractActivity> createActivities(Job job) {