diff --git a/jsprit-core/src/main/java/algorithms/NeighborhoodThresholdInitialiser.java b/jsprit-core/src/main/java/algorithms/NeighborhoodThresholdInitialiser.java index efd39118..84010d03 100644 --- a/jsprit-core/src/main/java/algorithms/NeighborhoodThresholdInitialiser.java +++ b/jsprit-core/src/main/java/algorithms/NeighborhoodThresholdInitialiser.java @@ -86,10 +86,10 @@ public class NeighborhoodThresholdInitialiser implements AlgorithmStartsListener VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); builder.addAllJobs(problem.getJobs().values()); builder.addAllVehicles(problem.getVehicles()); - VehicleRoutingProblem pblm = builder.build(); CrowFlyCosts crowFly = new CrowFlyCosts(builder.getLocations()); crowFly.speed = crowFlySpeed; - pblm.setTransportCosts(crowFly); + builder.setRoutingCost(crowFly); + VehicleRoutingProblem pblm = builder.build(); VehicleRoutingAlgorithm algo = routingAlgorithmFactory.createAlgorithm(pblm); Collection mySolutions = algo.searchSolutions(); diff --git a/jsprit-core/src/main/java/basics/VehicleRoutingProblem.java b/jsprit-core/src/main/java/basics/VehicleRoutingProblem.java index ddd87412..801e869f 100644 --- a/jsprit-core/src/main/java/basics/VehicleRoutingProblem.java +++ b/jsprit-core/src/main/java/basics/VehicleRoutingProblem.java @@ -80,6 +80,17 @@ public class VehicleRoutingProblem { private Collection vehicleTypes; + /** + * by default all locations are neighbors + */ + private Neighborhood neighborhood = new Neighborhood() { + + @Override + public boolean areNeighbors(String location1, String location2) { + return true; + } + }; + public Builder() { jobs = new HashMap(); vehicles = new ArrayList(); @@ -228,6 +239,10 @@ public class VehicleRoutingProblem { return this; } + public Builder setNeighborhood(Neighborhood neighborhood){ + this.neighborhood = neighborhood; + return this; + } /** * Sets the activityCostFunction that considers also activities on a vehicle-route. @@ -302,20 +317,6 @@ public class VehicleRoutingProblem { private Neighborhood neighborhood; - /** - * @return the neighborhood - */ - public Neighborhood getNeighborhood() { - return neighborhood; - } - - /** - * @param neighborhood the neighborhood to set - */ - public void setNeighborhood(Neighborhood neighborhood) { - this.neighborhood = neighborhood; - } - private final Map jobs; /** @@ -357,6 +358,13 @@ public class VehicleRoutingProblem { "transportCost="+transportCosts+"][activityCosts="+activityCosts+"]"; } + /** + * @return the neighborhood + */ + public Neighborhood getNeighborhood() { + return neighborhood; + } + /** * Returns fleet-composition. * @@ -425,42 +433,5 @@ public class VehicleRoutingProblem { return activityCosts; } - /** - * Is deprecated and is not going to be supported any longer. Use the builder instead. - */ - @Deprecated - public void setFleetComposition(FleetComposition fleetComposition){ - this.fleetComposition = fleetComposition; - } - - /** - * Is deprecated and is not going to be supported any longer. Use the builder instead. - */ - @Deprecated - public void setFleetSize(FleetSize fleetSize){ - this.fleetSize = fleetSize; - } - - /** - * Sets routing costs. - * Is deprecated and is not going to be supported any longer. Use the builder instead. - * - * @param costs - * @see VehicleRoutingTransportCosts - */ - @Deprecated - public void setTransportCosts(VehicleRoutingTransportCosts costs) { - this.transportCosts = costs; - logger.info("transport costs set to " + costs.getClass()); - } - - /** - * Is deprecated and is not going to be supported any longer. Use the builder instead. - */ - @Deprecated - public void setActivityCosts(VehicleRoutingActivityCosts activityCosts){ - this.activityCosts = activityCosts; - logger.info("activtiy costs set to " + activityCosts.getClass()); - } } diff --git a/jsprit-core/src/test/java/algorithms/CalcWithTimeSchedulingTest.java b/jsprit-core/src/test/java/algorithms/CalcWithTimeSchedulingTest.java index f54c9c53..406e879d 100644 --- a/jsprit-core/src/test/java/algorithms/CalcWithTimeSchedulingTest.java +++ b/jsprit-core/src/test/java/algorithms/CalcWithTimeSchedulingTest.java @@ -25,8 +25,8 @@ import static org.junit.Assert.assertEquals; import java.util.Collection; import util.Coordinate; +import util.CrowFlyCosts; import util.Solutions; -import algorithms.selectors.SelectBest; import basics.Service; import basics.VehicleRoutingAlgorithm; import basics.VehicleRoutingProblem; @@ -50,8 +50,8 @@ public class CalcWithTimeSchedulingTest { vrpBuilder.addVehicle(vehicle); vrpBuilder.addService(Service.Builder.newInstance("myService", 2).setLocationId("0,20").setCoord(Coordinate.newInstance(0, 20)).build()); vrpBuilder.setFleetSize(FleetSize.INFINITE); + vrpBuilder.setRoutingCost(getTpCosts(new CrowFlyCosts(vrpBuilder.getLocations()))); VehicleRoutingProblem vrp = vrpBuilder.build(); - vrp.setTransportCosts(getTpCosts(vrp.getTransportCosts())); VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/testConfig.xml"); Collection solutions = vra.searchSolutions(); diff --git a/jsprit-core/src/test/java/algorithms/TestDepartureTimeOpt.java b/jsprit-core/src/test/java/algorithms/TestDepartureTimeOpt.java index 8a2092e4..8c827a2d 100644 --- a/jsprit-core/src/test/java/algorithms/TestDepartureTimeOpt.java +++ b/jsprit-core/src/test/java/algorithms/TestDepartureTimeOpt.java @@ -32,6 +32,7 @@ import util.Solutions; import basics.Service; import basics.VehicleRoutingAlgorithm; import basics.VehicleRoutingProblem; +import basics.VehicleRoutingProblem.Builder; import basics.VehicleRoutingProblemSolution; import basics.costs.VehicleRoutingActivityCosts; import basics.route.Driver; @@ -51,8 +52,8 @@ public class TestDepartureTimeOpt { Vehicle vehicle = VehicleImpl.VehicleBuilder.newInstance("v").setLocationId("vehLoc").setLocationCoord(Coordinate.newInstance(0, 0)) .setType(VehicleType.Builder.newInstance("vType", 0).build()).build(); - VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addService(service).addVehicle(vehicle).build(); - vrp.setActivityCosts(new VehicleRoutingActivityCosts(){ + Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + vrpBuilder.setActivityCosts(new VehicleRoutingActivityCosts(){ @Override public double getActivityCost(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) { @@ -62,6 +63,7 @@ public class TestDepartureTimeOpt { } }); + VehicleRoutingProblem vrp = vrpBuilder.addService(service).addVehicle(vehicle).build(); VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfig.xml"); Collection solutions = vra.searchSolutions(); @@ -78,8 +80,8 @@ public class TestDepartureTimeOpt { Vehicle vehicle = VehicleImpl.VehicleBuilder.newInstance("v").setLocationId("vehLoc").setLocationCoord(Coordinate.newInstance(0, 0)) .setType(VehicleType.Builder.newInstance("vType", 0).build()).build(); - VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addService(service).addVehicle(vehicle).build(); - vrp.setActivityCosts(new VehicleRoutingActivityCosts(){ + Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + vrpBuilder.setActivityCosts(new VehicleRoutingActivityCosts(){ @Override public double getActivityCost(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) { @@ -89,6 +91,7 @@ public class TestDepartureTimeOpt { } }); + VehicleRoutingProblem vrp = vrpBuilder.addService(service).addVehicle(vehicle).build(); VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfig.xml"); Collection solutions = vra.searchSolutions(); @@ -104,8 +107,8 @@ public class TestDepartureTimeOpt { Vehicle vehicle = VehicleImpl.VehicleBuilder.newInstance("v").setLocationId("vehLoc").setLocationCoord(Coordinate.newInstance(0, 0)) .setType(VehicleType.Builder.newInstance("vType", 0).build()).build(); - VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addService(service).addVehicle(vehicle).build(); - vrp.setActivityCosts(new VehicleRoutingActivityCosts(){ + Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + vrpBuilder.setActivityCosts(new VehicleRoutingActivityCosts(){ @Override public double getActivityCost(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) { @@ -115,6 +118,8 @@ public class TestDepartureTimeOpt { } }); + VehicleRoutingProblem vrp = vrpBuilder.addService(service).addVehicle(vehicle).build(); + VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfigWithDepartureTimeChoice.xml"); Collection solutions = vra.searchSolutions(); @@ -130,8 +135,8 @@ public class TestDepartureTimeOpt { Vehicle vehicle = VehicleImpl.VehicleBuilder.newInstance("v").setLocationId("vehLoc").setLocationCoord(Coordinate.newInstance(0, 0)) .setType(VehicleType.Builder.newInstance("vType", 0).build()).build(); - VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addService(service).addVehicle(vehicle).build(); - vrp.setActivityCosts(new VehicleRoutingActivityCosts(){ + Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + vrpBuilder.setActivityCosts(new VehicleRoutingActivityCosts(){ @Override public double getActivityCost(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) { @@ -141,6 +146,8 @@ public class TestDepartureTimeOpt { } }); + VehicleRoutingProblem vrp = vrpBuilder.addService(service).addVehicle(vehicle).build(); + VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfigWithDepartureTimeChoice.xml"); Collection solutions = vra.searchSolutions(); @@ -160,8 +167,8 @@ public class TestDepartureTimeOpt { Vehicle vehicle = VehicleImpl.VehicleBuilder.newInstance("v").setLocationId("vehLoc").setLocationCoord(Coordinate.newInstance(0, 0)) .setType(VehicleType.Builder.newInstance("vType", 0).build()).build(); - VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addService(service).addService(service2).addVehicle(vehicle).build(); - vrp.setActivityCosts(new VehicleRoutingActivityCosts(){ + Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + vrpBuilder.setActivityCosts(new VehicleRoutingActivityCosts(){ @Override public double getActivityCost(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) { @@ -171,6 +178,8 @@ public class TestDepartureTimeOpt { } }); + VehicleRoutingProblem vrp = vrpBuilder.addService(service).addService(service2).addVehicle(vehicle).build(); + VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfigWithDepartureTimeChoice.xml"); Collection solutions = vra.searchSolutions(); @@ -190,8 +199,8 @@ public class TestDepartureTimeOpt { Vehicle vehicle = VehicleImpl.VehicleBuilder.newInstance("v").setLocationId("vehLoc").setLocationCoord(Coordinate.newInstance(0, 0)) .setType(VehicleType.Builder.newInstance("vType", 0).build()).build(); - VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addService(service).addService(service2).addVehicle(vehicle).build(); - vrp.setActivityCosts(new VehicleRoutingActivityCosts(){ + Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + vrpBuilder.setActivityCosts(new VehicleRoutingActivityCosts(){ @Override public double getActivityCost(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) { @@ -201,6 +210,8 @@ public class TestDepartureTimeOpt { } }); + VehicleRoutingProblem vrp = vrpBuilder.addService(service).addService(service2).addVehicle(vehicle).build(); + VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfigWithDepartureTimeChoice.xml"); Collection solutions = vra.searchSolutions();