diff --git a/jsprit-core/src/main/java/basics/VehicleRoutingProblem.java b/jsprit-core/src/main/java/basics/VehicleRoutingProblem.java index 801e869f..79695973 100644 --- a/jsprit-core/src/main/java/basics/VehicleRoutingProblem.java +++ b/jsprit-core/src/main/java/basics/VehicleRoutingProblem.java @@ -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; @@ -69,6 +68,8 @@ public class VehicleRoutingProblem { private VehicleRoutingActivityCosts activityCosts = new DefaultVehicleRoutingActivityCosts(); private Map jobs; + + private Collection services; private Collection vehicles; @@ -96,6 +97,7 @@ public class VehicleRoutingProblem { vehicles = new ArrayList(); coordinates = new HashMap(); vehicleTypes = new ArrayList(); + services = new ArrayList(); } /** @@ -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 getAddedVehicles(){ + return Collections.unmodifiableCollection(vehicles); + } + + public Collection 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); } diff --git a/jsprit-core/src/main/java/util/NeighborhoodImpl.java b/jsprit-core/src/main/java/util/NeighborhoodImpl.java index 2be36117..9a144d2a 100644 --- a/jsprit-core/src/main/java/util/NeighborhoodImpl.java +++ b/jsprit-core/src/main/java/util/NeighborhoodImpl.java @@ -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,34 +43,35 @@ 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); } private Map> neighbors; + + private Collection vehicles; + + private Collection services; - public NeighborhoodImpl(VehicleRoutingProblem vrp) { + public NeighborhoodImpl(Collection vehicles, Collection services) { neighborsToAll = new HashSet(); - this.vrp = vrp; + this.vehicles = vehicles; + this.services = services; neighbors = new HashMap>(); -// makeNeighbors(); } private void makeNeighbors() { - for(Job i : vrp.getJobs().values()){ + for(Service i : services){ Set neigh = new HashSet(); - 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; }