diff --git a/jsprit-examples/input/vrp_cordeau_08.xml b/jsprit-examples/input/vrp_cordeau_08.xml index 833a72f8..23f9e48e 100644 --- a/jsprit-examples/input/vrp_cordeau_08.xml +++ b/jsprit-examples/input/vrp_cordeau_08.xml @@ -1,368 +1,7 @@ - - FINITE - HOMOGENEOUS - - - - 1_1_cordeauVehicle - 1_cordeauType - - [x=-33.0][y=33.0] - - - - 0.0 - 310.0 - - - - 1_2_cordeauVehicle - 1_cordeauType - - [x=-33.0][y=33.0] - - - - 0.0 - 310.0 - - - - 1_3_cordeauVehicle - 1_cordeauType - - [x=-33.0][y=33.0] - - - - 0.0 - 310.0 - - - - 1_4_cordeauVehicle - 1_cordeauType - - [x=-33.0][y=33.0] - - - - 0.0 - 310.0 - - - - 1_5_cordeauVehicle - 1_cordeauType - - [x=-33.0][y=33.0] - - - - 0.0 - 310.0 - - - - 1_6_cordeauVehicle - 1_cordeauType - - [x=-33.0][y=33.0] - - - - 0.0 - 310.0 - - - - 1_7_cordeauVehicle - 1_cordeauType - - [x=-33.0][y=33.0] - - - - 0.0 - 310.0 - - - - 1_8_cordeauVehicle - 1_cordeauType - - [x=-33.0][y=33.0] - - - - 0.0 - 310.0 - - - - 1_9_cordeauVehicle - 1_cordeauType - - [x=-33.0][y=33.0] - - - - 0.0 - 310.0 - - - - 1_10_cordeauVehicle - 1_cordeauType - - [x=-33.0][y=33.0] - - - - 0.0 - 310.0 - - - - 1_11_cordeauVehicle - 1_cordeauType - - [x=-33.0][y=33.0] - - - - 0.0 - 310.0 - - - - 1_12_cordeauVehicle - 1_cordeauType - - [x=-33.0][y=33.0] - - - - 0.0 - 310.0 - - - - 1_13_cordeauVehicle - 1_cordeauType - - [x=-33.0][y=33.0] - - - - 0.0 - 310.0 - - - - 1_14_cordeauVehicle - 1_cordeauType - - [x=-33.0][y=33.0] - - - - 0.0 - 310.0 - - - - 2_1_cordeauVehicle - 2_cordeauType - - [x=33.0][y=-33.0] - - - - 0.0 - 310.0 - - - - 2_2_cordeauVehicle - 2_cordeauType - - [x=33.0][y=-33.0] - - - - 0.0 - 310.0 - - - - 2_3_cordeauVehicle - 2_cordeauType - - [x=33.0][y=-33.0] - - - - 0.0 - 310.0 - - - - 2_4_cordeauVehicle - 2_cordeauType - - [x=33.0][y=-33.0] - - - - 0.0 - 310.0 - - - - 2_5_cordeauVehicle - 2_cordeauType - - [x=33.0][y=-33.0] - - - - 0.0 - 310.0 - - - - 2_6_cordeauVehicle - 2_cordeauType - - [x=33.0][y=-33.0] - - - - 0.0 - 310.0 - - - - 2_7_cordeauVehicle - 2_cordeauType - - [x=33.0][y=-33.0] - - - - 0.0 - 310.0 - - - - 2_8_cordeauVehicle - 2_cordeauType - - [x=33.0][y=-33.0] - - - - 0.0 - 310.0 - - - - 2_9_cordeauVehicle - 2_cordeauType - - [x=33.0][y=-33.0] - - - - 0.0 - 310.0 - - - - 2_10_cordeauVehicle - 2_cordeauType - - [x=33.0][y=-33.0] - - - - 0.0 - 310.0 - - - - 2_11_cordeauVehicle - 2_cordeauType - - [x=33.0][y=-33.0] - - - - 0.0 - 310.0 - - - - 2_12_cordeauVehicle - 2_cordeauType - - [x=33.0][y=-33.0] - - - - 0.0 - 310.0 - - - - 2_13_cordeauVehicle - 2_cordeauType - - [x=33.0][y=-33.0] - - - - 0.0 - 310.0 - - - - 2_14_cordeauVehicle - 2_cordeauType - - [x=33.0][y=-33.0] - - - - 0.0 - 310.0 - - - - - - 1_cordeauType - 500 - - 0.0 - 1.0 - - - - - 2_cordeauType - 500 - - 0.0 - 1.0 - - - - + 35 diff --git a/jsprit-examples/src/main/java/examples/MultipleDepotExample.java b/jsprit-examples/src/main/java/examples/MultipleDepotExample.java new file mode 100644 index 00000000..b402ad72 --- /dev/null +++ b/jsprit-examples/src/main/java/examples/MultipleDepotExample.java @@ -0,0 +1,87 @@ +package examples; + +import java.util.Arrays; +import java.util.Collection; + +import util.Coordinate; +import util.Solutions; +import algorithms.VehicleRoutingAlgorithms; +import analysis.AlgorithmSearchProgressChartListener; +import analysis.SolutionPlotter; +import analysis.SolutionPrinter; +import basics.VehicleRoutingAlgorithm; +import basics.VehicleRoutingProblem; +import basics.VehicleRoutingProblem.FleetSize; +import basics.VehicleRoutingProblemSolution; +import basics.io.VrpXMLReader; +import basics.route.Vehicle; +import basics.route.VehicleImpl; +import basics.route.VehicleImpl.VehicleType; + +public class MultipleDepotExample { + + /** + * @param args + */ + public static void main(String[] args) { + + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + /* + * Read cordeau-instance p01, BUT only its services without any vehicles + */ + new VrpXMLReader(vrpBuilder).read("input/vrp_cordeau_01.xml"); + + /* + * add vehicles with its depots + * 4 depots: + * (20,20) + * (30,40) + * (50,30) + * (60,50) + * + * each with 4 vehicles each with a capacity of 80 + */ + int nuOfVehicles = 4; + int capacity = 80; + Coordinate firstDepotCoord = Coordinate.newInstance(20, 20); + Coordinate second = Coordinate.newInstance(30, 40); + Coordinate third = Coordinate.newInstance(50, 30); + Coordinate fourth = Coordinate.newInstance(60, 50); + + int depotCounter = 1; + for(Coordinate depotCoord : Arrays.asList(firstDepotCoord,second,third,fourth)){ + for(int i=0;i solutions = vra.searchSolutions(); + + SolutionPrinter.print(Solutions.getBest(solutions)); + SolutionPlotter.plotSolutionAsPNG(vrp, Solutions.getBest(solutions), "output/p01_solution.png", "p01"); + + } + +} diff --git a/jsprit-examples/src/main/java/examples/MultipleDepotExampleWithPenaltyVehicles.java b/jsprit-examples/src/main/java/examples/MultipleDepotExampleWithPenaltyVehicles.java new file mode 100644 index 00000000..7ba5f73c --- /dev/null +++ b/jsprit-examples/src/main/java/examples/MultipleDepotExampleWithPenaltyVehicles.java @@ -0,0 +1,105 @@ +package examples; + +import java.util.Arrays; +import java.util.Collection; + +import util.Coordinate; +import util.Solutions; +import algorithms.VehicleRoutingAlgorithms; +import analysis.AlgorithmSearchProgressChartListener; +import analysis.SolutionPlotter; +import analysis.SolutionPrinter; +import basics.VehicleRoutingAlgorithm; +import basics.VehicleRoutingProblem; +import basics.VehicleRoutingProblem.FleetSize; +import basics.VehicleRoutingProblemSolution; +import basics.io.VrpXMLReader; +import basics.route.Vehicle; +import basics.route.VehicleImpl; +import basics.route.VehicleImpl.VehicleType; + +public class MultipleDepotExampleWithPenaltyVehicles { + + /** + * @param args + */ + public static void main(String[] args) { + + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + /* + * Read cordeau-instance p01, BUT only its services without any vehicles + */ + new VrpXMLReader(vrpBuilder).read("input/vrp_cordeau_08.xml"); + + /* + * add vehicles with its depots + * 2 depots: + * (-33,33) + * (33,-33) + * + * each with 14 vehicles each with a capacity of 500 and a maximum duration of 310 + */ + int nuOfVehicles = 14; + int capacity = 500; + double maxDuration = 310; + Coordinate firstDepotCoord = Coordinate.newInstance(-33, 33); + Coordinate second = Coordinate.newInstance(33, -33); + + /* + * number of penalty vehicles + */ + int nuOfPenaltyVehicles = 4; + int depotCounter = 1; + for(Coordinate depotCoord : Arrays.asList(firstDepotCoord,second)){ + for(int i=0;i solutions = vra.searchSolutions(); + + SolutionPrinter.print(Solutions.getBest(solutions)); + SolutionPlotter.plotSolutionAsPNG(vrp, Solutions.getBest(solutions), "output/p08_solution.png", "p08"); + + } + +} diff --git a/jsprit-instances/src/main/java/readers/CordeauReader.java b/jsprit-instances/src/main/java/readers/CordeauReader.java index 981e7d1e..8e09362e 100644 --- a/jsprit-instances/src/main/java/readers/CordeauReader.java +++ b/jsprit-instances/src/main/java/readers/CordeauReader.java @@ -58,12 +58,20 @@ public class CordeauReader { private final VehicleRoutingProblem.Builder vrpBuilder; private double coordProjectionFactor = 1; + + private boolean addPenaltyVehicles = false; public CordeauReader(VehicleRoutingProblem.Builder vrpBuilder) { super(); this.vrpBuilder = vrpBuilder; } + public CordeauReader(VehicleRoutingProblem.Builder vrpBuilder, boolean penaltyVehicles) { + super(); + this.vrpBuilder = vrpBuilder; + this.addPenaltyVehicles = penaltyVehicles; + } + public void read(String fileName){ vrpBuilder.setFleetSize(FleetSize.FINITE); BufferedReader reader = getReader(fileName); @@ -124,12 +132,14 @@ public class CordeauReader { coord = vehicle.getCoord(); vrpBuilder.addVehicle(vehicle); } - for(int i=0;i<5;i++){ - VehicleType penaltyType = VehicleImpl.VehicleType.Builder.newInstance(counter + "_penaltyType", cap). - setCostPerDistance(3.0).setFixedCost(50).build(); - VehicleImpl penaltyVehicle = VehicleImpl.VehicleBuilder.newInstance(counter + "_" + (i+1) + "_penaltyVehicle").setLatestArrival(latestArrTime) - .setType(penaltyType).setLocationCoord(coord).build(); - vrpBuilder.addVehicle(penaltyVehicle); + if(addPenaltyVehicles){ + for(int i=0;i<5;i++){ + VehicleType penaltyType = VehicleImpl.VehicleType.Builder.newInstance(counter + "_penaltyType", cap). + setCostPerDistance(3.0).setFixedCost(50).build(); + VehicleImpl penaltyVehicle = VehicleImpl.VehicleBuilder.newInstance(counter + "_" + (i+1) + "_penaltyVehicle").setLatestArrival(latestArrTime) + .setType(penaltyType).setLocationCoord(coord).build(); + vrpBuilder.addVehicle(penaltyVehicle); + } } depotCounter++; }