mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
add MultipleDepotExamples
This commit is contained in:
parent
cc8f0ed2d8
commit
c55af1ce59
4 changed files with 209 additions and 368 deletions
|
|
@ -1,368 +1,7 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<problem xmlns="http://www.w3schools.com"
|
<problem xmlns="http://www.w3schools.com"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd">
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd">
|
||||||
<problemType>
|
|
||||||
<fleetSize>FINITE</fleetSize>
|
|
||||||
<fleetComposition>HOMOGENEOUS</fleetComposition>
|
|
||||||
</problemType>
|
|
||||||
<vehicles>
|
|
||||||
<vehicle>
|
|
||||||
<id>1_1_cordeauVehicle</id>
|
|
||||||
<typeId>1_cordeauType</typeId>
|
|
||||||
<location>
|
|
||||||
<id>[x=-33.0][y=33.0]</id>
|
|
||||||
<coord x="-33.0" y="33.0"/>
|
|
||||||
</location>
|
|
||||||
<timeSchedule>
|
|
||||||
<start>0.0</start>
|
|
||||||
<end>310.0</end>
|
|
||||||
</timeSchedule>
|
|
||||||
</vehicle>
|
|
||||||
<vehicle>
|
|
||||||
<id>1_2_cordeauVehicle</id>
|
|
||||||
<typeId>1_cordeauType</typeId>
|
|
||||||
<location>
|
|
||||||
<id>[x=-33.0][y=33.0]</id>
|
|
||||||
<coord x="-33.0" y="33.0"/>
|
|
||||||
</location>
|
|
||||||
<timeSchedule>
|
|
||||||
<start>0.0</start>
|
|
||||||
<end>310.0</end>
|
|
||||||
</timeSchedule>
|
|
||||||
</vehicle>
|
|
||||||
<vehicle>
|
|
||||||
<id>1_3_cordeauVehicle</id>
|
|
||||||
<typeId>1_cordeauType</typeId>
|
|
||||||
<location>
|
|
||||||
<id>[x=-33.0][y=33.0]</id>
|
|
||||||
<coord x="-33.0" y="33.0"/>
|
|
||||||
</location>
|
|
||||||
<timeSchedule>
|
|
||||||
<start>0.0</start>
|
|
||||||
<end>310.0</end>
|
|
||||||
</timeSchedule>
|
|
||||||
</vehicle>
|
|
||||||
<vehicle>
|
|
||||||
<id>1_4_cordeauVehicle</id>
|
|
||||||
<typeId>1_cordeauType</typeId>
|
|
||||||
<location>
|
|
||||||
<id>[x=-33.0][y=33.0]</id>
|
|
||||||
<coord x="-33.0" y="33.0"/>
|
|
||||||
</location>
|
|
||||||
<timeSchedule>
|
|
||||||
<start>0.0</start>
|
|
||||||
<end>310.0</end>
|
|
||||||
</timeSchedule>
|
|
||||||
</vehicle>
|
|
||||||
<vehicle>
|
|
||||||
<id>1_5_cordeauVehicle</id>
|
|
||||||
<typeId>1_cordeauType</typeId>
|
|
||||||
<location>
|
|
||||||
<id>[x=-33.0][y=33.0]</id>
|
|
||||||
<coord x="-33.0" y="33.0"/>
|
|
||||||
</location>
|
|
||||||
<timeSchedule>
|
|
||||||
<start>0.0</start>
|
|
||||||
<end>310.0</end>
|
|
||||||
</timeSchedule>
|
|
||||||
</vehicle>
|
|
||||||
<vehicle>
|
|
||||||
<id>1_6_cordeauVehicle</id>
|
|
||||||
<typeId>1_cordeauType</typeId>
|
|
||||||
<location>
|
|
||||||
<id>[x=-33.0][y=33.0]</id>
|
|
||||||
<coord x="-33.0" y="33.0"/>
|
|
||||||
</location>
|
|
||||||
<timeSchedule>
|
|
||||||
<start>0.0</start>
|
|
||||||
<end>310.0</end>
|
|
||||||
</timeSchedule>
|
|
||||||
</vehicle>
|
|
||||||
<vehicle>
|
|
||||||
<id>1_7_cordeauVehicle</id>
|
|
||||||
<typeId>1_cordeauType</typeId>
|
|
||||||
<location>
|
|
||||||
<id>[x=-33.0][y=33.0]</id>
|
|
||||||
<coord x="-33.0" y="33.0"/>
|
|
||||||
</location>
|
|
||||||
<timeSchedule>
|
|
||||||
<start>0.0</start>
|
|
||||||
<end>310.0</end>
|
|
||||||
</timeSchedule>
|
|
||||||
</vehicle>
|
|
||||||
<vehicle>
|
|
||||||
<id>1_8_cordeauVehicle</id>
|
|
||||||
<typeId>1_cordeauType</typeId>
|
|
||||||
<location>
|
|
||||||
<id>[x=-33.0][y=33.0]</id>
|
|
||||||
<coord x="-33.0" y="33.0"/>
|
|
||||||
</location>
|
|
||||||
<timeSchedule>
|
|
||||||
<start>0.0</start>
|
|
||||||
<end>310.0</end>
|
|
||||||
</timeSchedule>
|
|
||||||
</vehicle>
|
|
||||||
<vehicle>
|
|
||||||
<id>1_9_cordeauVehicle</id>
|
|
||||||
<typeId>1_cordeauType</typeId>
|
|
||||||
<location>
|
|
||||||
<id>[x=-33.0][y=33.0]</id>
|
|
||||||
<coord x="-33.0" y="33.0"/>
|
|
||||||
</location>
|
|
||||||
<timeSchedule>
|
|
||||||
<start>0.0</start>
|
|
||||||
<end>310.0</end>
|
|
||||||
</timeSchedule>
|
|
||||||
</vehicle>
|
|
||||||
<vehicle>
|
|
||||||
<id>1_10_cordeauVehicle</id>
|
|
||||||
<typeId>1_cordeauType</typeId>
|
|
||||||
<location>
|
|
||||||
<id>[x=-33.0][y=33.0]</id>
|
|
||||||
<coord x="-33.0" y="33.0"/>
|
|
||||||
</location>
|
|
||||||
<timeSchedule>
|
|
||||||
<start>0.0</start>
|
|
||||||
<end>310.0</end>
|
|
||||||
</timeSchedule>
|
|
||||||
</vehicle>
|
|
||||||
<vehicle>
|
|
||||||
<id>1_11_cordeauVehicle</id>
|
|
||||||
<typeId>1_cordeauType</typeId>
|
|
||||||
<location>
|
|
||||||
<id>[x=-33.0][y=33.0]</id>
|
|
||||||
<coord x="-33.0" y="33.0"/>
|
|
||||||
</location>
|
|
||||||
<timeSchedule>
|
|
||||||
<start>0.0</start>
|
|
||||||
<end>310.0</end>
|
|
||||||
</timeSchedule>
|
|
||||||
</vehicle>
|
|
||||||
<vehicle>
|
|
||||||
<id>1_12_cordeauVehicle</id>
|
|
||||||
<typeId>1_cordeauType</typeId>
|
|
||||||
<location>
|
|
||||||
<id>[x=-33.0][y=33.0]</id>
|
|
||||||
<coord x="-33.0" y="33.0"/>
|
|
||||||
</location>
|
|
||||||
<timeSchedule>
|
|
||||||
<start>0.0</start>
|
|
||||||
<end>310.0</end>
|
|
||||||
</timeSchedule>
|
|
||||||
</vehicle>
|
|
||||||
<vehicle>
|
|
||||||
<id>1_13_cordeauVehicle</id>
|
|
||||||
<typeId>1_cordeauType</typeId>
|
|
||||||
<location>
|
|
||||||
<id>[x=-33.0][y=33.0]</id>
|
|
||||||
<coord x="-33.0" y="33.0"/>
|
|
||||||
</location>
|
|
||||||
<timeSchedule>
|
|
||||||
<start>0.0</start>
|
|
||||||
<end>310.0</end>
|
|
||||||
</timeSchedule>
|
|
||||||
</vehicle>
|
|
||||||
<vehicle>
|
|
||||||
<id>1_14_cordeauVehicle</id>
|
|
||||||
<typeId>1_cordeauType</typeId>
|
|
||||||
<location>
|
|
||||||
<id>[x=-33.0][y=33.0]</id>
|
|
||||||
<coord x="-33.0" y="33.0"/>
|
|
||||||
</location>
|
|
||||||
<timeSchedule>
|
|
||||||
<start>0.0</start>
|
|
||||||
<end>310.0</end>
|
|
||||||
</timeSchedule>
|
|
||||||
</vehicle>
|
|
||||||
<vehicle>
|
|
||||||
<id>2_1_cordeauVehicle</id>
|
|
||||||
<typeId>2_cordeauType</typeId>
|
|
||||||
<location>
|
|
||||||
<id>[x=33.0][y=-33.0]</id>
|
|
||||||
<coord x="33.0" y="-33.0"/>
|
|
||||||
</location>
|
|
||||||
<timeSchedule>
|
|
||||||
<start>0.0</start>
|
|
||||||
<end>310.0</end>
|
|
||||||
</timeSchedule>
|
|
||||||
</vehicle>
|
|
||||||
<vehicle>
|
|
||||||
<id>2_2_cordeauVehicle</id>
|
|
||||||
<typeId>2_cordeauType</typeId>
|
|
||||||
<location>
|
|
||||||
<id>[x=33.0][y=-33.0]</id>
|
|
||||||
<coord x="33.0" y="-33.0"/>
|
|
||||||
</location>
|
|
||||||
<timeSchedule>
|
|
||||||
<start>0.0</start>
|
|
||||||
<end>310.0</end>
|
|
||||||
</timeSchedule>
|
|
||||||
</vehicle>
|
|
||||||
<vehicle>
|
|
||||||
<id>2_3_cordeauVehicle</id>
|
|
||||||
<typeId>2_cordeauType</typeId>
|
|
||||||
<location>
|
|
||||||
<id>[x=33.0][y=-33.0]</id>
|
|
||||||
<coord x="33.0" y="-33.0"/>
|
|
||||||
</location>
|
|
||||||
<timeSchedule>
|
|
||||||
<start>0.0</start>
|
|
||||||
<end>310.0</end>
|
|
||||||
</timeSchedule>
|
|
||||||
</vehicle>
|
|
||||||
<vehicle>
|
|
||||||
<id>2_4_cordeauVehicle</id>
|
|
||||||
<typeId>2_cordeauType</typeId>
|
|
||||||
<location>
|
|
||||||
<id>[x=33.0][y=-33.0]</id>
|
|
||||||
<coord x="33.0" y="-33.0"/>
|
|
||||||
</location>
|
|
||||||
<timeSchedule>
|
|
||||||
<start>0.0</start>
|
|
||||||
<end>310.0</end>
|
|
||||||
</timeSchedule>
|
|
||||||
</vehicle>
|
|
||||||
<vehicle>
|
|
||||||
<id>2_5_cordeauVehicle</id>
|
|
||||||
<typeId>2_cordeauType</typeId>
|
|
||||||
<location>
|
|
||||||
<id>[x=33.0][y=-33.0]</id>
|
|
||||||
<coord x="33.0" y="-33.0"/>
|
|
||||||
</location>
|
|
||||||
<timeSchedule>
|
|
||||||
<start>0.0</start>
|
|
||||||
<end>310.0</end>
|
|
||||||
</timeSchedule>
|
|
||||||
</vehicle>
|
|
||||||
<vehicle>
|
|
||||||
<id>2_6_cordeauVehicle</id>
|
|
||||||
<typeId>2_cordeauType</typeId>
|
|
||||||
<location>
|
|
||||||
<id>[x=33.0][y=-33.0]</id>
|
|
||||||
<coord x="33.0" y="-33.0"/>
|
|
||||||
</location>
|
|
||||||
<timeSchedule>
|
|
||||||
<start>0.0</start>
|
|
||||||
<end>310.0</end>
|
|
||||||
</timeSchedule>
|
|
||||||
</vehicle>
|
|
||||||
<vehicle>
|
|
||||||
<id>2_7_cordeauVehicle</id>
|
|
||||||
<typeId>2_cordeauType</typeId>
|
|
||||||
<location>
|
|
||||||
<id>[x=33.0][y=-33.0]</id>
|
|
||||||
<coord x="33.0" y="-33.0"/>
|
|
||||||
</location>
|
|
||||||
<timeSchedule>
|
|
||||||
<start>0.0</start>
|
|
||||||
<end>310.0</end>
|
|
||||||
</timeSchedule>
|
|
||||||
</vehicle>
|
|
||||||
<vehicle>
|
|
||||||
<id>2_8_cordeauVehicle</id>
|
|
||||||
<typeId>2_cordeauType</typeId>
|
|
||||||
<location>
|
|
||||||
<id>[x=33.0][y=-33.0]</id>
|
|
||||||
<coord x="33.0" y="-33.0"/>
|
|
||||||
</location>
|
|
||||||
<timeSchedule>
|
|
||||||
<start>0.0</start>
|
|
||||||
<end>310.0</end>
|
|
||||||
</timeSchedule>
|
|
||||||
</vehicle>
|
|
||||||
<vehicle>
|
|
||||||
<id>2_9_cordeauVehicle</id>
|
|
||||||
<typeId>2_cordeauType</typeId>
|
|
||||||
<location>
|
|
||||||
<id>[x=33.0][y=-33.0]</id>
|
|
||||||
<coord x="33.0" y="-33.0"/>
|
|
||||||
</location>
|
|
||||||
<timeSchedule>
|
|
||||||
<start>0.0</start>
|
|
||||||
<end>310.0</end>
|
|
||||||
</timeSchedule>
|
|
||||||
</vehicle>
|
|
||||||
<vehicle>
|
|
||||||
<id>2_10_cordeauVehicle</id>
|
|
||||||
<typeId>2_cordeauType</typeId>
|
|
||||||
<location>
|
|
||||||
<id>[x=33.0][y=-33.0]</id>
|
|
||||||
<coord x="33.0" y="-33.0"/>
|
|
||||||
</location>
|
|
||||||
<timeSchedule>
|
|
||||||
<start>0.0</start>
|
|
||||||
<end>310.0</end>
|
|
||||||
</timeSchedule>
|
|
||||||
</vehicle>
|
|
||||||
<vehicle>
|
|
||||||
<id>2_11_cordeauVehicle</id>
|
|
||||||
<typeId>2_cordeauType</typeId>
|
|
||||||
<location>
|
|
||||||
<id>[x=33.0][y=-33.0]</id>
|
|
||||||
<coord x="33.0" y="-33.0"/>
|
|
||||||
</location>
|
|
||||||
<timeSchedule>
|
|
||||||
<start>0.0</start>
|
|
||||||
<end>310.0</end>
|
|
||||||
</timeSchedule>
|
|
||||||
</vehicle>
|
|
||||||
<vehicle>
|
|
||||||
<id>2_12_cordeauVehicle</id>
|
|
||||||
<typeId>2_cordeauType</typeId>
|
|
||||||
<location>
|
|
||||||
<id>[x=33.0][y=-33.0]</id>
|
|
||||||
<coord x="33.0" y="-33.0"/>
|
|
||||||
</location>
|
|
||||||
<timeSchedule>
|
|
||||||
<start>0.0</start>
|
|
||||||
<end>310.0</end>
|
|
||||||
</timeSchedule>
|
|
||||||
</vehicle>
|
|
||||||
<vehicle>
|
|
||||||
<id>2_13_cordeauVehicle</id>
|
|
||||||
<typeId>2_cordeauType</typeId>
|
|
||||||
<location>
|
|
||||||
<id>[x=33.0][y=-33.0]</id>
|
|
||||||
<coord x="33.0" y="-33.0"/>
|
|
||||||
</location>
|
|
||||||
<timeSchedule>
|
|
||||||
<start>0.0</start>
|
|
||||||
<end>310.0</end>
|
|
||||||
</timeSchedule>
|
|
||||||
</vehicle>
|
|
||||||
<vehicle>
|
|
||||||
<id>2_14_cordeauVehicle</id>
|
|
||||||
<typeId>2_cordeauType</typeId>
|
|
||||||
<location>
|
|
||||||
<id>[x=33.0][y=-33.0]</id>
|
|
||||||
<coord x="33.0" y="-33.0"/>
|
|
||||||
</location>
|
|
||||||
<timeSchedule>
|
|
||||||
<start>0.0</start>
|
|
||||||
<end>310.0</end>
|
|
||||||
</timeSchedule>
|
|
||||||
</vehicle>
|
|
||||||
</vehicles>
|
|
||||||
<vehicleTypes>
|
|
||||||
<type>
|
|
||||||
<id>1_cordeauType</id>
|
|
||||||
<capacity>500</capacity>
|
|
||||||
<costs>
|
|
||||||
<fixed>0.0</fixed>
|
|
||||||
<distance>1.0</distance>
|
|
||||||
<time>0.0</time>
|
|
||||||
</costs>
|
|
||||||
</type>
|
|
||||||
<type>
|
|
||||||
<id>2_cordeauType</id>
|
|
||||||
<capacity>500</capacity>
|
|
||||||
<costs>
|
|
||||||
<fixed>0.0</fixed>
|
|
||||||
<distance>1.0</distance>
|
|
||||||
<time>0.0</time>
|
|
||||||
</costs>
|
|
||||||
</type>
|
|
||||||
</vehicleTypes>
|
|
||||||
<services>
|
<services>
|
||||||
<service id="35" type="service">
|
<service id="35" type="service">
|
||||||
<locationId>35</locationId>
|
<locationId>35</locationId>
|
||||||
|
|
|
||||||
|
|
@ -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<nuOfVehicles;i++){
|
||||||
|
VehicleType vehicleType = VehicleType.Builder.newInstance(depotCounter + "_" + (i+1) + "_type", capacity).setCostPerDistance(1.0).build();
|
||||||
|
Vehicle vehicle = VehicleImpl.VehicleBuilder.newInstance(depotCounter + "_" + (i+1) + "_vehicle").setLocationCoord(depotCoord).setType(vehicleType).build();
|
||||||
|
vrpBuilder.addVehicle(vehicle);
|
||||||
|
}
|
||||||
|
depotCounter++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* define problem with finite fleet
|
||||||
|
*/
|
||||||
|
vrpBuilder.setFleetSize(FleetSize.FINITE);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* build the problem
|
||||||
|
*/
|
||||||
|
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* plot to see how the problem looks like
|
||||||
|
*/
|
||||||
|
SolutionPlotter.plotVrpAsPNG(vrp, "output/problem01.png", "p01");
|
||||||
|
|
||||||
|
/*
|
||||||
|
* solve the problem
|
||||||
|
*/
|
||||||
|
VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "input/algorithmConfig.xml");
|
||||||
|
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
|
||||||
|
|
||||||
|
SolutionPrinter.print(Solutions.getBest(solutions));
|
||||||
|
SolutionPlotter.plotSolutionAsPNG(vrp, Solutions.getBest(solutions), "output/p01_solution.png", "p01");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -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<nuOfVehicles;i++){
|
||||||
|
VehicleType vehicleType = VehicleType.Builder.newInstance(depotCounter + "_" + (i+1) + "_type", capacity).setCostPerDistance(1.0).build();
|
||||||
|
String vehicleId = depotCounter + "_" + (i+1) + "_vehicle";
|
||||||
|
VehicleImpl.VehicleBuilder vehicleBuilder = VehicleImpl.VehicleBuilder.newInstance(vehicleId);
|
||||||
|
vehicleBuilder.setLocationCoord(depotCoord);
|
||||||
|
vehicleBuilder.setType(vehicleType);
|
||||||
|
vehicleBuilder.setLatestArrival(maxDuration);
|
||||||
|
Vehicle vehicle = vehicleBuilder.build();
|
||||||
|
vrpBuilder.addVehicle(vehicle);
|
||||||
|
}
|
||||||
|
for(int i=0;i<nuOfPenaltyVehicles;i++){
|
||||||
|
VehicleType penaltyType = VehicleType.Builder.newInstance(depotCounter + "_" + (i+1) + "_penaltyType", capacity).setFixedCost(50).setCostPerDistance(3.0).build();
|
||||||
|
String vehicleId = depotCounter + "_" + (i+1) + "_penaltyVehicle";
|
||||||
|
VehicleImpl.VehicleBuilder vehicleBuilder = VehicleImpl.VehicleBuilder.newInstance(vehicleId);
|
||||||
|
vehicleBuilder.setLocationCoord(depotCoord);
|
||||||
|
vehicleBuilder.setType(penaltyType);
|
||||||
|
vehicleBuilder.setLatestArrival(maxDuration);
|
||||||
|
Vehicle penaltyVehicle = vehicleBuilder.build();
|
||||||
|
vrpBuilder.addVehicle(penaltyVehicle);
|
||||||
|
}
|
||||||
|
depotCounter++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* define problem with finite fleet
|
||||||
|
*/
|
||||||
|
vrpBuilder.setFleetSize(FleetSize.FINITE);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* build the problem
|
||||||
|
*/
|
||||||
|
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* plot to see how the problem looks like
|
||||||
|
*/
|
||||||
|
SolutionPlotter.plotVrpAsPNG(vrp, "output/problem08.png", "p08");
|
||||||
|
|
||||||
|
/*
|
||||||
|
* solve the problem
|
||||||
|
*/
|
||||||
|
VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "input/algorithmConfig.xml");
|
||||||
|
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
|
||||||
|
|
||||||
|
SolutionPrinter.print(Solutions.getBest(solutions));
|
||||||
|
SolutionPlotter.plotSolutionAsPNG(vrp, Solutions.getBest(solutions), "output/p08_solution.png", "p08");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -59,11 +59,19 @@ public class CordeauReader {
|
||||||
|
|
||||||
private double coordProjectionFactor = 1;
|
private double coordProjectionFactor = 1;
|
||||||
|
|
||||||
|
private boolean addPenaltyVehicles = false;
|
||||||
|
|
||||||
public CordeauReader(VehicleRoutingProblem.Builder vrpBuilder) {
|
public CordeauReader(VehicleRoutingProblem.Builder vrpBuilder) {
|
||||||
super();
|
super();
|
||||||
this.vrpBuilder = vrpBuilder;
|
this.vrpBuilder = vrpBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CordeauReader(VehicleRoutingProblem.Builder vrpBuilder, boolean penaltyVehicles) {
|
||||||
|
super();
|
||||||
|
this.vrpBuilder = vrpBuilder;
|
||||||
|
this.addPenaltyVehicles = penaltyVehicles;
|
||||||
|
}
|
||||||
|
|
||||||
public void read(String fileName){
|
public void read(String fileName){
|
||||||
vrpBuilder.setFleetSize(FleetSize.FINITE);
|
vrpBuilder.setFleetSize(FleetSize.FINITE);
|
||||||
BufferedReader reader = getReader(fileName);
|
BufferedReader reader = getReader(fileName);
|
||||||
|
|
@ -124,12 +132,14 @@ public class CordeauReader {
|
||||||
coord = vehicle.getCoord();
|
coord = vehicle.getCoord();
|
||||||
vrpBuilder.addVehicle(vehicle);
|
vrpBuilder.addVehicle(vehicle);
|
||||||
}
|
}
|
||||||
for(int i=0;i<5;i++){
|
if(addPenaltyVehicles){
|
||||||
VehicleType penaltyType = VehicleImpl.VehicleType.Builder.newInstance(counter + "_penaltyType", cap).
|
for(int i=0;i<5;i++){
|
||||||
setCostPerDistance(3.0).setFixedCost(50).build();
|
VehicleType penaltyType = VehicleImpl.VehicleType.Builder.newInstance(counter + "_penaltyType", cap).
|
||||||
VehicleImpl penaltyVehicle = VehicleImpl.VehicleBuilder.newInstance(counter + "_" + (i+1) + "_penaltyVehicle").setLatestArrival(latestArrTime)
|
setCostPerDistance(3.0).setFixedCost(50).build();
|
||||||
.setType(penaltyType).setLocationCoord(coord).build();
|
VehicleImpl penaltyVehicle = VehicleImpl.VehicleBuilder.newInstance(counter + "_" + (i+1) + "_penaltyVehicle").setLatestArrival(latestArrTime)
|
||||||
vrpBuilder.addVehicle(penaltyVehicle);
|
.setType(penaltyType).setLocationCoord(coord).build();
|
||||||
|
vrpBuilder.addVehicle(penaltyVehicle);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
depotCounter++;
|
depotCounter++;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue