From cfc7c5bc97fa0381efc1ce11bfd7b1a95e83df8d Mon Sep 17 00:00:00 2001 From: oblonski <4sschroeder@gmail.com> Date: Mon, 13 Jan 2014 22:40:46 +0100 Subject: [PATCH 01/25] add vrph instances --- .../instances/vrph/orig/c100_19mix.txt | 126 +++++++++++++++++ .../instances/vrph/orig/c100_20mix.txt | 128 ++++++++++++++++++ .../instances/vrph/orig/c20_3mix.txt | 29 ++++ .../instances/vrph/orig/c20_4mix.txt | 27 ++++ .../instances/vrph/orig/c20_5mix.txt | 29 ++++ .../instances/vrph/orig/c20_6mix.txt | 27 ++++ .../instances/vrph/orig/c50_13mix.txt | 73 ++++++++++ .../instances/vrph/orig/c50_14mix.txt | 67 +++++++++ .../instances/vrph/orig/c50_15mix.txt | 73 ++++++++++ .../instances/vrph/orig/c50_16mix.txt | 70 ++++++++++ .../instances/vrph/orig/c75_17mix.txt | 94 +++++++++++++ .../instances/vrph/orig/c75_18mix.txt | 124 +++++++++++++++++ .../jsprit/instance/util/Vrph2jsprit.java | 63 +++++++++ 13 files changed, 930 insertions(+) create mode 100644 jsprit-instances/instances/vrph/orig/c100_19mix.txt create mode 100644 jsprit-instances/instances/vrph/orig/c100_20mix.txt create mode 100644 jsprit-instances/instances/vrph/orig/c20_3mix.txt create mode 100644 jsprit-instances/instances/vrph/orig/c20_4mix.txt create mode 100644 jsprit-instances/instances/vrph/orig/c20_5mix.txt create mode 100644 jsprit-instances/instances/vrph/orig/c20_6mix.txt create mode 100644 jsprit-instances/instances/vrph/orig/c50_13mix.txt create mode 100644 jsprit-instances/instances/vrph/orig/c50_14mix.txt create mode 100644 jsprit-instances/instances/vrph/orig/c50_15mix.txt create mode 100644 jsprit-instances/instances/vrph/orig/c50_16mix.txt create mode 100644 jsprit-instances/instances/vrph/orig/c75_17mix.txt create mode 100644 jsprit-instances/instances/vrph/orig/c75_18mix.txt create mode 100644 jsprit-instances/src/main/java/jsprit/instance/util/Vrph2jsprit.java diff --git a/jsprit-instances/instances/vrph/orig/c100_19mix.txt b/jsprit-instances/instances/vrph/orig/c100_19mix.txt new file mode 100644 index 00000000..3eea2cb8 --- /dev/null +++ b/jsprit-instances/instances/vrph/orig/c100_19mix.txt @@ -0,0 +1,126 @@ + 100 + 0 35 35 0 + 1 41 49 10 + 2 35 17 7 + 3 55 45 13 + 4 55 20 19 + 5 15 30 26 + 6 25 30 3 + 7 20 50 5 + 8 10 43 9 + 9 55 60 16 + 10 30 60 16 + 11 20 65 12 + 12 50 35 19 + 13 30 25 23 + 14 15 10 20 + 15 30 5 8 + 16 10 20 19 + 17 5 30 2 + 18 20 40 12 + 19 15 60 17 + 20 45 65 9 + 21 45 20 11 + 22 45 10 18 + 23 55 5 29 + 24 65 35 3 + 25 65 20 6 + 26 45 30 17 + 27 35 40 16 + 28 41 37 16 + 29 64 42 9 + 30 40 60 21 + 31 31 52 27 + 32 35 69 23 + 33 53 52 11 + 34 65 55 14 + 35 63 65 8 + 36 2 60 5 + 37 20 20 8 + 38 5 5 16 + 39 60 12 31 + 40 40 25 9 + 41 42 7 5 + 42 24 12 5 + 43 23 3 7 + 44 11 14 18 + 45 6 38 16 + 46 2 48 1 + 47 8 56 27 + 48 13 52 36 + 49 6 68 30 + 50 47 47 13 + 51 49 58 10 + 52 27 43 9 + 53 37 31 14 + 54 57 29 18 + 55 63 23 2 + 56 53 12 6 + 57 32 12 7 + 58 36 26 18 + 59 21 24 28 + 60 17 34 3 + 61 12 24 13 + 62 24 58 19 + 63 27 69 10 + 64 15 77 9 + 65 62 77 20 + 66 49 73 25 + 67 67 5 25 + 68 56 39 36 + 69 37 47 6 + 70 37 56 5 + 71 57 68 15 + 72 47 16 25 + 73 44 17 9 + 74 46 13 8 + 75 49 11 18 + 76 49 42 13 + 77 53 43 14 + 78 61 52 3 + 79 57 48 23 + 80 56 37 6 + 81 55 54 26 + 82 15 47 16 + 83 14 37 11 + 84 11 31 7 + 85 16 22 41 + 86 4 18 35 + 87 28 18 26 + 88 26 52 9 + 89 26 35 15 + 90 31 67 3 + 91 15 19 1 + 92 22 22 2 + 93 18 24 22 + 94 26 27 27 + 95 25 24 20 + 96 22 27 11 + 97 25 21 12 + 98 19 21 10 + 99 20 26 9 + 100 18 18 17 +//Vehicles characteristics: volume, fixed cost, variable cost, number available +//See E. D. Taillard, "A heuristic column generation method for the heterogeneous fleet vrp" +//RAIRO Rech. Op�r. 33 (1) 1999, pp 1-14) +//see http://ina2.eivd.ch/collaborateurs/etd/articles.dir/vrphen.pdf +v 1 100 500 1.0 4 +v 2 200 1200 1.4 3 +v 3 300 2100 1.7 3 + +15 200 0 1000000 + 5 12 80 68 76 28 546700 + 6 77 3 79 81 33 50 560066 + 7 1 30 20 66 32 70 69 591171 + 9 51 9 71 65 35 34 78 29 24 626544 + 6 26 54 4 72 21 40 564109 + 8 53 73 74 75 22 41 2 58 566885 + 6 56 23 67 39 25 55 601888 + 4 59 85 93 99 546338 + 7 88 62 11 63 90 10 31 578753 + 7 8 46 47 36 49 64 19 623582 + 6 27 52 7 48 82 18 560521 + 4 94 95 87 13 540372 + 9 57 15 43 42 14 38 44 100 92 610131 + 9 89 60 83 45 17 84 5 96 6 571667 + 7 61 86 16 91 98 37 97 575109 diff --git a/jsprit-instances/instances/vrph/orig/c100_20mix.txt b/jsprit-instances/instances/vrph/orig/c100_20mix.txt new file mode 100644 index 00000000..28c6f1c2 --- /dev/null +++ b/jsprit-instances/instances/vrph/orig/c100_20mix.txt @@ -0,0 +1,128 @@ + 100 + 0 35 35 0 + 1 41 49 10 + 2 35 17 7 + 3 55 45 13 + 4 55 20 19 + 5 15 30 26 + 6 25 30 3 + 7 20 50 5 + 8 10 43 9 + 9 55 60 16 + 10 30 60 16 + 11 20 65 12 + 12 50 35 19 + 13 30 25 23 + 14 15 10 20 + 15 30 5 8 + 16 10 20 19 + 17 5 30 2 + 18 20 40 12 + 19 15 60 17 + 20 45 65 9 + 21 45 20 11 + 22 45 10 18 + 23 55 5 29 + 24 65 35 3 + 25 65 20 6 + 26 45 30 17 + 27 35 40 16 + 28 41 37 16 + 29 64 42 9 + 30 40 60 21 + 31 31 52 27 + 32 35 69 23 + 33 53 52 11 + 34 65 55 14 + 35 63 65 8 + 36 2 60 5 + 37 20 20 8 + 38 5 5 16 + 39 60 12 31 + 40 40 25 9 + 41 42 7 5 + 42 24 12 5 + 43 23 3 7 + 44 11 14 18 + 45 6 38 16 + 46 2 48 1 + 47 8 56 27 + 48 13 52 36 + 49 6 68 30 + 50 47 47 13 + 51 49 58 10 + 52 27 43 9 + 53 37 31 14 + 54 57 29 18 + 55 63 23 2 + 56 53 12 6 + 57 32 12 7 + 58 36 26 18 + 59 21 24 28 + 60 17 34 3 + 61 12 24 13 + 62 24 58 19 + 63 27 69 10 + 64 15 77 9 + 65 62 77 20 + 66 49 73 25 + 67 67 5 25 + 68 56 39 36 + 69 37 47 6 + 70 37 56 5 + 71 57 68 15 + 72 47 16 25 + 73 44 17 9 + 74 46 13 8 + 75 49 11 18 + 76 49 42 13 + 77 53 43 14 + 78 61 52 3 + 79 57 48 23 + 80 56 37 6 + 81 55 54 26 + 82 15 47 16 + 83 14 37 11 + 84 11 31 7 + 85 16 22 41 + 86 4 18 35 + 87 28 18 26 + 88 26 52 9 + 89 26 35 15 + 90 31 67 3 + 91 15 19 1 + 92 22 22 2 + 93 18 24 22 + 94 26 27 27 + 95 25 24 20 + 96 22 27 11 + 97 25 21 12 + 98 19 21 10 + 99 20 26 9 + 100 18 18 17 +//Vehicles characteristics: volume, fixed cost, variable cost, number available +//See E. D. Taillard, "A heuristic column generation method for the heterogeneous fleet vrp" +//RAIRO Rech. Op�r. 33 (1) 1999, pp 1-14) +//see http://ina2.eivd.ch/collaborateurs/etd/articles.dir/vrphen.pdf +v 1 60 100 1.0 6 +v 2 140 300 1.7 4 +v 3 200 500 2.0 3 + +17 200 0 100000 1190.858809 + 11*100 + 6*300 = 4090.86 + 2 12 68 143589 + 4 76 3 77 28 144929 + 6 79 78 34 29 24 80 186635 + 7 18 83 8 45 17 84 60 175014 + 4 26 72 73 40 148608 + 5 21 74 75 22 41 165933 + 3 87 97 95 140494 + 3 13 58 53 126834 + 4 50 33 81 1 157707 + 6 42 14 43 15 57 2 183736 + 3 27 89 94 135338 + 8 52 7 48 47 19 11 62 88 383651 + 10 31 10 32 90 63 64 49 36 46 82 429222 + 10 51 9 35 71 65 66 20 30 70 69 415471 + 9 5 61 16 86 38 44 91 98 92 394398 + 8 59 37 100 85 93 99 96 6 352542 + 8 4 56 23 67 39 25 55 54 406754 diff --git a/jsprit-instances/instances/vrph/orig/c20_3mix.txt b/jsprit-instances/instances/vrph/orig/c20_3mix.txt new file mode 100644 index 00000000..9003a6d2 --- /dev/null +++ b/jsprit-instances/instances/vrph/orig/c20_3mix.txt @@ -0,0 +1,29 @@ +20 + 0 30 40 0 + 1 37 52 7 + 2 49 49 30 + 3 52 64 16 + 4 20 26 9 + 5 40 30 21 + 6 21 47 15 + 7 17 63 19 + 8 31 62 23 + 9 52 33 11 + 10 51 21 5 + 11 42 41 19 + 12 31 32 29 + 13 5 25 23 + 14 12 42 21 + 15 36 16 10 + 16 52 41 15 + 17 27 23 3 + 18 17 33 41 + 19 13 13 9 + 20 57 58 28 +//Vehicles characteristics: type, volume, fixed cost +5 +v 1 20 20 +v 2 30 35 +v 3 40 50 +v 4 70 120 +v 5 120 225 diff --git a/jsprit-instances/instances/vrph/orig/c20_4mix.txt b/jsprit-instances/instances/vrph/orig/c20_4mix.txt new file mode 100644 index 00000000..f7dd9eaa --- /dev/null +++ b/jsprit-instances/instances/vrph/orig/c20_4mix.txt @@ -0,0 +1,27 @@ +20 + 0 30 40 0 + 1 37 52 7 + 2 49 49 30 + 3 52 64 16 + 4 20 26 9 + 5 40 30 21 + 6 21 47 15 + 7 17 63 19 + 8 31 62 23 + 9 52 33 11 + 10 51 21 5 + 11 42 41 19 + 12 31 32 29 + 13 5 25 23 + 14 12 42 21 + 15 36 16 10 + 16 52 41 15 + 17 27 23 3 + 18 17 33 41 + 19 13 13 9 + 20 57 58 28 +//Vehicles characteristics: type, volume, fixed cost +3 +v 1 60 1000 +v 2 80 1500 +v 3 150 3000 diff --git a/jsprit-instances/instances/vrph/orig/c20_5mix.txt b/jsprit-instances/instances/vrph/orig/c20_5mix.txt new file mode 100644 index 00000000..5a9c33e7 --- /dev/null +++ b/jsprit-instances/instances/vrph/orig/c20_5mix.txt @@ -0,0 +1,29 @@ +20 + 0 30 40 0 + 1 37 52 7 + 2 49 49 30 + 3 52 64 16 + 4 20 26 9 + 5 40 30 21 + 6 21 47 15 + 7 17 63 19 + 8 31 62 23 + 9 52 33 11 + 10 51 21 5 + 11 42 41 19 + 12 31 32 29 + 13 5 25 23 + 14 12 42 21 + 15 36 16 10 + 16 52 41 15 + 17 27 23 3 + 18 17 33 41 + 19 13 13 9 + 20 57 58 28 +//Vehicles characteristics: type, volume, fixed cost +5 +v 1 20 20 +v 2 30 35 +v 3 40 50 +v 4 70 120 +v 5 120 225 \ No newline at end of file diff --git a/jsprit-instances/instances/vrph/orig/c20_6mix.txt b/jsprit-instances/instances/vrph/orig/c20_6mix.txt new file mode 100644 index 00000000..f7dd9eaa --- /dev/null +++ b/jsprit-instances/instances/vrph/orig/c20_6mix.txt @@ -0,0 +1,27 @@ +20 + 0 30 40 0 + 1 37 52 7 + 2 49 49 30 + 3 52 64 16 + 4 20 26 9 + 5 40 30 21 + 6 21 47 15 + 7 17 63 19 + 8 31 62 23 + 9 52 33 11 + 10 51 21 5 + 11 42 41 19 + 12 31 32 29 + 13 5 25 23 + 14 12 42 21 + 15 36 16 10 + 16 52 41 15 + 17 27 23 3 + 18 17 33 41 + 19 13 13 9 + 20 57 58 28 +//Vehicles characteristics: type, volume, fixed cost +3 +v 1 60 1000 +v 2 80 1500 +v 3 150 3000 diff --git a/jsprit-instances/instances/vrph/orig/c50_13mix.txt b/jsprit-instances/instances/vrph/orig/c50_13mix.txt new file mode 100644 index 00000000..9e58fa13 --- /dev/null +++ b/jsprit-instances/instances/vrph/orig/c50_13mix.txt @@ -0,0 +1,73 @@ +50 + 0 40 40 0 + 1 22 22 18 + 2 36 26 26 + 3 21 45 11 + 4 45 35 30 + 5 55 20 21 + 6 33 34 19 + 7 50 50 15 + 8 55 45 16 + 9 26 59 29 + 10 40 66 26 + 11 55 65 37 + 12 35 51 16 + 13 62 35 12 + 14 62 57 31 + 15 62 24 8 + 16 21 36 19 + 17 33 44 20 + 18 9 56 13 + 19 62 48 15 + 20 66 14 22 + 21 44 13 28 + 22 26 13 12 + 23 11 28 6 + 24 7 43 27 + 25 17 64 14 + 26 41 46 18 + 27 55 34 17 + 28 35 16 29 + 29 52 26 13 + 30 43 26 22 + 31 31 76 25 + 32 22 53 28 + 33 26 29 27 + 34 50 40 19 + 35 55 50 10 + 36 54 10 12 + 37 60 15 14 + 38 47 66 24 + 39 30 60 16 + 40 30 50 33 + 41 12 17 15 + 42 15 14 11 + 43 16 19 18 + 44 21 48 17 + 45 50 30 21 + 46 51 42 27 + 47 50 15 19 + 48 48 21 20 + 49 12 38 5 + 50 15 56 22 +//Vehicles characteristics: type, volume, fixed cost, variable cost, number available +6 +v 1 20 20 1.0 4 +v 2 30 35 1.1 2 +v 3 40 50 1.2 4 +v 4 70 120 1.7 4 +v 5 120 225 2.5 2 +v 6 200 400 3.2 1 + + +best solution with fixed costs: 588.784723 + 20 + 3*35 + 2*50 + 4*400 = 2413.78 + 2 27 13 807876 + 1 26 321656 + 2 17 12 774254 + 2 34 8 828825 + 1 46 573606 + 1 4 491422 + 9 39 31 10 38 11 14 19 35 7 5129601 + 11 2 28 22 1 43 42 41 23 16 33 6 5102713 + 10 40 32 9 25 50 18 24 49 3 44 5096803 + 11 30 48 21 47 36 37 20 15 5 29 45 5011089 diff --git a/jsprit-instances/instances/vrph/orig/c50_14mix.txt b/jsprit-instances/instances/vrph/orig/c50_14mix.txt new file mode 100644 index 00000000..a0689d17 --- /dev/null +++ b/jsprit-instances/instances/vrph/orig/c50_14mix.txt @@ -0,0 +1,67 @@ +50 + 0 40 40 0 + 1 22 22 18 + 2 36 26 26 + 3 21 45 11 + 4 45 35 30 + 5 55 20 21 + 6 33 34 19 + 7 50 50 15 + 8 55 45 16 + 9 26 59 29 + 10 40 66 26 + 11 55 65 37 + 12 35 51 16 + 13 62 35 12 + 14 62 57 31 + 15 62 24 8 + 16 21 36 19 + 17 33 44 20 + 18 9 56 13 + 19 62 48 15 + 20 66 14 22 + 21 44 13 28 + 22 26 13 12 + 23 11 28 6 + 24 7 43 27 + 25 17 64 14 + 26 41 46 18 + 27 55 34 17 + 28 35 16 29 + 29 52 26 13 + 30 43 26 22 + 31 31 76 25 + 32 22 53 28 + 33 26 29 27 + 34 50 40 19 + 35 55 50 10 + 36 54 10 12 + 37 60 15 14 + 38 47 66 24 + 39 30 60 16 + 40 30 50 33 + 41 12 17 15 + 42 15 14 11 + 43 16 19 18 + 44 21 48 17 + 45 50 30 21 + 46 51 42 27 + 47 50 15 19 + 48 48 21 20 + 49 12 38 5 + 50 15 56 22 +//Vehicles characteristics: volume, fixed cost, variable cost, number available +v 1 120 1000 1.0 4 +v 2 160 1500 1.1 2 +v 3 300 3500 1.4 1 + +160 +8 300 0 10000 625.679906 + 7*1000 + 1500 = + 7 26 7 35 19 8 46 34 10530637 + 4 10 38 11 14 10794953 + 8 33 1 43 42 41 23 49 16 10916479 + 6 48 47 36 21 28 22 10931709 + 7 27 13 15 20 37 5 29 10832981 + 6 44 32 50 18 24 3 10862722 + 5 6 2 30 45 4 10469680 + 7 12 39 31 25 9 40 17 15917639 diff --git a/jsprit-instances/instances/vrph/orig/c50_15mix.txt b/jsprit-instances/instances/vrph/orig/c50_15mix.txt new file mode 100644 index 00000000..bdd1a2e5 --- /dev/null +++ b/jsprit-instances/instances/vrph/orig/c50_15mix.txt @@ -0,0 +1,73 @@ +50 + 0 30 40 0 + 1 37 52 7 + 2 49 49 30 + 3 52 64 16 + 4 20 26 9 + 5 40 30 21 + 6 21 47 15 + 7 17 63 19 + 8 31 62 23 + 9 52 33 11 + 10 51 21 5 + 11 42 41 19 + 12 31 32 29 + 13 5 25 23 + 14 12 42 21 + 15 36 16 10 + 16 52 41 15 + 17 27 23 3 + 18 17 33 41 + 19 13 13 9 + 20 57 58 28 + 21 62 42 8 + 22 42 57 8 + 23 16 57 16 + 24 8 52 10 + 25 7 38 28 + 26 27 68 7 + 27 30 48 15 + 28 43 67 14 + 29 58 48 6 + 30 58 27 19 + 31 37 69 11 + 32 38 46 12 + 33 46 10 23 + 34 61 33 26 + 35 62 63 17 + 36 63 69 6 + 37 32 22 9 + 38 45 35 15 + 39 59 15 14 + 40 5 6 7 + 41 10 17 27 + 42 21 10 13 + 43 5 64 11 + 44 30 15 16 + 45 39 10 10 + 46 32 39 5 + 47 25 32 25 + 48 25 55 17 + 49 48 28 18 + 50 56 37 10 +//Vehicles characteristics: volume, fixed cost, variable cost, number available +//See E. D. Taillard, "A heuristic column generation method for the heterogeneous fleet vrp" +//RAIRO Rech. Op�r. 33 (1) 1999, pp 1-14) +//see http://ina2.eivd.ch/collaborateurs/etd/articles.dir/vrphen.pdf +v 1 50 100 1.0 4 +v 2 100 250 1.6 3 +v 3 160 450 2.0 2 + +12 160 0 9999999 798.063541 + 8*100 + 4*250 = 2598.06 + 4 24 43 7 26 1888114 + 3 11 16 38 1470725 + 2 25 14 1476007 + 3 6 23 48 1476130 + 3 28 31 8 1675334 + 3 1 2 32 1476635 + 2 4 18 1395853 + 2 47 27 1341971 + 7 12 37 15 45 33 39 10 3412795 + 7 13 41 40 19 42 44 17 3559482 + 6 5 49 30 34 9 46 3212631 + 8 22 3 36 35 20 29 21 50 3594959 diff --git a/jsprit-instances/instances/vrph/orig/c50_16mix.txt b/jsprit-instances/instances/vrph/orig/c50_16mix.txt new file mode 100644 index 00000000..44d1104c --- /dev/null +++ b/jsprit-instances/instances/vrph/orig/c50_16mix.txt @@ -0,0 +1,70 @@ +50 + 0 30 40 0 + 1 37 52 7 + 2 49 49 30 + 3 52 64 16 + 4 20 26 9 + 5 40 30 21 + 6 21 47 15 + 7 17 63 19 + 8 31 62 23 + 9 52 33 11 + 10 51 21 5 + 11 42 41 19 + 12 31 32 29 + 13 5 25 23 + 14 12 42 21 + 15 36 16 10 + 16 52 41 15 + 17 27 23 3 + 18 17 33 41 + 19 13 13 9 + 20 57 58 28 + 21 62 42 8 + 22 42 57 8 + 23 16 57 16 + 24 8 52 10 + 25 7 38 28 + 26 27 68 7 + 27 30 48 15 + 28 43 67 14 + 29 58 48 6 + 30 58 27 19 + 31 37 69 11 + 32 38 46 12 + 33 46 10 23 + 34 61 33 26 + 35 62 63 17 + 36 63 69 6 + 37 32 22 9 + 38 45 35 15 + 39 59 15 14 + 40 5 6 7 + 41 10 17 27 + 42 21 10 13 + 43 5 64 11 + 44 30 15 16 + 45 39 10 10 + 46 32 39 5 + 47 25 32 25 + 48 25 55 17 + 49 48 28 18 + 50 56 37 10 + +v 1 40 100 1.0 2 +v 2 80 200 1.6 4 +v 3 140 400 2.1 3 + +10 140 0 9999999 741.499345 + 10*200 = 2741.50 + 3 18 4 47 2396248 + 6 15 45 33 39 10 49 2916243 + 5 12 17 44 37 5 2591911 + 4 38 16 2 11 2562466 + 5 24 43 7 23 48 2805845 + 6 29 20 35 36 3 1 2975090 + 5 13 41 40 19 42 3011668 + 6 50 21 34 30 9 46 2813483 + 6 8 26 31 28 22 32 2773629 + 4 27 6 14 25 2568409 + + diff --git a/jsprit-instances/instances/vrph/orig/c75_17mix.txt b/jsprit-instances/instances/vrph/orig/c75_17mix.txt new file mode 100644 index 00000000..c137802e --- /dev/null +++ b/jsprit-instances/instances/vrph/orig/c75_17mix.txt @@ -0,0 +1,94 @@ +75 + 0 40 40 0 + 1 22 22 18 + 2 36 26 26 + 3 21 45 11 + 4 45 35 30 + 5 55 20 21 + 6 33 34 19 + 7 50 50 15 + 8 55 45 16 + 9 26 59 29 + 10 40 66 26 + 11 55 65 37 + 12 35 51 16 + 13 62 35 12 + 14 62 57 31 + 15 62 24 8 + 16 21 36 19 + 17 33 44 20 + 18 9 56 13 + 19 62 48 15 + 20 66 14 22 + 21 44 13 28 + 22 26 13 12 + 23 11 28 6 + 24 7 43 27 + 25 17 64 14 + 26 41 46 18 + 27 55 34 17 + 28 35 16 29 + 29 52 26 13 + 30 43 26 22 + 31 31 76 25 + 32 22 53 28 + 33 26 29 27 + 34 50 40 19 + 35 55 50 10 + 36 54 10 12 + 37 60 15 14 + 38 47 66 24 + 39 30 60 16 + 40 30 50 33 + 41 12 17 15 + 42 15 14 11 + 43 16 19 18 + 44 21 48 17 + 45 50 30 21 + 46 51 42 27 + 47 50 15 19 + 48 48 21 20 + 49 12 38 5 + 50 15 56 22 + 51 29 39 12 + 52 54 38 19 + 53 55 57 22 + 54 67 41 16 + 55 10 70 7 + 56 6 25 26 + 57 65 27 14 + 58 40 60 21 + 59 70 64 24 + 60 64 4 13 + 61 36 6 15 + 62 30 20 18 + 63 20 30 11 + 64 15 5 28 + 65 50 70 9 + 66 57 72 37 + 67 45 42 30 + 68 38 33 10 + 69 50 4 8 + 70 66 8 11 + 71 59 5 3 + 72 35 60 1 + 73 27 24 6 + 74 40 20 10 + 75 40 37 20 +//Vehicles characteristics: volume, fixed cost, variable cost, number available +//See E. D. Taillard, "A heuristic column generation method for the heterogeneous fleet vrp" +//RAIRO Rech. Op�r. 33 (1) 1999, pp 1-14) +//see http://ina2.eivd.ch/collaborateurs/etd/articles.dir/vrphen.pdf50 25 1.0 4 +v 1 120 80 1.2 4 +v 2 200 150 1.5 2 +v 3 350 320 1.8 1 + +7 350 0 1000000 703.124497 + 7 * 150 = 1753.12 + 14 27 57 15 37 20 70 60 71 69 36 47 5 29 45 2685412 + 8 7 53 14 59 11 66 65 38 2518938 + 11 51 16 49 24 18 50 25 55 31 10 58 2837925 + 10 26 12 72 39 9 32 44 3 40 17 2223923 + 12 6 33 63 23 56 41 43 42 64 22 1 73 2669773 + 10 67 34 46 8 35 19 54 13 52 4 2218010 + 10 68 2 62 28 61 21 74 48 30 75 2377261 + diff --git a/jsprit-instances/instances/vrph/orig/c75_18mix.txt b/jsprit-instances/instances/vrph/orig/c75_18mix.txt new file mode 100644 index 00000000..b2bc5cfe --- /dev/null +++ b/jsprit-instances/instances/vrph/orig/c75_18mix.txt @@ -0,0 +1,124 @@ +75 + 0 40 40 0 + 1 22 22 18 + 2 36 26 26 + 3 21 45 11 + 4 45 35 30 + 5 55 20 21 + 6 33 34 19 + 7 50 50 15 + 8 55 45 16 + 9 26 59 29 + 10 40 66 26 + 11 55 65 37 + 12 35 51 16 + 13 62 35 12 + 14 62 57 31 + 15 62 24 8 + 16 21 36 19 + 17 33 44 20 + 18 9 56 13 + 19 62 48 15 + 20 66 14 22 + 21 44 13 28 + 22 26 13 12 + 23 11 28 6 + 24 7 43 27 + 25 17 64 14 + 26 41 46 18 + 27 55 34 17 + 28 35 16 29 + 29 52 26 13 + 30 43 26 22 + 31 31 76 25 + 32 22 53 28 + 33 26 29 27 + 34 50 40 19 + 35 55 50 10 + 36 54 10 12 + 37 60 15 14 + 38 47 66 24 + 39 30 60 16 + 40 30 50 33 + 41 12 17 15 + 42 15 14 11 + 43 16 19 18 + 44 21 48 17 + 45 50 30 21 + 46 51 42 27 + 47 50 15 19 + 48 48 21 20 + 49 12 38 5 + 50 15 56 22 + 51 29 39 12 + 52 54 38 19 + 53 55 57 22 + 54 67 41 16 + 55 10 70 7 + 56 6 25 26 + 57 65 27 14 + 58 40 60 21 + 59 70 64 24 + 60 64 4 13 + 61 36 6 15 + 62 30 20 18 + 63 20 30 11 + 64 15 5 28 + 65 50 70 9 + 66 57 72 37 + 67 45 42 30 + 68 38 33 10 + 69 50 4 8 + 70 66 8 11 + 71 59 5 3 + 72 35 60 1 + 73 27 24 6 + 74 40 20 10 + 75 40 37 20 +//Vehicles characteristics: volume, fixed cost, variable cost, number available +//See E. D. Taillard, "A heuristic column generation method for the heterogeneous fleet vrp" +//RAIRO Rech. Op�r. 33 (1) 1999, pp 1-14) +//see http://ina2.eivd.ch/collaborateurs/etd/articles.dir/vrphen.pdf +v 1 20 10 1.0 4 +v 2 50 35 1.3 4 +v 3 100 100 1.9 2 +v 4 150 180 2.4 2 +v 5 250 400 2.9 1 +v 6 400 800 3.2 1 + + +16 400 0 1000000 + 2 4 75 504563 + 2 40 12 663241 + 2 34 46 584164 + 2 6 33 706263 + 2 26 67 521249 + 4 59 66 65 38 1928889 + 5 30 48 47 21 74 1621004 + 8 36 69 71 60 70 20 37 29 2030669 + 6 8 35 14 19 54 13 1786844 + 6 32 25 55 18 50 3 1957187 + 6 45 5 15 57 27 52 1680991 + 6 17 44 24 49 16 51 1714575 + 5 9 39 31 10 72 1856344 + 4 58 11 53 7 1665558 + 5 2 28 61 22 62 1772896 + 10 63 23 56 41 64 42 43 1 73 68 2874657 + + 2 40 12 663241 + 2 2 30 708780 + 2 34 46 584164 + 2 6 33 706263 + 2 26 67 521249 + 4 59 66 65 38 1928889 + 8 61 69 36 71 60 70 20 37 2163283 + 6 8 35 14 19 54 13 1786844 + 7 63 23 56 41 43 1 73 1845922 + 6 32 25 55 18 50 3 1957187 + 6 45 5 15 57 27 52 1680991 + 6 17 44 24 49 16 51 1714575 + 5 9 39 31 10 72 1856344 + 4 58 11 53 7 1665558 + 5 28 22 64 42 62 1951198 + 2 4 75 504563 + 6 68 74 21 47 48 29 1659867 diff --git a/jsprit-instances/src/main/java/jsprit/instance/util/Vrph2jsprit.java b/jsprit-instances/src/main/java/jsprit/instance/util/Vrph2jsprit.java new file mode 100644 index 00000000..09c918bc --- /dev/null +++ b/jsprit-instances/src/main/java/jsprit/instance/util/Vrph2jsprit.java @@ -0,0 +1,63 @@ +package jsprit.instance.util; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; + +import jsprit.core.problem.VehicleRoutingProblem; +import jsprit.core.problem.job.Service; +import jsprit.core.problem.vehicle.Vehicle; +import jsprit.core.problem.vehicle.VehicleImpl; +import jsprit.core.problem.vehicle.VehicleTypeImpl; +import jsprit.core.util.Coordinate; + +public class Vrph2jsprit { + + + public static void main(String[] args) throws IOException { + + for(int i=3;i<7;i++){ + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + String instance = "vrph/orig/c20_"+i+"mix.txt"; + BufferedReader reader = new BufferedReader(new FileReader(new File(instance))); + String line = null; + boolean firstline = true; + Coordinate depotCoord = null; + int customerCount=0; + while((line=reader.readLine())!=null){ + String trimedLine = line.trim(); + if(trimedLine.startsWith("//")) continue; + String[] tokens = trimedLine.split("\\s+"); + Integer nuOfCustomer = 0; + if(firstline){ + nuOfCustomer=Integer.parseInt(line); + customerCount=1; + firstline=false; + } + else if(customerCount<=nuOfCustomer) { + if(customerCount == 1){ + depotCoord = Coordinate.newInstance(Double.parseDouble(tokens[1]), Double.parseDouble(tokens[2])); + } + else{ + Service.Builder serviceBuilder = Service.Builder.newInstance(tokens[0], Integer.parseInt(tokens[0])); + serviceBuilder.setCoord(Coordinate.newInstance(Double.parseDouble(tokens[1]), Double.parseDouble(tokens[2]))); + vrpBuilder.addJob(serviceBuilder.build()); + customerCount++; + } + } + else if(trimedLine.startsWith("v")){ + VehicleTypeImpl.Builder typeBuilder = VehicleTypeImpl.Builder.newInstance("type_"+tokens[1], Integer.parseInt(tokens[2])); + typeBuilder.setFixedCost(Double.parseDouble(tokens[3])); + typeBuilder.setCostPerDistance(1.0); + VehicleTypeImpl type = typeBuilder.build(); + Vehicle vehicle = VehicleImpl.Builder.newInstance("vehicle_"+tokens[1]).setType(type).build(); + } + + } + reader.close(); + } + + } + +} From aca07a98f27acfb63e219ae43b5e548073159ed5 Mon Sep 17 00:00:00 2001 From: oblonski <4sschroeder@gmail.com> Date: Mon, 13 Jan 2014 22:57:05 +0100 Subject: [PATCH 02/25] add javadoc to vehicleType --- .../core/problem/vehicle/VehicleType.java | 29 ++++++- .../core/problem/vehicle/VehicleTypeImpl.java | 83 ++++++++++++++++++- 2 files changed, 108 insertions(+), 4 deletions(-) diff --git a/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleType.java b/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleType.java index 1f6da049..ab45dfa7 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleType.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleType.java @@ -18,15 +18,42 @@ package jsprit.core.problem.vehicle; import jsprit.core.problem.vehicle.VehicleTypeImpl.VehicleCostParams; - +/** + * Basic interface for vehicle-type-data. + * + * @author schroeder + * + */ public interface VehicleType { + /** + * Returns typeId. + * + * @return typeId + */ public String getTypeId(); + /** + * Returns capacity. + * + *
In future versions there will be a capacity-object with an arbitrary number of capacity dimensions. (stefan,11.01.14) + * + * @return cap + */ public int getCapacity(); + /** + * Returns maximum velocity of this vehicle-type. + * + * @return max velocity + */ public double getMaxVelocity(); + /** + * Return the cost-parameter of this vehicle-type. + * + * @return parameter + */ public VehicleCostParams getVehicleCostParams(); } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleTypeImpl.java b/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleTypeImpl.java index 828f3058..f0404396 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleTypeImpl.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleTypeImpl.java @@ -16,9 +16,22 @@ ******************************************************************************/ package jsprit.core.problem.vehicle; - +/** + * Implementation of {@link VehicleType}. + * + *
Two vehicle-types are equal if they have the same typeId. + * + * @author schroeder + * + */ public class VehicleTypeImpl implements VehicleType { + /** + * CostParameter consisting of fixed cost parameter, time-based cost parameter and distance-based cost parameter. + * + * @author schroeder + * + */ public static class VehicleCostParams { public static VehicleTypeImpl.VehicleCostParams newInstance(double fix, double perTimeUnit,double perDistanceUnit){ @@ -42,9 +55,24 @@ public class VehicleTypeImpl implements VehicleType { } } - + /** + * Builder that builds the vehicle-type. + * + * @author schroeder + * + */ public static class Builder{ + /** + * Returns a new instance. + * + *
Input parameters are id and capacity. Note that two vehicle-types are equal + * if they have the same vehicleId. + * + * @param id + * @param capacity + * @return + */ public static VehicleTypeImpl.Builder newInstance(String id, int capacity){ return new Builder(id,capacity); } @@ -59,20 +87,61 @@ public class VehicleTypeImpl implements VehicleType { private double perDistance = 1.0; private double perTime = 0.0; - public Builder(String id, int capacity) { + /** + * Constructs the builder. + * + * @param id + * @param capacity + */ + private Builder(String id, int capacity) { super(); this.id = id; this.capacity = capacity; } + /** + * Sets the maximum velocity this vehicle-type can go [in meter per seconds]. + * + * @param inMeterPerSeconds + * @return this builder + */ public VehicleTypeImpl.Builder setMaxVelocity(double inMeterPerSeconds){ this.maxVelo = inMeterPerSeconds; return this; } + /** + * Sets the fixed costs of the vehicle-type. + * + *
by default it is 0. + * + * @param fixedCost + * @return this builder + */ public VehicleTypeImpl.Builder setFixedCost(double fixedCost) { this.fixedCost = fixedCost; return this; } + /** + * Sets the cost per distance unit, for instance € per meter. + * + *
by default it is 1.0 + * + * @param perDistance + * @return this builder + */ public VehicleTypeImpl.Builder setCostPerDistance(double perDistance){ this.perDistance = perDistance; return this; } + /** + * Sets cost per time unit, for instance € per second. + * + *
by default it is 0.0
+ *
+ * @param perTime
+ * @return
+ */
public VehicleTypeImpl.Builder setCostPerTime(double perTime){ this.perTime = perTime; return this; }
+ /**
+ * Builds the vehicle-type.
+ *
+ * @return
+ */
public VehicleTypeImpl build(){
return new VehicleTypeImpl(this);
}
@@ -88,6 +157,9 @@ public class VehicleTypeImpl implements VehicleType {
return result;
}
+ /**
+ * Two vehicle-types are equal if they have the same vehicleId.
+ */
@Override
public boolean equals(Object obj) {
if (this == obj)
@@ -121,6 +193,11 @@ public class VehicleTypeImpl implements VehicleType {
return new VehicleTypeImpl(typeId, capacity, para);
}
+ /**
+ * priv constructor constructing vehicle-type
+ *
+ * @param builder
+ */
private VehicleTypeImpl(VehicleTypeImpl.Builder builder){
typeId = builder.id;
capacity = builder.capacity;
From 5954371789686f4affcad73f1a9a6ef2ff235976 Mon Sep 17 00:00:00 2001
From: oblonski <4sschroeder@gmail.com>
Date: Mon, 13 Jan 2014 23:01:49 +0100
Subject: [PATCH 03/25] vrph
---
.../src/main/java/jsprit/instance/util/Vrph2jsprit.java | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/jsprit-instances/src/main/java/jsprit/instance/util/Vrph2jsprit.java b/jsprit-instances/src/main/java/jsprit/instance/util/Vrph2jsprit.java
index 09c918bc..c69527a3 100644
--- a/jsprit-instances/src/main/java/jsprit/instance/util/Vrph2jsprit.java
+++ b/jsprit-instances/src/main/java/jsprit/instance/util/Vrph2jsprit.java
@@ -51,7 +51,10 @@ public class Vrph2jsprit {
typeBuilder.setFixedCost(Double.parseDouble(tokens[3]));
typeBuilder.setCostPerDistance(1.0);
VehicleTypeImpl type = typeBuilder.build();
- Vehicle vehicle = VehicleImpl.Builder.newInstance("vehicle_"+tokens[1]).setType(type).build();
+ Vehicle vehicle = VehicleImpl.Builder.newInstance("vehicle_"+tokens[1])
+ .setLocationCoord(depotCoord).setType(type).build();
+ vrpBuilder.addVehicle(vehicle);
+// vrpBuilder.s
}
}
From c4bd72bae800357e1499e053646c223270671f68 Mon Sep 17 00:00:00 2001
From: oblonski <4sschroeder@gmail.com>
Date: Mon, 13 Jan 2014 23:08:03 +0100
Subject: [PATCH 04/25] refine javaDoc
---
.../core/problem/VehicleRoutingProblem.java | 22 +++++++++++--------
1 file changed, 13 insertions(+), 9 deletions(-)
diff --git a/jsprit-core/src/main/java/jsprit/core/problem/VehicleRoutingProblem.java b/jsprit-core/src/main/java/jsprit/core/problem/VehicleRoutingProblem.java
index 56d2c28e..2ba256cb 100644
--- a/jsprit-core/src/main/java/jsprit/core/problem/VehicleRoutingProblem.java
+++ b/jsprit-core/src/main/java/jsprit/core/problem/VehicleRoutingProblem.java
@@ -138,6 +138,10 @@ public class VehicleRoutingProblem {
}
};
+ /**
+ * @deprecated use static method .newInstance() instead
+ */
+ @Deprecated
public Builder() {
jobs = new HashMap FleetSize is either FleetSize.INFINITE or FleetSize.FINITE
+ * FleetSize is either FleetSize.INFINITE or FleetSize.FINITE. By default it is FleetSize.INFINITE.
*
* @param fleetSize
- * @return
+ * @return this builder
*/
public Builder setFleetSize(FleetSize fleetSize){
this.fleetSize = fleetSize;
@@ -225,7 +229,7 @@ public class VehicleRoutingProblem {
* Note that job.getId() must be unique, i.e. no job (either it is a shipment or a service) is allowed to have an already allocated id.
*
* @param job
- * @return
+ * @return this builder
* @throws IllegalStateException if job is neither a shipment nor a service, or jobId has already been added.
*/
public Builder addJob(Job job) {
@@ -254,7 +258,7 @@ public class VehicleRoutingProblem {
*
*
* @param vehicle
- * @return
+ * @return this builder
*/
public Builder addVehicle(Vehicle vehicle) {
vehicles.add(vehicle);
@@ -271,7 +275,7 @@ public class VehicleRoutingProblem {
* By default it is set to zero.
*
* @param activityCosts
- * @return
+ * @return this builder
* @see VehicleRoutingActivityCosts
*/
public Builder setActivityCosts(VehicleRoutingActivityCosts activityCosts){
@@ -304,7 +308,7 @@ public class VehicleRoutingProblem {
* Adds a collection of jobs.
*
* @param jobs which is a collection of jobs that subclasses Job
- * @return
+ * @return this builder
*/
public Builder addAllJobs(Collection extends Job> jobs) {
for(Job j : jobs){
@@ -317,7 +321,7 @@ public class VehicleRoutingProblem {
* Adds a collection of vehicles.
*
* @param vehicles
- * @return
+ * @return this builder
*/
public Builder addAllVehicles(Collection diff. options of VrphType yields to different problem types for
* - vrphe with infinite fleet, i.e. different types with different variable costs and infinite number of vehicles of each type
* - vrphe with finite fleet, i.e. different types with different variable costs and finite number of vehicles of each type
- * - vfm, different types with different fixed costs
+ * - vfm, different types with different fixed costs
+ * - vfmvrc different types with different fixed costs and variable costs
*
+ * cxxx3-cxxx6 do not have variable costs and nuVehicle, thus they can only be used for vfm.
*
* @author schroeder
*
*/
public class VrphGoldenReader {
+ /**
+ *
+ * VRPHE_INFINITE - different types with different variable costs and infinite number of vehicles of each type
+ * VRPHE_FINITE - different types with different variable costs and finite number of vehicles of each type
+ * VFM - different types with different fixed costs
+ * VFMVRC - different types with different fixed costs and variable costs
+ *
+ * @author schroeder
+ *
+ */
public enum VrphType {
VRPH_INFINITE, VRPH_FINITE, VFM, VFMVRC
}
From 8272554e8e6b5a9cc7890da2272a5b4d3f7716ef Mon Sep 17 00:00:00 2001
From: oblonski <4sschroeder@gmail.com>
Date: Tue, 14 Jan 2014 09:44:38 -0500
Subject: [PATCH 07/25] add and test .getAddedVehicleTypes()
---
.../core/problem/VehicleRoutingProblem.java | 9 ++++
.../problem/VehicleRoutingProblemTest.java | 42 +++++++++++++++++++
2 files changed, 51 insertions(+)
diff --git a/jsprit-core/src/main/java/jsprit/core/problem/VehicleRoutingProblem.java b/jsprit-core/src/main/java/jsprit/core/problem/VehicleRoutingProblem.java
index 2ba256cb..4e98f7ca 100644
--- a/jsprit-core/src/main/java/jsprit/core/problem/VehicleRoutingProblem.java
+++ b/jsprit-core/src/main/java/jsprit/core/problem/VehicleRoutingProblem.java
@@ -339,6 +339,15 @@ public class VehicleRoutingProblem {
return Collections.unmodifiableCollection(vehicles);
}
+ /**
+ * Gets an unmodifiable collection of already added vehicle-types.
+ *
+ * @returns collection of vehicle-types
+ */
+ public Collection This only makes sense for FleetSize.FINITE. Thus, penaltyVehicles are only added if is FleetSize.FINITE.
+ * The id of penaltyVehicles is constructed as follows vehicleId = "penaltyVehicle" + "_" + {locationId} + "_" + {typeId}.
+ * By default: no penalty-vehicles are added
+ *
+ * @param penaltyFactor
+ * @return this builder
+ */
+ public Builder addPenaltyVehicles(double penaltyFactor){
+ this.addPenaltyVehicles = true;
+ this.penaltyFactor = penaltyFactor;
+ return this;
+ }
+
/**
* Returns an unmodifiable collection of already added jobs.
*
diff --git a/jsprit-core/src/test/java/jsprit/core/problem/VehicleRoutingProblemTest.java b/jsprit-core/src/test/java/jsprit/core/problem/VehicleRoutingProblemTest.java
index f9030222..e5aff4cf 100644
--- a/jsprit-core/src/test/java/jsprit/core/problem/VehicleRoutingProblemTest.java
+++ b/jsprit-core/src/test/java/jsprit/core/problem/VehicleRoutingProblemTest.java
@@ -17,6 +17,8 @@
package jsprit.core.problem;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -321,4 +323,126 @@ public class VehicleRoutingProblemTest {
assertEquals(2,builder.getAddedVehicleTypes().size());
}
+
+ @Test
+ public void whenSettingAddPenaltyVehicleOptions_itShouldAddPenaltyVehicle(){
+ VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
+ VehicleType type = VehicleTypeImpl.Builder.newInstance("type", 0).build();
+ Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setLocationId("loc").setType(type).build();
+
+ builder.addVehicle(vehicle);
+ builder.setFleetSize(FleetSize.FINITE);
+ builder.addPenaltyVehicles(3.0);
+
+ VehicleRoutingProblem vrp = builder.build();
+
+ assertEquals(2,vrp.getVehicles().size());
+
+ boolean penaltyVehicleInCollection = false;
+ for(Vehicle v : vrp.getVehicles()){
+ if(v.getId().equals("penaltyVehicle_loc_type")) penaltyVehicleInCollection = true;
+ }
+ assertTrue(penaltyVehicleInCollection);
+
+ }
+
+ @Test
+ public void whenSettingAddPenaltyVehicleOptionsAndFleetSizeIsInfinite_noPenaltyVehicleIsAdded(){
+ VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
+ VehicleType type = VehicleTypeImpl.Builder.newInstance("type", 0).build();
+ Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setLocationId("loc").setType(type).build();
+
+ builder.addVehicle(vehicle);
+ builder.addPenaltyVehicles(3.0);
+
+ VehicleRoutingProblem vrp = builder.build();
+
+ assertEquals(1,vrp.getVehicles().size());
+
+ boolean penaltyVehicleInCollection = false;
+ for(Vehicle v : vrp.getVehicles()){
+ if(v.getId().equals("penaltyVehicle_loc_type")) penaltyVehicleInCollection = true;
+ }
+ assertFalse(penaltyVehicleInCollection);
+
+ }
+
+ @Test
+ public void whenSettingAddPenaltyVehicleOptionsAndTwoVehiclesWithSameLocationAndType_onlyOnePenaltyVehicleIsAdded(){
+ VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
+ VehicleType type = VehicleTypeImpl.Builder.newInstance("type", 0).build();
+ Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setLocationId("loc").setType(type).build();
+ Vehicle vehicle2 = VehicleImpl.Builder.newInstance("v2").setLocationId("loc").setType(type).build();
+
+ builder.addVehicle(vehicle);
+ builder.addVehicle(vehicle2);
+ builder.setFleetSize(FleetSize.FINITE);
+ builder.addPenaltyVehicles(3.0);
+
+ VehicleRoutingProblem vrp = builder.build();
+
+ assertEquals(3,vrp.getVehicles().size());
+
+ boolean penaltyVehicleInCollection = false;
+ for(Vehicle v : vrp.getVehicles()){
+ if(v.getId().equals("penaltyVehicle_loc_type")) penaltyVehicleInCollection = true;
+ }
+ assertTrue(penaltyVehicleInCollection);
+
+ }
+
+ @Test
+ public void whenSettingAddPenaltyVehicleOptionsAndTwoVehiclesWithDiffLocationAndType_twoPenaltyVehicleIsAdded(){
+ VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
+ VehicleType type = VehicleTypeImpl.Builder.newInstance("type", 0).build();
+ Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setLocationId("loc").setType(type).build();
+ Vehicle vehicle2 = VehicleImpl.Builder.newInstance("v2").setLocationId("loc2").setType(type).build();
+
+ builder.addVehicle(vehicle);
+ builder.addVehicle(vehicle2);
+ builder.setFleetSize(FleetSize.FINITE);
+ builder.addPenaltyVehicles(3.0);
+
+ VehicleRoutingProblem vrp = builder.build();
+
+ assertEquals(4,vrp.getVehicles().size());
+
+ boolean penaltyVehicleInCollection = false;
+ boolean anotherPenVehInCollection = false;
+ for(Vehicle v : vrp.getVehicles()){
+ if(v.getId().equals("penaltyVehicle_loc_type")) penaltyVehicleInCollection = true;
+ if(v.getId().equals("penaltyVehicle_loc2_type")) anotherPenVehInCollection = true;
+ }
+ assertTrue(penaltyVehicleInCollection);
+ assertTrue(anotherPenVehInCollection);
+
+ }
+
+ @Test
+ public void whenSettingAddPenaltyVehicleOptionsAndTwoVehiclesWithSameLocationButDiffType_twoPenaltyVehicleIsAdded(){
+ VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
+ VehicleType type = VehicleTypeImpl.Builder.newInstance("type", 0).build();
+ VehicleType type2 = VehicleTypeImpl.Builder.newInstance("type2", 0).build();
+ Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setLocationId("loc").setType(type).build();
+ Vehicle vehicle2 = VehicleImpl.Builder.newInstance("v2").setLocationId("loc").setType(type2).build();
+
+ builder.addVehicle(vehicle);
+ builder.addVehicle(vehicle2);
+ builder.setFleetSize(FleetSize.FINITE);
+ builder.addPenaltyVehicles(3.0);
+
+ VehicleRoutingProblem vrp = builder.build();
+
+ assertEquals(4,vrp.getVehicles().size());
+
+ boolean penaltyVehicleInCollection = false;
+ boolean anotherPenVehInCollection = false;
+ for(Vehicle v : vrp.getVehicles()){
+ if(v.getId().equals("penaltyVehicle_loc_type")) penaltyVehicleInCollection = true;
+ if(v.getId().equals("penaltyVehicle_loc_type2")) anotherPenVehInCollection = true;
+ }
+ assertTrue(penaltyVehicleInCollection);
+ assertTrue(anotherPenVehInCollection);
+
+ }
}
From c809d4b7c930c901a0ad0fd29fcf63516cc5ccac Mon Sep 17 00:00:00 2001
From: oblonski <4sschroeder@gmail.com>
Date: Tue, 14 Jan 2014 10:52:35 -0500
Subject: [PATCH 09/25] mod
---
.../main/java/jsprit/core/problem/VehicleRoutingProblem.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/jsprit-core/src/main/java/jsprit/core/problem/VehicleRoutingProblem.java b/jsprit-core/src/main/java/jsprit/core/problem/VehicleRoutingProblem.java
index 95c6d62b..7a29b094 100644
--- a/jsprit-core/src/main/java/jsprit/core/problem/VehicleRoutingProblem.java
+++ b/jsprit-core/src/main/java/jsprit/core/problem/VehicleRoutingProblem.java
@@ -388,7 +388,7 @@ public class VehicleRoutingProblem {
Vehicle penVehicle = VehicleImpl.Builder.newInstance(vehicleId).setEarliestStart(v.getEarliestDeparture())
.setLatestArrival(v.getLatestArrival()).setLocationCoord(v.getCoord()).setLocationId(v.getLocationId())
.setReturnToDepot(v.isReturnToDepot()).setType(penType).build();
- vehicles.add(penVehicle);
+ addVehicle(penVehicle);
}
}
From fb4ee4f8d67a0f12aa0b27fdf16d0ea343049c22 Mon Sep 17 00:00:00 2001
From: oblonski <4sschroeder@gmail.com>
Date: Tue, 14 Jan 2014 12:30:18 -0500
Subject: [PATCH 10/25] fix goldenReader bug
---
.../instance/reader/VrphGoldenReader.java | 8 +-
.../instance/reader/GoldenReaderTest.java | 303 ++++++++++++++++++
2 files changed, 307 insertions(+), 4 deletions(-)
create mode 100644 jsprit-instances/src/test/java/jsprit/instance/reader/GoldenReaderTest.java
diff --git a/jsprit-instances/src/main/java/jsprit/instance/reader/VrphGoldenReader.java b/jsprit-instances/src/main/java/jsprit/instance/reader/VrphGoldenReader.java
index 3a97705c..48f572a8 100644
--- a/jsprit-instances/src/main/java/jsprit/instance/reader/VrphGoldenReader.java
+++ b/jsprit-instances/src/main/java/jsprit/instance/reader/VrphGoldenReader.java
@@ -78,7 +78,7 @@ public class VrphGoldenReader {
depotCoord = Coordinate.newInstance(Double.parseDouble(tokens[1]), Double.parseDouble(tokens[2]));
}
else{
- Service.Builder serviceBuilder = Service.Builder.newInstance(tokens[0], Integer.parseInt(tokens[0]));
+ Service.Builder serviceBuilder = Service.Builder.newInstance(tokens[0], Integer.parseInt(tokens[3]));
serviceBuilder.setCoord(Coordinate.newInstance(Double.parseDouble(tokens[1]), Double.parseDouble(tokens[2])));
vrpBuilder.addJob(serviceBuilder.build());
}
@@ -126,8 +126,8 @@ public class VrphGoldenReader {
try {
reader.close();
} catch (IOException e) {
- // TODO Auto-generated catch block
e.printStackTrace();
+ System.exit(1);
}
}
@@ -136,8 +136,8 @@ public class VrphGoldenReader {
try {
readLine = reader.readLine();
} catch (IOException e) {
- // TODO Auto-generated catch block
e.printStackTrace();
+ System.exit(1);
}
return readLine;
}
@@ -148,8 +148,8 @@ public class VrphGoldenReader {
bufferedReader = new BufferedReader(new FileReader(new File(filename)));
return bufferedReader;
} catch (FileNotFoundException e) {
- // TODO Auto-generated catch block
e.printStackTrace();
+ System.exit(1);
}
return bufferedReader;
}
diff --git a/jsprit-instances/src/test/java/jsprit/instance/reader/GoldenReaderTest.java b/jsprit-instances/src/test/java/jsprit/instance/reader/GoldenReaderTest.java
new file mode 100644
index 00000000..abea2b60
--- /dev/null
+++ b/jsprit-instances/src/test/java/jsprit/instance/reader/GoldenReaderTest.java
@@ -0,0 +1,303 @@
+package jsprit.instance.reader;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import jsprit.core.problem.VehicleRoutingProblem;
+import jsprit.core.problem.job.Job;
+import jsprit.core.problem.job.Service;
+import jsprit.core.problem.vehicle.Vehicle;
+import jsprit.core.util.Coordinate;
+import jsprit.instance.reader.VrphGoldenReader.VrphType;
+
+import org.junit.Test;
+
+public class GoldenReaderTest {
+
+ @Test
+ public void whenReadingInstance_itShouldReadCorrectNuOfVehicles(){
+ VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
+ new VrphGoldenReader(vrpBuilder, VrphType.VRPH_FINITE)
+ .read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath());
+ VehicleRoutingProblem vrp = vrpBuilder.build();
+ assertEquals(17,vrp.getVehicles().size());
+ }
+
+ @Test
+ public void whenReadingInstance_itShouldReadCorrectNuOfType1Vehicles(){
+ VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
+ new VrphGoldenReader(vrpBuilder, VrphType.VRPH_FINITE)
+ .read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath());
+ VehicleRoutingProblem vrp = vrpBuilder.build();
+ int nuOfType1Vehicles = 0;
+ for(Vehicle v : vrp.getVehicles()){
+ if(v.getType().getTypeId().equals("type_1")){
+ nuOfType1Vehicles++;
+ }
+ }
+ assertEquals(4,nuOfType1Vehicles);
+ }
+
+ @Test
+ public void whenReadingInstance_theSumOfType1VehicleShouldHvTheCorrectCapacity(){
+ VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
+ new VrphGoldenReader(vrpBuilder, VrphType.VRPH_FINITE)
+ .read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath());
+ VehicleRoutingProblem vrp = vrpBuilder.build();
+ int sumOfType1Cap = 0;
+ for(Vehicle v : vrp.getVehicles()){
+ if(v.getType().getTypeId().equals("type_1")){
+ sumOfType1Cap+=v.getCapacity();
+ }
+ }
+ assertEquals(80,sumOfType1Cap);
+ }
+
+ @Test
+ public void whenReadingInstance_itShouldReadCorrectNuOfType2Vehicles(){
+ VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
+ new VrphGoldenReader(vrpBuilder, VrphType.VRPH_FINITE)
+ .read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath());
+ VehicleRoutingProblem vrp = vrpBuilder.build();
+ int nuOfType1Vehicles = 0;
+ for(Vehicle v : vrp.getVehicles()){
+ if(v.getType().getTypeId().equals("type_2")){
+ nuOfType1Vehicles++;
+ }
+ }
+ assertEquals(2,nuOfType1Vehicles);
+ }
+
+ @Test
+ public void whenReadingInstance_theSumOfType2VehicleShouldHvTheCorrectCapacity(){
+ VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
+ new VrphGoldenReader(vrpBuilder, VrphType.VRPH_FINITE)
+ .read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath());
+ VehicleRoutingProblem vrp = vrpBuilder.build();
+ int sumOfType1Cap = 0;
+ for(Vehicle v : vrp.getVehicles()){
+ if(v.getType().getTypeId().equals("type_2")){
+ sumOfType1Cap+=v.getCapacity();
+ }
+ }
+ assertEquals(60,sumOfType1Cap);
+ }
+
+ @Test
+ public void whenReadingInstance_itShouldReadCorrectNuOfType3Vehicles(){
+ VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
+ new VrphGoldenReader(vrpBuilder, VrphType.VRPH_FINITE)
+ .read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath());
+ VehicleRoutingProblem vrp = vrpBuilder.build();
+ int nuOfType1Vehicles = 0;
+ for(Vehicle v : vrp.getVehicles()){
+ if(v.getType().getTypeId().equals("type_3")){
+ nuOfType1Vehicles++;
+ }
+ }
+ assertEquals(4,nuOfType1Vehicles);
+ }
+
+ @Test
+ public void whenReadingInstance_theSumOfType3VehicleShouldHvTheCorrectCapacity(){
+ VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
+ new VrphGoldenReader(vrpBuilder, VrphType.VRPH_FINITE)
+ .read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath());
+ VehicleRoutingProblem vrp = vrpBuilder.build();
+ int sumOfType1Cap = 0;
+ for(Vehicle v : vrp.getVehicles()){
+ if(v.getType().getTypeId().equals("type_3")){
+ sumOfType1Cap+=v.getCapacity();
+ }
+ }
+ assertEquals(160,sumOfType1Cap);
+ }
+
+ @Test
+ public void whenReadingInstance_itShouldReadCorrectNuOfType4Vehicles(){
+ VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
+ new VrphGoldenReader(vrpBuilder, VrphType.VRPH_FINITE)
+ .read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath());
+ VehicleRoutingProblem vrp = vrpBuilder.build();
+ int nuOfType1Vehicles = 0;
+ for(Vehicle v : vrp.getVehicles()){
+ if(v.getType().getTypeId().equals("type_4")){
+ nuOfType1Vehicles++;
+ }
+ }
+ assertEquals(4,nuOfType1Vehicles);
+ }
+
+ @Test
+ public void whenReadingInstance_theSumOfType4VehicleShouldHvTheCorrectCapacity(){
+ VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
+ new VrphGoldenReader(vrpBuilder, VrphType.VRPH_FINITE)
+ .read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath());
+ VehicleRoutingProblem vrp = vrpBuilder.build();
+ int sumOfType1Cap = 0;
+ for(Vehicle v : vrp.getVehicles()){
+ if(v.getType().getTypeId().equals("type_4")){
+ sumOfType1Cap+=v.getCapacity();
+ }
+ }
+ assertEquals(280,sumOfType1Cap);
+ }
+
+ @Test
+ public void whenReadingInstance_itShouldReadCorrectNuOfType5Vehicles(){
+ VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
+ new VrphGoldenReader(vrpBuilder, VrphType.VRPH_FINITE)
+ .read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath());
+ VehicleRoutingProblem vrp = vrpBuilder.build();
+ int nuOfType1Vehicles = 0;
+ for(Vehicle v : vrp.getVehicles()){
+ if(v.getType().getTypeId().equals("type_5")){
+ nuOfType1Vehicles++;
+ }
+ }
+ assertEquals(2,nuOfType1Vehicles);
+ }
+
+ @Test
+ public void whenReadingInstance_theSumOfType5VehicleShouldHvTheCorrectCapacity(){
+ VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
+ new VrphGoldenReader(vrpBuilder, VrphType.VRPH_FINITE)
+ .read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath());
+ VehicleRoutingProblem vrp = vrpBuilder.build();
+ int sumOfType1Cap = 0;
+ for(Vehicle v : vrp.getVehicles()){
+ if(v.getType().getTypeId().equals("type_5")){
+ sumOfType1Cap+=v.getCapacity();
+ }
+ }
+ assertEquals(240,sumOfType1Cap);
+ }
+
+ @Test
+ public void whenReadingInstance_itShouldReadCorrectNuOfType6Vehicles(){
+ VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
+ new VrphGoldenReader(vrpBuilder, VrphType.VRPH_FINITE)
+ .read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath());
+ VehicleRoutingProblem vrp = vrpBuilder.build();
+ int nuOfType1Vehicles = 0;
+ for(Vehicle v : vrp.getVehicles()){
+ if(v.getType().getTypeId().equals("type_6")){
+ nuOfType1Vehicles++;
+ }
+ }
+ assertEquals(1,nuOfType1Vehicles);
+ }
+
+ @Test
+ public void whenReadingInstance_theSumOfType6VehicleShouldHvTheCorrectCapacity(){
+ VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
+ new VrphGoldenReader(vrpBuilder, VrphType.VRPH_FINITE)
+ .read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath());
+ VehicleRoutingProblem vrp = vrpBuilder.build();
+ int sumOfType1Cap = 0;
+ for(Vehicle v : vrp.getVehicles()){
+ if(v.getType().getTypeId().equals("type_6")){
+ sumOfType1Cap+=v.getCapacity();
+ }
+ }
+ assertEquals(200,sumOfType1Cap);
+ }
+
+ @Test
+ public void whenReadingInstance_vehicleShouldHvTheCorrectCoord(){
+ VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
+ new VrphGoldenReader(vrpBuilder, VrphType.VRPH_FINITE)
+ .read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath());
+ VehicleRoutingProblem vrp = vrpBuilder.build();
+ for(Vehicle v : vrp.getVehicles()){
+ if(v.getCoord().getX() != 40.0){
+ assertFalse(true);
+ }
+ if(v.getCoord().getY() != 40.0){
+ assertFalse(true);
+ }
+ }
+ assertTrue(true);
+ }
+
+ @Test
+ public void whenReadingInstance_service1MustHaveCorrectDemand(){
+ VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
+ new VrphGoldenReader(vrpBuilder, VrphType.VRPH_FINITE)
+ .read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath());
+ VehicleRoutingProblem vrp = vrpBuilder.build();
+ Job job = getJob("1",vrp);
+ assertEquals(18,job.getCapacityDemand());
+ }
+
+ @Test
+ public void whenReadingInstance_service1MustHaveCorrectCoordinate(){
+ VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
+ new VrphGoldenReader(vrpBuilder, VrphType.VRPH_FINITE)
+ .read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath());
+ VehicleRoutingProblem vrp = vrpBuilder.build();
+ Coordinate coord = getCoord("1",vrp);
+ assertEquals(22.0,coord.getX(),0.01);
+ assertEquals(22.0,coord.getY(),0.01);
+ }
+
+ @Test
+ public void whenReadingInstance_service15MustHaveCorrectCoordinate(){
+ VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
+ new VrphGoldenReader(vrpBuilder, VrphType.VRPH_FINITE)
+ .read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath());
+ VehicleRoutingProblem vrp = vrpBuilder.build();
+ Coordinate coord = getCoord("15",vrp);
+ assertEquals(62.0,coord.getX(),0.01);
+ assertEquals(24.0,coord.getY(),0.01);
+ }
+
+
+
+ @Test
+ public void whenReadingInstance_service50MustHaveCorrectCoordinate(){
+ VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
+ new VrphGoldenReader(vrpBuilder, VrphType.VRPH_FINITE)
+ .read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath());
+ VehicleRoutingProblem vrp = vrpBuilder.build();
+ Coordinate coord = getCoord("50",vrp);
+ assertEquals(15.0,coord.getX(),0.01);
+ assertEquals(56.0,coord.getY(),0.01);
+ }
+
+ private Coordinate getCoord(String string, VehicleRoutingProblem vrp) {
+ Job j = getJob(string,vrp);
+ return ((Service)j).getCoord();
+ }
+
+ @Test
+ public void whenReadingInstance_service4MustHaveCorrectDemand(){
+ VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
+ new VrphGoldenReader(vrpBuilder, VrphType.VRPH_FINITE)
+ .read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath());
+ VehicleRoutingProblem vrp = vrpBuilder.build();
+ Job job = getJob("4",vrp);
+ assertEquals(30,job.getCapacityDemand());
+ }
+
+ @Test
+ public void whenReadingInstance_service50MustHaveCorrectDemand(){
+ VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
+ new VrphGoldenReader(vrpBuilder, VrphType.VRPH_FINITE)
+ .read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath());
+ VehicleRoutingProblem vrp = vrpBuilder.build();
+ Job job = getJob("50",vrp);
+ assertEquals(22,job.getCapacityDemand());
+ }
+
+ private Job getJob(String string, VehicleRoutingProblem vrp) {
+ for(Job j : vrp.getJobs().values()){
+ if(j.getId().equals(string)){
+ return j;
+ }
+ }
+ return null;
+ }
+
+
+}
From 9bb111633f7f45e2d47e523cae295cb720814927 Mon Sep 17 00:00:00 2001
From: oblonski <4sschroeder@gmail.com>
Date: Tue, 14 Jan 2014 12:30:48 -0500
Subject: [PATCH 11/25] add golden instance to test/resources
---
.../src/test/resources/cn_13mix.txt | 73 +++++++++++++++++++
1 file changed, 73 insertions(+)
create mode 100644 jsprit-instances/src/test/resources/cn_13mix.txt
diff --git a/jsprit-instances/src/test/resources/cn_13mix.txt b/jsprit-instances/src/test/resources/cn_13mix.txt
new file mode 100644
index 00000000..9e58fa13
--- /dev/null
+++ b/jsprit-instances/src/test/resources/cn_13mix.txt
@@ -0,0 +1,73 @@
+50
+ 0 40 40 0
+ 1 22 22 18
+ 2 36 26 26
+ 3 21 45 11
+ 4 45 35 30
+ 5 55 20 21
+ 6 33 34 19
+ 7 50 50 15
+ 8 55 45 16
+ 9 26 59 29
+ 10 40 66 26
+ 11 55 65 37
+ 12 35 51 16
+ 13 62 35 12
+ 14 62 57 31
+ 15 62 24 8
+ 16 21 36 19
+ 17 33 44 20
+ 18 9 56 13
+ 19 62 48 15
+ 20 66 14 22
+ 21 44 13 28
+ 22 26 13 12
+ 23 11 28 6
+ 24 7 43 27
+ 25 17 64 14
+ 26 41 46 18
+ 27 55 34 17
+ 28 35 16 29
+ 29 52 26 13
+ 30 43 26 22
+ 31 31 76 25
+ 32 22 53 28
+ 33 26 29 27
+ 34 50 40 19
+ 35 55 50 10
+ 36 54 10 12
+ 37 60 15 14
+ 38 47 66 24
+ 39 30 60 16
+ 40 30 50 33
+ 41 12 17 15
+ 42 15 14 11
+ 43 16 19 18
+ 44 21 48 17
+ 45 50 30 21
+ 46 51 42 27
+ 47 50 15 19
+ 48 48 21 20
+ 49 12 38 5
+ 50 15 56 22
+//Vehicles characteristics: type, volume, fixed cost, variable cost, number available
+6
+v 1 20 20 1.0 4
+v 2 30 35 1.1 2
+v 3 40 50 1.2 4
+v 4 70 120 1.7 4
+v 5 120 225 2.5 2
+v 6 200 400 3.2 1
+
+
+best solution with fixed costs: 588.784723 + 20 + 3*35 + 2*50 + 4*400 = 2413.78
+ 2 27 13 807876
+ 1 26 321656
+ 2 17 12 774254
+ 2 34 8 828825
+ 1 46 573606
+ 1 4 491422
+ 9 39 31 10 38 11 14 19 35 7 5129601
+ 11 2 28 22 1 43 42 41 23 16 33 6 5102713
+ 10 40 32 9 25 50 18 24 49 3 44 5096803
+ 11 30 48 21 47 36 37 20 15 5 29 45 5011089
From e5130cb26233bc3544b90be62881558c49f78a0f Mon Sep 17 00:00:00 2001
From: oblonski <4sschroeder@gmail.com>
Date: Tue, 14 Jan 2014 17:43:25 -0500
Subject: [PATCH 12/25] use .addPenaltyVehicle()
---
.../java/jsprit/examples/BicycleMessenger.java | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/jsprit-examples/src/main/java/jsprit/examples/BicycleMessenger.java b/jsprit-examples/src/main/java/jsprit/examples/BicycleMessenger.java
index beeefaa5..fa770fbc 100644
--- a/jsprit-examples/src/main/java/jsprit/examples/BicycleMessenger.java
+++ b/jsprit-examples/src/main/java/jsprit/examples/BicycleMessenger.java
@@ -228,6 +228,8 @@ public class BicycleMessenger {
problemBuilder.addConstraint(new ThreeTimesLessThanBestDirectRouteConstraint(nearestMessengers, routingCosts, stateManager));
problemBuilder.addConstraint(new IgnoreMessengerThatCanNeverMeetTimeRequirements(nearestMessengers, routingCosts));
+ problemBuilder.addPenaltyVehicles(10.0);
+
//finally build the problem
VehicleRoutingProblem bicycleMessengerProblem = problemBuilder.build();
@@ -239,7 +241,7 @@ public class BicycleMessenger {
//if you want, terminate it after 1000 iterations with no change
// algorithm.setPrematureAlgorithmTermination(new IterationWithoutImprovementTermination(1000));
// algorithm.addListener(new AlgorithmSearchProgressChartListener("output/progress.png"));
- algorithm.setNuOfIterations(200);
+ algorithm.setNuOfIterations(1000);
Collection This only makes sense for FleetSize.FINITE. Thus, penaltyVehicles are only added if is FleetSize.FINITE.
* The id of penaltyVehicles is constructed as follows vehicleId = "penaltyVehicle" + "_" + {locationId} + "_" + {typeId}.
@@ -468,6 +475,24 @@ public class VehicleRoutingProblem {
return this;
}
+ /**
+ * Adds penaltyVehicles, i.e. for every unique vehicle-location and type combination a penalty-vehicle is constructed having penaltyFactor times higher fixed and variable costs.
+ * This method takes penaltyFixedCosts as absolute value in contrary to the method without penaltyFixedCosts where fixedCosts is the product of penaltyFactor and typeFixedCosts.
+ * This only makes sense for FleetSize.FINITE. Thus, penaltyVehicles are only added if is FleetSize.FINITE.
+ * The id of penaltyVehicles is constructed as follows vehicleId = "penaltyVehicle" + "_" + {locationId} + "_" + {typeId}.
+ * By default: no penalty-vehicles are added
+ *
+ * @param penaltyFactor
+ * @param penaltyFixedCosts which is an absolute penaltyValue (in contrary to penaltyFactor)
+ * @return this builder
+ */
+ public Builder addPenaltyVehicles(double penaltyFactor, double penaltyFixedCosts){
+ this.addPenaltyVehicles = true;
+ this.penaltyFactor = penaltyFactor;
+ this.penaltyFixedCosts = penaltyFixedCosts;
+ return this;
+ }
+
/**
* Returns an unmodifiable collection of already added jobs.
*
diff --git a/jsprit-core/src/test/java/jsprit/core/problem/VehicleRoutingProblemTest.java b/jsprit-core/src/test/java/jsprit/core/problem/VehicleRoutingProblemTest.java
index e5aff4cf..fb2ce5b2 100644
--- a/jsprit-core/src/test/java/jsprit/core/problem/VehicleRoutingProblemTest.java
+++ b/jsprit-core/src/test/java/jsprit/core/problem/VehicleRoutingProblemTest.java
@@ -391,6 +391,32 @@ public class VehicleRoutingProblemTest {
}
+ @Test
+ public void whenSettingAddPenaltyVehicleOptionsWithAbsoluteFixedCostsAndTwoVehiclesWithSameLocationAndType_onePenaltyVehicleIsAddedWithTheCorrectPenaltyFixedCosts(){
+ VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
+ VehicleType type = VehicleTypeImpl.Builder.newInstance("type", 0).build();
+ Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setLocationId("loc").setType(type).build();
+ Vehicle vehicle2 = VehicleImpl.Builder.newInstance("v2").setLocationId("loc").setType(type).build();
+
+ builder.addVehicle(vehicle);
+ builder.addVehicle(vehicle2);
+ builder.setFleetSize(FleetSize.FINITE);
+ builder.addPenaltyVehicles(3.0,10000);
+
+ VehicleRoutingProblem vrp = builder.build();
+
+ assertEquals(3,vrp.getVehicles().size());
+
+ double fix = 0.0;
+ for(Vehicle v : vrp.getVehicles()){
+ if(v.getId().equals("penaltyVehicle_loc_type")) {
+ fix = v.getType().getVehicleCostParams().fix;
+ }
+ }
+ assertEquals(10000,fix,0.01);
+
+ }
+
@Test
public void whenSettingAddPenaltyVehicleOptionsAndTwoVehiclesWithDiffLocationAndType_twoPenaltyVehicleIsAdded(){
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
From 4dbf2e938832093cb785977d5a8e799fbb317abf Mon Sep 17 00:00:00 2001
From: oblonski <4sschroeder@gmail.com>
Date: Tue, 14 Jan 2014 18:01:15 -0500
Subject: [PATCH 14/25] improve penVehicle setting
---
.../src/main/java/jsprit/examples/BicycleMessenger.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/jsprit-examples/src/main/java/jsprit/examples/BicycleMessenger.java b/jsprit-examples/src/main/java/jsprit/examples/BicycleMessenger.java
index fa770fbc..14b67a24 100644
--- a/jsprit-examples/src/main/java/jsprit/examples/BicycleMessenger.java
+++ b/jsprit-examples/src/main/java/jsprit/examples/BicycleMessenger.java
@@ -228,7 +228,7 @@ public class BicycleMessenger {
problemBuilder.addConstraint(new ThreeTimesLessThanBestDirectRouteConstraint(nearestMessengers, routingCosts, stateManager));
problemBuilder.addConstraint(new IgnoreMessengerThatCanNeverMeetTimeRequirements(nearestMessengers, routingCosts));
- problemBuilder.addPenaltyVehicles(10.0);
+ problemBuilder.addPenaltyVehicles(10.0,50000);
//finally build the problem
VehicleRoutingProblem bicycleMessengerProblem = problemBuilder.build();
@@ -241,7 +241,7 @@ public class BicycleMessenger {
//if you want, terminate it after 1000 iterations with no change
// algorithm.setPrematureAlgorithmTermination(new IterationWithoutImprovementTermination(1000));
// algorithm.addListener(new AlgorithmSearchProgressChartListener("output/progress.png"));
- algorithm.setNuOfIterations(1000);
+ algorithm.setNuOfIterations(200);
Collection diff. options of VrphType yields to different problem types for
- * - vrphe with infinite fleet, i.e. different types with different variable costs and infinite number of vehicles of each type
- * - vrphe with finite fleet, i.e. different types with different variable costs and finite number of vehicles of each type
- * - vfm, different types with different fixed costs
- * - vfmvrc different types with different fixed costs and variable costs
+ * See {@link VrphType} what kind of problems can be generated
*
- * cxxx3-cxxx6 do not have variable costs and nuVehicle, thus they can only be used for vfm.
+ * Note that c20_3-c20_6 do not have variable costs and a limited nuVehicle, thus they can only be used for FSMF.
*
* @author schroeder
*
@@ -35,16 +32,21 @@ public class VrphGoldenReader {
/**
*
- * VRPHE_INFINITE - different types with different variable costs and infinite number of vehicles of each type
- * VRPHE_FINITE - different types with different variable costs and finite number of vehicles of each type
- * VFM - different types with different fixed costs
- * VFMVRC - different types with different fixed costs and variable costs
- *
+ * FSMD - Fleet Size and Mix with Dependent costs
+ * FSMF - Fleet Size and Mix with Fixed costs
+ * FSMFD - Fleet Size and Mix with Fixed and Dependent costs
+ * HVRPD - Heterogeneous Vehicle Routing Problem with Dependent costs and finite (limited) fleet
+ * HVRPFD - Heterogeneous Vehicle Routing Problem with Fixed and Dependent costs and finite (limited) fleet
+ *
* @author schroeder
*
*/
public enum VrphType {
- VRPH_INFINITE, VRPH_FINITE, VFM, VFMVRC
+ FSMD,
+ HVRPD,
+ FSMF,
+ FSMFD,
+ HVRPFD
}
private final VehicleRoutingProblem.Builder vrpBuilder;
@@ -87,23 +89,23 @@ public class VrphGoldenReader {
else if(trimedLine.startsWith("v")){
VehicleTypeImpl.Builder typeBuilder = VehicleTypeImpl.Builder.newInstance("type_"+tokens[1], Integer.parseInt(tokens[2]));
int nuOfVehicles = 1;
- if(vrphType.equals(VrphType.VFM)){
+ if(vrphType.equals(VrphType.FSMF)){
typeBuilder.setFixedCost(Double.parseDouble(tokens[3]));
}
- else if(vrphType.equals(VrphType.VFMVRC)){
+ else if(vrphType.equals(VrphType.FSMFD)){
typeBuilder.setFixedCost(Double.parseDouble(tokens[3]));
if(tokens.length > 4){
typeBuilder.setCostPerDistance(Double.parseDouble(tokens[4]));
}
else throw new IllegalStateException("option " + vrphType + " cannot be applied with this instance");
}
- else if(vrphType.equals(VrphType.VRPH_INFINITE)){
+ else if(vrphType.equals(VrphType.FSMD)){
if(tokens.length > 4){
typeBuilder.setCostPerDistance(Double.parseDouble(tokens[4]));
}
else throw new IllegalStateException("option " + vrphType + " cannot be applied with this instance");
}
- else { //VrphType.VRPH_FINITE
+ else if(vrphType.equals(VrphType.HVRPD)){
if(tokens.length > 4){
typeBuilder.setCostPerDistance(Double.parseDouble(tokens[4]));
nuOfVehicles = Integer.parseInt(tokens[5]);
@@ -111,6 +113,15 @@ public class VrphGoldenReader {
}
else throw new IllegalStateException("option " + vrphType + " cannot be applied with this instance");
}
+ else if (vrphType.equals(VrphType.HVRPFD)){
+ if(tokens.length > 4){
+ typeBuilder.setFixedCost(Double.parseDouble(tokens[3]));
+ typeBuilder.setCostPerDistance(Double.parseDouble(tokens[4]));
+ nuOfVehicles = Integer.parseInt(tokens[5]);
+ vrpBuilder.setFleetSize(FleetSize.FINITE);
+ }
+ else throw new IllegalStateException("option " + vrphType + " cannot be applied with this instance");
+ }
for(int i=0;i These instances are from Golden and Taillard and copied from http://mistic.heig-vd.ch/taillard/problemes.dir/vrp.dir/vrp.html.
+ *
+ * You can find best results of different problems, instances and authors here:
+ * These instances are from Golden and Taillard and copied from http://mistic.heig-vd.ch/taillard/problemes.dir/vrp.dir/vrp.html.
+ * These instances are from Golden and Taillard and copied from
+ * .
*
* You can find best results of different problems, instances and authors here:
* if {@link VehicleType} is not set, default vehicle-type is set with id="default" and
+ * capacity=0
+ *
* @return vehicle
* @throw IllegalStateException if both locationId and locationCoord is not set
*/
@@ -189,6 +194,8 @@ public class VehicleImpl implements Vehicle {
/**
* Returns empty/noVehicle which is a vehicle having no capacity, no type and no reasonable id.
*
+ * NoVehicle has id="noVehicle" and extends {@link VehicleImpl}
+ *
* @return emptyVehicle
*/
public static NoVehicle createNoVehicle(){
@@ -219,9 +226,14 @@ public class VehicleImpl implements Vehicle {
returnToDepot = builder.returnToDepot;
}
+ /**
+ * Returns String with attributes of this vehicle
+ *
+ * String has the following format [attr1=val1][attr2=val2]...[attrn=valn]
+ */
@Override
public String toString() {
- return "[id="+id+"][type="+type+"][locationId="+locationId+"][coord=" + coord + "]";
+ return "[id="+id+"][type="+type+"][locationId="+locationId+"][coord=" + coord + "][isReturnToDepot=" + isReturnToDepot() + "]";
}
public Coordinate getCoord() {
diff --git a/jsprit-core/src/test/java/jsprit/core/problem/vehicle/VehicleImplTest.java b/jsprit-core/src/test/java/jsprit/core/problem/vehicle/VehicleImplTest.java
new file mode 100644
index 00000000..5f3fa4cd
--- /dev/null
+++ b/jsprit-core/src/test/java/jsprit/core/problem/vehicle/VehicleImplTest.java
@@ -0,0 +1,102 @@
+package jsprit.core.problem.vehicle;
+
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.*;
+import jsprit.core.problem.vehicle.VehicleImpl.NoVehicle;
+import jsprit.core.util.Coordinate;
+
+import org.junit.Test;
+
+
+public class VehicleImplTest {
+
+ @Test
+ public void whenSettingTypeWithBuilder_typeShouldBeSet(){
+ VehicleType type = mock(VehicleType.class);
+ Vehicle v = VehicleImpl.Builder.newInstance("v").setLocationId("loc").setType(type).build();
+ assertEquals(type,v.getType());
+ }
+
+ @Test(expected=IllegalStateException.class)
+ public void whenTypeIsNull_itThrowsIllegalStateException(){
+ @SuppressWarnings("unused")
+ Vehicle v = VehicleImpl.Builder.newInstance("v").setLocationId("loc").setType(null).build();
+ }
+
+ @Test
+ public void whenTypeIsNotSet_defaultTypeIsSet(){
+ Vehicle v = VehicleImpl.Builder.newInstance("v").setLocationId("loc").build();
+ assertEquals("default",v.getType().getTypeId());
+ assertEquals(0,v.getType().getCapacity());
+ }
+
+ @Test(expected=IllegalStateException.class)
+ public void whenVehicleIsBuiltWithoutSettingNeitherLocationNorCoord_itThrowsAnIllegalStateException(){
+ @SuppressWarnings("unused")
+ Vehicle v = VehicleImpl.Builder.newInstance("v").build();
+ }
+
+ @Test
+ public void whenVehicleIsBuiltAndReturnToDepotFlagIsNotSet_itShouldReturnToDepot(){
+ Vehicle v = VehicleImpl.Builder.newInstance("v").setLocationId("loc").build();
+ assertTrue(v.isReturnToDepot());
+ }
+
+ @Test
+ public void whenVehicleIsBuiltToReturnToDepot_itShouldReturnToDepot(){
+ Vehicle v = VehicleImpl.Builder.newInstance("v").setReturnToDepot(true).setLocationId("loc").build();
+ assertTrue(v.isReturnToDepot());
+ }
+
+ @Test
+ public void whenVehicleIsBuiltToNotReturnToDepot_itShouldNotReturnToDepot(){
+ Vehicle v = VehicleImpl.Builder.newInstance("v").setReturnToDepot(false).setLocationId("loc").build();
+ assertFalse(v.isReturnToDepot());
+ }
+
+ @Test
+ public void whenVehicleIsBuiltWithLocation_itShouldHvTheCorrectLocation(){
+ Vehicle v = VehicleImpl.Builder.newInstance("v").setLocationId("loc").build();
+ assertEquals("loc",v.getLocationId());
+ }
+
+ @Test
+ public void whenVehicleIsBuiltWithCoord_itShouldHvTheCorrectCoord(){
+ Vehicle v = VehicleImpl.Builder.newInstance("v").setLocationCoord(Coordinate.newInstance(1, 2)).build();
+ assertEquals(1.0,v.getCoord().getX(),0.01);
+ assertEquals(2.0,v.getCoord().getY(),0.01);
+ }
+
+ @Test
+ public void whenVehicleIsBuiltAndEarliestStartIsNotSet_itShouldSetTheDefaultOfZero(){
+ Vehicle v = VehicleImpl.Builder.newInstance("v").setLocationCoord(Coordinate.newInstance(1, 2)).build();
+ assertEquals(0.0,v.getEarliestDeparture(),0.01);
+ }
+
+ @Test
+ public void whenVehicleIsBuiltAndEarliestStartSet_itShouldBeSetCorrectly(){
+ Vehicle v = VehicleImpl.Builder.newInstance("v").setEarliestStart(10.0).setLocationCoord(Coordinate.newInstance(1, 2)).build();
+ assertEquals(10.0,v.getEarliestDeparture(),0.01);
+ }
+
+ @Test
+ public void whenVehicleIsBuiltAndLatestArrivalIsNotSet_itShouldSetDefaultOfDoubleMaxValue(){
+ Vehicle v = VehicleImpl.Builder.newInstance("v").setLocationCoord(Coordinate.newInstance(1, 2)).build();
+ assertEquals(Double.MAX_VALUE,v.getLatestArrival(),0.01);
+ }
+
+ @Test
+ public void whenVehicleIsBuiltAndLatestArrivalIsSet_itShouldBeSetCorrectly(){
+ Vehicle v = VehicleImpl.Builder.newInstance("v").setLatestArrival(30.0).setLocationCoord(Coordinate.newInstance(1, 2)).build();
+ assertEquals(30.0,v.getLatestArrival(),0.01);
+ }
+
+ @Test
+ public void whenNoVehicleIsCreate_itShouldHvTheCorrectId(){
+ Vehicle v = VehicleImpl.createNoVehicle();
+ assertTrue(v instanceof NoVehicle);
+ assertEquals("noVehicle",v.getId());
+ }
+
+
+}
From d41ad158cdd99450b08b8675e27bcf6f63586965 Mon Sep 17 00:00:00 2001
From: oblonski <4sschroeder@gmail.com>
Date: Wed, 15 Jan 2014 21:06:33 -0500
Subject: [PATCH 22/25] adds value boundaries for vehicleType as well as
vehicleTypeTests
---
.../core/problem/vehicle/VehicleTypeImpl.java | 49 +++++++++--
.../problem/vehicle/VehicleTypeImplTest.java | 85 +++++++++++++++++++
2 files changed, 125 insertions(+), 9 deletions(-)
create mode 100644 jsprit-core/src/test/java/jsprit/core/problem/vehicle/VehicleTypeImplTest.java
diff --git a/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleTypeImpl.java b/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleTypeImpl.java
index f0404396..e669e7cf 100644
--- a/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleTypeImpl.java
+++ b/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleTypeImpl.java
@@ -37,7 +37,7 @@ public class VehicleTypeImpl implements VehicleType {
public static VehicleTypeImpl.VehicleCostParams newInstance(double fix, double perTimeUnit,double perDistanceUnit){
return new VehicleCostParams(fix, perTimeUnit, perDistanceUnit);
}
-
+
public final double fix;
public final double perTimeUnit;
public final double perDistanceUnit;
@@ -71,9 +71,12 @@ public class VehicleTypeImpl implements VehicleType {
*
* @param id
* @param capacity
- * @return
+ * @return the vehicleType builder
+ * @throws IllegalStateException if capacity is smaller than zero or id is null
*/
public static VehicleTypeImpl.Builder newInstance(String id, int capacity){
+ if(capacity < 0) throw new IllegalStateException("capacity cannot be smaller than zero");
+ if(id == null) throw new IllegalStateException("typeId must be null");
return new Builder(id,capacity);
}
@@ -104,8 +107,12 @@ public class VehicleTypeImpl implements VehicleType {
*
* @param inMeterPerSeconds
* @return this builder
+ * @throws IllegalStateException if velocity is smaller than zero
*/
- public VehicleTypeImpl.Builder setMaxVelocity(double inMeterPerSeconds){ this.maxVelo = inMeterPerSeconds; return this; }
+ public VehicleTypeImpl.Builder setMaxVelocity(double inMeterPerSeconds){
+ if(inMeterPerSeconds < 0.0) throw new IllegalStateException("velocity cannot be smaller than zero");
+ this.maxVelo = inMeterPerSeconds; return this;
+ }
/**
* Sets the fixed costs of the vehicle-type.
@@ -114,8 +121,13 @@ public class VehicleTypeImpl implements VehicleType {
*
* @param fixedCost
* @return this builder
+ * @throws IllegalStateException if fixedCost is smaller than zero
*/
- public VehicleTypeImpl.Builder setFixedCost(double fixedCost) { this.fixedCost = fixedCost; return this; }
+ public VehicleTypeImpl.Builder setFixedCost(double fixedCost) {
+ if(fixedCost < 0.0) throw new IllegalStateException("fixed costs cannot be smaller than zero");
+ this.fixedCost = fixedCost;
+ return this;
+ }
/**
* Sets the cost per distance unit, for instance € per meter.
@@ -124,8 +136,13 @@ public class VehicleTypeImpl implements VehicleType {
*
* @param perDistance
* @return this builder
+ * @throws IllegalStateException if perDistance is smaller than zero
*/
- public VehicleTypeImpl.Builder setCostPerDistance(double perDistance){ this.perDistance = perDistance; return this; }
+ public VehicleTypeImpl.Builder setCostPerDistance(double perDistance){
+ if(perDistance < 0.0) throw new IllegalStateException("cost per distance must not be smaller than zero");
+ this.perDistance = perDistance;
+ return this;
+ }
/**
* Sets cost per time unit, for instance € per second.
@@ -133,14 +150,19 @@ public class VehicleTypeImpl implements VehicleType {
* by default it is 0.0
*
* @param perTime
- * @return
+ * @return this builder
+ * @throws IllegalStateException if costPerTime is smaller than zero
*/
- public VehicleTypeImpl.Builder setCostPerTime(double perTime){ this.perTime = perTime; return this; }
+ public VehicleTypeImpl.Builder setCostPerTime(double perTime){
+ if(perTime < 0.0) throw new IllegalStateException();
+ this.perTime = perTime;
+ return this;
+ }
/**
* Builds the vehicle-type.
*
- * @return
+ * @return VehicleTypeImpl
*/
public VehicleTypeImpl build(){
return new VehicleTypeImpl(this);
@@ -183,7 +205,7 @@ public class VehicleTypeImpl implements VehicleType {
private final VehicleTypeImpl.VehicleCostParams vehicleCostParams;
- private double maxVelocity;
+ private final double maxVelocity;
/**
* @deprecated use builder instead
@@ -205,11 +227,20 @@ public class VehicleTypeImpl implements VehicleType {
vehicleCostParams = new VehicleCostParams(builder.fixedCost, builder.perTime, builder.perDistance);
}
+ /**
+ * @deprecated use Builder.newInstance(...) instead.
+ *
+ * @param typeId
+ * @param capacity
+ * @param vehicleCostParams
+ */
+ @Deprecated
public VehicleTypeImpl(String typeId, int capacity,VehicleTypeImpl.VehicleCostParams vehicleCostParams) {
super();
this.typeId = typeId;
this.capacity = capacity;
this.vehicleCostParams = vehicleCostParams;
+ this.maxVelocity = Double.MAX_VALUE;
}
/* (non-Javadoc)
diff --git a/jsprit-core/src/test/java/jsprit/core/problem/vehicle/VehicleTypeImplTest.java b/jsprit-core/src/test/java/jsprit/core/problem/vehicle/VehicleTypeImplTest.java
new file mode 100644
index 00000000..19c05e50
--- /dev/null
+++ b/jsprit-core/src/test/java/jsprit/core/problem/vehicle/VehicleTypeImplTest.java
@@ -0,0 +1,85 @@
+package jsprit.core.problem.vehicle;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+public class VehicleTypeImplTest {
+
+ @Test
+ public void whenCallingStaticNewBuilderInstance_itShouldReturnNewBuilderInstance(){
+ VehicleTypeImpl.Builder builder = VehicleTypeImpl.Builder.newInstance("foo", 0);
+ assertNotNull(builder);
+ }
+
+ @Test
+ public void whenBuildingTypeJustByCallingNewInstance_typeIdMustBeCorrect(){
+ VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("foo", 0).build();
+ assertEquals("foo",type.getTypeId());
+ }
+
+ @Test
+ public void whenBuildingTypeJustByCallingNewInstance_capMustBeCorrect(){
+ VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("foo", 0).build();
+ assertEquals(0,type.getCapacity());
+ }
+
+ @Test(expected=IllegalStateException.class)
+ public void whenBuildingTypeWithCapSmallerThanZero_throwIllegalStateException(){
+ @SuppressWarnings("unused")
+ VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("foo", -10).build();
+ }
+
+ @Test(expected=IllegalStateException.class)
+ public void whenBuildingTypeWithNullId_throwIllegalStateException(){
+ @SuppressWarnings("unused")
+ VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance(null, 10).build();
+ }
+
+ @Test
+ public void whenSettingMaxVelocity_itShouldBeSetCorrectly(){
+ VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type", 10).setMaxVelocity(10).build();
+ assertEquals(10,type.getMaxVelocity(),0.0);
+ }
+
+ @Test(expected=IllegalStateException.class)
+ public void whenMaxVelocitySmallerThanZero_itShouldThrowException(){
+ @SuppressWarnings("unused")
+ VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type", 10).setMaxVelocity(-10).build();
+ }
+
+ @Test(expected=IllegalStateException.class)
+ public void whenFixedCostsSmallerThanZero_itShouldThrowException(){
+ @SuppressWarnings("unused")
+ VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type", 10).setFixedCost(-10).build();
+ }
+
+ public void whenSettingFixedCosts_itShouldBeSetCorrectly(){
+ VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type", 10).setFixedCost(10).build();
+ assertEquals(10.0, type.getVehicleCostParams().fix,0.0);
+ }
+
+ @Test(expected=IllegalStateException.class)
+ public void whenPerDistanceCostsSmallerThanZero_itShouldThrowException(){
+ @SuppressWarnings("unused")
+ VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type", 10).setCostPerDistance(-10).build();
+ }
+
+ public void whenSettingPerDistanceCosts_itShouldBeSetCorrectly(){
+ VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type", 10).setCostPerDistance(10).build();
+ assertEquals(10.0, type.getVehicleCostParams().perDistanceUnit,0.0);
+ }
+
+ @Test(expected=IllegalStateException.class)
+ public void whenPerTimeCostsSmallerThanZero_itShouldThrowException(){
+ @SuppressWarnings("unused")
+ VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type", 10).setCostPerTime(-10).build();
+ }
+
+ public void whenSettingPerTimeCosts_itShouldBeSetCorrectly(){
+ VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type", 10).setCostPerTime(10).build();
+ assertEquals(10.0, type.getVehicleCostParams().perDistanceUnit,0.0);
+ }
+
+
+}
From 937702e136b9d76ad5c5d12a4c12f56f907de426 Mon Sep 17 00:00:00 2001
From: oblonski <4sschroeder@gmail.com>
Date: Wed, 15 Jan 2014 21:18:00 -0500
Subject: [PATCH 23/25] test VehicleFleetManagers
---
.../vehicle/FiniteFleetManagerFactory.java | 6 +++++-
.../FiniteVehicleFleetManagerFactoryTest.java | 16 ++++++++++++++++
...ger.java => TestVehicleFleetManagerImpl.java} | 2 +-
3 files changed, 22 insertions(+), 2 deletions(-)
create mode 100644 jsprit-core/src/test/java/jsprit/core/problem/vehicle/FiniteVehicleFleetManagerFactoryTest.java
rename jsprit-core/src/test/java/jsprit/core/problem/vehicle/{TestVehicleFleetManager.java => TestVehicleFleetManagerImpl.java} (98%)
diff --git a/jsprit-core/src/main/java/jsprit/core/problem/vehicle/FiniteFleetManagerFactory.java b/jsprit-core/src/main/java/jsprit/core/problem/vehicle/FiniteFleetManagerFactory.java
index 51a783a0..6fa3e180 100644
--- a/jsprit-core/src/main/java/jsprit/core/problem/vehicle/FiniteFleetManagerFactory.java
+++ b/jsprit-core/src/main/java/jsprit/core/problem/vehicle/FiniteFleetManagerFactory.java
@@ -27,7 +27,6 @@ public class FiniteFleetManagerFactory implements VehicleFleetManagerFactory{
private Collection
http://www2.ic.uff.br/~satoru/conteudo/artigos/PAPER%20PUCA-JHeuristics-2011.pdf
+ *
http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.100.2331&rep=rep1&type=pdf
+ *
+ * @author schroeder
+ *
+ */
+public class HVRPBenchmarkExample {
+
+ public static void main(String[] args) {
+ VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
+ //read modified Golden-instance, you can find all relevant instances in jsprit-instances/instances/vrph
+ //you can build various problems, see VrphType doc for more details
+ new VrphGoldenReader(vrpBuilder, VrphType.HVRPFD).read("input/cn_14mix.txt");
+ vrpBuilder.addPenaltyVehicles(10.0);
+ VehicleRoutingProblem vrp = vrpBuilder.build();
+
+ VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "input/algorithmConfig_considerFixedCosts.xml");
+ vra.setNuOfIterations(10000);
+// vra.setPrematureAlgorithmTermination(new IterationWithoutImprovementTermination(500));
+ vra.addListener(new AlgorithmSearchProgressChartListener("output/progress.png"));
+ Collection
http://www2.ic.uff.br/~satoru/conteudo/artigos/PAPER%20PUCA-JHeuristics-2011.pdf
@@ -30,6 +32,7 @@ import jsprit.instance.reader.VrphGoldenReader.VrphType;
public class HVRPBenchmarkExample {
public static void main(String[] args) {
+ Examples.createOutputFolder();
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
//read modified Golden-instance, you can find all relevant instances in jsprit-instances/instances/vrph
//you can build various problems, see VrphType doc for more details
@@ -57,5 +60,4 @@ public class HVRPBenchmarkExample {
new GraphStreamViewer(vrp, best).setRenderDelay(100).display();
}
-
}
diff --git a/jsprit-examples/src/main/java/jsprit/util/Examples.java b/jsprit-examples/src/main/java/jsprit/util/Examples.java
new file mode 100644
index 00000000..37a4463a
--- /dev/null
+++ b/jsprit-examples/src/main/java/jsprit/util/Examples.java
@@ -0,0 +1,17 @@
+package jsprit.util;
+
+import java.io.File;
+
+public class Examples {
+
+ public static void createOutputFolder(){
+ 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");
+ }
+ }
+
+}
From 623e89fb239b888b8f9a43da3be266f02d5023b5 Mon Sep 17 00:00:00 2001
From: oblonski <4sschroeder@gmail.com>
Date: Wed, 15 Jan 2014 11:35:46 -0500
Subject: [PATCH 21/25] add vehicle test
---
.../core/problem/vehicle/VehicleImpl.java | 16 ++-
.../core/problem/vehicle/VehicleImplTest.java | 102 ++++++++++++++++++
2 files changed, 116 insertions(+), 2 deletions(-)
create mode 100644 jsprit-core/src/test/java/jsprit/core/problem/vehicle/VehicleImplTest.java
diff --git a/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleImpl.java b/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleImpl.java
index 2692a24d..3f40b3f1 100644
--- a/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleImpl.java
+++ b/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleImpl.java
@@ -94,12 +94,14 @@ public class VehicleImpl implements Vehicle {
}
/**
- * Sets the {@link VehicleType}.
+ * Sets the {@link VehicleType}.
*
* @param type
+ * @throws IllegalStateException if type is null
* @return this builder
*/
public Builder setType(VehicleType type){
+ if(type==null) throw new IllegalStateException("type cannot be null.");
this.type = type;
return this;
}
@@ -166,6 +168,9 @@ public class VehicleImpl implements Vehicle {
/**
* Builds and returns the vehicle.
*
+ *