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

further refinements

This commit is contained in:
oblonski 2013-06-20 17:25:53 +02:00
parent 665b4a8970
commit 5eaa288735
5 changed files with 32 additions and 15 deletions

View file

@ -250,6 +250,7 @@ class VehicleFleetManagerImpl implements VehicleFleetManager {
if(vehicles.isEmpty() || vehicle instanceof NoVehicle){ if(vehicles.isEmpty() || vehicle instanceof NoVehicle){
return; return;
} }
if(vehicle.getType().getTypeId().contains("penalty")) return;
boolean locked = lockedVehicles.add(vehicle); boolean locked = lockedVehicles.add(vehicle);
removeVehicle(vehicle); removeVehicle(vehicle);
if(!locked){ if(!locked){
@ -266,6 +267,7 @@ class VehicleFleetManagerImpl implements VehicleFleetManager {
return; return;
} }
if(vehicle == null) return; if(vehicle == null) return;
if(vehicle.getType().getTypeId().contains("penalty")) return;
lockedVehicles.remove(vehicle); lockedVehicles.remove(vehicle);
addVehicle(vehicle); addVehicle(vehicle);
} }

View file

@ -46,7 +46,7 @@
</module> </module>
</modules> </modules>
<probability>0.5</probability> <probability>0.3</probability>
</searchStrategy> </searchStrategy>
<searchStrategy name="radialRuinAndRecreate"> <searchStrategy name="radialRuinAndRecreate">
@ -61,7 +61,22 @@
</module> </module>
</modules> </modules>
<probability>0.5</probability> <probability>0.3</probability>
</searchStrategy>
<searchStrategy name="radialRuinAndRecreate">
<selector name="selectBest"/>
<acceptor name="schrimpfAcceptance"/>
<modules>
<module name="ruin_and_recreate">
<ruin name="radialRuin" id="1">
<share>0.1</share>
</ruin>
<insertion name="bestInsertion"/>
</module>
</modules>
<probability>0.4</probability>
</searchStrategy> </searchStrategy>
</searchStrategies> </searchStrategies>

View file

@ -56,7 +56,7 @@ public class ConcurrentMultipleDepotExampleWithPenaltyVehicles {
int depotCounter = 1; int depotCounter = 1;
for(Coordinate depotCoord : Arrays.asList(firstDepotCoord,second)){ for(Coordinate depotCoord : Arrays.asList(firstDepotCoord,second)){
for(int i=0;i<nuOfVehicles;i++){ for(int i=0;i<nuOfVehicles;i++){
VehicleType vehicleType = VehicleType.Builder.newInstance(depotCounter + "_" + (i+1) + "_type", capacity).setCostPerDistance(1.0).build(); VehicleType vehicleType = VehicleType.Builder.newInstance(depotCounter + "_type", capacity).setCostPerDistance(1.0).build();
String vehicleId = depotCounter + "_" + (i+1) + "_vehicle"; String vehicleId = depotCounter + "_" + (i+1) + "_vehicle";
VehicleImpl.VehicleBuilder vehicleBuilder = VehicleImpl.VehicleBuilder.newInstance(vehicleId); VehicleImpl.VehicleBuilder vehicleBuilder = VehicleImpl.VehicleBuilder.newInstance(vehicleId);
vehicleBuilder.setLocationCoord(depotCoord); vehicleBuilder.setLocationCoord(depotCoord);
@ -65,16 +65,16 @@ public class ConcurrentMultipleDepotExampleWithPenaltyVehicles {
Vehicle vehicle = vehicleBuilder.build(); Vehicle vehicle = vehicleBuilder.build();
vrpBuilder.addVehicle(vehicle); vrpBuilder.addVehicle(vehicle);
} }
for(int i=0;i<nuOfPenaltyVehicles;i++){ // for(int i=0;i<nuOfPenaltyVehicles;i++){
VehicleType penaltyType = VehicleType.Builder.newInstance(depotCounter + "_" + (i+1) + "_penaltyType", capacity).setFixedCost(50).setCostPerDistance(3.0).build(); VehicleType penaltyType = VehicleType.Builder.newInstance(depotCounter + "_type#penalty", capacity).setFixedCost(50).setCostPerDistance(3.0).build();
String vehicleId = depotCounter + "_" + (i+1) + "_penaltyVehicle"; String vehicleId = depotCounter + "_vehicle#penalty";
VehicleImpl.VehicleBuilder vehicleBuilder = VehicleImpl.VehicleBuilder.newInstance(vehicleId); VehicleImpl.VehicleBuilder vehicleBuilder = VehicleImpl.VehicleBuilder.newInstance(vehicleId);
vehicleBuilder.setLocationCoord(depotCoord); vehicleBuilder.setLocationCoord(depotCoord);
vehicleBuilder.setType(penaltyType); vehicleBuilder.setType(penaltyType);
vehicleBuilder.setLatestArrival(maxDuration); vehicleBuilder.setLatestArrival(maxDuration);
Vehicle penaltyVehicle = vehicleBuilder.build(); Vehicle penaltyVehicle = vehicleBuilder.build();
vrpBuilder.addVehicle(penaltyVehicle); vrpBuilder.addVehicle(penaltyVehicle);
} // }
depotCounter++; depotCounter++;
} }

View file

@ -53,7 +53,7 @@ public class MultipleDepotExample {
int depotCounter = 1; int depotCounter = 1;
for(Coordinate depotCoord : Arrays.asList(firstDepotCoord,second,third,fourth)){ for(Coordinate depotCoord : Arrays.asList(firstDepotCoord,second,third,fourth)){
for(int i=0;i<nuOfVehicles;i++){ for(int i=0;i<nuOfVehicles;i++){
VehicleType vehicleType = VehicleType.Builder.newInstance(depotCounter + "_" + (i+1) + "_type", capacity).setCostPerDistance(1.0).build(); VehicleType vehicleType = VehicleType.Builder.newInstance(depotCounter + "_type", capacity).setCostPerDistance(1.0).build();
Vehicle vehicle = VehicleImpl.VehicleBuilder.newInstance(depotCounter + "_" + (i+1) + "_vehicle").setLocationCoord(depotCoord).setType(vehicleType).build(); Vehicle vehicle = VehicleImpl.VehicleBuilder.newInstance(depotCounter + "_" + (i+1) + "_vehicle").setLocationCoord(depotCoord).setType(vehicleType).build();
vrpBuilder.addVehicle(vehicle); vrpBuilder.addVehicle(vehicle);
} }
@ -81,7 +81,7 @@ public class MultipleDepotExample {
VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "input/algorithmConfig.xml"); VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "input/algorithmConfig.xml");
vra.setNuOfIterations(10000); vra.setNuOfIterations(10000);
vra.getAlgorithmListeners().addListener(new StopWatch(),Priority.HIGH); vra.getAlgorithmListeners().addListener(new StopWatch(),Priority.HIGH);
vra.getAlgorithmListeners().addListener(new AlgorithmSearchProgressChartListener("output/progress.png")); // vra.getAlgorithmListeners().addListener(new AlgorithmSearchProgressChartListener("output/progress.png"));
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions(); Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
SolutionPrinter.print(Solutions.getBest(solutions)); SolutionPrinter.print(Solutions.getBest(solutions));

View file

@ -54,7 +54,7 @@ public class MultipleDepotExampleWithPenaltyVehicles {
int depotCounter = 1; int depotCounter = 1;
for(Coordinate depotCoord : Arrays.asList(firstDepotCoord,second)){ for(Coordinate depotCoord : Arrays.asList(firstDepotCoord,second)){
for(int i=0;i<nuOfVehicles;i++){ for(int i=0;i<nuOfVehicles;i++){
VehicleType vehicleType = VehicleType.Builder.newInstance(depotCounter + "_" + (i+1) + "_type", capacity).setCostPerDistance(1.0).build(); VehicleType vehicleType = VehicleType.Builder.newInstance(depotCounter + "_type", capacity).setCostPerDistance(1.0).build();
String vehicleId = depotCounter + "_" + (i+1) + "_vehicle"; String vehicleId = depotCounter + "_" + (i+1) + "_vehicle";
VehicleImpl.VehicleBuilder vehicleBuilder = VehicleImpl.VehicleBuilder.newInstance(vehicleId); VehicleImpl.VehicleBuilder vehicleBuilder = VehicleImpl.VehicleBuilder.newInstance(vehicleId);
vehicleBuilder.setLocationCoord(depotCoord); vehicleBuilder.setLocationCoord(depotCoord);
@ -63,16 +63,16 @@ public class MultipleDepotExampleWithPenaltyVehicles {
Vehicle vehicle = vehicleBuilder.build(); Vehicle vehicle = vehicleBuilder.build();
vrpBuilder.addVehicle(vehicle); vrpBuilder.addVehicle(vehicle);
} }
for(int i=0;i<nuOfPenaltyVehicles;i++){ // for(int i=0;i<nuOfPenaltyVehicles;i++){
VehicleType penaltyType = VehicleType.Builder.newInstance(depotCounter + "_" + (i+1) + "_type#penalty", capacity).setFixedCost(50).setCostPerDistance(3.0).build(); VehicleType penaltyType = VehicleType.Builder.newInstance(depotCounter + "_type#penalty", capacity).setFixedCost(50).setCostPerDistance(3.0).build();
String vehicleId = depotCounter + "_" + (i+1) + "_vehicle#penalty"; String vehicleId = depotCounter + "_vehicle#penalty";
VehicleImpl.VehicleBuilder vehicleBuilder = VehicleImpl.VehicleBuilder.newInstance(vehicleId); VehicleImpl.VehicleBuilder vehicleBuilder = VehicleImpl.VehicleBuilder.newInstance(vehicleId);
vehicleBuilder.setLocationCoord(depotCoord); vehicleBuilder.setLocationCoord(depotCoord);
vehicleBuilder.setType(penaltyType); vehicleBuilder.setType(penaltyType);
vehicleBuilder.setLatestArrival(maxDuration); vehicleBuilder.setLatestArrival(maxDuration);
Vehicle penaltyVehicle = vehicleBuilder.build(); Vehicle penaltyVehicle = vehicleBuilder.build();
vrpBuilder.addVehicle(penaltyVehicle); vrpBuilder.addVehicle(penaltyVehicle);
} // }
depotCounter++; depotCounter++;
} }
@ -91,7 +91,7 @@ public class MultipleDepotExampleWithPenaltyVehicles {
/* /*
* plot to see how the problem looks like * plot to see how the problem looks like
*/ */
SolutionPlotter.plotVrpAsPNG(vrp, "output/problem08.png", "p08"); // SolutionPlotter.plotVrpAsPNG(vrp, "output/problem08.png", "p08");
/* /*
* solve the problem * solve the problem