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

reproduce bug #186

This commit is contained in:
oblonski 2015-09-19 17:00:31 +02:00
parent 16421656f2
commit e5ada2f6d9
3 changed files with 561 additions and 0 deletions

View file

@ -29,9 +29,14 @@ import jsprit.core.problem.job.Job;
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
import jsprit.core.problem.solution.route.VehicleRoute;
import jsprit.core.problem.vehicle.Vehicle;
import jsprit.core.util.FastVehicleRoutingTransportCostsMatrix;
import jsprit.core.util.Solutions;
import org.junit.Test;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@ -544,6 +549,34 @@ public class MeetTimeWindowConstraint_IT {
assertTrue(containsJob(vrp.getJobs().get("2"), getRoute("19", Solutions.bestOf(solutions))));
}
@Test
public void driverTimesShouldBeMet() throws IOException {
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
new VrpXMLReader(vrpBuilder).read("src/test/resources/twbug.xml");
final FastVehicleRoutingTransportCostsMatrix matrix = createMatrix();
vrpBuilder.setRoutingCost(matrix);
VehicleRoutingProblem vrp = vrpBuilder.build();
VehicleRoutingAlgorithm algorithm = Jsprit.Builder.newInstance(vrp).buildAlgorithm();
algorithm.setMaxIterations(1000);
VehicleRoutingProblemSolution solution = Solutions.bestOf(algorithm.searchSolutions());
for(VehicleRoute r : solution.getRoutes()){
assertTrue(r.getVehicle().getEarliestDeparture() <= r.getDepartureTime());
assertTrue(r.getVehicle().getLatestArrival() >= r.getEnd().getArrTime());
}
}
private FastVehicleRoutingTransportCostsMatrix createMatrix() throws IOException {
BufferedReader reader = new BufferedReader(new FileReader(new File("src/test/resources/matrix.txt")));
String line;
FastVehicleRoutingTransportCostsMatrix.Builder builder = FastVehicleRoutingTransportCostsMatrix.Builder.newInstance(11,false);
while((line = reader.readLine()) != null){
String[] split = line.split("\t");
builder.addTransportDistance(Integer.parseInt(split[0]),Integer.parseInt(split[1]),Double.parseDouble(split[2]));
builder.addTransportTime(Integer.parseInt(split[0]), Integer.parseInt(split[1]), Double.parseDouble(split[3]));
}
return builder.build();
}
private boolean containsJob(Job job, VehicleRoute route) {
if (route == null) return false;

View file

@ -0,0 +1,121 @@
0 0 0.0 0.0
0 1 7641.0 394.0
0 2 7244.0 370.0
0 3 15236.0 747.0
0 4 7841.0 452.0
0 5 7013.0 388.0
0 6 3336.0 232.0
0 7 6729.0 364.0
0 8 22401.0 918.0
0 9 16830.0 772.0
0 10 8311.0 434.0
1 0 7463.0 381.0
1 1 0.0 0.0
1 2 1605.0 90.0
1 3 8336.0 380.0
1 4 4949.0 304.0
1 5 3632.0 221.0
1 6 5611.0 324.0
1 7 3407.0 212.0
1 8 29674.0 1216.0
1 9 9378.0 513.0
1 10 633.0 42.0
2 0 5857.0 291.0
2 1 1366.0 78.0
2 2 0.0 0.0
2 3 8961.0 431.0
2 4 5346.0 325.0
2 5 1994.0 144.0
2 6 4006.0 234.0
2 7 1802.0 122.0
2 8 28069.0 1126.0
2 9 9809.0 536.0
2 10 2035.0 118.0
3 0 15179.0 645.0
3 1 7322.0 329.0
3 2 7534.0 364.0
3 3 0.0 0.0
3 4 10908.0 483.0
3 5 9605.0 470.0
3 6 13327.0 588.0
3 7 9336.0 486.0
3 8 36409.0 1438.0
3 9 4130.0 236.0
3 10 6404.0 321.0
4 0 7652.0 457.0
4 1 4611.0 288.0
4 2 4948.0 303.0
4 3 10982.0 539.0
4 4 0.0 0.0
4 5 6942.0 447.0
4 6 6199.0 415.0
4 7 6750.0 425.0
4 8 29970.0 1270.0
4 9 10932.0 566.0
4 10 4384.0 277.0
5 0 4845.0 284.0
5 1 3010.0 187.0
5 2 2612.0 163.0
5 3 10784.0 530.0
5 4 6990.0 435.0
5 5 0.0 0.0
5 6 2964.0 219.0
5 7 819.0 68.0
5 8 27332.0 1124.0
5 9 13064.0 615.0
5 10 3679.0 227.0
6 0 2952.0 209.0
6 1 5089.0 297.0
6 2 4691.0 273.0
6 3 12684.0 650.0
6 4 6489.0 430.0
6 5 4460.0 291.0
6 6 0.0 0.0
6 7 4176.0 267.0
6 8 25472.0 1083.0
6 9 14278.0 675.0
6 10 5758.0 337.0
7 0 4334.0 253.0
7 1 2956.0 182.0
7 2 2559.0 158.0
7 3 10551.0 535.0
7 4 6936.0 429.0
7 5 2081.0 162.0
7 6 2453.0 188.0
7 7 0.0 0.0
7 8 26821.0 1092.0
7 9 13010.0 610.0
7 10 3625.0 222.0
8 0 22667.0 926.0
8 1 29281.0 1189.0
8 2 28884.0 1165.0
8 3 37504.0 1484.0
8 4 29608.0 1240.0
8 5 28008.0 1174.0
8 6 25198.0 1063.0
8 7 27518.0 1151.0
8 8 0.0 0.0
8 9 36799.0 1529.0
8 10 29950.0 1230.0
9 0 15604.0 722.0
9 1 8945.0 492.0
9 2 9283.0 507.0
9 3 3730.0 212.0
9 4 11018.0 594.0
9 5 12864.0 633.0
9 6 13753.0 665.0
9 7 12558.0 607.0
9 8 36821.0 1553.0
9 9 0.0 0.0
9 10 8307.0 472.0
10 0 7591.0 404.0
10 1 1117.0 81.0
10 2 1733.0 113.0
10 3 7844.0 354.0
10 4 5077.0 327.0
10 5 3914.0 243.0
10 6 5739.0 347.0
10 7 3535.0 235.0
10 8 29802.0 1239.0
10 9 8906.0 493.0
10 10 0.0 0.0

View file

@ -0,0 +1,407 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<problemType>
<fleetSize>FINITE</fleetSize>
</problemType>
<vehicles>
<vehicle>
<id>vehicle0</id>
<typeId>vehicle_type_0</typeId>
<startLocation>
<id>v0_start</id>
<index>0</index>
</startLocation>
<endLocation>
<id>v0_start</id>
<index>0</index>
</endLocation>
<timeSchedule>
<start>60.0</start>
<end>18060.0</end>
</timeSchedule>
<returnToDepot>true</returnToDepot>
<skills>primemover</skills>
</vehicle>
<vehicle>
<id>vehicle1</id>
<typeId>vehicle_type_1</typeId>
<startLocation>
<id>v1_start</id>
<index>0</index>
</startLocation>
<endLocation>
<id>v1_start</id>
<index>0</index>
</endLocation>
<timeSchedule>
<start>60.0</start>
<end>18060.0</end>
</timeSchedule>
<returnToDepot>true</returnToDepot>
<skills>primemover</skills>
</vehicle>
<vehicle>
<id>vehicle2</id>
<typeId>vehicle_type_2</typeId>
<startLocation>
<id>v2_start</id>
<index>0</index>
</startLocation>
<endLocation>
<id>v2_start</id>
<index>0</index>
</endLocation>
<timeSchedule>
<start>7200.0</start>
<end>36060.0</end>
</timeSchedule>
<returnToDepot>true</returnToDepot>
<skills>primemover</skills>
</vehicle>
<vehicle>
<id>vehicle3</id>
<typeId>vehicle_type_3</typeId>
<startLocation>
<id>v3_start</id>
<index>0</index>
</startLocation>
<endLocation>
<id>v3_start</id>
<index>0</index>
</endLocation>
<timeSchedule>
<start>36000.0</start>
<end>54060.0</end>
</timeSchedule>
<returnToDepot>true</returnToDepot>
<skills>primemover</skills>
</vehicle>
<vehicle>
<id>vehicle4</id>
<typeId>vehicle_type_4</typeId>
<startLocation>
<id>v4_start</id>
<index>0</index>
</startLocation>
<endLocation>
<id>v4_start</id>
<index>0</index>
</endLocation>
<timeSchedule>
<start>36000.0</start>
<end>54060.0</end>
</timeSchedule>
<returnToDepot>true</returnToDepot>
<skills>primemover</skills>
</vehicle>
</vehicles>
<vehicleTypes>
<type>
<id>vehicle_type_0</id>
<capacity-dimensions>
<dimension index="0">20</dimension>
</capacity-dimensions>
<costs>
<fixed>0.0</fixed>
<distance>0.0</distance>
<time>1.0</time>
</costs>
</type>
<type>
<id>vehicle_type_1</id>
<capacity-dimensions>
<dimension index="0">20</dimension>
</capacity-dimensions>
<costs>
<fixed>0.0</fixed>
<distance>0.0</distance>
<time>1.0</time>
</costs>
</type>
<type>
<id>vehicle_type_2</id>
<capacity-dimensions>
<dimension index="0">20</dimension>
</capacity-dimensions>
<costs>
<fixed>0.0</fixed>
<distance>0.0</distance>
<time>1.0</time>
</costs>
</type>
<type>
<id>vehicle_type_3</id>
<capacity-dimensions>
<dimension index="0">20</dimension>
</capacity-dimensions>
<costs>
<fixed>0.0</fixed>
<distance>0.0</distance>
<time>1.0</time>
</costs>
</type>
<type>
<id>vehicle_type_4</id>
<capacity-dimensions>
<dimension index="0">20</dimension>
</capacity-dimensions>
<costs>
<fixed>0.0</fixed>
<distance>0.0</distance>
<time>1.0</time>
</costs>
</type>
</vehicleTypes>
<services>
<service id="1" type="service">
<location>
<id>js0</id>
<index>1</index>
</location>
<capacity-dimensions>
<dimension index="0">1</dimension>
</capacity-dimensions>
<duration>600.0</duration>
<timeWindows>
<timeWindow>
<start>0.0</start>
<end>1800.0</end>
</timeWindow>
</timeWindows>
<name>Test</name>
</service>
<service id="2" type="service">
<location>
<id>js2</id>
<index>2</index>
</location>
<capacity-dimensions>
<dimension index="0">2</dimension>
</capacity-dimensions>
<duration>600.0</duration>
<timeWindows>
<timeWindow>
<start>5400.0</start>
<end>7200.0</end>
</timeWindow>
</timeWindows>
<name>Test</name>
</service>
<service id="3" type="service">
<location>
<id>js5</id>
<index>3</index>
</location>
<capacity-dimensions>
<dimension index="0">10</dimension>
</capacity-dimensions>
<duration>1800.0</duration>
<timeWindows>
<timeWindow>
<start>17100.0</start>
<end>18000.0</end>
</timeWindow>
</timeWindows>
<name>Test</name>
</service>
<service id="4" type="service">
<location>
<id>js6</id>
<index>4</index>
</location>
<capacity-dimensions>
<dimension index="0">2</dimension>
</capacity-dimensions>
<duration>900.0</duration>
<timeWindows>
<timeWindow>
<start>0.0</start>
<end>1.7976931348623157E308</end>
</timeWindow>
</timeWindows>
<name>Test</name>
</service>
<service id="5" type="service">
<location>
<id>js8</id>
<index>5</index>
</location>
<capacity-dimensions>
<dimension index="0">4</dimension>
</capacity-dimensions>
<duration>600.0</duration>
<timeWindows>
<timeWindow>
<start>0.0</start>
<end>1.7976931348623157E308</end>
</timeWindow>
</timeWindows>
<name>Test</name>
</service>
<service id="6" type="service">
<location>
<id>js10</id>
<index>6</index>
</location>
<capacity-dimensions>
<dimension index="0">10</dimension>
</capacity-dimensions>
<duration>1500.0</duration>
<timeWindows>
<timeWindow>
<start>29700.0</start>
<end>32400.0</end>
</timeWindow>
</timeWindows>
<name>Test</name>
</service>
<service id="7" type="service">
<location>
<id>jsp3</id>
<index>7</index>
</location>
<capacity-dimensions>
<dimension index="0">0</dimension>
</capacity-dimensions>
<duration>5594.0</duration>
<timeWindows>
<timeWindow>
<start>0.0</start>
<end>1.7976931348623157E308</end>
</timeWindow>
</timeWindows>
<name>Test</name>
</service>
</services>
<shipments>
<shipment id="shipment1">
<pickup>
<location>
<id>jsp1</id>
<index>1</index>
</location>
<duration>900.0</duration>
<timeWindows>
<timeWindow>
<start>0.0</start>
<end>1.7976931348623157E308</end>
</timeWindow>
</timeWindows>
</pickup>
<delivery>
<location>
<id>jsd1</id>
<index>8</index>
</location>
<duration>900.0</duration>
<timeWindows>
<timeWindow>
<start>0.0</start>
<end>1.7976931348623157E308</end>
</timeWindow>
</timeWindows>
</delivery>
<capacity-dimensions>
<dimension index="0">0</dimension>
</capacity-dimensions>
<name>Test</name>
</shipment>
<shipment id="shipment2">
<pickup>
<location>
<id>jsp4</id>
<index>9</index>
</location>
<duration>1200.0</duration>
<timeWindows>
<timeWindow>
<start>21600.0</start>
<end>23400.0</end>
</timeWindow>
</timeWindows>
</pickup>
<delivery>
<location>
<id>jsd4</id>
<index>8</index>
</location>
<duration>900.0</duration>
<timeWindows>
<timeWindow>
<start>25200.0</start>
<end>27000.0</end>
</timeWindow>
</timeWindows>
</delivery>
<capacity-dimensions>
<dimension index="0">0</dimension>
</capacity-dimensions>
<name>Test</name>
</shipment>
<shipment id="shipment3">
<pickup>
<location>
<id>jsp7</id>
<index>9</index>
</location>
<duration>1200.0</duration>
<timeWindows>
<timeWindow>
<start>37800.0</start>
<end>41400.0</end>
</timeWindow>
</timeWindows>
</pickup>
<delivery>
<location>
<id>jsd7</id>
<index>8</index>
</location>
<duration>1800.0</duration>
<timeWindows>
<timeWindow>
<start>43200.0</start>
<end>45900.0</end>
</timeWindow>
</timeWindows>
</delivery>
<capacity-dimensions>
<dimension index="0">0</dimension>
</capacity-dimensions>
<name>Test</name>
</shipment>
<shipment id="shipment4">
<pickup>
<location>
<id>jsp9</id>
<index>10</index>
</location>
<duration>300.0</duration>
<timeWindows>
<timeWindow>
<start>45000.0</start>
<end>48600.0</end>
</timeWindow>
</timeWindows>
</pickup>
<delivery>
<location>
<id>jsd9</id>
<index>8</index>
</location>
<duration>300.0</duration>
<timeWindows>
<timeWindow>
<start>50400.0</start>
<end>52200.0</end>
</timeWindow>
</timeWindows>
</delivery>
<capacity-dimensions>
<dimension index="0">0</dimension>
</capacity-dimensions>
<name>Test</name>
</shipment>
</shipments>
</problem>