From 2291bd23c213ad5a9a2a9b7b8b25b73da5fd0ab5 Mon Sep 17 00:00:00 2001 From: Stefan Schroeder <4sschroeder@gmail.com> Date: Fri, 29 Nov 2013 11:59:02 +0100 Subject: [PATCH] add Examples and testTemplate for open-routes --- .../TestCalculatesServiceInsertion.java | 8 +- ...alculatesServiceInsertionOnRouteLevel.java | 7 + .../route/VehicleRouteBuilderTest.java | 16 + .../test/resources/infiniteWriterV2Test.xml | 2 + .../input/algorithmConfig_open.xml | 71 + ...eliveries_solomon_r101_withoutTWs_open.xml | 1236 +++++++++++++++++ .../examples/PickupAndDeliveryExample.java | 2 +- .../PickupAndDeliveryOpenExample.java | 108 ++ 8 files changed, 1448 insertions(+), 2 deletions(-) create mode 100755 jsprit-examples/input/algorithmConfig_open.xml create mode 100644 jsprit-examples/input/pickups_and_deliveries_solomon_r101_withoutTWs_open.xml create mode 100644 jsprit-examples/src/main/java/jsprit/examples/PickupAndDeliveryOpenExample.java diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestCalculatesServiceInsertion.java b/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestCalculatesServiceInsertion.java index 5ee1abf7..c634b076 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestCalculatesServiceInsertion.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestCalculatesServiceInsertion.java @@ -16,6 +16,7 @@ ******************************************************************************/ package jsprit.core.algorithm.recreate; +import static org.junit.Assert.*; import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -80,12 +81,14 @@ public class TestCalculatesServiceInsertion { when(vehicle.getLocationId()).thenReturn("depot"); when(vehicle.getEarliestDeparture()).thenReturn(0.0); when(vehicle.getLatestArrival()).thenReturn(100.0); + when(vehicle.isReturnToDepot()).thenReturn(true); newVehicle = mock(Vehicle.class); when(newVehicle.getCapacity()).thenReturn(1000); when(newVehicle.getLocationId()).thenReturn("depot"); when(newVehicle.getEarliestDeparture()).thenReturn(0.0); when(newVehicle.getLatestArrival()).thenReturn(100.0); + when(newVehicle.isReturnToDepot()).thenReturn(true); driver = DriverImpl.noDriver(); @@ -264,6 +267,9 @@ public class TestCalculatesServiceInsertion { assertEquals(2, iData.getDeliveryInsertionIndex()); } - + @Test + public void whenInsertingAndRouteIsOpen(){ + assertTrue(false); + } } diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestCalculatesServiceInsertionOnRouteLevel.java b/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestCalculatesServiceInsertionOnRouteLevel.java index 46e7f430..0c621a74 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestCalculatesServiceInsertionOnRouteLevel.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestCalculatesServiceInsertionOnRouteLevel.java @@ -17,6 +17,7 @@ package jsprit.core.algorithm.recreate; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -239,4 +240,10 @@ public class TestCalculatesServiceInsertionOnRouteLevel { assertEquals(2, iData.getDeliveryInsertionIndex()); } + @Test + public void whenInsertingAndRouteIsOpen(){ + assertTrue(false); + } + + } diff --git a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/VehicleRouteBuilderTest.java b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/VehicleRouteBuilderTest.java index b9219432..5d998aaa 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/VehicleRouteBuilderTest.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/VehicleRouteBuilderTest.java @@ -1,5 +1,6 @@ package jsprit.core.problem.solution.route; +import static org.junit.Assert.*; import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.mock; import jsprit.core.problem.driver.Driver; @@ -58,4 +59,19 @@ public class VehicleRouteBuilderTest { assertEquals(4,route.getTourActivities().getActivities().size()); } + @Test + public void whenBuildingOpenRoute(){ + assertTrue(false); + } + + @Test + public void whenSettingDepartureTime(){ + assertTrue(false); + } + + + @Test + public void whenSettingEndTime(){ + assertTrue(false); + } } diff --git a/jsprit-core/src/test/resources/infiniteWriterV2Test.xml b/jsprit-core/src/test/resources/infiniteWriterV2Test.xml index ec10a45f..4d5bf129 100644 --- a/jsprit-core/src/test/resources/infiniteWriterV2Test.xml +++ b/jsprit-core/src/test/resources/infiniteWriterV2Test.xml @@ -16,6 +16,7 @@ 0.0 1.7976931348623157E308 + true v2 @@ -27,6 +28,7 @@ 0.0 1.7976931348623157E308 + true diff --git a/jsprit-examples/input/algorithmConfig_open.xml b/jsprit-examples/input/algorithmConfig_open.xml new file mode 100755 index 00000000..e66a2ac3 --- /dev/null +++ b/jsprit-examples/input/algorithmConfig_open.xml @@ -0,0 +1,71 @@ + + + + + 2000 + + + + + + + + + 1 + + + + + + + + + 0.5 + + + + + + 0.5 + + + + + + + + + + 0.3 + + + + + + 0.5 + + + + + + diff --git a/jsprit-examples/input/pickups_and_deliveries_solomon_r101_withoutTWs_open.xml b/jsprit-examples/input/pickups_and_deliveries_solomon_r101_withoutTWs_open.xml new file mode 100644 index 00000000..46fba629 --- /dev/null +++ b/jsprit-examples/input/pickups_and_deliveries_solomon_r101_withoutTWs_open.xml @@ -0,0 +1,1236 @@ + + + + INFINITE + HOMOGENEOUS + + + + solomonVehicle + solomonType + + 0 + + + + 0.0 + 230.0 + + false + + + + + solomonType + 200 + + 0.0 + 1.0 + + + + + + + [x=63.0][y=65.0] + + 8 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=2.0][y=60.0] + + 5 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=53.0][y=52.0] + + 11 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=65.0][y=55.0] + + 14 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=60.0][y=12.0] + + 31 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=20.0][y=20.0] + + 8 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=5.0][y=5.0] + + 16 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=23.0][y=3.0] + + 7 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=24.0][y=12.0] + + 5 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=42.0][y=7.0] + + 5 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=40.0][y=25.0] + + 9 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=45.0][y=10.0] + + 18 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=55.0][y=5.0] + + 29 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=65.0][y=35.0] + + 3 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=65.0][y=20.0] + + 6 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=45.0][y=30.0] + + 17 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=35.0][y=40.0] + + 16 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=41.0][y=37.0] + + 16 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=64.0][y=42.0] + + 9 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=55.0][y=45.0] + + 13 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=35.0][y=17.0] + + 7 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=41.0][y=49.0] + + 10 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=40.0][y=60.0] + + 21 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=20.0][y=50.0] + + 5 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=25.0][y=30.0] + + 3 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=15.0][y=30.0] + + 26 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=35.0][y=69.0] + + 23 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=55.0][y=20.0] + + 19 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=31.0][y=52.0] + + 27 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=55.0][y=60.0] + + 16 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=10.0][y=43.0] + + 9 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=15.0][y=60.0] + + 17 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=5.0][y=30.0] + + 2 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=20.0][y=40.0] + + 12 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=30.0][y=5.0] + + 8 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=10.0][y=20.0] + + 19 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=30.0][y=25.0] + + 23 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=15.0][y=10.0] + + 20 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=20.0][y=65.0] + + 12 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=50.0][y=35.0] + + 19 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=45.0][y=20.0] + + 11 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=45.0][y=65.0] + + 9 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=20.0][y=26.0] + + 9 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=18.0][y=18.0] + + 17 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=19.0][y=21.0] + + 10 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=25.0][y=21.0] + + 12 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=22.0][y=27.0] + + 11 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=25.0][y=24.0] + + 20 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=26.0][y=27.0] + + 27 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=18.0][y=24.0] + + 22 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=22.0][y=22.0] + + 2 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=15.0][y=19.0] + + 1 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=31.0][y=67.0] + + 3 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=30.0][y=60.0] + + 16 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=26.0][y=52.0] + + 9 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=26.0][y=35.0] + + 15 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=57.0][y=48.0] + + 23 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=61.0][y=52.0] + + 3 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=53.0][y=43.0] + + 14 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=15.0][y=47.0] + + 16 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=14.0][y=37.0] + + 11 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=56.0][y=37.0] + + 6 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=55.0][y=54.0] + + 26 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=4.0][y=18.0] + + 35 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=28.0][y=18.0] + + 26 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=11.0][y=31.0] + + 7 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=16.0][y=22.0] + + 41 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=67.0][y=5.0] + + 25 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=49.0][y=73.0] + + 25 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=37.0][y=47.0] + + 6 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=56.0][y=39.0] + + 36 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=37.0][y=56.0] + + 5 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=57.0][y=68.0] + + 15 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=47.0][y=16.0] + + 25 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=44.0][y=17.0] + + 9 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=46.0][y=13.0] + + 8 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=49.0][y=11.0] + + 18 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=49.0][y=42.0] + + 13 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=21.0][y=24.0] + + 28 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=36.0][y=26.0] + + 18 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=32.0][y=12.0] + + 7 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=53.0][y=12.0] + + 6 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=63.0][y=23.0] + + 2 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=15.0][y=77.0] + + 9 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=62.0][y=77.0] + + 20 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=24.0][y=58.0] + + 19 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=27.0][y=69.0] + + 10 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=17.0][y=34.0] + + 3 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=12.0][y=24.0] + + 13 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=6.0][y=68.0] + + 30 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=13.0][y=52.0] + + 36 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=6.0][y=38.0] + + 16 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=11.0][y=14.0] + + 18 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=8.0][y=56.0] + + 27 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=2.0][y=48.0] + + 1 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=49.0][y=58.0] + + 10 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=27.0][y=43.0] + + 9 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=37.0][y=31.0] + + 14 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=57.0][y=29.0] + + 18 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=47.0][y=47.0] + + 13 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + diff --git a/jsprit-examples/src/main/java/jsprit/examples/PickupAndDeliveryExample.java b/jsprit-examples/src/main/java/jsprit/examples/PickupAndDeliveryExample.java index 30399f20..04aafdaa 100644 --- a/jsprit-examples/src/main/java/jsprit/examples/PickupAndDeliveryExample.java +++ b/jsprit-examples/src/main/java/jsprit/examples/PickupAndDeliveryExample.java @@ -57,7 +57,7 @@ public class PickupAndDeliveryExample { /* * A solomonReader reads solomon-instance files, and stores the required information in the builder. */ - new VrpXMLReader(vrpBuilder).read("input/pickups_and_deliveries_solomon_r101.xml"); + new VrpXMLReader(vrpBuilder).read("input/pickups_and_deliveries_solomon_r101_withoutTWs.xml"); /* * Finally, the problem can be built. By default, transportCosts are crowFlyDistances (as usually used for vrp-instances). diff --git a/jsprit-examples/src/main/java/jsprit/examples/PickupAndDeliveryOpenExample.java b/jsprit-examples/src/main/java/jsprit/examples/PickupAndDeliveryOpenExample.java new file mode 100644 index 00000000..340b595e --- /dev/null +++ b/jsprit-examples/src/main/java/jsprit/examples/PickupAndDeliveryOpenExample.java @@ -0,0 +1,108 @@ +/******************************************************************************* + * Copyright (C) 2013 Stefan Schroeder + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3.0 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + ******************************************************************************/ +package jsprit.examples; + +import java.io.File; +import java.util.Collection; + +import jsprit.analysis.toolbox.AlgorithmSearchProgressChartListener; +import jsprit.analysis.toolbox.Plotter; +import jsprit.analysis.toolbox.Plotter.Label; +import jsprit.analysis.toolbox.SolutionPlotter; +import jsprit.analysis.toolbox.SolutionPrinter; +import jsprit.core.algorithm.VehicleRoutingAlgorithm; +import jsprit.core.algorithm.io.VehicleRoutingAlgorithms; +import jsprit.core.algorithm.selector.SelectBest; +import jsprit.core.problem.VehicleRoutingProblem; +import jsprit.core.problem.io.VrpXMLReader; +import jsprit.core.problem.solution.VehicleRoutingProblemSolution; + + +public class PickupAndDeliveryOpenExample { + + public static void main(String[] args) { + + /* + * some preparation - create output folder + */ + File dir = new File("output"); + // if the directory does not exist, create it + if (!dir.exists()){ + System.out.println("creating directory ./output"); + boolean result = dir.mkdir(); + if(result) System.out.println("./output created"); + } + + /* + * Build the problem. + * + * But define a problem-builder first. + */ + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + + /* + * A solomonReader reads solomon-instance files, and stores the required information in the builder. + */ + new VrpXMLReader(vrpBuilder).read("input/pickups_and_deliveries_solomon_r101_withoutTWs_open.xml"); + + /* + * Finally, the problem can be built. By default, transportCosts are crowFlyDistances (as usually used for vrp-instances). + */ + + VehicleRoutingProblem vrp = vrpBuilder.build(); + +// SolutionPlotter.plotVrpAsPNG(vrp, "output/pd_solomon_r101_o.png", "pd_r101"); + + /* + * Define the required vehicle-routing algorithms to solve the above problem. + * + * The algorithm can be defined and configured in an xml-file. + */ +// VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp); + VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "input/algorithmConfig_open.xml"); + vra.getAlgorithmListeners().addListener(new AlgorithmSearchProgressChartListener("output/sol_progress.png")); + /* + * Solve the problem. + * + * + */ + Collection solutions = vra.searchSolutions(); + + /* + * Retrieve best solution. + */ + VehicleRoutingProblemSolution solution = new SelectBest().selectSolution(solutions); + + /* + * print solution + */ + SolutionPrinter.print(solution); + + /* + * Plot solution. + */ +// SolutionPlotter.plotSolutionAsPNG(vrp, solution, "output/pd_solomon_r101_solution.png","pd_r101"); + Plotter plotter = new Plotter(vrp, solution); + plotter.setLabel(Label.SIZE); + plotter.setShowFirstActivity(true); + plotter.plot("output/pd_solomon_r101_solution_open.png","pd_r101"); + + + + } + +}