From 3f67a13ae43f0046f2126a76146e82ae835cb959 Mon Sep 17 00:00:00 2001 From: Stefan Schroeder <4sschroeder@gmail.com> Date: Mon, 2 Sep 2013 18:04:54 +0200 Subject: [PATCH] add example input --- .../input/pd_christophides_vrpnc1_vcap50.xml | 635 +++++++++ ...> pickups_and_deliveries_solomon_c101.xml} | 0 ...nd_deliveries_solomon_c101_withoutTWs.xml} | 0 .../pickups_and_deliveries_solomon_r101.xml | 1235 +++++++++++++++++ ...nd_deliveries_solomon_r101_withoutTWs.xml} | 0 .../examples/PickupAndDeliveryExample.java | 11 +- .../examples/PickupAndDeliveryExample2.java | 93 ++ .../examples/VRPWithBackhaulsExample.java | 11 +- .../examples/VRPWithBackhaulsExample2.java | 93 ++ 9 files changed, 2071 insertions(+), 7 deletions(-) create mode 100644 jsprit-examples/input/pd_christophides_vrpnc1_vcap50.xml rename jsprit-examples/input/{pickups_and_deliveries_tw_solomon_c101.xml => pickups_and_deliveries_solomon_c101.xml} (100%) rename jsprit-examples/input/{pickups_and_deliveries_solomon_withoutTWs_c101.xml => pickups_and_deliveries_solomon_c101_withoutTWs.xml} (100%) create mode 100644 jsprit-examples/input/pickups_and_deliveries_solomon_r101.xml rename jsprit-examples/input/{pickups_and_deliveries_tw_solomon_r101.xml => pickups_and_deliveries_solomon_r101_withoutTWs.xml} (100%) create mode 100644 jsprit-examples/src/main/java/examples/PickupAndDeliveryExample2.java create mode 100644 jsprit-examples/src/main/java/examples/VRPWithBackhaulsExample2.java diff --git a/jsprit-examples/input/pd_christophides_vrpnc1_vcap50.xml b/jsprit-examples/input/pd_christophides_vrpnc1_vcap50.xml new file mode 100644 index 00000000..d35d0432 --- /dev/null +++ b/jsprit-examples/input/pd_christophides_vrpnc1_vcap50.xml @@ -0,0 +1,635 @@ + + + + INFINITE + HOMOGENEOUS + + + + christophidesVehicle + christophidesType + + [x=30.0][y=40.0] + + + + 0.0 + 999999.0 + + + + + + christophidesType + 50 + + 0.0 + 1.0 + + + + + + + [x=62.0][y=63.0] + + 17 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=63.0][y=69.0] + + 6 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=46.0][y=10.0] + + 23 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=61.0][y=33.0] + + 26 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=59.0][y=15.0] + + 14 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=32.0][y=22.0] + + 9 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=45.0][y=35.0] + + 15 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=5.0][y=64.0] + + 11 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=21.0][y=10.0] + + 13 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=10.0][y=17.0] + + 27 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=5.0][y=6.0] + + 7 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=42.0][y=57.0] + + 8 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=16.0][y=57.0] + + 16 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=8.0][y=52.0] + + 10 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=7.0][y=38.0] + + 28 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=27.0][y=68.0] + + 7 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=30.0][y=48.0] + + 15 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=43.0][y=67.0] + + 14 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=58.0][y=48.0] + + 6 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=52.0][y=64.0] + + 16 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=49.0][y=49.0] + + 30 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=37.0][y=52.0] + + 7 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=17.0][y=63.0] + + 19 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=58.0][y=27.0] + + 19 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=21.0][y=47.0] + + 15 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=40.0][y=30.0] + + 21 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=38.0][y=46.0] + + 12 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=20.0][y=26.0] + + 9 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=37.0][y=69.0] + + 11 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=52.0][y=33.0] + + 11 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=31.0][y=62.0] + + 23 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=13.0][y=13.0] + + 9 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=27.0][y=23.0] + + 3 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=17.0][y=33.0] + + 41 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=36.0][y=16.0] + + 10 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=52.0][y=41.0] + + 15 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=5.0][y=25.0] + + 23 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=12.0][y=42.0] + + 21 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=42.0][y=41.0] + + 19 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=31.0][y=32.0] + + 29 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=62.0][y=42.0] + + 8 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=57.0][y=58.0] + + 28 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=48.0][y=28.0] + + 18 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=25.0][y=55.0] + + 17 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=39.0][y=10.0] + + 10 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=30.0][y=15.0] + + 16 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=25.0][y=32.0] + + 25 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=32.0][y=39.0] + + 5 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=51.0][y=21.0] + + 5 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=56.0][y=37.0] + + 10 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + diff --git a/jsprit-examples/input/pickups_and_deliveries_tw_solomon_c101.xml b/jsprit-examples/input/pickups_and_deliveries_solomon_c101.xml similarity index 100% rename from jsprit-examples/input/pickups_and_deliveries_tw_solomon_c101.xml rename to jsprit-examples/input/pickups_and_deliveries_solomon_c101.xml diff --git a/jsprit-examples/input/pickups_and_deliveries_solomon_withoutTWs_c101.xml b/jsprit-examples/input/pickups_and_deliveries_solomon_c101_withoutTWs.xml similarity index 100% rename from jsprit-examples/input/pickups_and_deliveries_solomon_withoutTWs_c101.xml rename to jsprit-examples/input/pickups_and_deliveries_solomon_c101_withoutTWs.xml diff --git a/jsprit-examples/input/pickups_and_deliveries_solomon_r101.xml b/jsprit-examples/input/pickups_and_deliveries_solomon_r101.xml new file mode 100644 index 00000000..cda89ffa --- /dev/null +++ b/jsprit-examples/input/pickups_and_deliveries_solomon_r101.xml @@ -0,0 +1,1235 @@ + + + + INFINITE + HOMOGENEOUS + + + + solomonVehicle + solomonType + + 0 + + + + 0.0 + 230.0 + + + + + + solomonType + 200 + + 0.0 + 1.0 + + + + + + + [x=63.0][y=65.0] + + 8 + 10.0 + + + 143.0 + 153.0 + + + + + [x=2.0][y=60.0] + + 5 + 10.0 + + + 41.0 + 51.0 + + + + + [x=53.0][y=52.0] + + 11 + 10.0 + + + 37.0 + 47.0 + + + + + [x=65.0][y=55.0] + + 14 + 10.0 + + + 117.0 + 127.0 + + + + + [x=60.0][y=12.0] + + 31 + 10.0 + + + 44.0 + 54.0 + + + + + [x=20.0][y=20.0] + + 8 + 10.0 + + + 134.0 + 144.0 + + + + + [x=5.0][y=5.0] + + 16 + 10.0 + + + 83.0 + 93.0 + + + + + [x=23.0][y=3.0] + + 7 + 10.0 + + + 132.0 + 142.0 + + + + + [x=24.0][y=12.0] + + 5 + 10.0 + + + 31.0 + 41.0 + + + + + [x=42.0][y=7.0] + + 5 + 10.0 + + + 97.0 + 107.0 + + + + + [x=40.0][y=25.0] + + 9 + 10.0 + + + 85.0 + 95.0 + + + + + [x=45.0][y=10.0] + + 18 + 10.0 + + + 97.0 + 107.0 + + + + + [x=55.0][y=5.0] + + 29 + 10.0 + + + 68.0 + 78.0 + + + + + [x=65.0][y=35.0] + + 3 + 10.0 + + + 153.0 + 163.0 + + + + + [x=65.0][y=20.0] + + 6 + 10.0 + + + 172.0 + 182.0 + + + + + [x=45.0][y=30.0] + + 17 + 10.0 + + + 132.0 + 142.0 + + + + + [x=35.0][y=40.0] + + 16 + 10.0 + + + 37.0 + 47.0 + + + + + [x=41.0][y=37.0] + + 16 + 10.0 + + + 39.0 + 49.0 + + + + + [x=64.0][y=42.0] + + 9 + 10.0 + + + 63.0 + 73.0 + + + + + [x=55.0][y=45.0] + + 13 + 10.0 + + + 116.0 + 126.0 + + + + + [x=35.0][y=17.0] + + 7 + 10.0 + + + 50.0 + 60.0 + + + + + [x=41.0][y=49.0] + + 10 + 10.0 + + + 161.0 + 171.0 + + + + + [x=40.0][y=60.0] + + 21 + 10.0 + + + 71.0 + 81.0 + + + + + [x=20.0][y=50.0] + + 5 + 10.0 + + + 81.0 + 91.0 + + + + + [x=25.0][y=30.0] + + 3 + 10.0 + + + 99.0 + 109.0 + + + + + [x=15.0][y=30.0] + + 26 + 10.0 + + + 34.0 + 44.0 + + + + + [x=35.0][y=69.0] + + 23 + 10.0 + + + 141.0 + 151.0 + + + + + [x=55.0][y=20.0] + + 19 + 10.0 + + + 149.0 + 159.0 + + + + + [x=31.0][y=52.0] + + 27 + 10.0 + + + 50.0 + 60.0 + + + + + [x=55.0][y=60.0] + + 16 + 10.0 + + + 97.0 + 107.0 + + + + + [x=10.0][y=43.0] + + 9 + 10.0 + + + 95.0 + 105.0 + + + + + [x=15.0][y=60.0] + + 17 + 10.0 + + + 76.0 + 86.0 + + + + + [x=5.0][y=30.0] + + 2 + 10.0 + + + 157.0 + 167.0 + + + + + [x=20.0][y=40.0] + + 12 + 10.0 + + + 87.0 + 97.0 + + + + + [x=30.0][y=5.0] + + 8 + 10.0 + + + 61.0 + 71.0 + + + + + [x=10.0][y=20.0] + + 19 + 10.0 + + + 75.0 + 85.0 + + + + + [x=30.0][y=25.0] + + 23 + 10.0 + + + 159.0 + 169.0 + + + + + [x=15.0][y=10.0] + + 20 + 10.0 + + + 32.0 + 42.0 + + + + + [x=20.0][y=65.0] + + 12 + 10.0 + + + 67.0 + 77.0 + + + + + [x=50.0][y=35.0] + + 19 + 10.0 + + + 63.0 + 73.0 + + + + + [x=45.0][y=20.0] + + 11 + 10.0 + + + 62.0 + 72.0 + + + + + [x=45.0][y=65.0] + + 9 + 10.0 + + + 126.0 + 136.0 + + + + + [x=20.0][y=26.0] + + 9 + 10.0 + + + 83.0 + 93.0 + + + + + [x=18.0][y=18.0] + + 17 + 10.0 + + + 185.0 + 195.0 + + + + + [x=19.0][y=21.0] + + 10 + 10.0 + + + 58.0 + 68.0 + + + + + [x=25.0][y=21.0] + + 12 + 10.0 + + + 133.0 + 143.0 + + + + + [x=22.0][y=27.0] + + 11 + 10.0 + + + 135.0 + 145.0 + + + + + [x=25.0][y=24.0] + + 20 + 10.0 + + + 39.0 + 49.0 + + + + + [x=26.0][y=27.0] + + 27 + 10.0 + + + 100.0 + 110.0 + + + + + [x=18.0][y=24.0] + + 22 + 10.0 + + + 188.0 + 198.0 + + + + + [x=22.0][y=22.0] + + 2 + 10.0 + + + 18.0 + 28.0 + + + + + [x=15.0][y=19.0] + + 1 + 10.0 + + + 160.0 + 170.0 + + + + + [x=31.0][y=67.0] + + 3 + 10.0 + + + 95.0 + 105.0 + + + + + [x=30.0][y=60.0] + + 16 + 10.0 + + + 124.0 + 134.0 + + + + + [x=26.0][y=52.0] + + 9 + 10.0 + + + 74.0 + 84.0 + + + + + [x=26.0][y=35.0] + + 15 + 10.0 + + + 176.0 + 186.0 + + + + + [x=57.0][y=48.0] + + 23 + 10.0 + + + 92.0 + 102.0 + + + + + [x=61.0][y=52.0] + + 3 + 10.0 + + + 96.0 + 106.0 + + + + + [x=53.0][y=43.0] + + 14 + 10.0 + + + 179.0 + 189.0 + + + + + [x=15.0][y=47.0] + + 16 + 10.0 + + + 55.0 + 65.0 + + + + + [x=14.0][y=37.0] + + 11 + 10.0 + + + 44.0 + 54.0 + + + + + [x=56.0][y=37.0] + + 6 + 10.0 + + + 182.0 + 192.0 + + + + + [x=55.0][y=54.0] + + 26 + 10.0 + + + 94.0 + 104.0 + + + + + [x=4.0][y=18.0] + + 35 + 10.0 + + + 94.0 + 104.0 + + + + + [x=28.0][y=18.0] + + 26 + 10.0 + + + 93.0 + 103.0 + + + + + [x=11.0][y=31.0] + + 7 + 10.0 + + + 101.0 + 111.0 + + + + + [x=16.0][y=22.0] + + 41 + 10.0 + + + 91.0 + 101.0 + + + + + [x=67.0][y=5.0] + + 25 + 10.0 + + + 83.0 + 93.0 + + + + + [x=49.0][y=73.0] + + 25 + 10.0 + + + 127.0 + 137.0 + + + + + [x=37.0][y=47.0] + + 6 + 10.0 + + + 50.0 + 60.0 + + + + + [x=56.0][y=39.0] + + 36 + 10.0 + + + 142.0 + 152.0 + + + + + [x=37.0][y=56.0] + + 5 + 10.0 + + + 182.0 + 192.0 + + + + + [x=57.0][y=68.0] + + 15 + 10.0 + + + 77.0 + 87.0 + + + + + [x=47.0][y=16.0] + + 25 + 10.0 + + + 35.0 + 45.0 + + + + + [x=44.0][y=17.0] + + 9 + 10.0 + + + 78.0 + 88.0 + + + + + [x=46.0][y=13.0] + + 8 + 10.0 + + + 149.0 + 159.0 + + + + + [x=49.0][y=11.0] + + 18 + 10.0 + + + 69.0 + 79.0 + + + + + [x=49.0][y=42.0] + + 13 + 10.0 + + + 73.0 + 83.0 + + + + + [x=21.0][y=24.0] + + 28 + 10.0 + + + 18.0 + 28.0 + + + + + [x=36.0][y=26.0] + + 18 + 10.0 + + + 200.0 + 210.0 + + + + + [x=32.0][y=12.0] + + 7 + 10.0 + + + 101.0 + 111.0 + + + + + [x=53.0][y=12.0] + + 6 + 10.0 + + + 130.0 + 140.0 + + + + + [x=63.0][y=23.0] + + 2 + 10.0 + + + 136.0 + 146.0 + + + + + [x=15.0][y=77.0] + + 9 + 10.0 + + + 73.0 + 83.0 + + + + + [x=62.0][y=77.0] + + 20 + 10.0 + + + 51.0 + 61.0 + + + + + [x=24.0][y=58.0] + + 19 + 10.0 + + + 58.0 + 68.0 + + + + + [x=27.0][y=69.0] + + 10 + 10.0 + + + 34.0 + 44.0 + + + + + [x=17.0][y=34.0] + + 3 + 10.0 + + + 162.0 + 172.0 + + + + + [x=12.0][y=24.0] + + 13 + 10.0 + + + 76.0 + 86.0 + + + + + [x=6.0][y=68.0] + + 30 + 10.0 + + + 108.0 + 118.0 + + + + + [x=13.0][y=52.0] + + 36 + 10.0 + + + 165.0 + 175.0 + + + + + [x=6.0][y=38.0] + + 16 + 10.0 + + + 32.0 + 42.0 + + + + + [x=11.0][y=14.0] + + 18 + 10.0 + + + 69.0 + 79.0 + + + + + [x=8.0][y=56.0] + + 27 + 10.0 + + + 51.0 + 61.0 + + + + + [x=2.0][y=48.0] + + 1 + 10.0 + + + 117.0 + 127.0 + + + + + [x=49.0][y=58.0] + + 10 + 10.0 + + + 88.0 + 98.0 + + + + + [x=27.0][y=43.0] + + 9 + 10.0 + + + 52.0 + 62.0 + + + + + [x=37.0][y=31.0] + + 14 + 10.0 + + + 95.0 + 105.0 + + + + + [x=57.0][y=29.0] + + 18 + 10.0 + + + 140.0 + 150.0 + + + + + [x=47.0][y=47.0] + + 13 + 10.0 + + + 124.0 + 134.0 + + + + + diff --git a/jsprit-examples/input/pickups_and_deliveries_tw_solomon_r101.xml b/jsprit-examples/input/pickups_and_deliveries_solomon_r101_withoutTWs.xml similarity index 100% rename from jsprit-examples/input/pickups_and_deliveries_tw_solomon_r101.xml rename to jsprit-examples/input/pickups_and_deliveries_solomon_r101_withoutTWs.xml diff --git a/jsprit-examples/src/main/java/examples/PickupAndDeliveryExample.java b/jsprit-examples/src/main/java/examples/PickupAndDeliveryExample.java index f851366d..b7f72257 100644 --- a/jsprit-examples/src/main/java/examples/PickupAndDeliveryExample.java +++ b/jsprit-examples/src/main/java/examples/PickupAndDeliveryExample.java @@ -6,6 +6,8 @@ import java.util.Collection; import algorithms.VehicleRoutingAlgorithms; import algorithms.selectors.SelectBest; import analysis.AlgorithmSearchProgressChartListener; +import analysis.Plotter; +import analysis.Plotter.Label; import analysis.SolutionPlotter; import analysis.SolutionPrinter; import analysis.SolutionPrinter.Print; @@ -40,7 +42,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_tw_solomon_r101.xml"); + new VrpXMLReader(vrpBuilder).read("input/pickups_and_deliveries_solomon_r101.xml"); /* * Finally, the problem can be built. By default, transportCosts are crowFlyDistances (as usually used for vrp-instances). @@ -78,8 +80,11 @@ public class PickupAndDeliveryExample { /* * Plot solution. */ - SolutionPlotter.plotSolutionAsPNG(vrp, solution, "output/pd_solomon_r101_solution.png","pd_r101"); - +// 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.png","pd_r101"); diff --git a/jsprit-examples/src/main/java/examples/PickupAndDeliveryExample2.java b/jsprit-examples/src/main/java/examples/PickupAndDeliveryExample2.java new file mode 100644 index 00000000..827a4c48 --- /dev/null +++ b/jsprit-examples/src/main/java/examples/PickupAndDeliveryExample2.java @@ -0,0 +1,93 @@ +package examples; + +import java.io.File; +import java.util.Collection; + +import algorithms.VehicleRoutingAlgorithms; +import algorithms.selectors.SelectBest; +import analysis.AlgorithmSearchProgressChartListener; +import analysis.Plotter; +import analysis.Plotter.Label; +import analysis.SolutionPlotter; +import analysis.SolutionPrinter; +import analysis.SolutionPrinter.Print; +import basics.VehicleRoutingAlgorithm; +import basics.VehicleRoutingProblem; +import basics.VehicleRoutingProblemSolution; +import basics.VehicleRoutingProblem.Constraint; +import basics.io.VrpXMLReader; + +public class PickupAndDeliveryExample2 { + + 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/pd_christophides_vrpnc1_vcap50.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_christophides_vrpnc1.png", "pd_vrpnc1"); + + /* + * 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_solomon.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, Print.VERBOSE); + + /* + * 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_christophides_vrpnc1.png","pd_vrpnc1"); + + + + } + +} diff --git a/jsprit-examples/src/main/java/examples/VRPWithBackhaulsExample.java b/jsprit-examples/src/main/java/examples/VRPWithBackhaulsExample.java index 5c142589..e07b7b2e 100644 --- a/jsprit-examples/src/main/java/examples/VRPWithBackhaulsExample.java +++ b/jsprit-examples/src/main/java/examples/VRPWithBackhaulsExample.java @@ -6,8 +6,10 @@ import java.util.Collection; import algorithms.VehicleRoutingAlgorithms; import algorithms.selectors.SelectBest; import analysis.AlgorithmSearchProgressChartListener; +import analysis.Plotter; import analysis.SolutionPlotter; import analysis.SolutionPrinter; +import analysis.Plotter.Label; import analysis.SolutionPrinter.Print; import basics.VehicleRoutingAlgorithm; import basics.VehicleRoutingProblem; @@ -40,7 +42,7 @@ public class VRPWithBackhaulsExample { /* * A solomonReader reads solomon-instance files, and stores the required information in the builder. */ - new VrpXMLReader(vrpBuilder).read("input/pickups_and_deliveries_tw_solomon_r101.xml"); + new VrpXMLReader(vrpBuilder).read("input/pickups_and_deliveries_solomon_r101.xml"); /* * Finally, the problem can be built. By default, transportCosts are crowFlyDistances (as usually used for vrp-instances). @@ -78,9 +80,10 @@ public class VRPWithBackhaulsExample { /* * Plot solution. */ - SolutionPlotter.plotSolutionAsPNG(vrp, solution, "output/pd_withBackhauls_solomon_r101_solution.png","pd_withBackhauls_r101"); - - + Plotter plotter = new Plotter(vrp, solution); + plotter.setLabel(Label.SIZE); + plotter.setShowFirstActivity(true); + plotter.plot("output/pd_withBackhauls_solomon_r101_solution.png","pd_withBackhauls_r101"); } diff --git a/jsprit-examples/src/main/java/examples/VRPWithBackhaulsExample2.java b/jsprit-examples/src/main/java/examples/VRPWithBackhaulsExample2.java new file mode 100644 index 00000000..c12dbfb9 --- /dev/null +++ b/jsprit-examples/src/main/java/examples/VRPWithBackhaulsExample2.java @@ -0,0 +1,93 @@ +package examples; + +import java.io.File; +import java.util.Collection; + +import algorithms.VehicleRoutingAlgorithms; +import algorithms.selectors.SelectBest; +import analysis.AlgorithmSearchProgressChartListener; +import analysis.Plotter; +import analysis.Plotter.Label; +import analysis.SolutionPlotter; +import analysis.SolutionPrinter; +import analysis.SolutionPrinter.Print; +import basics.VehicleRoutingAlgorithm; +import basics.VehicleRoutingProblem; +import basics.VehicleRoutingProblemSolution; +import basics.VehicleRoutingProblem.Constraint; +import basics.io.VrpXMLReader; + +public class VRPWithBackhaulsExample2 { + + 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/pd_christophides_vrpnc1_vcap50.xml"); + + /* + * Finally, the problem can be built. By default, transportCosts are crowFlyDistances (as usually used for vrp-instances). + */ + vrpBuilder.addProblemConstraint(Constraint.DELIVERIES_FIRST); + VehicleRoutingProblem vrp = vrpBuilder.build(); + + SolutionPlotter.plotVrpAsPNG(vrp, "output/pd_christophides_vrpnc1.png", "pd_vrpnc1"); + + /* + * 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_solomon.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, Print.VERBOSE); + + /* + * 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/vrpwbh_christophides_vrpnc1.png","vrpwbh_vrpnc1"); + + + + } + +}