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

add getAddedServices(), getAddedVehicles() to

VehicleRoutingProblem.Builder to get a snapshot of what has already been
built
This commit is contained in:
Stefan Schroeder 2013-06-11 14:00:09 +02:00
parent 611d71f272
commit 885eab5eff
2 changed files with 28 additions and 19 deletions

View file

@ -24,7 +24,6 @@ import util.Coordinate;
import util.CrowFlyCosts;
import util.Locations;
import util.Neighborhood;
import util.NeighborhoodImpl;
import basics.costs.DefaultVehicleRoutingActivityCosts;
import basics.costs.VehicleRoutingActivityCosts;
import basics.costs.VehicleRoutingTransportCosts;
@ -70,6 +69,8 @@ public class VehicleRoutingProblem {
private Map<String,Job> jobs;
private Collection<Service> services;
private Collection<Vehicle> vehicles;
private Map<String, Coordinate> coordinates;
@ -96,6 +97,7 @@ public class VehicleRoutingProblem {
vehicles = new ArrayList<Vehicle>();
coordinates = new HashMap<String, Coordinate>();
vehicleTypes = new ArrayList<VehicleImpl.VehicleType>();
services = new ArrayList<Service>();
}
/**
@ -193,6 +195,7 @@ public class VehicleRoutingProblem {
coordinates.put(service.getLocationId(), service.getCoord());
if(jobs.containsKey(service.getId())){ logger.warn("service " + service + " already in job list. overrides existing job."); }
jobs.put(service.getId(),service);
services.add(service);
return this;
}
@ -285,6 +288,15 @@ public class VehicleRoutingProblem {
}
return this;
}
public Collection<Vehicle> getAddedVehicles(){
return Collections.unmodifiableCollection(vehicles);
}
public Collection<Service> getAddedServices(){
return Collections.unmodifiableCollection(services);
}
}
/**
@ -348,7 +360,7 @@ public class VehicleRoutingProblem {
this.vehicleTypes = builder.vehicleTypes;
this.transportCosts = builder.transportCosts;
this.activityCosts = builder.activityCosts;
this.neighborhood = new NeighborhoodImpl(this);
this.neighborhood = builder.neighborhood;
log.info("initialise " + this);
}

View file

@ -25,11 +25,10 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.apache.log4j.Logger;
import basics.Job;
import basics.Service;
import basics.VehicleRoutingProblem;
import basics.route.Vehicle;
@ -44,8 +43,6 @@ public class NeighborhoodImpl implements Neighborhood{
private boolean initialised = false;
private VehicleRoutingProblem vrp;
public void setThreshold(double threshold) {
this.threshold = threshold;
log.info("set threshold to " + threshold);
@ -53,25 +50,28 @@ public class NeighborhoodImpl implements Neighborhood{
private Map<String,Set<String>> neighbors;
public NeighborhoodImpl(VehicleRoutingProblem vrp) {
private Collection<Vehicle> vehicles;
private Collection<Service> services;
public NeighborhoodImpl(Collection<Vehicle> vehicles, Collection<Service> services) {
neighborsToAll = new HashSet<String>();
this.vrp = vrp;
this.vehicles = vehicles;
this.services = services;
neighbors = new HashMap<String, Set<String>>();
// makeNeighbors();
}
private void makeNeighbors() {
for(Job i : vrp.getJobs().values()){
for(Service i : services){
Set<String> neigh = new HashSet<String>();
for(Vehicle v : vrp.getVehicles()){
double dist2depot = EuclideanDistanceCalculator.calculateDistance(v.getCoord(), ((Service)i).getCoord());
for(Vehicle v : vehicles){
double dist2depot = EuclideanDistanceCalculator.calculateDistance(v.getCoord(), i.getCoord());
if(dist2depot <= threshold){
neighborsToAll.add(((Service)i).getLocationId());
}
}
for(Job j : vrp.getJobs().values()){
double crowFlyDistance = EuclideanDistanceCalculator.calculateDistance(((Service)i).getCoord(), ((Service)j).getCoord());
for(Service j : services){
double crowFlyDistance = EuclideanDistanceCalculator.calculateDistance(i.getCoord(), j.getCoord());
if(crowFlyDistance <= threshold) {
neigh.add(((Service)j).getLocationId());
}
@ -85,14 +85,11 @@ public class NeighborhoodImpl implements Neighborhood{
for(Vehicle v : vehicles){
neighborsToAll.add(v.getLocationId());
}
// for(Job j : vrp.getJobs().values()){
//
// }
}
public void initialise(){
log.info("initialise neighboorhood [threshold="+ this.threshold + "]");
makeNeighborsToAll(vrp.getVehicles());
makeNeighborsToAll(vehicles);
makeNeighbors();
initialised = true;
}