mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
make VehicleRoutingProblem immutable
This commit is contained in:
parent
f93f621c5b
commit
611d71f272
4 changed files with 49 additions and 67 deletions
|
|
@ -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<VehicleRoutingProblemSolution> mySolutions = algo.searchSolutions();
|
||||
|
|
|
|||
|
|
@ -80,6 +80,17 @@ public class VehicleRoutingProblem {
|
|||
|
||||
private Collection<VehicleType> 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<String, Job>();
|
||||
vehicles = new ArrayList<Vehicle>();
|
||||
|
|
@ -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<String, Job> 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());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
|
||||
|
|
|
|||
|
|
@ -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<VehicleRoutingProblemSolution> 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<VehicleRoutingProblemSolution> 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<VehicleRoutingProblemSolution> 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<VehicleRoutingProblemSolution> 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<VehicleRoutingProblemSolution> 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<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue