├── .classpath ├── .gitignore ├── .project ├── .settings ├── org.eclipse.jdt.core.prefs └── org.eclipse.m2e.core.prefs ├── README.md ├── input ├── abe │ ├── Matrix.txt │ ├── abrahamProblem.xml │ ├── algorithmConfig.xml │ ├── algorithmConfig_stefan.xml │ └── vrp_cordeau_01.xml ├── sschroeder │ ├── C101_solomon.txt │ ├── cordeau_p01.xml │ └── rr_ta.xml └── stackoverflow │ ├── rr_ta.xml │ └── vrpnc1-jsprit.xml ├── output └── abe │ ├── abeProblem.png │ ├── abeProblemWithSolution.png │ ├── costOfTimeSensitivity.txt │ ├── progress.png │ ├── sensitivity_costPerTimeUnit_tpDistance.png │ └── sensitivity_costPerTimeUnit_tpTime.png ├── pom.xml ├── src ├── abe │ ├── AbeProblem.java │ ├── AbeProblemFastRelation.java │ ├── AbeProblemFastVehicle.java │ ├── AbeProblemInverseTimeDistance.java │ ├── AbeProblemMinMax.java │ ├── AbeProblemRandomSpeedup.java │ ├── MatrixReader.java │ └── MultipleDepotTimeCostSensitivity.java ├── sschroeder │ ├── DepartureTimeReScheduler.java │ ├── MultipleDepotExample.java │ ├── SimpleExampleWithOperationTimeOfDriver.java │ ├── SolomonExample.java │ ├── SpeedVariations.java │ ├── StateIds.java │ ├── TimeWindowConstraintWithDriverTime.java │ └── UpdateDepartureTimeAndPracticalTimeWindows.java └── stackoverflow │ ├── Stackoverflow_RelatedJobs_13_and_21_inSameRoute.java │ ├── Stackoverflow_RelatedJobs_13_and_21_inSameRoute_13_immediatelyAfter_21.java │ ├── Stackoverflow_RelatedJobs_13_and_21_inSameRoute_21_first.java │ ├── Stackoverflow_RelatedJobs_CapacityConstraints.java │ └── Stackoverflow_RelatedJobs_noConstraints.java ├── stackoverflow ├── jsprit_vrpnc1_13_21_inSameRoute.png ├── jsprit_vrpnc1_13_rightAfter_21.png ├── jsprit_vrpnc1_21_first.png ├── jsprit_vrpnc1_capConstraints.png └── jsprit_vrpnc1_noConstraints.png └── test └── sschroeder └── TestTimeWindowConstraintWithDriver.java /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | /bin 3 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | jsprit-playground 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.m2e.core.maven2Nature 21 | org.eclipse.jdt.core.javanature 22 | 23 | 24 | -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 5 | org.eclipse.jdt.core.compiler.compliance=1.6 6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 11 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 12 | org.eclipse.jdt.core.compiler.source=1.6 13 | -------------------------------------------------------------------------------- /.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | playground 2 | ========== 3 | 4 | to experiment with jsprit 5 | -------------------------------------------------------------------------------- /input/abe/Matrix.txt: -------------------------------------------------------------------------------- 1 | Vehicle;Service;Distance;Time 2 | 0;4;627,925894642352;124,896866825247 3 | 0;5;1095,33893126991;144,255542435701 4 | 0;6;256,940132257748;48,8820287367602 5 | 0;7;390,897478322134;72,8308208501911 6 | 0;8;390,897478322134;72,8308208501911 7 | 0;9;2537,63972922215;329,755881818953 8 | 0;10;319,037879432953;57,0756271629136 9 | 0;11;2612,33786505654;350,134147599029 10 | 0;12;211,549228954781;57,7285712466315 11 | 0;13;530,08714160743;97,8524766067324 12 | 0;14;2351,71633972658;306,369397775272 13 | 0;15;2232,27397806311;282,769547735502 14 | 0;16;600,113213650645;112,894353793844 15 | 0;17;2310,91482339303;303,431688599256 16 | 0;18;2551,11494154448;345,042034308031 17 | 0;19;2540,12720879296;344,934980348051 18 | ------------------------------------------------------ 19 | Vehicle;Service;Distance;Time 20 | 1;4;2625,65015042305;336,595160089348 21 | 1;5;1545,96047753767;229,70545793447 22 | 1;6;2300,18892598267;295,315921786058 23 | 1;7;2454,33463218299;294,260442776063 24 | 1;8;2454,33463218299;294,260442776063 25 | 1;9;9,12684094184217;0,657132547812636 26 | 1;10;2528,02024973174;307,514833071939 27 | 1;11;196,720627426113;44,1638851746801 28 | 1;12;2736,61244083998;339,584444999366 29 | 1;13;2527,81139738813;289,550769870833 30 | 1;14;348,639960724323;55,1020771721513 31 | 1;15;468,08230481448;78,7019259466425 32 | 1;16;2597,83746943135;324,592647057945 33 | 1;17;482,438588847731;69,7355783970366 34 | 1;18;766,257232704299;155,614944945833 35 | 1;19;268,931284668272;49,3630524961156 36 | ------------------------------------------------------ 37 | Vehicle;Service;Distance;Time 38 | 2;4;186,32130349217;43,4151338514362 39 | 2;5;1194,50515278095;173,898483622609 40 | 2;6;356,106353768793;78,5249699236682 41 | 2;7;490,063699833179;102,473762037099 42 | 2;8;490,063699833179;102,473762037099 43 | 2;9;2636,80595073319;359,398823005861 44 | 2;10;418,204100943998;86,7185683498216 45 | 2;11;2711,50408754616;379,777088856395 46 | 2;12;310,715450465826;67,3715124335395 47 | 2;13;172,669717836822;67,4322196842512 48 | 2;14;2450,88256123763;336,01233896218 49 | 2;15;2331,44019957416;312,41248892241 50 | 2;16;678,208042128497;118,830979033252 51 | 2;17;2410,08104490408;333,074629786164 52 | 2;18;2650,28116305553;374,684975494939 53 | 2;19;2639,293430304;374,577921534959 54 | ------------------------------------------------------ 55 | Vehicle;Service;Distance;Time 56 | 3;4;1411,66135023897;224,367640211612 57 | 3;5;1977,58205005434;232,149046744148 58 | 3;6;1208,77359454608;172,41403802152 59 | 3;7;1342,73094061046;196,362830134951 60 | 3;8;1342,73094061046;196,362830134951 61 | 3;9;2025,66628273166;274,178060291837 62 | 3;10;1270,87134172128;180,607636447673 63 | 3;11;2040,19181888289;281,893810959568 64 | 3;12;1163,38269124311;181,260580531391 65 | 3;13;1347,49894466374;254,747947010195 66 | 3;14;2181,29598463246;325,02448743252 67 | 3;15;2300,73832872262;348,624336207011 68 | 3;16;1551,94667593897;236,426363078604 69 | 3;17;2315,09461275587;339,657988657406 70 | 3;18;2598,91325661244;405,537355206202 71 | 3;19;2382,78178000962;344,648744986194 72 | ------------------------------------------------------ 73 | Service;Service;Distance;Time 74 | 4;5;1234,88574613328;201,805886343977 75 | 4;6;396,486947121124;106,432372645036 76 | 4;7;530,44429318551;130,381164758467 77 | 4;8;530,44429318551;130,381164758467 78 | 4;9;2677,18654408552;387,306225727229 79 | 4;10;458,584694296329;114,625971071189 80 | 4;11;2751,88468089849;407,684491577763 81 | 4;12;351,096043818157;95,2789151549073 82 | 4;13;213,050311189153;95,339622405619 83 | 4;14;2491,26315458996;363,919741683548 84 | 4;15;2371,82079292649;340,319891643778 85 | 4;16;739,660028514021;170,44469770212 86 | 4;17;2450,46163825641;360,982032507532 87 | 4;18;2690,66175640786;402,592378216307 88 | 4;19;2679,67402365633;402,485324256327 89 | 5;6;888,554776728524;133,27980696212 90 | 5;7;954,83214807923;128,747914661705 91 | 5;8;954,83214807923;128,747914661705 92 | 5;9;1661,62063473291;226,29136763146 93 | 5;10;882,972549190049;132,992720974427 94 | 5;11;1736,31877154589;246,669633481994 95 | 5;12;1569,92816067637;257,221859320618 96 | 5;13;1361,12711722453;207,188184192085 97 | 5;14;1475,69724523735;202,90488358778 98 | 5;15;1356,25488357388;179,30503354801 99 | 5;16;1431,15318926774;242,230061379196 100 | 5;17;1434,8957289038;199,967174411764 101 | 5;18;1675,09584705525;241,577520120539 102 | 5;19;1664,10811430373;241,470466160559 103 | 6;7;133,957353799813;23,9487925112529 104 | 6;8;133,957353799813;23,9487925112529 105 | 6;9;2280,69960469983;280,873853480014 106 | 6;10;62,0977549106317;8,19359882397534 107 | 6;11;2355,3977415128;301,252119330548 108 | 6;12;481,948060536954;99,004123396327 109 | 6;13;273,147017085109;48,9704482677942 110 | 6;14;2094,77621520426;257,487369436334 111 | 6;15;1975,33385354079;233,887519396564 112 | 6;16;343,173089128324;64,0123254549056 113 | 6;17;2053,97469887071;254,549660260318 114 | 6;18;2294,17481702216;296,160005969093 115 | 6;19;2283,18708427064;296,052952009113 116 | 7;8;0;0 117 | 7;9;2346,97697605053;296,341961179599 118 | 7;10;128,375126261338;23,6617065235599 119 | 7;11;2421,6751128635;316,720227030133 120 | 7;12;347,990782184982;75,0553363173187 121 | 7;13;139,189738733137;25,0216611887858 122 | 7;14;2161,05358655497;272,955477135919 123 | 7;15;2041,6112248915;249,355627096149 124 | 7;16;209,215810776351;40,0635383758973 125 | 7;17;2120,25207022142;270,017767959903 126 | 7;18;2360,45218837287;311,628113668677 127 | 7;19;2349,46445562134;311,521059708697 128 | 8;9;2346,97697605053;296,341961179599 129 | 8;10;128,375126261338;23,6617065235599 130 | 8;11;2421,6751128635;316,720227030133 131 | 8;12;347,990782184982;75,0553363173187 132 | 8;13;139,189738733137;25,0216611887858 133 | 8;14;2161,05358655497;272,955477135919 134 | 8;15;2041,6112248915;249,355627096149 135 | 8;16;209,215810776351;40,0635383758973 136 | 8;17;2120,25207022142;270,017767959903 137 | 8;18;2360,45218837287;311,628113668677 138 | 8;19;2349,46445562134;311,521059708697 139 | 9;10;2607,03494651463;362,805435162668 140 | 9;11;205,847468367955;44,8210177224928 141 | 9;12;2815,62713762287;394,875047090095 142 | 9;13;2606,82609417102;344,841371961562 143 | 9;14;357,766801666165;55,7592097199639 144 | 9;15;477,209145756322;79,3590584944552 145 | 9;16;2734,78290749439;451,779202629116 146 | 9;17;491,565429789573;70,3927109448493 147 | 9;18;775,384073646141;156,272077493646 148 | 9;19;278,058125610114;50,0201850439282 149 | 10;11;2293,30016001026;293,058529424704 150 | 10;12;476,365832998478;98,717037408634 151 | 10;13;267,564789546633;48,6833622801011 152 | 10;14;2032,67863370173;249,29377953049 153 | 10;15;1913,23627203826;225,69392949072 154 | 10;16;337,590861589848;63,7252394672126 155 | 10;17;1991,87711736818;246,356070354474 156 | 10;18;2232,07723551963;287,966416063248 157 | 10;19;2221,08950276811;287,859362103268 158 | 11;12;2668,88565190204;379,309660118196 159 | 11;13;2460,0846084502;329,275984989663 160 | 11;14;211,025315945338;40,1938227480644 161 | 11;15;330,467660035495;63,7936715225556 162 | 11;16;2588,04142177357;436,213815657217 163 | 11;17;344,823944068746;54,8273239729497 164 | 11;18;628,642587925314;140,706690521746 165 | 11;19;72,2106572421592;5,19916732143546 166 | 12;13;589,250795943593;92,4260573079387 167 | 12;14;2410,87999406275;320,942978476479 168 | 12;15;2291,43763239928;297,343128436709 169 | 12;16;659,276867986808;107,46793449505 170 | 12;17;2370,07847772919;318,005269300463 171 | 12;18;2610,27859588065;359,615615009237 172 | 12;19;2599,29086312912;359,508561049257 173 | 13;14;2348,96884819578;318,674551623167 174 | 13;15;2229,52648653231;295,074701583397 175 | 13;16;597,365722119843;125,199507641739 176 | 13;17;2308,16733186223;315,736842447151 177 | 13;18;2548,36745001368;357,347188155926 178 | 13;19;2537,37971726216;357,240134195946 179 | 14;15;119,442669667457;23,5998722160569 180 | 14;16;2377,01643140553;396,020016350718 181 | 14;17;133,798953700709;14,633524666451 182 | 14;18;975,584481404895;188,657683391259 183 | 14;19;792,094927808734;156,130498330465 184 | 15;16;2321,85863103872;402,048654724308 185 | 15;17;78,6411533339032;20,662163040041 186 | 15;18;526,404960146702;102,217094332432 187 | 15;19;515,417227395178;102,110040372453 188 | 16;17;2538,74532065343;374,054680069987 189 | 16;18;2778,94543880488;415,665025778761 190 | 16;19;2767,95770605335;415,557971818782 191 | 17;18;1002,953349375;216,52857835687 192 | 17;19;991,965616623473;216,42152439689 193 | 18;19;68,9928502217136;9,96748521596338 194 | ------------------------------------------------------ -------------------------------------------------------------------------------- /input/abe/abrahamProblem.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | FINITE 6 | HOMOGENEOUS 7 | 8 | 9 | 10 | 2MF1CC92BA 11 | Flexibles 12 | 13 | 0 14 | 15 | 16 | 17 | 0.0 18 | 1.7976931348623157E308 19 | 20 | false 21 | 22 | 23 | 2MF1CC93BA 24 | Flexibles 25 | 26 | 1 27 | 28 | 29 | 30 | 0.0 31 | 1.7976931348623157E308 32 | 33 | false 34 | 35 | 36 | 2MF1CC94BA 37 | Flexibles 38 | 39 | 2 40 | 41 | 42 | 43 | 0.0 44 | 1.7976931348623157E308 45 | 46 | false 47 | 48 | 49 | 2MF2CC04AA 50 | Flexibles 51 | 52 | 3 53 | 54 | 55 | 56 | 0.0 57 | 1.7976931348623157E308 58 | 59 | false 60 | 61 | 62 | 63 | 64 | Flexibles 65 | 1000000 66 | 67 | 0.0 68 | .0 69 | 70 | 71 | 72 | 73 | 74 | 75 | 4 76 | 77 | 1 78 | 180.0 79 | 80 | 81 | 0.0 82 | 1.7976931348623157E308 83 | 84 | 85 | 86 | 87 | 10 88 | 89 | 1 90 | 180.0 91 | 92 | 93 | 0.0 94 | 1.7976931348623157E308 95 | 96 | 97 | 98 | 99 | 16 100 | 101 | 1 102 | 180.0 103 | 104 | 105 | 0.0 106 | 1.7976931348623157E308 107 | 108 | 109 | 110 | 111 | 11 112 | 113 | 1 114 | 180.0 115 | 116 | 117 | 0.0 118 | 1.7976931348623157E308 119 | 120 | 121 | 122 | 123 | 17 124 | 125 | 1 126 | 180.0 127 | 128 | 129 | 0.0 130 | 1.7976931348623157E308 131 | 132 | 133 | 134 | 135 | 18 136 | 137 | 1 138 | 180.0 139 | 140 | 141 | 0.0 142 | 1.7976931348623157E308 143 | 144 | 145 | 146 | 147 | 12 148 | 149 | 1 150 | 180.0 151 | 152 | 153 | 0.0 154 | 1.7976931348623157E308 155 | 156 | 157 | 158 | 159 | 6 160 | 161 | 1 162 | 180.0 163 | 164 | 165 | 0.0 166 | 1.7976931348623157E308 167 | 168 | 169 | 170 | 171 | 14 172 | 173 | 1 174 | 180.0 175 | 176 | 177 | 0.0 178 | 1.7976931348623157E308 179 | 180 | 181 | 182 | 183 | 13 184 | 185 | 1 186 | 180.0 187 | 188 | 189 | 0.0 190 | 1.7976931348623157E308 191 | 192 | 193 | 194 | 195 | 15 196 | 197 | 1 198 | 180.0 199 | 200 | 201 | 0.0 202 | 1.7976931348623157E308 203 | 204 | 205 | 206 | 207 | 8 208 | 209 | 1 210 | 180.0 211 | 212 | 213 | 0.0 214 | 1.7976931348623157E308 215 | 216 | 217 | 218 | 219 | 19 220 | 221 | 1 222 | 180.0 223 | 224 | 225 | 0.0 226 | 1.7976931348623157E308 227 | 228 | 229 | 230 | 231 | 7 232 | 233 | 1 234 | 180.0 235 | 236 | 237 | 0.0 238 | 1.7976931348623157E308 239 | 240 | 241 | 242 | 243 | 9 244 | 245 | 1 246 | 180.0 247 | 248 | 249 | 0.0 250 | 1.7976931348623157E308 251 | 252 | 253 | 254 | 255 | 5 256 | 257 | 1 258 | 180.0 259 | 260 | 261 | 0.0 262 | 1.7976931348623157E308 263 | 264 | 265 | 266 | 267 | 268 | -------------------------------------------------------------------------------- /input/abe/algorithmConfig.xml: -------------------------------------------------------------------------------- 1 |  2 | 22 | 23 | 24 | 2000 25 | 26 | 27 | 28 | false 29 | 30 | 31 | 32 | 33 | 1 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 0.3 43 | 44 | 45 | 46 | 47 | 48 | 0.2 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 0.15 59 | 60 | 61 | 62 | 63 | 64 | 0.2 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 0.05 74 | 75 | 76 | 77 | 78 | 79 | 0.6 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /input/abe/algorithmConfig_stefan.xml: -------------------------------------------------------------------------------- 1 |  2 | 22 | 23 | 24 | 2000 25 | 26 | 27 | 28 | true 29 | 30 | 31 | 32 | 33 | 1 34 | 35 | 36 | 37 | 38 | 0.05 39 | 20 40 | 41 | 42 | 43 | 44 | 0.5 45 | 46 | 47 | 48 | 49 | 50 | 0.5 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 0.3 60 | 61 | 62 | 63 | 64 | 65 | 0.5 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /input/abe/vrp_cordeau_01.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 35 8 | 9 | 17 10 | 0.0 11 | 12 | 13 | 0.0 14 | 1.7976931348623157E308 15 | 16 | 17 | 18 | 19 | 36 20 | 21 | 6 22 | 0.0 23 | 24 | 25 | 0.0 26 | 1.7976931348623157E308 27 | 28 | 29 | 30 | 31 | 33 32 | 33 | 23 34 | 0.0 35 | 36 | 37 | 0.0 38 | 1.7976931348623157E308 39 | 40 | 41 | 42 | 43 | 34 44 | 45 | 26 46 | 0.0 47 | 48 | 49 | 0.0 50 | 1.7976931348623157E308 51 | 52 | 53 | 54 | 55 | 39 56 | 57 | 14 58 | 0.0 59 | 60 | 61 | 0.0 62 | 1.7976931348623157E308 63 | 64 | 65 | 66 | 67 | 37 68 | 69 | 9 70 | 0.0 71 | 72 | 73 | 0.0 74 | 1.7976931348623157E308 75 | 76 | 77 | 78 | 79 | 38 80 | 81 | 15 82 | 0.0 83 | 84 | 85 | 0.0 86 | 1.7976931348623157E308 87 | 88 | 89 | 90 | 91 | 43 92 | 93 | 11 94 | 0.0 95 | 96 | 97 | 0.0 98 | 1.7976931348623157E308 99 | 100 | 101 | 102 | 103 | 42 104 | 105 | 13 106 | 0.0 107 | 108 | 109 | 0.0 110 | 1.7976931348623157E308 111 | 112 | 113 | 114 | 115 | 41 116 | 117 | 27 118 | 0.0 119 | 120 | 121 | 0.0 122 | 1.7976931348623157E308 123 | 124 | 125 | 126 | 127 | 40 128 | 129 | 7 130 | 0.0 131 | 132 | 133 | 0.0 134 | 1.7976931348623157E308 135 | 136 | 137 | 138 | 139 | 22 140 | 141 | 8 142 | 0.0 143 | 144 | 145 | 0.0 146 | 1.7976931348623157E308 147 | 148 | 149 | 150 | 151 | 23 152 | 153 | 16 154 | 0.0 155 | 156 | 157 | 0.0 158 | 1.7976931348623157E308 159 | 160 | 161 | 162 | 163 | 24 164 | 165 | 10 166 | 0.0 167 | 168 | 169 | 0.0 170 | 1.7976931348623157E308 171 | 172 | 173 | 174 | 175 | 25 176 | 177 | 28 178 | 0.0 179 | 180 | 181 | 0.0 182 | 1.7976931348623157E308 183 | 184 | 185 | 186 | 187 | 26 188 | 189 | 7 190 | 0.0 191 | 192 | 193 | 0.0 194 | 1.7976931348623157E308 195 | 196 | 197 | 198 | 199 | 27 200 | 201 | 15 202 | 0.0 203 | 204 | 205 | 0.0 206 | 1.7976931348623157E308 207 | 208 | 209 | 210 | 211 | 28 212 | 213 | 14 214 | 0.0 215 | 216 | 217 | 0.0 218 | 1.7976931348623157E308 219 | 220 | 221 | 222 | 223 | 29 224 | 225 | 6 226 | 0.0 227 | 228 | 229 | 0.0 230 | 1.7976931348623157E308 231 | 232 | 233 | 234 | 235 | 3 236 | 237 | 16 238 | 0.0 239 | 240 | 241 | 0.0 242 | 1.7976931348623157E308 243 | 244 | 245 | 246 | 247 | 2 248 | 249 | 30 250 | 0.0 251 | 252 | 253 | 0.0 254 | 1.7976931348623157E308 255 | 256 | 257 | 258 | 259 | 1 260 | 261 | 7 262 | 0.0 263 | 264 | 265 | 0.0 266 | 1.7976931348623157E308 267 | 268 | 269 | 270 | 271 | 7 272 | 273 | 19 274 | 0.0 275 | 276 | 277 | 0.0 278 | 1.7976931348623157E308 279 | 280 | 281 | 282 | 283 | 30 284 | 285 | 19 286 | 0.0 287 | 288 | 289 | 0.0 290 | 1.7976931348623157E308 291 | 292 | 293 | 294 | 295 | 6 296 | 297 | 15 298 | 0.0 299 | 300 | 301 | 0.0 302 | 1.7976931348623157E308 303 | 304 | 305 | 306 | 307 | 5 308 | 309 | 21 310 | 0.0 311 | 312 | 313 | 0.0 314 | 1.7976931348623157E308 315 | 316 | 317 | 318 | 319 | 32 320 | 321 | 12 322 | 0.0 323 | 324 | 325 | 0.0 326 | 1.7976931348623157E308 327 | 328 | 329 | 330 | 331 | 4 332 | 333 | 9 334 | 0.0 335 | 336 | 337 | 0.0 338 | 1.7976931348623157E308 339 | 340 | 341 | 342 | 343 | 31 344 | 345 | 11 346 | 0.0 347 | 348 | 349 | 0.0 350 | 1.7976931348623157E308 351 | 352 | 353 | 354 | 355 | 9 356 | 357 | 11 358 | 0.0 359 | 360 | 361 | 0.0 362 | 1.7976931348623157E308 363 | 364 | 365 | 366 | 367 | 8 368 | 369 | 23 370 | 0.0 371 | 372 | 373 | 0.0 374 | 1.7976931348623157E308 375 | 376 | 377 | 378 | 379 | 19 380 | 381 | 9 382 | 0.0 383 | 384 | 385 | 0.0 386 | 1.7976931348623157E308 387 | 388 | 389 | 390 | 391 | 17 392 | 393 | 3 394 | 0.0 395 | 396 | 397 | 0.0 398 | 1.7976931348623157E308 399 | 400 | 401 | 402 | 403 | 18 404 | 405 | 41 406 | 0.0 407 | 408 | 409 | 0.0 410 | 1.7976931348623157E308 411 | 412 | 413 | 414 | 415 | 15 416 | 417 | 10 418 | 0.0 419 | 420 | 421 | 0.0 422 | 1.7976931348623157E308 423 | 424 | 425 | 426 | 427 | 16 428 | 429 | 15 430 | 0.0 431 | 432 | 433 | 0.0 434 | 1.7976931348623157E308 435 | 436 | 437 | 438 | 439 | 13 440 | 441 | 23 442 | 0.0 443 | 444 | 445 | 0.0 446 | 1.7976931348623157E308 447 | 448 | 449 | 450 | 451 | 14 452 | 453 | 21 454 | 0.0 455 | 456 | 457 | 0.0 458 | 1.7976931348623157E308 459 | 460 | 461 | 462 | 463 | 11 464 | 465 | 19 466 | 0.0 467 | 468 | 469 | 0.0 470 | 1.7976931348623157E308 471 | 472 | 473 | 474 | 475 | 12 476 | 477 | 29 478 | 0.0 479 | 480 | 481 | 0.0 482 | 1.7976931348623157E308 483 | 484 | 485 | 486 | 487 | 21 488 | 489 | 8 490 | 0.0 491 | 492 | 493 | 0.0 494 | 1.7976931348623157E308 495 | 496 | 497 | 498 | 499 | 20 500 | 501 | 28 502 | 0.0 503 | 504 | 505 | 0.0 506 | 1.7976931348623157E308 507 | 508 | 509 | 510 | 511 | 49 512 | 513 | 18 514 | 0.0 515 | 516 | 517 | 0.0 518 | 1.7976931348623157E308 519 | 520 | 521 | 522 | 523 | 48 524 | 525 | 17 526 | 0.0 527 | 528 | 529 | 0.0 530 | 1.7976931348623157E308 531 | 532 | 533 | 534 | 535 | 45 536 | 537 | 10 538 | 0.0 539 | 540 | 541 | 0.0 542 | 1.7976931348623157E308 543 | 544 | 545 | 546 | 547 | 44 548 | 549 | 16 550 | 0.0 551 | 552 | 553 | 0.0 554 | 1.7976931348623157E308 555 | 556 | 557 | 558 | 559 | 47 560 | 561 | 25 562 | 0.0 563 | 564 | 565 | 0.0 566 | 1.7976931348623157E308 567 | 568 | 569 | 570 | 571 | 46 572 | 573 | 5 574 | 0.0 575 | 576 | 577 | 0.0 578 | 1.7976931348623157E308 579 | 580 | 581 | 582 | 583 | 10 584 | 585 | 5 586 | 0.0 587 | 588 | 589 | 0.0 590 | 1.7976931348623157E308 591 | 592 | 593 | 594 | 595 | 50 596 | 597 | 10 598 | 0.0 599 | 600 | 601 | 0.0 602 | 1.7976931348623157E308 603 | 604 | 605 | 606 | 607 | 608 | -------------------------------------------------------------------------------- /input/sschroeder/C101_solomon.txt: -------------------------------------------------------------------------------- 1 | C101 2 | 3 | VEHICLE 4 | NUMBER CAPACITY 5 | 25 200 6 | 7 | CUSTOMER 8 | CUST NO. XCOORD. YCOORD. DEMAND READY TIME DUE DATE SERVICE TIME 9 | 10 | 0 40 50 0 0 1236 0 11 | 1 45 68 10 912 967 90 12 | 2 45 70 30 825 870 90 13 | 3 42 66 10 65 146 90 14 | 4 42 68 10 727 782 90 15 | 5 42 65 10 15 67 90 16 | 6 40 69 20 621 702 90 17 | 7 40 66 20 170 225 90 18 | 8 38 68 20 255 324 90 19 | 9 38 70 10 534 605 90 20 | 10 35 66 10 357 410 90 21 | 11 35 69 10 448 505 90 22 | 12 25 85 20 652 721 90 23 | 13 22 75 30 30 92 90 24 | 14 22 85 10 567 620 90 25 | 15 20 80 40 384 429 90 26 | 16 20 85 40 475 528 90 27 | 17 18 75 20 99 148 90 28 | 18 15 75 20 179 254 90 29 | 19 15 80 10 278 345 90 30 | 20 30 50 10 10 73 90 31 | 21 30 52 20 914 965 90 32 | 22 28 52 20 812 883 90 33 | 23 28 55 10 732 777 90 34 | 24 25 50 10 65 144 90 35 | 25 25 52 40 169 224 90 36 | 26 25 55 10 622 701 90 37 | 27 23 52 10 261 316 90 38 | 28 23 55 20 546 593 90 39 | 29 20 50 10 358 405 90 40 | 30 20 55 10 449 504 90 41 | 31 10 35 20 200 237 90 42 | 32 10 40 30 31 100 90 43 | 33 8 40 40 87 158 90 44 | 34 8 45 20 751 816 90 45 | 35 5 35 10 283 344 90 46 | 36 5 45 10 665 716 90 47 | 37 2 40 20 383 434 90 48 | 38 0 40 30 479 522 90 49 | 39 0 45 20 567 624 90 50 | 40 35 30 10 264 321 90 51 | 41 35 32 10 166 235 90 52 | 42 33 32 20 68 149 90 53 | 43 33 35 10 16 80 90 54 | 44 32 30 10 359 412 90 55 | 45 30 30 10 541 600 90 56 | 46 30 32 30 448 509 90 57 | 47 30 35 10 1054 1127 90 58 | 48 28 30 10 632 693 90 59 | 49 28 35 10 1001 1066 90 60 | 50 26 32 10 815 880 90 61 | 51 25 30 10 725 786 90 62 | 52 25 35 10 912 969 90 63 | 53 44 5 20 286 347 90 64 | 54 42 10 40 186 257 90 65 | 55 42 15 10 95 158 90 66 | 56 40 5 30 385 436 90 67 | 57 40 15 40 35 87 90 68 | 58 38 5 30 471 534 90 69 | 59 38 15 10 651 740 90 70 | 60 35 5 20 562 629 90 71 | 61 50 30 10 531 610 90 72 | 62 50 35 20 262 317 90 73 | 63 50 40 50 171 218 90 74 | 64 48 30 10 632 693 90 75 | 65 48 40 10 76 129 90 76 | 66 47 35 10 826 875 90 77 | 67 47 40 10 12 77 90 78 | 68 45 30 10 734 777 90 79 | 69 45 35 10 916 969 90 80 | 70 95 30 30 387 456 90 81 | 71 95 35 20 293 360 90 82 | 72 53 30 10 450 505 90 83 | 73 92 30 10 478 551 90 84 | 74 53 35 50 353 412 90 85 | 75 45 65 20 997 1068 90 86 | 76 90 35 10 203 260 90 87 | 77 88 30 10 574 643 90 88 | 78 88 35 20 109 170 90 89 | 79 87 30 10 668 731 90 90 | 80 85 25 10 769 820 90 91 | 81 85 35 30 47 124 90 92 | 82 75 55 20 369 420 90 93 | 83 72 55 10 265 338 90 94 | 84 70 58 20 458 523 90 95 | 85 68 60 30 555 612 90 96 | 86 66 55 10 173 238 90 97 | 87 65 55 20 85 144 90 98 | 88 65 60 30 645 708 90 99 | 89 63 58 10 737 802 90 100 | 90 60 55 10 20 84 90 101 | 91 60 60 10 836 889 90 102 | 92 67 85 20 368 441 90 103 | 93 65 85 40 475 518 90 104 | 94 65 82 10 285 336 90 105 | 95 62 80 30 196 239 90 106 | 96 60 80 10 95 156 90 107 | 97 60 85 30 561 622 90 108 | 98 58 75 20 30 84 90 109 | 99 55 80 10 743 820 90 110 | 100 55 85 20 647 726 90 111 | -------------------------------------------------------------------------------- /input/sschroeder/rr_ta.xml: -------------------------------------------------------------------------------- 1 | 2 | 22 | 24 | 25 | 5000 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 1 35 | 36 | 37 | 38 | 39 | 0.1 40 | 20 41 | 42 | 43 | 44 | 45 | 0.5 46 | 47 | 48 | 49 | 50 | 51 | 0.5 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 0.3 62 | 63 | 64 | 65 | 66 | 67 | .5 68 | 69 | 70 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /input/stackoverflow/rr_ta.xml: -------------------------------------------------------------------------------- 1 | 2 | 22 | 24 | 25 | 1000 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 1 36 | 37 | 38 | 39 | 40 | 0.3 41 | 20 42 | 43 | 44 | 45 | 46 | 0.5 47 | 48 | 49 | 50 | 51 | 52 | 0.5 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 0.3 63 | 64 | 65 | 66 | 67 | 68 | .5 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /output/abe/abeProblem.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jsprit/playground/e42858e70a42c4614ae55a5baff87e654a8cde4b/output/abe/abeProblem.png -------------------------------------------------------------------------------- /output/abe/abeProblemWithSolution.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jsprit/playground/e42858e70a42c4614ae55a5baff87e654a8cde4b/output/abe/abeProblemWithSolution.png -------------------------------------------------------------------------------- /output/abe/costOfTimeSensitivity.txt: -------------------------------------------------------------------------------- 1 | costPerTimeUnit;run;costs;time;distance 2 | 0.0;0;576.8656874818463;445.79659458164963;576.8656874818463 3 | 0.0;1;586.972077210544;441.4366991228075;586.9720772105441 4 | 0.0;2;607.9627658356816;483.9138529768986;607.9627658356817 5 | 0.1;0;645.2578959486718;425.1506041871497;602.742835529957 6 | 0.1;1;634.6302148789391;426.4648375337318;591.9837311255662 7 | 0.1;2;641.6092627715961;454.92515101614936;596.1167476699814 8 | 0.2;0;669.1833884067086;435.66746012394265;582.04989638192 9 | 0.2;1;659.2697139668012;392.7470356339277;580.720306840016 10 | 0.2;2;682.316435976629;434.34194195021524;595.448047586586 11 | 0.30000000000000004;0;719.7483630239067;421.81560455801014;593.2036816565036 12 | 0.30000000000000004;1;699.1387208382777;387.2867560122398;582.9526940346058 13 | 0.30000000000000004;2;713.6947446406396;416.3077957487008;588.8024059160294 14 | 0.4;0;780.075479635721;417.45620361498897;613.0929981897256 15 | 0.4;1;743.7644273639131;396.30201900103873;585.2436197634976 16 | 0.4;2;771.97516576955;401.2593766262281;611.4714151190587 17 | 0.5;0;776.5960720407256;387.2867560122398;582.9526940346058 18 | 0.5;1;781.969559273784;381.2961131761681;591.3215026856998 19 | 0.5;2;802.1270403757853;415.33705540938024;594.4585126710954 20 | 0.6;0;828.1008064020999;384.38019931930484;597.4726868105168 21 | 0.6;1;831.0039729259679;397.32045661320865;592.6116989580429 22 | 0.6;2;815.3247476419494;387.2867560122398;582.9526940346059 23 | 0.7;0;887.1867671599512;418.11748651897693;594.5045265966676 24 | 0.7;1;876.0539109281247;399.23567880839096;596.588935762251 25 | 0.7;2;879.9087672821663;402.64206304122723;598.0593231533071 26 | 0.7999999999999999;0;951.8091412323405;404.3799754962895;628.305160835309 27 | 0.7999999999999999;1;910.3065945887186;381.87550711928986;604.806188893287 28 | 0.7999999999999999;2;891.6506547596595;380.01851524738356;587.6358425617528 29 | 0.8999999999999999;0;979.383040581318;402.3366901677565;617.280019430337 30 | 0.8999999999999999;1;941.3795572525166;381.26470606090476;598.2413217977024 31 | 0.8999999999999999;2;980.3080967886748;407.458567576219;613.5953859700779 32 | 0.9999999999999999;0;1002.9520768105186;406.37442505102786;596.5776517594909 33 | 0.9999999999999999;1;981.8528861298217;384.3801993193048;597.4726868105168 34 | 0.9999999999999999;2;1031.2576784305136;401.4316973946313;629.8259810358828 35 | 1.0999999999999999;0;1078.8241842427194;411.2559102776751;626.4426829372765 36 | 1.0999999999999999;1;1005.6562093338744;380.01851524738356;587.6358425617526 37 | 1.0999999999999999;2;1009.4301297231412;385.4787948690714;585.4034553671627 38 | 1.2;0;1082.3153425082285;393.11809775918726;610.573625197204 39 | 1.2;1;1090.774742236197;398.50815415385273;612.5649572515736 40 | 1.2;2;1043.9952358885744;380.1238824442466;587.8465769554789 41 | 1.3;0;1132.2227278530747;399.9030825777925;612.3487205019449 42 | 1.3;1;1109.4055503780985;383.7803594413213;610.4910831043809 43 | 1.3;2;1082.0076241329991;380.12388244424653;587.8465769554784 44 | 1.4000000000000001;0;1150.3832246405188;397.76100106907626;593.5178231438124 45 | 1.4000000000000001;1;1147.2474324221196;392.77032702273686;597.3689745902878 46 | 1.4000000000000001;2;1167.1865811000928;383.2210119212117;630.6771644103961 47 | 1.5000000000000002;0;1162.3355354152077;379.0353216398043;593.7825529555013 48 | 1.5000000000000002;1;1209.424339042212;404.5109713700699;602.6578819871073 49 | 1.5000000000000002;2;1178.5840508590388;383.94809782011544;602.6619041288656 50 | 1.6000000000000003;0;1215.704145237446;380.81484096530374;606.4003996929601 51 | 1.6000000000000003;1;1246.3665481015616;389.3846544569501;623.3511009704412 52 | 1.6000000000000003;2;1277.385170314991;401.432410005092;635.093314306844 53 | 1.7000000000000004;0;1265.8329138167219;386.76587475999156;608.3309267247365 54 | 1.7000000000000004;1;1266.143102502444;380.8713340371422;618.6618346393024 55 | 1.7000000000000004;2;1296.5273175834982;390.5427738343329;632.6046020651326 56 | 1.8000000000000005;0;1331.615179445817;391.48453418986725;626.9430179040559 57 | 1.8000000000000005;1;1297.8210389462436;382.6197792941725;609.1054362167334 58 | 1.8000000000000005;2;1325.9400622392186;386.9960532868772;629.3471663228394 59 | 1.9000000000000006;0;1357.0878484563777;384.9311080763306;625.7187431113493 60 | 1.9000000000000006;1;1362.681450312893;393.7738450851086;614.5111446511864 61 | 1.9000000000000006;2;1343.0562720027835;379.9037159138401;621.2392117664871 62 | 2.0000000000000004;0;1414.452949441134;402.5919941995359;609.2689610420621 63 | 2.0000000000000004;1;1406.5318467961115;390.2299726745222;626.0719014470667 64 | 2.0000000000000004;2;1424.3221514504746;391.71120576280714;640.8997399248602 65 | 2.1000000000000005;0;1459.6314381189613;402.356294514419;614.6832196386816 66 | 2.1000000000000005;1;1475.6423451461483;394.56827470102246;647.048968274001 67 | 2.1000000000000005;2;1488.2526401084338;392.8358455974023;663.2973643538891 68 | 2.2000000000000006;0;1470.4265776286713;377.95463593056576;638.9263785814265 69 | 2.2000000000000006;1;1480.5668662779315;388.5397671389146;625.779378572319 70 | 2.2000000000000006;2;1439.9123781774301;377.11565593643195;610.2579351172794 71 | 2.3000000000000007;0;1522.4096065543824;382.00654313110624;643.7945573528376 72 | 2.3000000000000007;1;1587.1251439696496;401.54957951186503;663.5611110923599 73 | 2.3000000000000007;2;1512.6545394959874;381.4606942864297;635.2949426371989 74 | 2.400000000000001;0;1554.8558218412818;385.7643372855385;629.0214123559891 75 | 2.400000000000001;1;1587.4260146423087;392.68190215246057;644.9894494764031 76 | 2.400000000000001;2;1525.4143444525137;390.09291753090645;589.191342378338 77 | 2.500000000000001;0;1624.9800804738961;389.1742099058175;652.0445557093526 78 | 2.500000000000001;1;1579.4514234101325;387.69675228322944;610.209542702059 79 | 2.500000000000001;2;1628.4358483856008;396.32041532143944;637.6348100820018 80 | 2.600000000000001;0;1623.0105204841377;382.10612433931715;629.5345972019129 81 | 2.600000000000001;1;1655.8382107427224;380.25220594764244;667.1824752788518 82 | 2.600000000000001;2;1621.6515324817526;383.91063557258605;623.4838799930285 83 | 2.700000000000001;0;1664.5080635712636;378.7796525412959;641.8030017097647 84 | 2.700000000000001;1;1653.246248447906;383.7415361612235;617.144100812603 85 | 2.700000000000001;2;1632.876367747391;380.25108483442045;606.1984386944553 86 | 2.800000000000001;0;1728.0953465250789;388.6403907474536;639.9022524322081 87 | 2.800000000000001;1;1736.4725801996976;395.9993948139927;627.6742747205178 88 | 2.800000000000001;2;1729.1662293333663;396.89309717380894;617.8655572467009 89 | 2.9000000000000012;0;1706.6449171257589;372.164517091733;627.3678175597333 90 | 2.9000000000000012;1;1721.355980245745;377.5824803985138;626.3667870900547 91 | 2.9000000000000012;2;1804.7921328591501;395.6210583930368;657.4910635193431 92 | 3.0000000000000013;0;1754.713568704291;373.512288192456;634.1767041269223 93 | 3.0000000000000013;1;1747.3784801651682;375.9972507464115;619.3867279259333 94 | 3.0000000000000013;2;1790.5809838192963;381.12170264120664;647.2158758956757 95 | 3.1000000000000014;0;1795.4143004212851;376.3096178705374;628.8544850226189 96 | 3.1000000000000014;1;1865.438337865256;393.1612791413457;646.6383725270838 97 | 3.1000000000000014;2;1804.338116196479;382.1092596676829;619.799411226661 98 | 3.2000000000000015;0;1868.6692976154598;381.40947427812966;648.1589799254438 99 | 3.2000000000000015;1;1837.4852988700006;377.49732527787484;629.4938579808005 100 | 3.2000000000000015;2;1858.4908513347261;384.68031264087836;627.5138508839146 101 | 3.3000000000000016;0;1877.2071143435512;384.1796326662589;609.4143265448967 102 | 3.3000000000000016;1;1851.2869469655361;374.7012135144079;614.7729423679896 103 | 3.3000000000000016;2;1872.4946504904722;380.6051933580265;616.4975124089846 104 | 3.4000000000000017;0;1911.9096875168937;378.31602359419475;625.6352072966307 105 | 3.4000000000000017;1;1894.6815845101269;375.82004198521327;616.8934417604011 106 | 3.4000000000000017;2;1948.7399444876803;386.96486119007756;633.0594164414161 107 | 3.5000000000000018;0;2001.2723935401605;389.38197070355113;638.435496077731 108 | 3.5000000000000018;1;1971.3192766688308;385.5809827429796;621.7858370684015 109 | 3.5000000000000018;2;1999.2032152540623;390.29743412202174;633.1621958269856 110 | 3.600000000000002;0;2014.5432706926526;385.5342158955683;626.6200934686062 111 | 3.600000000000002;1;2038.0128652162134;385.4535803414326;650.3799759870557 112 | 3.600000000000002;2;1964.1118467136764;371.8876461659389;625.3163205162957 113 | 3.700000000000002;0;2074.6877180197894;389.3542647935703;634.0769382835787 114 | 3.700000000000002;1;2001.2529991741883;374.8653455269671;614.2512207244102 115 | 3.700000000000002;2;2050.831007655165;384.68031264087836;627.5138508839146 116 | 3.800000000000002;0;2143.3348542188164;392.31573857225953;652.535047644229 117 | 3.800000000000002;1;2090.1394614834257;386.89579472582864;619.9354415252761 118 | 3.800000000000002;2;2150.863947459755;391.60912769785824;662.7492622078928 119 | 3.900000000000002;0;2182.371714436258;394.766563956249;642.7821150068861 120 | 3.900000000000002;1;2139.0020379921284;381.2396273135165;652.1674914694133 121 | 3.900000000000002;2;2156.7457737471186;387.8563882088256;644.1058597326976 122 | 4.000000000000002;0;2183.1686697646487;381.9824775143397;655.2387597072895 123 | 4.000000000000002;1;2205.2891958930036;385.8466046578833;661.9027772614696 124 | 4.000000000000002;2;2200.9023241319665;384.7881296902399;661.7498053710065 125 | 4.100000000000001;0;2164.1686564013457;375.86768542447174;623.1111461610113 126 | 4.100000000000001;1;2154.1519733299324;377.7327249280486;605.4478011249331 127 | 4.100000000000001;2;2199.8435233400187;375.68229792776646;659.5461018361763 128 | 4.200000000000001;0;2294.1815000462166;387.30599704090224;667.4963124744278 129 | 4.200000000000001;1;2273.059576744283;385.8019193977128;652.6915152738886 130 | 4.200000000000001;2;2200.089109911442;376.3449417330207;619.4403546327551 131 | 4.300000000000001;0;2321.5710515270835;388.7028115755442;650.1489617522433 132 | 4.300000000000001;1;2243.411605327089;378.01281799559746;617.9564879460199 133 | 4.300000000000001;2;2319.4596321208032;388.19517381528277;650.2203847150872 134 | 4.4;0;2297.1216459071265;376.8418322173919;639.0175841506016 135 | 4.4;1;2355.6647443316183;387.47297557363873;650.7836518076081 136 | 4.4;2;2348.481290011907;384.65896387777616;655.981848949692 137 | 4.5;0;2399.66300031875;390.9231545148877;640.5088050017556 138 | 4.5;1;2459.5600423549276;398.99706286503834;664.0732594622555 139 | 4.5;2;2458.566391358051;400.1028320575855;658.1036470989162 140 | 4.6;0;2369.333730923765;376.4654206555241;637.5927959083551 141 | 4.6;1;2410.288249335148;383.5453139583026;645.9798051269563 142 | 4.6;2;2425.105325002551;385.2337320674387;653.0301574923334 143 | 4.699999999999999;0;2440.936694227224;384.81023582319426;632.3285858582112 144 | 4.699999999999999;1;2419.1461701317266;379.8724263356025;633.7457663543954 145 | 4.699999999999999;2;2466.9571057062335;383.55483652249507;664.2493740505078 146 | 4.799999999999999;0;2506.415015626004;388.53481379131097;641.4479094277116 147 | 4.799999999999999;1;2542.487596607152;395.1281067185788;645.8726843579751 148 | 4.799999999999999;2;2512.4330600264293;385.45029486486453;662.27164467508 149 | 4.899999999999999;0;2527.6074395701294;384.97709812305294;641.2196587671698 150 | 4.899999999999999;1;2545.462532396856;387.3333345997578;647.5291928580434 151 | 4.899999999999999;2;2486.1317068235417;377.0593752760917;638.5407679706932 152 | 4.999999999999998;0;2622.506202218977;392.5987231369164;659.5125865343957 153 | 4.999999999999998;1;2583.56104724251;389.283821679148;637.1419388467709 154 | 4.999999999999998;2;2569.369944582358;385.06378680865157;644.0510105391007 155 | 5.099999999999998;0;2633.4040859088527;388.3537052660224;652.8001890521393 156 | 5.099999999999998;1;2648.5701739433616;390.561610289937;656.7059614646831 157 | 5.099999999999998;2;2635.47843421613;388.9011459556168;652.0825898424858 158 | 5.1999999999999975;0;2661.8088869328476;382.27596672928166;673.9738599405841 159 | 5.1999999999999975;1;2628.9989813701927;380.59902660250975;649.8840430371425 160 | 5.1999999999999975;2;2694.6271668740264;390.34651401507836;664.8252939956201 161 | 5.299999999999997;0;2823.10206426841;406.95272678480825;666.252612308928 162 | 5.299999999999997;1;2621.504218534681;379.6487633864747;609.3657725863666 163 | 5.299999999999997;2;2646.8049934743294;382.9468645976375;617.1866111068524 164 | 5.399999999999997;0;2694.1329708026888;381.19193219911676;635.6965369274602 165 | 5.399999999999997;1;2769.1866906020414;394.7813762354794;637.3672589304545 166 | 5.399999999999997;2;2722.721144504325;383.725466926565;650.603623100875 167 | 5.4999999999999964;0;2702.402479030191;375.3878236050802;637.769449202251 168 | 5.4999999999999964;1;2822.7241815171346;392.588292316017;663.4885737790427 169 | 5.4999999999999964;2;2799.2737029441305;388.91022399739626;660.2674709584525 170 | 5.599999999999996;0;2780.505328245538;379.78678135340687;653.6993526664616 171 | 5.599999999999996;1;2890.75371809444;394.04543001576934;684.0993100061338 172 | 5.599999999999996;2;2755.6525530875374;378.46075327159144;636.272334766627 173 | 5.699999999999996;0;2834.9788036470295;381.16811876078475;662.3205267105585 174 | 5.699999999999996;1;2905.5281247571943;394.3324947194314;657.8329048564375 175 | 5.699999999999996;2;2856.9619524785253;385.88267616416067;657.4306983428127 176 | 5.799999999999995;0;2908.5700219856994;385.26249986422357;674.0475227732043 177 | 5.799999999999995;1;2929.217411501518;389.5520145796212;669.8157269397173 178 | 5.799999999999995;2;2925.479116855215;387.4691749140634;678.1579023536499 179 | 5.899999999999995;0;2938.4754939482004;387.1833612271628;654.0936627079423 180 | 5.899999999999995;1;2977.470475658331;389.76999221531946;677.8275215879482 181 | 5.899999999999995;2;3020.6419932356193;397.7211209168332;674.0873798263061 182 | 5.999999999999995;0;2911.16827077517;378.9639400914978;637.3846302261848 183 | 5.999999999999995;1;2874.4596147046573;375.0329658895133;624.2618193675806 184 | 5.999999999999995;2;2989.9906489379373;389.57289760186677;652.553263326739 185 | 6.099999999999994;0;3023.7018228703164;387.92001605286214;657.3897249478599 186 | 6.099999999999994;1;3020.4008929213064;390.0696931107103;640.9757649459754 187 | 6.099999999999994;2;3026.661509262774;387.45388031708467;663.19283932856 188 | 6.199999999999994;0;3046.2983987640873;387.6657487030682;642.7707568050669 189 | 6.199999999999994;1;3059.2106279163436;385.6640153012505;668.0937330485934 190 | 6.199999999999994;2;2994.912009453031;380.4934470671726;635.8526376365627 191 | 6.299999999999994;0;3030.8981108688645;378.5350337707516;646.1273981131311 192 | 6.299999999999994;1;3014.850682143784;377.5873385057735;636.050449557414 193 | 6.299999999999994;2;3049.3164371138278;378.7606178782636;663.124544480769 194 | 6.399999999999993;0;3129.208861087994;386.90973426752686;652.9865617758256 195 | 6.399999999999993;1;3167.89102698192;389.2656595385977;676.5908059348974 196 | 6.399999999999993;2;3103.228589404154;384.1932750122979;644.3916293254501 197 | 6.499999999999993;0;3151.768790728033;386.0575606318364;642.3946466210989 198 | 6.499999999999993;1;3148.5401400649;382.2412301766548;663.9721439166467 199 | 6.499999999999993;2;3231.2411242771564;391.5111468034118;686.4186700549822 200 | 6.5999999999999925;0;3191.8665285836073;386.59871436065606;640.3150138032806 201 | 6.5999999999999925;1;3071.9534161336032;371.90816767599836;617.3595094720167 202 | 6.5999999999999925;2;3202.8017270380396;386.6329574892079;651.0242076092702 203 | 6.699999999999992;0;3113.5850182075947;373.9302931245969;608.2520542727985 204 | 6.699999999999992;1;3237.4833725035337;383.09743073477756;670.7305865805267 205 | 6.699999999999992;2;3195.4379137955766;382.0801585740401;635.5008513495103 206 | 6.799999999999992;0;3201.5420432288643;376.84183221739204;639.0175841506015 207 | 6.799999999999992;1;3240.0863569188077;381.35999081332466;646.8384193882039 208 | 6.799999999999992;2;3326.9718208828945;391.5337403886157;664.5423862403107 209 | 6.8999999999999915;0;3280.5942271562;383.69124031648477;633.1246689724578 210 | 6.8999999999999915;1;3442.8949006742705;401.7963893714223;670.4998140114595 211 | 6.8999999999999915;2;3241.5061062254204;375.77150620448384;648.6827134144854 212 | 6.999999999999991;0;3445.330769904867;396.81101498438545;667.6536650141728 213 | 6.999999999999991;1;3309.132375570337;379.15609222909654;655.0397299666655 214 | 6.999999999999991;2;3314.8178756671823;380.1647423166546;653.6646794506044 215 | 7.099999999999991;0;3488.630335362098;398.0033205454517;662.8067594893951 216 | 7.099999999999991;1;3387.0625683158205;384.5521771720584;656.7421103942091 217 | 7.099999999999991;2;3345.2949832339295;382.8105079654874;627.3403766789733 218 | 7.19999999999999;0;3371.1038881489635;378.6082854553488;645.1242328704559 219 | 7.19999999999999;1;3494.9637966809614;391.1484649967243;678.6948487045507 220 | 7.19999999999999;2;3454.3838153694023;387.29515454173105;665.8587026689426 221 | 7.29999999999999;0;3448.548236160561;383.34636875175283;650.1197442727683 222 | 7.29999999999999;1;3531.0896024716994;393.30318509558236;659.9763512739519 223 | 7.29999999999999;2;3511.2778733935575;389.8844974157724;665.1210422584231 224 | 7.39999999999999;0;3501.777085187544;384.53074716572473;656.2495561611851 225 | 7.39999999999999;1;3435.474824663726;378.2071824389272;636.7416746156691 226 | 7.39999999999999;2;3465.858373546557;378.093871659075;667.9637232694071 227 | 7.499999999999989;0;3685.9309562117314;400.9141556967629;679.0747884860137 228 | 7.499999999999989;1;3574.4951202300335;386.22895623770637;677.7779484472401 229 | 7.499999999999989;2;3530.552616975984;387.4283594837125;624.8399208481452 230 | 7.599999999999989;0;3635.4015908650763;389.8360503825605;672.6476079576205 231 | 7.599999999999989;1;3530.548415856151;378.41697872641026;654.5793775354388 232 | 7.599999999999989;2;3566.651464535404;384.02573488901226;648.0558793789145 233 | 7.699999999999989;0;3646.770096237129;388.121923429748;658.2312858280742 234 | 7.699999999999989;1;3522.0643847756146;377.7704686732976;613.2317759912271 235 | 7.699999999999989;2;3706.0474679532285;393.3129324555342;677.5378880456201 236 | 7.799999999999988;0;3734.4990195469018;391.7642010733967;678.7382511744129 237 | 7.799999999999988;1;3579.3981459947972;379.259081413753;621.1773109675286 238 | 7.799999999999988;2;3669.2964505455184;386.5156022487066;654.4747530056106 239 | 7.899999999999988;0;3663.547525196581;381.5658456287271;649.177344729642 240 | 7.899999999999988;1;3818.9866869724533;399.1146983964009;665.9805696408905 241 | 7.899999999999988;2;3724.2723261957085;387.5107060177075;662.9377486558238 242 | 7.999999999999988;0;3591.7462282594274;372.66212870995435;610.4491985797973 243 | 7.999999999999988;1;3710.549232005213;381.1894915825694;661.033299344662 244 | 7.999999999999988;2;3714.6269454554395;385.48206818208837;630.770399998737 245 | 8.099999999999987;0;3922.4588258908702;399.23494728134455;688.6557529119849 246 | 8.099999999999987;1;3840.0976079107054;393.71701505647354;650.9897859532745 247 | 8.099999999999987;2;3757.0803122987045;383.21377796498757;653.0487107823095 248 | 8.199999999999987;0;3793.947985921305;381.1412739995525;668.5895391249799 249 | 8.199999999999987;1;3878.7849152773642;388.75199438241185;691.0185613415927 250 | 8.199999999999987;2;3761.1061617138093;379.04607178208664;652.9283731007042 251 | 8.299999999999986;0;3816.628764319862;380.874005673534;655.3745172295352 252 | 8.299999999999986;1;3947.460204551589;395.9065184745388;661.4361012129217 253 | 8.299999999999986;2;3887.170389231452;389.0837469139841;657.7752898453898 254 | 8.399999999999986;0;3917.813325829805;387.82800136084944;660.0581143986753 255 | 8.399999999999986;1;3951.9730072957555;392.09008041852326;658.4163317801663 256 | 8.399999999999986;2;3882.2271976456905;384.22427957537167;654.7432492125743 257 | 8.499999999999986;0;3821.500179779571;375.7520735794185;627.6075543545194 258 | 8.499999999999986;1;3838.0976946202604;381.0383979800374;599.2713117899474 259 | 8.499999999999986;2;3956.379151252343;387.4693052039453;662.8900570188133 260 | 8.599999999999985;0;4102.758861686171;399.80783112808325;664.4115139846608 261 | 8.599999999999985;1;3934.4089209032495;379.23108419262184;673.0215968467076 262 | 8.599999999999985;2;4040.481710028848;393.4593586200099;656.7312258967684 263 | 8.699999999999985;0;3935.005032313256;375.55619068246966;667.6661733757763 264 | 8.699999999999985;1;4091.5276214702653;392.2981258489592;678.5339265843261 265 | 8.699999999999985;2;3988.9804756511035;384.24735581043757;646.028480100303 266 | 8.799999999999985;0;4012.976139250829;379.53248439664344;673.0902765603726 267 | 8.799999999999985;1;4220.126826088266;400.7921410061718;693.1559852339593 268 | 8.799999999999985;2;4099.455147797391;389.24369360126065;674.1106441063039 269 | 8.899999999999984;0;4095.642324231932;385.9976399889776;660.2633283300364 270 | 8.899999999999984;1;4094.6491391846885;386.4740019846327;655.0305215214638 271 | 8.899999999999984;2;4138.9447269538705;387.8240986490699;687.3102489771543 272 | 8.999999999999984;0;4146.88234880376;384.2951058262491;688.2263963675256 273 | 8.999999999999984;1;4096.336879104079;383.78912122614065;642.2347880688202 274 | 8.999999999999984;2;4151.3366985529;387.28120238552765;665.8058770831573 275 | 9.099999999999984;0;4217.324838921914;388.9600942074848;677.7879816338095 276 | 9.099999999999984;1;4056.001679183512;376.3531300001091;631.188196182526 277 | 9.099999999999984;2;4091.6055897462293;378.82792534034365;644.271469149108 278 | 9.199999999999983;0;4362.723512786968;403.2367315261421;652.9455827464667 279 | 9.199999999999983;1;4230.322640000565;386.67530907203025;672.9097965378937 280 | 9.199999999999983;2;4208.50252506746;384.7689363552247;668.628310599399 281 | 9.299999999999983;0;4294.195078701321;389.8959280377432;668.1629479503157 282 | 9.299999999999983;1;4130.149946350045;375.81022777005336;635.1148280885564 283 | 9.299999999999983;2;4206.712286426415;381.058689399361;662.8664750123631 284 | 9.399999999999983;0;4244.391789979543;384.08610608639214;633.9823927674634 285 | 9.399999999999983;1;4216.214083332738;378.4512649481059;658.772192820548 286 | 9.399999999999983;2;4204.316088011602;381.3673657680649;619.4628497918003 287 | 9.499999999999982;0;4196.648235867426;374.44252256934993;639.4442714586075 288 | 9.499999999999982;1;4222.188409237439;375.999504953269;650.1931121813909 289 | 9.499999999999982;2;4311.087693067638;384.17998000622333;661.377883008523 290 | 9.599999999999982;0;4388.506670794374;386.47516752576183;678.345062547068 291 | 9.599999999999982;1;4412.349047389518;388.79844917234936;679.8839353349716 292 | 9.599999999999982;2;4374.284354930482;383.3085040883667;694.5227156821696 293 | 9.699999999999982;0;4347.360533518752;381.5284177919728;646.5348809366241 294 | 9.699999999999982;1;4455.266277405107;390.69569539664036;665.5180320577037 295 | 9.699999999999982;2;4311.719261683936;375.60616439671475;668.3394670358094 296 | 9.799999999999981;0;4498.368466960913;393.70945028772445;640.0158541412208 297 | 9.799999999999981;1;4422.875464979921;382.6943917601262;672.4704257306917 298 | 9.799999999999981;2;4376.23560705188;380.6238616471335;646.1217629099787 299 | 9.89999999999998;0;4633.789232020346;398.98567453521105;683.8310541217638 300 | 9.89999999999998;1;4430.052928395276;380.32287055276475;664.8565099229124 301 | 9.89999999999998;2;4544.100446700847;388.26884857739645;700.2388457846296 302 | 9.99999999999998;0;4470.294445243417;381.9662362585055;650.6320826583698 303 | 9.99999999999998;1;4505.863693650068;382.2949340040595;682.9143536094812 304 | 9.99999999999998;2;4445.252764416623;377.4358589919804;670.8941744968283 305 | -------------------------------------------------------------------------------- /output/abe/progress.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jsprit/playground/e42858e70a42c4614ae55a5baff87e654a8cde4b/output/abe/progress.png -------------------------------------------------------------------------------- /output/abe/sensitivity_costPerTimeUnit_tpDistance.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jsprit/playground/e42858e70a42c4614ae55a5baff87e654a8cde4b/output/abe/sensitivity_costPerTimeUnit_tpDistance.png -------------------------------------------------------------------------------- /output/abe/sensitivity_costPerTimeUnit_tpTime.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jsprit/playground/e42858e70a42c4614ae55a5baff87e654a8cde4b/output/abe/sensitivity_costPerTimeUnit_tpTime.png -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | jsprit-playground 4 | jsprit-playground 5 | 0.0.1-SNAPSHOT 6 | 7 | src 8 | 9 | 10 | maven-compiler-plugin 11 | 3.0 12 | 13 | 1.6 14 | 1.6 15 | 16 | 17 | 18 | 19 | 20 | 21 | jsprit 22 | jsprit-core 23 | 1.3.0 24 | 25 | 26 | jsprit 27 | jsprit-analysis 28 | 1.3.0 29 | 30 | 31 | jsprit 32 | jsprit-instances 33 | 1.3.0 34 | 35 | 36 | 37 | org.mockito 38 | mockito-all 39 | 1.9.5 40 | test 41 | 42 | 43 | 44 | 45 | 46 | jsprit-releases 47 | https://github.com/jsprit/mvn-rep/raw/master/releases 48 | 49 | 50 | -------------------------------------------------------------------------------- /src/abe/AbeProblem.java: -------------------------------------------------------------------------------- 1 | package abe; 2 | 3 | import java.io.IOException; 4 | import java.util.Collection; 5 | 6 | import jsprit.analysis.toolbox.AlgorithmSearchProgressChartListener; 7 | import jsprit.analysis.toolbox.Plotter; 8 | import jsprit.core.algorithm.VehicleRoutingAlgorithm; 9 | import jsprit.core.algorithm.io.VehicleRoutingAlgorithms; 10 | import jsprit.core.problem.VehicleRoutingProblem; 11 | import jsprit.core.problem.io.VrpXMLReader; 12 | import jsprit.core.problem.solution.VehicleRoutingProblemSolution; 13 | import jsprit.core.problem.solution.route.VehicleRoute; 14 | import jsprit.core.problem.solution.route.activity.TourActivity; 15 | import jsprit.core.reporting.SolutionPrinter; 16 | import jsprit.core.reporting.SolutionPrinter.Print; 17 | import jsprit.core.util.Solutions; 18 | import jsprit.core.util.VehicleRoutingTransportCostsMatrix; 19 | 20 | public class AbeProblem { 21 | 22 | 23 | public static void main(String[] args) throws IOException { 24 | VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); 25 | new VrpXMLReader(vrpBuilder).read("input/abe/abrahamProblem.xml"); 26 | VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(true); 27 | final MatrixReader matrixReader = new MatrixReader(matrixBuilder); 28 | matrixReader.read("input/abe/Matrix.txt"); 29 | VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build(); 30 | 31 | vrpBuilder.setRoutingCost(matrix); 32 | VehicleRoutingProblem problem = vrpBuilder.build(); 33 | 34 | Plotter plotter = new Plotter(problem); 35 | plotter.plot("output/abe/abeProblem.png", "abe"); 36 | 37 | // VehicleRoutingAlgorithm algo = new SchrimpfFactory().createAlgorithm(problem); 38 | VehicleRoutingAlgorithm algo = VehicleRoutingAlgorithms.readAndCreateAlgorithm(problem, "/Users/schroeder/Documents/jsprit/abraham/algorithmConfig_stefan.xml"); 39 | algo.addListener(new AlgorithmSearchProgressChartListener("output/progress.png")); 40 | // VariationCoefficientTermination prematureAlgorithmTermination = new VariationCoefficientTermination(200, 0.01); 41 | // algo.addListener(prematureAlgorithmTermination); 42 | // algo.setPrematureAlgorithmTermination(prematureAlgorithmTermination); 43 | Collection solutions = algo.searchSolutions(); 44 | 45 | Plotter plotter2 = new Plotter(problem,Solutions.bestOf(solutions)); 46 | plotter2.setShowFirstActivity(true); 47 | plotter2.plot("output/abe/abeProblemWithSolution.png", "abe"); 48 | 49 | SolutionPrinter.print(problem, Solutions.bestOf(solutions), Print.VERBOSE); 50 | 51 | System.out.println("total-time: " + getTotalTime(problem, Solutions.bestOf(solutions))); 52 | System.out.println("total-distance: " + getTotalDistance(matrixReader, Solutions.bestOf(solutions))); 53 | 54 | } 55 | 56 | private static double getTotalDistance(MatrixReader matrix,VehicleRoutingProblemSolution bestOf) { 57 | double dist = 0.0; 58 | for(VehicleRoute r : bestOf.getRoutes()){ 59 | TourActivity last = r.getStart(); 60 | for(TourActivity act : r.getActivities()){ 61 | dist += matrix.getDistance(last.getLocationId(), act.getLocationId()); 62 | last=act; 63 | } 64 | dist+=matrix.getDistance(last.getLocationId(), r.getEnd().getLocationId()); 65 | } 66 | return dist; 67 | } 68 | 69 | private static double getTotalTime(VehicleRoutingProblem problem,VehicleRoutingProblemSolution bestOf) { 70 | double time = 0.0; 71 | for(VehicleRoute r : bestOf.getRoutes()) time+=r.getEnd().getArrTime(); 72 | return time; 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /src/abe/AbeProblemFastRelation.java: -------------------------------------------------------------------------------- 1 | package abe; 2 | 3 | import java.io.IOException; 4 | import java.util.Collection; 5 | 6 | import jsprit.analysis.toolbox.AlgorithmSearchProgressChartListener; 7 | import jsprit.analysis.toolbox.Plotter; 8 | import jsprit.analysis.toolbox.Plotter.Label; 9 | import jsprit.core.algorithm.VehicleRoutingAlgorithm; 10 | import jsprit.core.algorithm.io.VehicleRoutingAlgorithms; 11 | import jsprit.core.problem.VehicleRoutingProblem; 12 | import jsprit.core.problem.cost.AbstractForwardVehicleRoutingTransportCosts; 13 | import jsprit.core.problem.cost.VehicleRoutingTransportCosts; 14 | import jsprit.core.problem.driver.Driver; 15 | import jsprit.core.problem.io.VrpXMLReader; 16 | import jsprit.core.problem.solution.VehicleRoutingProblemSolution; 17 | import jsprit.core.problem.solution.route.VehicleRoute; 18 | import jsprit.core.problem.solution.route.activity.TourActivity; 19 | import jsprit.core.problem.vehicle.Vehicle; 20 | import jsprit.core.reporting.SolutionPrinter; 21 | import jsprit.core.reporting.SolutionPrinter.Print; 22 | import jsprit.core.util.Solutions; 23 | import jsprit.core.util.VehicleRoutingTransportCostsMatrix; 24 | 25 | public class AbeProblemFastRelation { 26 | 27 | 28 | public static void main(String[] args) throws IOException { 29 | VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); 30 | new VrpXMLReader(vrpBuilder).read("input/abe/abrahamProblem.xml"); 31 | VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(true); 32 | final MatrixReader matrixReader = new MatrixReader(matrixBuilder); 33 | matrixReader.read("input/abe/abraham/Matrix.txt"); 34 | // VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build(); 35 | 36 | VehicleRoutingTransportCosts costs = new AbstractForwardVehicleRoutingTransportCosts() { 37 | 38 | @Override 39 | public double getTransportTime(String fromId, String toId, double departureTime, Driver driver, Vehicle vehicle) { 40 | double defaultVelocity = 1; 41 | //fast connection on relation 17 --> 16 42 | if(fromId.equals("17") && toId.equals("16")){ 43 | return getDistance(fromId, toId)/100.; 44 | } 45 | return getDistance(fromId, toId)/defaultVelocity; 46 | } 47 | 48 | @Override 49 | public double getTransportCost(String fromId, String toId, double departureTime, Driver driver, Vehicle vehicle) { 50 | if(vehicle != null){ 51 | return vehicle.getType().getVehicleCostParams().perDistanceUnit*getDistance(fromId,toId) 52 | + vehicle.getType().getVehicleCostParams().perTimeUnit*getTransportTime(fromId, toId, departureTime, driver, vehicle); 53 | } 54 | return getDistance(fromId,toId); 55 | } 56 | 57 | private double getDistance(String fromId, String toId) { 58 | return matrixReader.getDistance(fromId, toId); 59 | } 60 | 61 | }; 62 | 63 | vrpBuilder.setRoutingCost(costs); 64 | VehicleRoutingProblem problem = vrpBuilder.build(); 65 | 66 | Plotter plotter = new Plotter(problem); 67 | plotter.setLabel(Label.ID); 68 | plotter.plot("output/abe/abeProblem.png", "abe"); 69 | 70 | // VehicleRoutingAlgorithm algo = new SchrimpfFactory().createAlgorithm(problem); 71 | VehicleRoutingAlgorithm algo = VehicleRoutingAlgorithms.readAndCreateAlgorithm(problem, "input/abe/algorithmConfig_stefan.xml"); 72 | algo.addListener(new AlgorithmSearchProgressChartListener("output/progress.png")); 73 | Collection solutions = algo.searchSolutions(); 74 | 75 | Plotter plotter2 = new Plotter(problem,Solutions.bestOf(solutions)); 76 | plotter2.plot("output/abe/abeProblemFastRelation.png", "abe"); 77 | 78 | SolutionPrinter.print(problem, Solutions.bestOf(solutions), Print.VERBOSE); 79 | 80 | System.out.println("total-time: " + getTotalTime(problem, Solutions.bestOf(solutions))); 81 | System.out.println("total-distance: " + getTotalDistance(matrixReader, Solutions.bestOf(solutions))); 82 | 83 | } 84 | 85 | private static double getTotalDistance(MatrixReader matrix,VehicleRoutingProblemSolution bestOf) { 86 | double dist = 0.0; 87 | for(VehicleRoute r : bestOf.getRoutes()){ 88 | TourActivity last = r.getStart(); 89 | for(TourActivity act : r.getActivities()){ 90 | dist += matrix.getDistance(last.getLocationId(), act.getLocationId()); 91 | last=act; 92 | } 93 | dist+=matrix.getDistance(last.getLocationId(), r.getEnd().getLocationId()); 94 | } 95 | return dist; 96 | } 97 | 98 | private static double getTotalTime(VehicleRoutingProblem problem,VehicleRoutingProblemSolution bestOf) { 99 | double time = 0.0; 100 | for(VehicleRoute r : bestOf.getRoutes()) time+=r.getEnd().getArrTime(); 101 | return time; 102 | } 103 | 104 | } 105 | -------------------------------------------------------------------------------- /src/abe/AbeProblemFastVehicle.java: -------------------------------------------------------------------------------- 1 | package abe; 2 | 3 | import java.io.IOException; 4 | import java.util.Collection; 5 | 6 | import jsprit.analysis.toolbox.AlgorithmSearchProgressChartListener; 7 | import jsprit.analysis.toolbox.Plotter; 8 | import jsprit.core.algorithm.VehicleRoutingAlgorithm; 9 | import jsprit.core.algorithm.io.VehicleRoutingAlgorithms; 10 | import jsprit.core.problem.VehicleRoutingProblem; 11 | import jsprit.core.problem.cost.AbstractForwardVehicleRoutingTransportCosts; 12 | import jsprit.core.problem.cost.VehicleRoutingTransportCosts; 13 | import jsprit.core.problem.driver.Driver; 14 | import jsprit.core.problem.io.VrpXMLReader; 15 | import jsprit.core.problem.solution.VehicleRoutingProblemSolution; 16 | import jsprit.core.problem.solution.route.VehicleRoute; 17 | import jsprit.core.problem.solution.route.activity.TourActivity; 18 | import jsprit.core.problem.vehicle.Vehicle; 19 | import jsprit.core.reporting.SolutionPrinter; 20 | import jsprit.core.reporting.SolutionPrinter.Print; 21 | import jsprit.core.util.Solutions; 22 | import jsprit.core.util.VehicleRoutingTransportCostsMatrix; 23 | 24 | public class AbeProblemFastVehicle { 25 | 26 | 27 | public static void main(String[] args) throws IOException { 28 | VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); 29 | new VrpXMLReader(vrpBuilder).read("input/abe/abrahamProblem.xml"); 30 | VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(true); 31 | final MatrixReader matrixReader = new MatrixReader(matrixBuilder); 32 | matrixReader.read("input/abe/Matrix.txt"); 33 | // VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build(); 34 | 35 | VehicleRoutingTransportCosts costs = new AbstractForwardVehicleRoutingTransportCosts() { 36 | 37 | @Override 38 | public double getTransportTime(String fromId, String toId, double departureTime, Driver driver, Vehicle vehicle) { 39 | double defaultVelocity = 1; 40 | if(vehicle != null){ 41 | if(vehicle.getId().equals("2MF2CC04AA")){ 42 | return getDistance(fromId, toId)/5.; 43 | } 44 | } 45 | return getDistance(fromId, toId)/defaultVelocity; 46 | } 47 | 48 | @Override 49 | public double getTransportCost(String fromId, String toId, double departureTime, Driver driver, Vehicle vehicle) { 50 | if(vehicle != null){ 51 | return vehicle.getType().getVehicleCostParams().perDistanceUnit*getDistance(fromId,toId) 52 | + vehicle.getType().getVehicleCostParams().perTimeUnit*getTransportTime(fromId, toId, departureTime, driver, vehicle); 53 | } 54 | return getDistance(fromId,toId); 55 | } 56 | 57 | private double getDistance(String fromId, String toId) { 58 | return matrixReader.getDistance(fromId, toId); 59 | } 60 | 61 | }; 62 | 63 | vrpBuilder.setRoutingCost(costs); 64 | VehicleRoutingProblem problem = vrpBuilder.build(); 65 | 66 | Plotter plotter = new Plotter(problem); 67 | plotter.plot("output/abeProblem.png", "abe"); 68 | 69 | // VehicleRoutingAlgorithm algo = new SchrimpfFactory().createAlgorithm(problem); 70 | VehicleRoutingAlgorithm algo = VehicleRoutingAlgorithms.readAndCreateAlgorithm(problem, "input/abe/algorithmConfig_stefan.xml"); 71 | algo.addListener(new AlgorithmSearchProgressChartListener("output/progress.png")); 72 | Collection solutions = algo.searchSolutions(); 73 | 74 | Plotter plotter2 = new Plotter(problem,Solutions.bestOf(solutions)); 75 | plotter2.plot("output/abeProblemWithSolution.png", "abe"); 76 | 77 | SolutionPrinter.print(problem, Solutions.bestOf(solutions), Print.VERBOSE); 78 | 79 | System.out.println("total-time: " + getTotalTime(problem, Solutions.bestOf(solutions))); 80 | System.out.println("total-distance: " + getTotalDistance(matrixReader, Solutions.bestOf(solutions))); 81 | 82 | } 83 | 84 | private static double getTotalDistance(MatrixReader matrix,VehicleRoutingProblemSolution bestOf) { 85 | double dist = 0.0; 86 | for(VehicleRoute r : bestOf.getRoutes()){ 87 | TourActivity last = r.getStart(); 88 | for(TourActivity act : r.getActivities()){ 89 | dist += matrix.getDistance(last.getLocationId(), act.getLocationId()); 90 | last=act; 91 | } 92 | dist+=matrix.getDistance(last.getLocationId(), r.getEnd().getLocationId()); 93 | } 94 | return dist; 95 | } 96 | 97 | private static double getTotalTime(VehicleRoutingProblem problem,VehicleRoutingProblemSolution bestOf) { 98 | double time = 0.0; 99 | for(VehicleRoute r : bestOf.getRoutes()) time+=r.getEnd().getArrTime(); 100 | return time; 101 | } 102 | 103 | } 104 | -------------------------------------------------------------------------------- /src/abe/AbeProblemInverseTimeDistance.java: -------------------------------------------------------------------------------- 1 | package abe; 2 | 3 | import java.io.IOException; 4 | import java.util.Collection; 5 | 6 | import jsprit.analysis.toolbox.AlgorithmSearchProgressChartListener; 7 | import jsprit.analysis.toolbox.Plotter; 8 | import jsprit.core.algorithm.VehicleRoutingAlgorithm; 9 | import jsprit.core.algorithm.io.VehicleRoutingAlgorithms; 10 | import jsprit.core.problem.VehicleRoutingProblem; 11 | import jsprit.core.problem.cost.AbstractForwardVehicleRoutingTransportCosts; 12 | import jsprit.core.problem.cost.VehicleRoutingTransportCosts; 13 | import jsprit.core.problem.driver.Driver; 14 | import jsprit.core.problem.io.VrpXMLReader; 15 | import jsprit.core.problem.solution.VehicleRoutingProblemSolution; 16 | import jsprit.core.problem.solution.route.VehicleRoute; 17 | import jsprit.core.problem.solution.route.activity.TourActivity; 18 | import jsprit.core.problem.vehicle.Vehicle; 19 | import jsprit.core.reporting.SolutionPrinter; 20 | import jsprit.core.reporting.SolutionPrinter.Print; 21 | import jsprit.core.util.Solutions; 22 | import jsprit.core.util.VehicleRoutingTransportCostsMatrix; 23 | 24 | public class AbeProblemInverseTimeDistance { 25 | 26 | /** 27 | * Note that by default the algorithm minimizes total costs and 28 | * total costs = sumOfFixed + sumOfTransportCosts 29 | * sumOfTransportCosts = sumOf(costPerTime*transportTime + costPerDistance*transportDistance) 30 | * 31 | * @param args 32 | * @throws IOException 33 | */ 34 | public static void main(String[] args) throws IOException { 35 | VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); 36 | new VrpXMLReader(vrpBuilder).read("input/abe/abrahamProblem.xml"); 37 | VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(true); 38 | final MatrixReader matrixReader = new MatrixReader(matrixBuilder); 39 | matrixReader.read("/input/abe/Matrix.txt"); 40 | // VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build(); 41 | 42 | VehicleRoutingTransportCosts costs = new AbstractForwardVehicleRoutingTransportCosts() { 43 | 44 | @Override 45 | public double getTransportTime(String fromId, String toId, double departureTime, Driver driver, Vehicle vehicle) { 46 | //just a mean to 'inverse' transport times such that the longest relations become the fastest and the other way around 47 | return 4000. - getDistance(fromId, toId); 48 | } 49 | 50 | @Override 51 | public double getTransportCost(String fromId, String toId, double departureTime, Driver driver, Vehicle vehicle) { 52 | if(vehicle != null){ 53 | return vehicle.getType().getVehicleCostParams().perDistanceUnit*getDistance(fromId,toId) 54 | + vehicle.getType().getVehicleCostParams().perTimeUnit*getTransportTime(fromId, toId, departureTime, driver, vehicle); 55 | } 56 | return getDistance(fromId,toId); 57 | } 58 | 59 | private double getDistance(String fromId, String toId) { 60 | return matrixReader.getDistance(fromId, toId); 61 | } 62 | 63 | }; 64 | 65 | vrpBuilder.setRoutingCost(costs); 66 | VehicleRoutingProblem problem = vrpBuilder.build(); 67 | 68 | Plotter plotter = new Plotter(problem); 69 | plotter.plot("output/abeProblem.png", "abe"); 70 | 71 | // VehicleRoutingAlgorithm algo = new SchrimpfFactory().createAlgorithm(problem); 72 | VehicleRoutingAlgorithm algo = VehicleRoutingAlgorithms.readAndCreateAlgorithm(problem, "input/abe/algorithmConfig_stefan.xml"); 73 | algo.addListener(new AlgorithmSearchProgressChartListener("output/abe/progress.png")); 74 | Collection solutions = algo.searchSolutions(); 75 | 76 | Plotter plotter2 = new Plotter(problem,Solutions.bestOf(solutions)); 77 | plotter2.plot("output/abe/abeProblemWithSolution.png", "abe"); 78 | 79 | SolutionPrinter.print(problem, Solutions.bestOf(solutions), Print.VERBOSE); 80 | 81 | System.out.println("total-time: " + getTotalTime(problem, Solutions.bestOf(solutions))); 82 | System.out.println("total-distance: " + getTotalDistance(matrixReader, Solutions.bestOf(solutions))); 83 | 84 | } 85 | 86 | private static double getTotalDistance(MatrixReader matrix,VehicleRoutingProblemSolution bestOf) { 87 | double dist = 0.0; 88 | for(VehicleRoute r : bestOf.getRoutes()){ 89 | TourActivity last = r.getStart(); 90 | for(TourActivity act : r.getActivities()){ 91 | dist += matrix.getDistance(last.getLocationId(), act.getLocationId()); 92 | last=act; 93 | } 94 | dist+=matrix.getDistance(last.getLocationId(), r.getEnd().getLocationId()); 95 | } 96 | return dist; 97 | } 98 | 99 | private static double getTotalTime(VehicleRoutingProblem problem,VehicleRoutingProblemSolution bestOf) { 100 | double time = 0.0; 101 | for(VehicleRoute r : bestOf.getRoutes()) time+=r.getEnd().getArrTime(); 102 | return time; 103 | } 104 | 105 | } 106 | -------------------------------------------------------------------------------- /src/abe/AbeProblemMinMax.java: -------------------------------------------------------------------------------- 1 | package abe; 2 | 3 | import java.io.IOException; 4 | import java.util.Collection; 5 | 6 | import jsprit.analysis.toolbox.AlgorithmSearchProgressChartListener; 7 | import jsprit.analysis.toolbox.Plotter; 8 | import jsprit.core.algorithm.VehicleRoutingAlgorithm; 9 | import jsprit.core.algorithm.VehicleRoutingAlgorithmBuilder; 10 | import jsprit.core.algorithm.recreate.VariableTransportCostCalculator; 11 | import jsprit.core.algorithm.state.StateManager; 12 | import jsprit.core.algorithm.state.StateUpdater; 13 | import jsprit.core.algorithm.termination.VariationCoefficientTermination; 14 | import jsprit.core.problem.VehicleRoutingProblem; 15 | import jsprit.core.problem.constraint.ConstraintManager; 16 | import jsprit.core.problem.constraint.SoftActivityConstraint; 17 | import jsprit.core.problem.cost.ForwardTransportTime; 18 | import jsprit.core.problem.cost.VehicleRoutingTransportCosts; 19 | import jsprit.core.problem.io.VrpXMLReader; 20 | import jsprit.core.problem.misc.JobInsertionContext; 21 | import jsprit.core.problem.solution.SolutionCostCalculator; 22 | import jsprit.core.problem.solution.VehicleRoutingProblemSolution; 23 | import jsprit.core.problem.solution.route.VehicleRoute; 24 | import jsprit.core.problem.solution.route.activity.ActivityVisitor; 25 | import jsprit.core.problem.solution.route.activity.End; 26 | import jsprit.core.problem.solution.route.activity.TourActivity; 27 | import jsprit.core.problem.solution.route.state.StateFactory; 28 | import jsprit.core.problem.solution.route.state.StateFactory.StateId; 29 | import jsprit.core.reporting.SolutionPrinter; 30 | import jsprit.core.reporting.SolutionPrinter.Print; 31 | import jsprit.core.util.ActivityTimeTracker; 32 | import jsprit.core.util.CalculationUtils; 33 | import jsprit.core.util.Solutions; 34 | import jsprit.core.util.VehicleRoutingTransportCostsMatrix; 35 | 36 | public class AbeProblemMinMax { 37 | 38 | /* 39 | * This updates the state "max-transport-time" which is introduced below. Once either the insertion procedure starts or a job has 40 | * been inserted, UpdateMaxTransportTime is called for the route that has been changed. 41 | * 42 | * It must not only be an ActivityVisitor which indicates that the update procedure starts at the beginning of route all the way to end 43 | * (in contrary to the ReverseActivityVisitor) but also be a StateUpdater which is just a marker to register it in the StateManager. 44 | * 45 | * You do not need to declare this as static inner class. You can just choose your preferred approach. However, be aware 46 | * that this requires the stateName "max-transport-time" you define below. If you choose to define this as class in a new file, 47 | * you might define "max-transport-time" as static id in another file, to make sure you do not have type errors etc.. 48 | */ 49 | static class UpdateMaxTransportTime implements ActivityVisitor, StateUpdater { 50 | 51 | private StateManager stateManager; 52 | 53 | private ActivityTimeTracker timeTracker; 54 | 55 | public UpdateMaxTransportTime(StateManager stateManager, ForwardTransportTime transportTime) { 56 | super(); 57 | this.stateManager = stateManager; 58 | this.timeTracker = new ActivityTimeTracker(transportTime); 59 | } 60 | 61 | @Override 62 | public void begin(VehicleRoute route) { 63 | timeTracker.begin(route); 64 | } 65 | 66 | @Override 67 | public void visit(TourActivity activity) { 68 | timeTracker.visit(activity); 69 | } 70 | 71 | @Override 72 | public void finish() { 73 | timeTracker.finish(); 74 | double newRouteEndTime = timeTracker.getActArrTime(); 75 | double currentMaxTransportTime = stateManager.getProblemState(StateFactory.createId("max-transport-time"), Double.class); 76 | if(newRouteEndTime > currentMaxTransportTime){ 77 | stateManager.putProblemState(StateFactory.createId("max-transport-time"), Double.class, newRouteEndTime); 78 | } 79 | } 80 | 81 | } 82 | 83 | public static void main(String[] args) throws IOException { 84 | VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); 85 | new VrpXMLReader(vrpBuilder).read("input/abe/abrahamProblem.xml"); 86 | VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(true); 87 | final MatrixReader matrixReader = new MatrixReader(matrixBuilder); 88 | matrixReader.read("input/abe/Matrix.txt"); 89 | VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build(); 90 | vrpBuilder.setRoutingCost(matrix); 91 | 92 | final VehicleRoutingProblem problem = vrpBuilder.build(); 93 | 94 | /* 95 | * Your custom objective function that min max transport times. Additionally you can try to consider overall transport times 96 | * in your objective as well. Thus you minimize max transport times first, and second, you minimize overall transport time. 97 | * 98 | * If you choose to consider overall transport times, makes sure you scale it appropriately. 99 | */ 100 | SolutionCostCalculator objectiveFunction = new SolutionCostCalculator() { 101 | 102 | private double scalingParameter = 0.2; 103 | 104 | @Override 105 | public double getCosts(VehicleRoutingProblemSolution solution) { 106 | double maxTransportTime = 0.; 107 | double sumTransportTimes = 0.; 108 | for(VehicleRoute route : solution.getRoutes()){ 109 | double tpTime = route.getEnd().getArrTime() - route.getStart().getEndTime(); 110 | sumTransportTimes+=tpTime; 111 | if(tpTime > maxTransportTime){ 112 | maxTransportTime = tpTime; 113 | } 114 | } 115 | return maxTransportTime + scalingParameter*sumTransportTimes; 116 | } 117 | }; 118 | 119 | final StateManager stateManager = new StateManager(problem.getTransportCosts()); 120 | //introduce a new state called "max-transport-time" 121 | StateId max_transport_time_state = StateFactory.createId("max-transport-time"); 122 | //add a default-state for "max-transport-time" 123 | stateManager.addDefaultProblemState(max_transport_time_state, Double.class, 0.); 124 | // 125 | stateManager.addStateUpdater(new UpdateMaxTransportTime(stateManager,problem.getTransportCosts())); 126 | 127 | /* 128 | * The insertion heuristics is controlled with your constraints 129 | */ 130 | ConstraintManager constraintManager = new ConstraintManager(problem, stateManager); 131 | // soft constraint that calculates additional transport costs when inserting a job(activity) at specified position 132 | constraintManager.addConstraint(new VariableTransportCostCalculator(problem.getTransportCosts())); 133 | /* 134 | * soft constraint that penalyzes a shift of max-route transport time, i.e. once the insertion heuristic 135 | * tries to insert a jobActivity at position which results in a shift of max-transport-time, it is penalyzed with 136 | * penaltyForEachTimeUnitAboveCurrentMaxTime 137 | * 138 | */ 139 | SoftActivityConstraint penalyzeShiftOfMaxTransportTime = new SoftActivityConstraint() { 140 | private final VehicleRoutingTransportCosts routingCosts = problem.getTransportCosts(); 141 | 142 | private final double penaltyForEachTimeUnitAboveCurrentMaxTime = 3.; 143 | 144 | @Override 145 | public double getCosts(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double depTimeAtPrevAct) { 146 | /* 147 | * determines maximum of all routes' transport times, which is here basically a state that can be fetched via the stateManager 148 | */ 149 | double maxTime = stateManager.getProblemState(StateFactory.createId("max-transport-time"), Double.class); 150 | /* 151 | * determines additional time of route when inserting newAct between prevAct and nextAct 152 | * 153 | */ 154 | double tp_time_prevAct_newAct = routingCosts.getTransportTime(prevAct.getLocationId(), newAct.getLocationId(), depTimeAtPrevAct, iFacts.getNewDriver(), iFacts.getNewVehicle()); 155 | double newAct_arrTime = depTimeAtPrevAct + tp_time_prevAct_newAct; 156 | double newAct_endTime = CalculationUtils.getActivityEndTime(newAct_arrTime, newAct); 157 | /* 158 | * open routes - if route is set to be open, i.e. end is endogeneously determined by the algorithm, then inserting of newAct between prevAct 159 | * and end just shifts the route's end time to by tp_time_prevAct_newAct 160 | * 161 | */ 162 | if(nextAct instanceof End){ 163 | if(!iFacts.getNewVehicle().isReturnToDepot()){ 164 | double additionalTime = tp_time_prevAct_newAct; 165 | double new_routes_transport_time = iFacts.getRoute().getEnd().getArrTime() - iFacts.getRoute().getStart().getEndTime() + additionalTime; 166 | return penaltyForEachTimeUnitAboveCurrentMaxTime*Math.max(0,new_routes_transport_time-maxTime); 167 | } 168 | } 169 | double tp_time_newAct_nextAct = routingCosts.getTransportTime(newAct.getLocationId(), nextAct.getLocationId(), newAct_endTime, iFacts.getNewDriver(), iFacts.getNewVehicle()); 170 | double nextAct_arrTime = newAct_endTime + tp_time_newAct_nextAct; 171 | double oldTime; 172 | if(iFacts.getRoute().isEmpty()){ 173 | oldTime = (nextAct.getArrTime() - depTimeAtPrevAct); 174 | } 175 | else{ 176 | oldTime = (nextAct.getArrTime() - iFacts.getRoute().getDepartureTime()); 177 | } 178 | double additionalTime = (nextAct_arrTime - iFacts.getNewDepTime()) - oldTime; 179 | double tpTime = iFacts.getRoute().getEnd().getArrTime() - iFacts.getRoute().getStart().getEndTime() + additionalTime; 180 | 181 | return penaltyForEachTimeUnitAboveCurrentMaxTime*Math.max(0,tpTime-maxTime); 182 | 183 | } 184 | }; 185 | constraintManager.addConstraint(penalyzeShiftOfMaxTransportTime); 186 | 187 | VehicleRoutingAlgorithmBuilder algorithmBuilder = new VehicleRoutingAlgorithmBuilder(problem, "/Users/schroeder/Documents/jsprit/abraham/algorithmConfig_stefan.xml"); 188 | algorithmBuilder.setObjectiveFunction(objectiveFunction); 189 | algorithmBuilder.setStateManager(stateManager); 190 | algorithmBuilder.setStateAndConstraintManager(stateManager, constraintManager); 191 | algorithmBuilder.addCoreConstraints(); 192 | 193 | 194 | VehicleRoutingAlgorithm algo = algorithmBuilder.build(); 195 | 196 | algo.addListener(new AlgorithmSearchProgressChartListener("output/abe/progress.png")); 197 | VariationCoefficientTermination prematureAlgorithmTermination = new VariationCoefficientTermination(150, 0.001); 198 | algo.addListener(prematureAlgorithmTermination); 199 | algo.setPrematureAlgorithmTermination(prematureAlgorithmTermination); 200 | 201 | Collection solutions = algo.searchSolutions(); 202 | 203 | Plotter plotter2 = new Plotter(problem,Solutions.bestOf(solutions)); 204 | plotter2.setShowFirstActivity(true); 205 | plotter2.plot("output/abe/abeProblemWithSolution.png", "abe"); 206 | 207 | SolutionPrinter.print(problem, Solutions.bestOf(solutions), Print.VERBOSE); 208 | 209 | System.out.println("total-time: " + getTotalTime(problem, Solutions.bestOf(solutions))); 210 | System.out.println("total-distance: " + getTotalDistance(matrixReader, Solutions.bestOf(solutions))); 211 | 212 | } 213 | 214 | private static double getTotalDistance(MatrixReader matrix,VehicleRoutingProblemSolution bestOf) { 215 | double dist = 0.0; 216 | for(VehicleRoute r : bestOf.getRoutes()){ 217 | TourActivity last = r.getStart(); 218 | for(TourActivity act : r.getActivities()){ 219 | dist += matrix.getDistance(last.getLocationId(), act.getLocationId()); 220 | last=act; 221 | } 222 | dist+=matrix.getDistance(last.getLocationId(), r.getEnd().getLocationId()); 223 | } 224 | return dist; 225 | } 226 | 227 | private static double getTotalTime(VehicleRoutingProblem problem,VehicleRoutingProblemSolution bestOf) { 228 | double time = 0.0; 229 | for(VehicleRoute r : bestOf.getRoutes()) time+=r.getEnd().getArrTime(); 230 | return time; 231 | } 232 | 233 | } 234 | -------------------------------------------------------------------------------- /src/abe/AbeProblemRandomSpeedup.java: -------------------------------------------------------------------------------- 1 | package abe; 2 | 3 | import java.io.IOException; 4 | import java.util.Collection; 5 | 6 | import jsprit.analysis.toolbox.AlgorithmSearchProgressChartListener; 7 | import jsprit.analysis.toolbox.Plotter; 8 | import jsprit.core.algorithm.VehicleRoutingAlgorithm; 9 | import jsprit.core.algorithm.io.VehicleRoutingAlgorithms; 10 | import jsprit.core.problem.VehicleRoutingProblem; 11 | import jsprit.core.problem.io.VrpXMLReader; 12 | import jsprit.core.problem.solution.VehicleRoutingProblemSolution; 13 | import jsprit.core.problem.solution.route.VehicleRoute; 14 | import jsprit.core.problem.solution.route.activity.TourActivity; 15 | import jsprit.core.reporting.SolutionPrinter; 16 | import jsprit.core.reporting.SolutionPrinter.Print; 17 | import jsprit.core.util.Solutions; 18 | import jsprit.core.util.VehicleRoutingTransportCostsMatrix; 19 | 20 | public class AbeProblemRandomSpeedup { 21 | 22 | 23 | public static void main(String[] args) throws IOException { 24 | VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); 25 | new VrpXMLReader(vrpBuilder).read("input/abe/abrahamProblem.xml"); 26 | VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(true); 27 | final MatrixReader matrixReader = new MatrixReader(matrixBuilder,0.5,0.5); 28 | matrixReader.read("input/abe/Matrix.txt"); 29 | VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build(); 30 | 31 | vrpBuilder.setRoutingCost(matrix); 32 | VehicleRoutingProblem problem = vrpBuilder.build(); 33 | 34 | Plotter plotter = new Plotter(problem); 35 | plotter.plot("output/abe/abeProblem.png", "abe"); 36 | 37 | // VehicleRoutingAlgorithm algo = new SchrimpfFactory().createAlgorithm(problem); 38 | VehicleRoutingAlgorithm algo = VehicleRoutingAlgorithms.readAndCreateAlgorithm(problem, "/Users/schroeder/Documents/jsprit/abraham/algorithmConfig_stefan.xml"); 39 | algo.addListener(new AlgorithmSearchProgressChartListener("output/abe/progress.png")); 40 | // VariationCoefficientTermination prematureAlgorithmTermination = new VariationCoefficientTermination(200, 0.01); 41 | // algo.addListener(prematureAlgorithmTermination); 42 | // algo.setPrematureAlgorithmTermination(prematureAlgorithmTermination); 43 | Collection solutions = algo.searchSolutions(); 44 | 45 | Plotter plotter2 = new Plotter(problem,Solutions.bestOf(solutions)); 46 | plotter2.setShowFirstActivity(true); 47 | plotter2.plot("output/abe/abeProblemWithSolution.png", "abe"); 48 | 49 | SolutionPrinter.print(problem, Solutions.bestOf(solutions), Print.VERBOSE); 50 | 51 | System.out.println("total-time: " + getTotalTime(problem, Solutions.bestOf(solutions))); 52 | System.out.println("total-distance: " + getTotalDistance(matrixReader, Solutions.bestOf(solutions))); 53 | 54 | } 55 | 56 | private static double getTotalDistance(MatrixReader matrix,VehicleRoutingProblemSolution bestOf) { 57 | double dist = 0.0; 58 | for(VehicleRoute r : bestOf.getRoutes()){ 59 | TourActivity last = r.getStart(); 60 | for(TourActivity act : r.getActivities()){ 61 | dist += matrix.getDistance(last.getLocationId(), act.getLocationId()); 62 | last=act; 63 | } 64 | dist+=matrix.getDistance(last.getLocationId(), r.getEnd().getLocationId()); 65 | } 66 | return dist; 67 | } 68 | 69 | private static double getTotalTime(VehicleRoutingProblem problem,VehicleRoutingProblemSolution bestOf) { 70 | double time = 0.0; 71 | for(VehicleRoute r : bestOf.getRoutes()) time+=r.getEnd().getArrTime(); 72 | return time; 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /src/abe/MatrixReader.java: -------------------------------------------------------------------------------- 1 | package abe; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.File; 5 | import java.io.FileReader; 6 | import java.io.IOException; 7 | import java.util.ArrayList; 8 | import java.util.HashMap; 9 | import java.util.List; 10 | import java.util.Map; 11 | import java.util.Random; 12 | 13 | import jsprit.core.util.VehicleRoutingTransportCostsMatrix; 14 | 15 | public class MatrixReader { 16 | 17 | 18 | public static void main(String[] args) throws IOException { 19 | VehicleRoutingTransportCostsMatrix.Builder builder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(true); 20 | new MatrixReader(builder).read("/Users/schroeder/Documents/jsprit/abraham/Matrix.txt"); 21 | VehicleRoutingTransportCostsMatrix matrix = builder.build(); 22 | 23 | System.out.println(matrix.getTransportCost("18", "19", 0, null, null)); 24 | } 25 | 26 | private VehicleRoutingTransportCostsMatrix.Builder costMatrixBuilder; 27 | 28 | private Map distances = new HashMap(); 29 | 30 | private double probRelation = 0.0; 31 | 32 | private double percentSpeedup = 0.0; 33 | 34 | private Random random = new Random(Long.MAX_VALUE); 35 | 36 | public MatrixReader(VehicleRoutingTransportCostsMatrix.Builder costMatrixBuilder) { 37 | super(); 38 | this.costMatrixBuilder = costMatrixBuilder; 39 | } 40 | 41 | public MatrixReader(VehicleRoutingTransportCostsMatrix.Builder costMatrixBuilder, double probRelation, double percentSpeedup) { 42 | super(); 43 | this.costMatrixBuilder = costMatrixBuilder; 44 | this.probRelation = probRelation; 45 | this.percentSpeedup = percentSpeedup; 46 | } 47 | 48 | public void setRandom(Random random){ 49 | this.random = random; 50 | } 51 | 52 | public double getDistance(String from, String to){ 53 | if(from.equals(to)) return 0.0; 54 | String key = from+"_"+to; 55 | if(!distances.containsKey(key)){ 56 | key = to+"_"+from; 57 | } 58 | if(!distances.containsKey(key)) throw new IllegalStateException("key " + key + " does not exists"); 59 | return distances.get(key); 60 | } 61 | 62 | public void read(String filename) throws IOException{ 63 | BufferedReader reader = new BufferedReader(new FileReader(new File(filename))); 64 | String line = null; 65 | List dataset = new ArrayList(); 66 | // List distances = new ArrayList(); 67 | // List times = new ArrayList(); 68 | while((line=reader.readLine())!=null){ 69 | String cleanedLine = line.trim(); 70 | String[] tokens = cleanedLine.split(";"); 71 | if(tokens.length == 4){ 72 | if(!cleanedLine.contains("Distance")){ 73 | dataset.add(tokens); 74 | String distance = tokens[2].replace(",", "."); 75 | double dist = Double.parseDouble(distance); 76 | String time = tokens[3].replace(",", "."); 77 | double t = Double.parseDouble(time); 78 | costMatrixBuilder.addTransportDistance(tokens[0], tokens[1], dist); 79 | double randomNumber = random.nextDouble(); 80 | boolean speedupRelation = randomNumber < probRelation; 81 | if(speedupRelation){ 82 | costMatrixBuilder.addTransportTime(tokens[0], tokens[1], (t - t*percentSpeedup)); 83 | } 84 | else{ 85 | costMatrixBuilder.addTransportTime(tokens[0], tokens[1], t); 86 | } 87 | distances.put(tokens[0]+"_"+tokens[1], dist); 88 | } 89 | } 90 | } 91 | // Comparator comparator = new Comparator(){ 92 | // 93 | // @Override 94 | // public int compare(Double o1, Double o2) { 95 | // if(o1 < o2) return -1; 96 | // if(o1 > o2) return 1; 97 | // return 0; 98 | // } 99 | // 100 | // }; 101 | // Collections.sort(distances, comparator); 102 | // Collections.sort(times, comparator); 103 | // 104 | // for(String[] data : dataset){ 105 | // double dist = Double.parseDouble(data[2].replace(",", ".")); 106 | // double time = Double.parseDouble(data[3].replace(",", ".")); 107 | // System.out.println(data[2]+";"+data[3]+";"+distances.indexOf(dist)+";"+times.indexOf(time)); 108 | // } 109 | reader.close(); 110 | } 111 | 112 | } 113 | -------------------------------------------------------------------------------- /src/abe/MultipleDepotTimeCostSensitivity.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2013 Stefan Schroeder 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 3.0 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library. If not, see . 16 | ******************************************************************************/ 17 | package abe; 18 | 19 | import java.io.BufferedWriter; 20 | import java.io.File; 21 | import java.io.FileWriter; 22 | import java.io.IOException; 23 | import java.util.Arrays; 24 | import java.util.Collection; 25 | import java.util.Random; 26 | 27 | import jsprit.core.algorithm.VehicleRoutingAlgorithm; 28 | import jsprit.core.algorithm.io.VehicleRoutingAlgorithms; 29 | import jsprit.core.problem.VehicleRoutingProblem; 30 | import jsprit.core.problem.VehicleRoutingProblem.FleetSize; 31 | import jsprit.core.problem.io.VrpXMLReader; 32 | import jsprit.core.problem.solution.VehicleRoutingProblemSolution; 33 | import jsprit.core.problem.solution.route.VehicleRoute; 34 | import jsprit.core.problem.solution.route.activity.TourActivity; 35 | import jsprit.core.problem.vehicle.Vehicle; 36 | import jsprit.core.problem.vehicle.VehicleImpl; 37 | import jsprit.core.problem.vehicle.VehicleTypeImpl; 38 | import jsprit.core.util.Coordinate; 39 | import jsprit.core.util.EuclideanDistanceCalculator; 40 | import jsprit.core.util.Solutions; 41 | import jsprit.core.util.VehicleRoutingTransportCostsMatrix; 42 | 43 | 44 | public class MultipleDepotTimeCostSensitivity { 45 | 46 | /** 47 | * @param args 48 | * @throws IOException 49 | */ 50 | public static void main(String[] args) throws IOException { 51 | 52 | VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(false); 53 | boolean matrixSet = false; 54 | 55 | BufferedWriter writer = new BufferedWriter(new FileWriter(new File("output/abe/costOfTimeSensitivity.txt"))); 56 | 57 | // double costPerTime = 1.0; 58 | writer.write("costPerTimeUnit;run;costs;time;distance\n"); 59 | 60 | for(double costPerTime = 0.0; costPerTime <= 10.; costPerTime += 0.1){ 61 | for(int run = 0; run < 3; run++){ 62 | final VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); 63 | /* 64 | * Read cordeau-instance p01, BUT only its services without any vehicles 65 | */ 66 | new VrpXMLReader(vrpBuilder).read("input/abe/vrp_cordeau_01.xml"); 67 | 68 | /* 69 | * add vehicles with its depots 70 | * 4 depots: 71 | * (20,20) 72 | * (30,40) 73 | * (50,30) 74 | * (60,50) 75 | * 76 | * each with 4 vehicles each with a capacity of 80 77 | */ 78 | int nuOfVehicles = 4; 79 | int capacity = 80; 80 | Coordinate firstDepotCoord = Coordinate.newInstance(20, 20); 81 | Coordinate second = Coordinate.newInstance(30, 40); 82 | Coordinate third = Coordinate.newInstance(50, 30); 83 | Coordinate fourth = Coordinate.newInstance(60, 50); 84 | 85 | double costPerDistance = 1.0; 86 | 87 | 88 | VehicleTypeImpl vehicleType = VehicleTypeImpl.Builder.newInstance("type").addCapacityDimension(0, capacity) 89 | .setCostPerDistance(costPerDistance).setCostPerTime(costPerTime).build(); 90 | 91 | int depotCounter = 1; 92 | for(Coordinate depotCoord : Arrays.asList(firstDepotCoord,second,third,fourth)){ 93 | for(int i=0;i solutions = vra.searchSolutions(); 147 | 148 | // SolutionPrinter.print(Solutions.bestOf(solutions)); 149 | 150 | // new Plotter(vrp, Solutions.bestOf(solutions)).plot("output/p01_solution.png", "p01"); 151 | 152 | writer.write(costPerTime + ";" + run + ";" + Solutions.bestOf(solutions).getCost() + ";" + getTotalTime(vrp, Solutions.bestOf(solutions)) + ";" + getTotalDistance(vrpBuilder, Solutions.bestOf(solutions)) + "\n"); 153 | // System.out.println("total-time: " + getTotalTime(vrp, Solutions.bestOf(solutions))); 154 | // System.out.println("total-distance: " + ); 155 | } 156 | } 157 | writer.close(); 158 | 159 | } 160 | 161 | private static double getDistance(final VehicleRoutingProblem.Builder vrpBuilder,String fromLocation, String toLocation) { 162 | return EuclideanDistanceCalculator.calculateDistance(vrpBuilder.getLocationMap().get(fromLocation), vrpBuilder.getLocationMap().get(toLocation)); 163 | } 164 | 165 | private static double getTotalDistance(final VehicleRoutingProblem.Builder vrpBuilder, VehicleRoutingProblemSolution bestOf) { 166 | double dist = 0.0; 167 | for(VehicleRoute r : bestOf.getRoutes()){ 168 | TourActivity last = r.getStart(); 169 | for(TourActivity act : r.getActivities()){ 170 | dist += getDistance(vrpBuilder, last.getLocationId(), act.getLocationId()); 171 | last=act; 172 | } 173 | // dist+=matrix.getDistance(last.getLocationId(), r.getEnd().getLocationId()); 174 | dist+=getDistance(vrpBuilder, last.getLocationId(), r.getEnd().getLocationId()); 175 | } 176 | return dist; 177 | } 178 | 179 | private static double getTotalTime(VehicleRoutingProblem problem,VehicleRoutingProblemSolution bestOf) { 180 | double time = 0.0; 181 | for(VehicleRoute r : bestOf.getRoutes()) time+=r.getEnd().getArrTime(); 182 | return time; 183 | } 184 | 185 | } 186 | -------------------------------------------------------------------------------- /src/sschroeder/DepartureTimeReScheduler.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2013 Stefan Schroeder 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 3.0 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library. If not, see . 16 | ******************************************************************************/ 17 | package sschroeder; 18 | 19 | import java.util.Collection; 20 | 21 | import jsprit.core.algorithm.listener.AlgorithmEndsListener; 22 | import jsprit.core.algorithm.state.UpdateActivityTimes; 23 | import jsprit.core.problem.VehicleRoutingProblem; 24 | import jsprit.core.problem.cost.TransportTime; 25 | import jsprit.core.problem.solution.VehicleRoutingProblemSolution; 26 | import jsprit.core.problem.solution.route.RouteActivityVisitor; 27 | import jsprit.core.problem.solution.route.VehicleRoute; 28 | import jsprit.core.problem.solution.route.activity.TourActivity; 29 | import jsprit.core.util.Solutions; 30 | 31 | public class DepartureTimeReScheduler implements AlgorithmEndsListener { 32 | 33 | @Override 34 | public void informAlgorithmEnds(VehicleRoutingProblem problem,Collection solutions) { 35 | VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions); 36 | for(VehicleRoute route : solution.getRoutes()){ 37 | if(!route.isEmpty()){ 38 | double earliestDepartureTime = route.getDepartureTime(); 39 | TourActivity firstActivity = route.getActivities().get(0); 40 | double tpTime_startToFirst = problem.getTransportCosts().getTransportTime(route.getStart().getLocationId(), firstActivity.getLocationId(), 41 | earliestDepartureTime, null, route.getVehicle()); 42 | double newDepartureTime = Math.max(earliestDepartureTime, firstActivity.getTheoreticalEarliestOperationStartTime()-tpTime_startToFirst); 43 | route.setVehicleAndDepartureTime(route.getVehicle(), newDepartureTime); 44 | updateActivityTimes(route, problem.getTransportCosts()); 45 | } 46 | } 47 | } 48 | 49 | public void updateActivityTimes(VehicleRoute route, TransportTime transportTimes){ 50 | RouteActivityVisitor routeVisitor = new RouteActivityVisitor(); 51 | routeVisitor.addActivityVisitor(new UpdateActivityTimes(transportTimes)); 52 | routeVisitor.visit(route); 53 | } 54 | 55 | } -------------------------------------------------------------------------------- /src/sschroeder/MultipleDepotExample.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2013 Stefan Schroeder 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 3.0 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library. If not, see . 16 | ******************************************************************************/ 17 | package sschroeder; 18 | 19 | import java.util.Collection; 20 | 21 | import jsprit.analysis.toolbox.AlgorithmSearchProgressChartListener; 22 | import jsprit.analysis.toolbox.Plotter; 23 | import jsprit.analysis.toolbox.SolutionPrinter; 24 | import jsprit.analysis.toolbox.SolutionPrinter.Print; 25 | import jsprit.core.algorithm.VehicleRoutingAlgorithm; 26 | import jsprit.core.algorithm.VehicleRoutingAlgorithmBuilder; 27 | import jsprit.core.algorithm.state.StateManager; 28 | import jsprit.core.problem.VehicleRoutingProblem; 29 | import jsprit.core.problem.constraint.ConstraintManager; 30 | import jsprit.core.problem.constraint.ConstraintManager.Priority; 31 | import jsprit.core.problem.io.VrpXMLReader; 32 | import jsprit.core.problem.solution.VehicleRoutingProblemSolution; 33 | import jsprit.core.util.Solutions; 34 | 35 | 36 | public class MultipleDepotExample { 37 | 38 | /** 39 | * @param args 40 | */ 41 | public static void main(String[] args) { 42 | /* 43 | * some preparation - create output folder 44 | */ 45 | 46 | 47 | VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); 48 | /* 49 | * Read cordeau-instance p01, BUT only its services without any vehicles 50 | */ 51 | new VrpXMLReader(vrpBuilder).read("input/sschroeder/cordeau_p01.xml"); 52 | 53 | /* 54 | * build the problem 55 | */ 56 | VehicleRoutingProblem vrp = vrpBuilder.build(); 57 | 58 | /* 59 | * plot to see how the problem looks like 60 | */ 61 | // SolutionPlotter.plotVrpAsPNG(vrp, "output/problem01.png", "p01"); 62 | 63 | /* 64 | * solve the problem 65 | */ 66 | VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(vrp, "input/sschroeder/rr_ta.xml"); 67 | vraBuilder.addDefaultCostCalculators(); 68 | 69 | double maxDriverTime = 70.; 70 | StateManager stateManager = new StateManager(vrp.getTransportCosts()); 71 | stateManager.updateLoadStates(); 72 | // stateManager.updateTimeWindowStates(); 73 | stateManager.addStateUpdater(new UpdateDepartureTimeAndPracticalTimeWindows(stateManager, vrp.getTransportCosts(), maxDriverTime)); 74 | 75 | ConstraintManager constraintManager = new ConstraintManager(vrp, stateManager); 76 | constraintManager.addLoadConstraint(); 77 | // constraintManager.addTimeWindowConstraint(); 78 | constraintManager.addConstraint(new TimeWindowConstraintWithDriverTime(stateManager, vrp.getTransportCosts(), maxDriverTime),Priority.CRITICAL); 79 | 80 | vraBuilder.setStateAndConstraintManager(stateManager, constraintManager); 81 | 82 | VehicleRoutingAlgorithm algorithm = vraBuilder.build(); 83 | algorithm.setNuOfIterations(2000); 84 | algorithm.addListener(new DepartureTimeReScheduler()); 85 | 86 | algorithm.getAlgorithmListeners().addListener(new AlgorithmSearchProgressChartListener("output/sschroeder/progress.png")); 87 | Collection solutions = algorithm.searchSolutions(); 88 | 89 | SolutionPrinter.print(vrp,Solutions.bestOf(solutions),Print.VERBOSE); 90 | 91 | new Plotter(vrp, Solutions.bestOf(solutions)).plot("output/sschroeder/cordeau_p01_comp.png", "p01"); 92 | 93 | // new GraphStreamViewer(vrp, Solutions.bestOf(solutions)).setRenderDelay(100).display(); 94 | 95 | } 96 | 97 | } 98 | -------------------------------------------------------------------------------- /src/sschroeder/SimpleExampleWithOperationTimeOfDriver.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2013 Stefan Schroeder 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 3.0 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library. If not, see . 16 | ******************************************************************************/ 17 | package sschroeder; 18 | 19 | import java.util.Collection; 20 | 21 | import jsprit.core.algorithm.VehicleRoutingAlgorithm; 22 | import jsprit.core.algorithm.VehicleRoutingAlgorithmBuilder; 23 | import jsprit.core.algorithm.state.StateManager; 24 | import jsprit.core.problem.VehicleRoutingProblem; 25 | import jsprit.core.problem.constraint.ConstraintManager; 26 | import jsprit.core.problem.constraint.ConstraintManager.Priority; 27 | import jsprit.core.problem.job.Service; 28 | import jsprit.core.problem.solution.VehicleRoutingProblemSolution; 29 | import jsprit.core.problem.solution.route.activity.TimeWindow; 30 | import jsprit.core.problem.vehicle.Vehicle; 31 | import jsprit.core.problem.vehicle.VehicleImpl; 32 | import jsprit.core.problem.vehicle.VehicleImpl.Builder; 33 | import jsprit.core.problem.vehicle.VehicleType; 34 | import jsprit.core.problem.vehicle.VehicleTypeImpl; 35 | import jsprit.core.reporting.SolutionPrinter; 36 | import jsprit.core.reporting.SolutionPrinter.Print; 37 | import jsprit.core.util.Coordinate; 38 | import jsprit.core.util.Solutions; 39 | 40 | public class SimpleExampleWithOperationTimeOfDriver { 41 | 42 | public static void main(String[] args) { 43 | 44 | /* 45 | * get a vehicle type-builder and build a type with the typeId "vehicleType" and one capacity dimension, i.e. weight, and capacity dimension value of 2 46 | */ 47 | final int WEIGHT_INDEX = 0; 48 | VehicleTypeImpl.Builder vehicleTypeBuilder = VehicleTypeImpl.Builder.newInstance("vehicleType").addCapacityDimension(WEIGHT_INDEX, 2); 49 | VehicleType vehicleType = vehicleTypeBuilder.build(); 50 | 51 | /* 52 | * get a vehicle-builder and build a vehicle located at (10,10) with type "vehicleType" 53 | */ 54 | Builder vehicleBuilder = VehicleImpl.Builder.newInstance("vehicle"); 55 | vehicleBuilder.setStartLocationCoordinate(Coordinate.newInstance(0, 0)); 56 | vehicleBuilder.setType(vehicleType); 57 | vehicleBuilder.setLatestArrival(35.); 58 | Vehicle vehicle = vehicleBuilder.build(); 59 | 60 | /* 61 | * build services at the required locations, each with a capacity-demand of 1. 62 | */ 63 | 64 | Service service1 = Service.Builder.newInstance("1").addSizeDimension(WEIGHT_INDEX, 1).setCoord(Coordinate.newInstance(10, 0)) 65 | .setTimeWindow(TimeWindow.newInstance(15., 30.)).setServiceTime(1.).build(); 66 | Service service2 = Service.Builder.newInstance("2").setServiceTime(1.).addSizeDimension(WEIGHT_INDEX, 1).setCoord(Coordinate.newInstance(10, 0)) 67 | .setTimeWindow(TimeWindow.newInstance(15.,30.)).build(); 68 | 69 | 70 | VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); 71 | vrpBuilder.addVehicle(vehicle); 72 | vrpBuilder.addJob(service1).addJob(service2); 73 | 74 | VehicleRoutingProblem problem = vrpBuilder.build(); 75 | 76 | /* 77 | * get the algorithm out-of-the-box. 78 | */ 79 | VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(problem, "input/sschroeder/rr_ta.xml"); 80 | vraBuilder.addDefaultCostCalculators(); 81 | 82 | double maxDriverTime = 21.; 83 | StateManager stateManager = new StateManager(problem.getTransportCosts()); 84 | stateManager.updateLoadStates(); 85 | stateManager.addStateUpdater(new UpdateDepartureTimeAndPracticalTimeWindows(stateManager, problem.getTransportCosts(), maxDriverTime)); 86 | 87 | ConstraintManager constraintManager = new ConstraintManager(problem, stateManager); 88 | constraintManager.addLoadConstraint(); 89 | constraintManager.addConstraint(new TimeWindowConstraintWithDriverTime(stateManager, problem.getTransportCosts(), maxDriverTime),Priority.CRITICAL); 90 | 91 | vraBuilder.setStateAndConstraintManager(stateManager, constraintManager); 92 | 93 | VehicleRoutingAlgorithm algorithm = vraBuilder.build(); 94 | algorithm.addListener(new DepartureTimeReScheduler()); 95 | 96 | /* 97 | * and search a solution 98 | */ 99 | Collection solutions = algorithm.searchSolutions(); 100 | 101 | /* 102 | * get the best 103 | */ 104 | VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions); 105 | 106 | // new VrpXMLWriter(problem, solutions).write("output/problem-with-solution.xml"); 107 | 108 | SolutionPrinter.print(problem,bestSolution,Print.VERBOSE); 109 | 110 | 111 | } 112 | 113 | } 114 | -------------------------------------------------------------------------------- /src/sschroeder/SolomonExample.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2013 Stefan Schroeder 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 3.0 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library. If not, see . 16 | ******************************************************************************/ 17 | package sschroeder; 18 | 19 | import java.util.Collection; 20 | 21 | import jsprit.analysis.toolbox.GraphStreamViewer; 22 | import jsprit.analysis.toolbox.GraphStreamViewer.Label; 23 | import jsprit.analysis.toolbox.Plotter; 24 | import jsprit.analysis.toolbox.SolutionPrinter; 25 | import jsprit.analysis.toolbox.SolutionPrinter.Print; 26 | import jsprit.core.algorithm.VehicleRoutingAlgorithm; 27 | import jsprit.core.algorithm.VehicleRoutingAlgorithmBuilder; 28 | import jsprit.core.algorithm.selector.SelectBest; 29 | import jsprit.core.algorithm.state.StateManager; 30 | import jsprit.core.problem.VehicleRoutingProblem; 31 | import jsprit.core.problem.constraint.ConstraintManager; 32 | import jsprit.core.problem.constraint.ConstraintManager.Priority; 33 | import jsprit.core.problem.solution.VehicleRoutingProblemSolution; 34 | import jsprit.instance.reader.SolomonReader; 35 | 36 | 37 | public class SolomonExample { 38 | 39 | public static void main(String[] args) { 40 | /* 41 | * some preparation - create output folder 42 | */ 43 | 44 | 45 | /* 46 | * Build the problem. 47 | * 48 | * But define a problem-builder first. 49 | */ 50 | VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); 51 | 52 | /* 53 | * A solomonReader reads solomon-instance files, and stores the required information in the builder. 54 | */ 55 | new SolomonReader(vrpBuilder).read("input/sschroeder/C101_solomon.txt"); 56 | 57 | /* 58 | * Finally, the problem can be built. By default, transportCosts are crowFlyDistances (as usually used for vrp-instances). 59 | */ 60 | VehicleRoutingProblem problem = vrpBuilder.build(); 61 | 62 | // new Plotter(vrp).plot("output/solomon_C101.png", "C101"); 63 | 64 | /* 65 | * Define the required vehicle-routing algorithms to solve the above problem. 66 | * 67 | * The algorithm can be defined and configured in an xml-file. 68 | */ 69 | VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(problem, "input/sschroeder/rr_ta.xml"); 70 | vraBuilder.addDefaultCostCalculators(); 71 | 72 | /* 73 | * The next lines of code are to consider a maximum working time of drivers of 600. time units. Additionally, the algorithm 74 | * optimizes departure times at the depot such that waiting times at the first activity of a route are avoided, i.e. the 75 | * vehicle starts at the depot such that it just arrives at the earliestOperationStartTime of the first activity, i.e. 76 | * actualDepartureTime = max(earliestStartOfVehicle, firstActivity.earliestOperationStart - tpTime(start,firstActivity)). 77 | * If the vehicle departs later, it can also arrive at its endLocation later as long as actualArrival@depot <= latestArrivalOfVehicle 78 | * and actualArrival@depot-actualDepartureTime <= driverOperationTime hold. 79 | * 80 | * For example: 81 | * 82 | * |----- vehicle's operation time -------| (i.e. [earliestDeparture,latestArrival] 83 | * 84 | * actDeparture actArrival 85 | * |---- driver's operation time ---| 86 | * 87 | */ 88 | 89 | //set max driver time 90 | double maxDriverTime = 600.; 91 | StateManager stateManager = new StateManager(problem.getTransportCosts()); 92 | //adds core load/capacity constraints 93 | stateManager.updateLoadStates(); 94 | //replaces the default twUpdater and updates departureTime and practical time windows 95 | stateManager.addStateUpdater(new UpdateDepartureTimeAndPracticalTimeWindows(stateManager, problem.getTransportCosts(), maxDriverTime)); 96 | 97 | ConstraintManager constraintManager = new ConstraintManager(problem, stateManager); 98 | constraintManager.addLoadConstraint(); 99 | //replaces the default twConstraint to consider departureTime and driver's working hour as well 100 | constraintManager.addConstraint(new TimeWindowConstraintWithDriverTime(stateManager, problem.getTransportCosts(), maxDriverTime),Priority.CRITICAL); 101 | 102 | vraBuilder.setStateAndConstraintManager(stateManager, constraintManager); 103 | 104 | VehicleRoutingAlgorithm algorithm = vraBuilder.build(); 105 | //finally re-schedules the departure time of vehicles to avoid waiting times at first activity 106 | algorithm.addListener(new DepartureTimeReScheduler()); 107 | 108 | 109 | /* 110 | * Solve the problem. 111 | * 112 | * 113 | */ 114 | Collection solutions = algorithm.searchSolutions(); 115 | 116 | /* 117 | * Retrieve best solution. 118 | */ 119 | VehicleRoutingProblemSolution solution = new SelectBest().selectSolution(solutions); 120 | 121 | /* 122 | * print solution 123 | */ 124 | SolutionPrinter.print(problem,solution,Print.VERBOSE); 125 | 126 | /* 127 | * Plot solution. 128 | */ 129 | Plotter plotter = new Plotter(problem,solution); 130 | // plotter.setBoundingBox(30, 0, 50, 20); 131 | plotter.plot("output/sschroeder/solomon_C101_solution.png", "C101"); 132 | // SolutionPlotter.plotSolutionAsPNG(vrp, solution, "output/solomon_C101_solution.png","C101"); 133 | 134 | // GraphStream.display(vrp,100); 135 | 136 | new GraphStreamViewer(problem,solution).labelWith(Label.ID).setRenderDelay(100).display(); 137 | 138 | } 139 | 140 | } 141 | -------------------------------------------------------------------------------- /src/sschroeder/SpeedVariations.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2013 Stefan Schroeder 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 3.0 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library. If not, see . 16 | ******************************************************************************/ 17 | package sschroeder; 18 | 19 | import jsprit.core.problem.VehicleRoutingProblem; 20 | import jsprit.core.problem.cost.AbstractForwardVehicleRoutingTransportCosts; 21 | import jsprit.core.problem.cost.VehicleRoutingTransportCosts; 22 | import jsprit.core.problem.driver.Driver; 23 | import jsprit.core.problem.vehicle.Vehicle; 24 | import jsprit.core.problem.vehicle.VehicleImpl; 25 | import jsprit.core.problem.vehicle.VehicleType; 26 | import jsprit.core.problem.vehicle.VehicleTypeImpl; 27 | import jsprit.core.problem.vehicle.VehicleTypeImpl.VehicleCostParams; 28 | import jsprit.core.util.VehicleRoutingTransportCostsMatrix; 29 | 30 | public class SpeedVariations { 31 | 32 | 33 | 34 | public static void main(String[] args) { 35 | 36 | VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(true); 37 | //base time 38 | matrixBuilder.addTransportTime("from", "to", 100.); 39 | final VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build(); 40 | VehicleRoutingTransportCosts modifiedMatrix = new AbstractForwardVehicleRoutingTransportCosts() { 41 | 42 | @Override 43 | public double getTransportTime(String fromId, String toId,double departureTime, Driver driver, Vehicle vehicle) { 44 | if(vehicle.getType().getTypeId().equals("A")){ 45 | return matrix.getTransportTime(fromId, toId, departureTime, driver, vehicle)*1.1; 46 | } 47 | return matrix.getTransportTime(fromId, toId, departureTime, driver, vehicle); 48 | } 49 | 50 | @Override 51 | public double getTransportCost(String fromId, String toId, double departureTime, Driver driver, Vehicle vehicle) { 52 | if(vehicle == null) return matrix.getDistance(fromId, toId); 53 | VehicleCostParams costParams = vehicle.getType().getVehicleCostParams(); 54 | return costParams.perDistanceUnit*matrix.getDistance(fromId, toId) + 55 | costParams.perTimeUnit*getTransportTime(fromId, toId, departureTime, driver, vehicle); 56 | } 57 | }; 58 | 59 | VehicleType typeA = VehicleTypeImpl.Builder.newInstance("A").build(); 60 | VehicleType typeB = VehicleTypeImpl.Builder.newInstance("B").build(); 61 | 62 | Vehicle vehOfTypeA = VehicleImpl.Builder.newInstance("ofTypeA").setType(typeA).setStartLocationId("start").build(); 63 | Vehicle vehOfTypeB = VehicleImpl.Builder.newInstance("ofTypeB").setType(typeB).setStartLocationId("start").build(); 64 | 65 | System.out.println("tpTime of A: "+ modifiedMatrix.getTransportTime("from", "to", 0., null, vehOfTypeA)); 66 | System.out.println("tpTime of B: "+ modifiedMatrix.getTransportTime("from", "to", 0., null, vehOfTypeB)); 67 | assert modifiedMatrix.getTransportTime("from", "to", 0., null, vehOfTypeA) >= 110.*0.99 && modifiedMatrix.getTransportTime("from", "to", 0., null, vehOfTypeA) <= 110.*1.01 : "110 should be the correct value for vehicle " + vehOfTypeA; 68 | assert modifiedMatrix.getTransportTime("from", "to", 0., null, vehOfTypeB) == 100. : "100 should be the correct value for vehicle " + vehOfTypeB; 69 | 70 | //set modifiedMatrix instead of matrix 71 | VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); 72 | vrpBuilder.setRoutingCost(modifiedMatrix); 73 | 74 | 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /src/sschroeder/StateIds.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2013 Stefan Schroeder 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 3.0 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library. If not, see . 16 | ******************************************************************************/ 17 | package sschroeder; 18 | 19 | import jsprit.core.problem.solution.route.state.StateFactory; 20 | import jsprit.core.problem.solution.route.state.StateFactory.StateId; 21 | 22 | public class StateIds { 23 | 24 | public static final StateId LATEST_ACTIVITY_START = StateFactory.createId("latest_start"); 25 | 26 | public static final StateId DEPARTURE_AT_DEPOT = StateFactory.createId("departure"); 27 | 28 | public static final StateId LATEST_ARR_AT_DEPOT = StateFactory.createId("latestArrTimeAtDepot"); 29 | 30 | public static final StateId ARRIVAL_AT_DEPOT = StateFactory.createId("arrTimeAtDepot");; 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/sschroeder/TimeWindowConstraintWithDriverTime.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2013 Stefan Schroeder 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 3.0 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library. If not, see . 16 | ******************************************************************************/ 17 | package sschroeder; 18 | 19 | import jsprit.core.problem.constraint.HardActivityStateLevelConstraint; 20 | import jsprit.core.problem.cost.VehicleRoutingTransportCosts; 21 | import jsprit.core.problem.misc.JobInsertionContext; 22 | import jsprit.core.problem.solution.route.activity.End; 23 | import jsprit.core.problem.solution.route.activity.Start; 24 | import jsprit.core.problem.solution.route.activity.TourActivity; 25 | import jsprit.core.problem.solution.route.state.RouteAndActivityStateGetter; 26 | import jsprit.core.util.CalculationUtils; 27 | 28 | 29 | /** 30 | * 31 | * @author stefan 32 | * 33 | */ 34 | class TimeWindowConstraintWithDriverTime implements HardActivityStateLevelConstraint { 35 | 36 | private RouteAndActivityStateGetter states; 37 | 38 | private VehicleRoutingTransportCosts routingCosts; 39 | 40 | private double maxDriverTime; 41 | 42 | public TimeWindowConstraintWithDriverTime(RouteAndActivityStateGetter states, VehicleRoutingTransportCosts routingCosts, double maxDriverTime) { 43 | super(); 44 | this.states = states; 45 | this.routingCosts = routingCosts; 46 | this.maxDriverTime=maxDriverTime; 47 | } 48 | 49 | @Override 50 | public ConstraintsStatus fulfilled(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) { 51 | 52 | // double actualDeparture = getActualDeparture(iFacts,newAct); 53 | double latest_arr_at_depot = getLatestArrAtDepot(iFacts,newAct); 54 | 55 | /* 56 | * if actualDeparture changes --> latestArr changes too 57 | * 58 | * 59 | * 60 | */ 61 | double actualEnd = getCurrentArrTimeAtEnd(iFacts); 62 | if(prevAct instanceof Start){ 63 | double newDepartureTime = getVehicleDeparture(iFacts, newAct); 64 | if(actualEnd - newDepartureTime > maxDriverTime){ 65 | return ConstraintsStatus.NOT_FULFILLED; 66 | } 67 | } 68 | 69 | 70 | double latestVehicleArrival = Math.min(iFacts.getNewVehicle().getLatestArrival(),latest_arr_at_depot); 71 | 72 | /* 73 | * if latest arrival of vehicle (at its end) is smaller than earliest operation start times of activities, 74 | * then vehicle can never conduct activities. 75 | * 76 | * |--- vehicle's operation time ---| 77 | * |--- prevAct or newAct or nextAct ---| 78 | */ 79 | if(latestVehicleArrival < prevAct.getTheoreticalEarliestOperationStartTime() || 80 | latestVehicleArrival < newAct.getTheoreticalEarliestOperationStartTime() || 81 | latestVehicleArrival < nextAct.getTheoreticalEarliestOperationStartTime()){ 82 | return ConstraintsStatus.NOT_FULFILLED_BREAK; 83 | } 84 | /* 85 | * if the latest operation start-time of new activity is smaller than the earliest start of prev. activity, 86 | * then 87 | * 88 | * |--- prevAct ---| 89 | * |--- newAct ---| 90 | */ 91 | if(newAct.getTheoreticalLatestOperationStartTime() < prevAct.getTheoreticalEarliestOperationStartTime()){ 92 | return ConstraintsStatus.NOT_FULFILLED_BREAK; 93 | } 94 | 95 | /* 96 | * |--- prevAct ---| 97 | * |- earliest arrival of vehicle 98 | * |--- nextAct ---| 99 | */ 100 | double arrTimeAtNextOnDirectRouteWithNewVehicle = prevActDepTime + routingCosts.getTransportTime(prevAct.getLocationId(), nextAct.getLocationId(), prevActDepTime, iFacts.getNewDriver(), iFacts.getNewVehicle()); 101 | if(arrTimeAtNextOnDirectRouteWithNewVehicle > nextAct.getTheoreticalLatestOperationStartTime()){ 102 | return ConstraintsStatus.NOT_FULFILLED_BREAK; 103 | } 104 | /* 105 | * |--- newAct ---| 106 | * |--- nextAct ---| 107 | */ 108 | if(newAct.getTheoreticalEarliestOperationStartTime() > nextAct.getTheoreticalLatestOperationStartTime()){ 109 | return ConstraintsStatus.NOT_FULFILLED; 110 | } 111 | // log.info("check insertion of " + newAct + " between " + prevAct + " and " + nextAct + ". prevActDepTime=" + prevActDepTime); 112 | double arrTimeAtNewAct = prevActDepTime + routingCosts.getTransportTime(prevAct.getLocationId(), newAct.getLocationId(), prevActDepTime, iFacts.getNewDriver(), iFacts.getNewVehicle()); 113 | double endTimeAtNewAct = CalculationUtils.getActivityEndTime(arrTimeAtNewAct, newAct); 114 | double latestArrTimeAtNewAct = getLatestNewActStart(newAct,nextAct,iFacts,latestVehicleArrival,endTimeAtNewAct); 115 | 116 | // log.info(newAct + " arrTime=" + arrTimeAtNewAct); 117 | 118 | double arrTimeAtNextAct = endTimeAtNewAct + routingCosts.getTransportTime(newAct.getLocationId(), nextAct.getLocationId(), endTimeAtNewAct, iFacts.getNewDriver(), iFacts.getNewVehicle()); 119 | double latestArrTimeAtNextAct = getLatestActStartOfNext(nextAct,iFacts,latestVehicleArrival); 120 | /* 121 | * |--- newAct ---| 122 | * |--- vehicle's arrival @nextAct 123 | * latest arrival of vehicle @nextAct ---| 124 | */ 125 | if(arrTimeAtNextAct > latestVehicleArrival){ 126 | return ConstraintsStatus.NOT_FULFILLED_BREAK; 127 | } 128 | if(arrTimeAtNextAct > latestArrTimeAtNextAct){ 129 | return ConstraintsStatus.NOT_FULFILLED; 130 | } 131 | /* 132 | * |--- prevAct ---| 133 | * |--- vehicle's arrival @newAct 134 | * latest arrival of vehicle @newAct ---| 135 | */ 136 | if(arrTimeAtNewAct > latestVehicleArrival){ 137 | return ConstraintsStatus.NOT_FULFILLED_BREAK; 138 | } 139 | if(arrTimeAtNewAct > latestArrTimeAtNewAct){ 140 | return ConstraintsStatus.NOT_FULFILLED; 141 | } 142 | 143 | 144 | // if vehicle cannot even manage direct-route - break 145 | if(arrTimeAtNextOnDirectRouteWithNewVehicle > latestArrTimeAtNextAct){ 146 | return ConstraintsStatus.NOT_FULFILLED_BREAK; 147 | } 148 | return ConstraintsStatus.FULFILLED; 149 | } 150 | 151 | private double getCurrentArrTimeAtEnd(JobInsertionContext iFacts) { 152 | return iFacts.getRoute().getEnd().getArrTime(); 153 | } 154 | 155 | private double getLatestNewActStart(TourActivity newAct, TourActivity nextAct, JobInsertionContext iFacts, double latestVehicleArrival, double departureAtNewAct) { 156 | double latestNextActStart = getLatestActStartOfNext(nextAct, iFacts, latestVehicleArrival); 157 | double latestNewAct = latestNextActStart - routingCosts.getTransportTime(newAct.getLocationId(), nextAct.getLocationId(), 158 | departureAtNewAct, iFacts.getNewDriver(), iFacts.getNewVehicle()); 159 | return Math.min(newAct.getTheoreticalLatestOperationStartTime(), latestNewAct); 160 | } 161 | 162 | private double getLatestActStartOfNext(TourActivity nextAct,JobInsertionContext iFacts, double latestVehicleArrival) { 163 | if(nextAct instanceof End){ 164 | return latestVehicleArrival; 165 | } 166 | if(states.getActivityState(nextAct, StateIds.LATEST_ACTIVITY_START, Double.class) != null){ 167 | return states.getActivityState(nextAct, StateIds.LATEST_ACTIVITY_START, Double.class); 168 | } 169 | else{ 170 | return nextAct.getTheoreticalLatestOperationStartTime(); 171 | } 172 | } 173 | 174 | private double getLatestArrAtDepot(JobInsertionContext iFacts, TourActivity newActivity) { 175 | if(states.getRouteState(iFacts.getRoute(), StateIds.LATEST_ARR_AT_DEPOT, Double.class) != null){ 176 | return states.getRouteState(iFacts.getRoute(), StateIds.LATEST_ARR_AT_DEPOT, Double.class); 177 | } 178 | else return Math.min(iFacts.getNewVehicle().getLatestArrival(),getVehicleDeparture(iFacts,newActivity)+maxDriverTime); 179 | } 180 | 181 | private double getVehicleDeparture(JobInsertionContext iFacts, TourActivity newActivity) { 182 | double tpTime = routingCosts.getTransportTime(iFacts.getNewVehicle().getStartLocationId(), newActivity.getLocationId(), iFacts.getNewDepTime(), iFacts.getNewDriver(), iFacts.getNewVehicle()); 183 | double newDepTime = newActivity.getTheoreticalEarliestOperationStartTime() - tpTime; 184 | return Math.max(iFacts.getNewDepTime(),newDepTime); 185 | } 186 | } -------------------------------------------------------------------------------- /src/sschroeder/UpdateDepartureTimeAndPracticalTimeWindows.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2013 Stefan Schroeder 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 3.0 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library. If not, see . 16 | ******************************************************************************/ 17 | package sschroeder; 18 | 19 | import jsprit.core.algorithm.state.StateManager; 20 | import jsprit.core.algorithm.state.StateUpdater; 21 | import jsprit.core.problem.cost.VehicleRoutingTransportCosts; 22 | import jsprit.core.problem.solution.route.VehicleRoute; 23 | import jsprit.core.problem.solution.route.activity.ReverseActivityVisitor; 24 | import jsprit.core.problem.solution.route.activity.TourActivity; 25 | 26 | /** 27 | * Updates and memorizes latest operation start times at activities. 28 | * 29 | * @author schroeder 30 | * 31 | */ 32 | class UpdateDepartureTimeAndPracticalTimeWindows implements ReverseActivityVisitor, StateUpdater{ 33 | 34 | private StateManager states; 35 | 36 | private VehicleRoute route; 37 | 38 | private VehicleRoutingTransportCosts transportCosts; 39 | 40 | private double latestArrTimeAtPrevAct; 41 | 42 | private TourActivity prevAct; 43 | 44 | private double maxOperationTimeOfDriver; 45 | 46 | public UpdateDepartureTimeAndPracticalTimeWindows(StateManager states, VehicleRoutingTransportCosts transportCosts, double maxDriverTime) { 47 | super(); 48 | this.states = states; 49 | this.transportCosts = transportCosts; 50 | maxOperationTimeOfDriver = maxDriverTime; 51 | } 52 | 53 | @Override 54 | public void begin(VehicleRoute route) { 55 | this.route = route; 56 | double newDepartureTime = getNewDepartureTime(route); 57 | double latestArrAtDepot = Math.min(route.getEnd().getTheoreticalLatestOperationStartTime(),newDepartureTime+maxOperationTimeOfDriver); 58 | states.putTypedRouteState(route, StateIds.LATEST_ARR_AT_DEPOT, Double.class, latestArrAtDepot); 59 | latestArrTimeAtPrevAct = latestArrAtDepot; 60 | prevAct = route.getEnd(); 61 | } 62 | 63 | @Override 64 | public void visit(TourActivity activity) { 65 | double potentialLatestArrivalTimeAtCurrAct = latestArrTimeAtPrevAct - transportCosts.getBackwardTransportTime(activity.getLocationId(), prevAct.getLocationId(), latestArrTimeAtPrevAct, route.getDriver(),route.getVehicle()) - activity.getOperationTime(); 66 | double latestArrivalTime = Math.min(activity.getTheoreticalLatestOperationStartTime(), potentialLatestArrivalTimeAtCurrAct); 67 | states.putTypedActivityState(activity, StateIds.LATEST_ACTIVITY_START, Double.class, latestArrivalTime); 68 | latestArrTimeAtPrevAct = latestArrivalTime; 69 | prevAct = activity; 70 | } 71 | 72 | @Override 73 | public void finish() {} 74 | 75 | 76 | public double getNewDepartureTime(VehicleRoute route){ 77 | double earliestDepartureTime = route.getDepartureTime(); 78 | TourActivity firstActivity = route.getActivities().get(0); 79 | double tpTime_startToFirst = transportCosts.getTransportTime(route.getStart().getLocationId(), firstActivity.getLocationId(), 80 | earliestDepartureTime, null, route.getVehicle()); 81 | double newDepartureTime = Math.max(earliestDepartureTime, firstActivity.getTheoreticalEarliestOperationStartTime()-tpTime_startToFirst); 82 | return newDepartureTime; 83 | } 84 | 85 | } -------------------------------------------------------------------------------- /src/stackoverflow/Stackoverflow_RelatedJobs_13_and_21_inSameRoute.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2013 Stefan Schroeder 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 3.0 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library. If not, see . 16 | ******************************************************************************/ 17 | 18 | package stackoverflow; 19 | 20 | import java.util.Collection; 21 | 22 | import jsprit.analysis.toolbox.AlgorithmSearchProgressChartListener; 23 | import jsprit.analysis.toolbox.Plotter; 24 | import jsprit.analysis.toolbox.Plotter.Label; 25 | import jsprit.core.algorithm.VehicleRoutingAlgorithm; 26 | import jsprit.core.algorithm.VehicleRoutingAlgorithmBuilder; 27 | import jsprit.core.algorithm.state.StateManager; 28 | import jsprit.core.algorithm.state.StateUpdater; 29 | import jsprit.core.problem.VehicleRoutingProblem; 30 | import jsprit.core.problem.constraint.ConstraintManager; 31 | import jsprit.core.problem.constraint.SoftRouteConstraint; 32 | import jsprit.core.problem.io.VrpXMLReader; 33 | import jsprit.core.problem.job.Job; 34 | import jsprit.core.problem.misc.JobInsertionContext; 35 | import jsprit.core.problem.solution.SolutionCostCalculator; 36 | import jsprit.core.problem.solution.VehicleRoutingProblemSolution; 37 | import jsprit.core.problem.solution.route.VehicleRoute; 38 | import jsprit.core.problem.solution.route.activity.ActivityVisitor; 39 | import jsprit.core.problem.solution.route.activity.TourActivity; 40 | import jsprit.core.problem.solution.route.activity.TourActivity.JobActivity; 41 | import jsprit.core.problem.solution.route.state.StateFactory; 42 | import jsprit.core.reporting.SolutionPrinter; 43 | import jsprit.core.reporting.SolutionPrinter.Print; 44 | import jsprit.core.util.Solutions; 45 | 46 | /** 47 | * http://stackoverflow.com/questions/24447451/related-jobs-in-jsprit 48 | * 49 | * @author schroeder 50 | * 51 | */ 52 | public class Stackoverflow_RelatedJobs_13_and_21_inSameRoute { 53 | 54 | static class JobsInRouteMemorizer implements StateUpdater, ActivityVisitor { 55 | 56 | private StateManager stateManager; 57 | private VehicleRoute route; 58 | 59 | 60 | public JobsInRouteMemorizer(StateManager stateManager) { 61 | super(); 62 | this.stateManager = stateManager; 63 | } 64 | 65 | @Override 66 | public void begin(VehicleRoute route) { 67 | this.route=route; 68 | } 69 | 70 | @Override 71 | public void visit(TourActivity activity) { 72 | if(activity instanceof JobActivity){ 73 | String jobId = ((JobActivity) activity).getJob().getId(); 74 | stateManager.putProblemState(StateFactory.createId(jobId), VehicleRoute.class, this.route); 75 | } 76 | 77 | } 78 | 79 | @Override 80 | public void finish() {} 81 | 82 | } 83 | 84 | static class TwentyOneAndThirteenInSameRouteConstraint implements SoftRouteConstraint { 85 | 86 | private StateManager stateManager; 87 | 88 | public TwentyOneAndThirteenInSameRouteConstraint(StateManager stateManager) { 89 | super(); 90 | this.stateManager = stateManager; 91 | } 92 | 93 | @Override 94 | public double getCosts(JobInsertionContext insertionContext) { 95 | if(insertionContext.getJob().getId().equals("13")){ 96 | VehicleRoute route = stateManager.getProblemState(StateFactory.createId("21"), VehicleRoute.class); 97 | if(route==null){ 98 | return 0.; 99 | } 100 | if(route!=null){ 101 | if(route==insertionContext.getRoute()){ 102 | return -100.; 103 | } 104 | else return 0.; 105 | } 106 | } 107 | if(insertionContext.getJob().getId().equals("21")){ 108 | VehicleRoute route = stateManager.getProblemState(StateFactory.createId("13"), VehicleRoute.class); 109 | if(route==null){ 110 | return 0.; 111 | } 112 | if(route!=null){ 113 | if(route==insertionContext.getRoute()){ 114 | return -100.; 115 | } 116 | else return 0.; 117 | } 118 | } 119 | return 0; 120 | } 121 | } 122 | 123 | 124 | 125 | static class RewardAndPenaltiesThroughSoftConstraints { 126 | 127 | private VehicleRoutingProblem vrp; 128 | 129 | public RewardAndPenaltiesThroughSoftConstraints(VehicleRoutingProblem vrp) { 130 | super(); 131 | this.vrp = vrp; 132 | } 133 | 134 | public double getCosts(VehicleRoute route) { 135 | boolean serves13 = route.getTourActivities().servesJob(getJob("13")); 136 | boolean serves21 = route.getTourActivities().servesJob(getJob("21")); 137 | if(serves13 && serves21) { //then reward 138 | return -100; 139 | } 140 | return 0; 141 | } 142 | 143 | private Job getJob(String string) { 144 | return vrp.getJobs().get(string); 145 | } 146 | 147 | } 148 | 149 | public static void main(String[] args) { 150 | 151 | VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); 152 | 153 | /* 154 | * A solomonReader reads solomon-instance files, and stores the required information in the builder. 155 | */ 156 | new VrpXMLReader(vrpBuilder).read("input/vrpnc1-jsprit.xml"); 157 | 158 | /* 159 | * Finally, the problem can be built. By default, transportCosts are crowFlyDistances (as usually used for vrp-instances). 160 | */ 161 | VehicleRoutingProblem vrp = vrpBuilder.build(); 162 | 163 | final StateManager stateManager = new StateManager(vrp.getTransportCosts()); 164 | stateManager.addStateUpdater(new JobsInRouteMemorizer(stateManager)); 165 | 166 | ConstraintManager constraintManager = new ConstraintManager(vrp,stateManager); 167 | constraintManager.addConstraint(new TwentyOneAndThirteenInSameRouteConstraint(stateManager)); 168 | 169 | final RewardAndPenaltiesThroughSoftConstraints softConstraintContributionToOverallObjective = new RewardAndPenaltiesThroughSoftConstraints(vrp); 170 | SolutionCostCalculator costCalculator = new SolutionCostCalculator() { 171 | 172 | @Override 173 | public double getCosts(VehicleRoutingProblemSolution solution) { 174 | double costs = 0.; 175 | for(VehicleRoute route : solution.getRoutes()){ 176 | costs+=route.getVehicle().getType().getVehicleCostParams().fix; 177 | costs+=stateManager.getRouteState(route, StateFactory.COSTS, Double.class); 178 | costs+=softConstraintContributionToOverallObjective.getCosts(route); 179 | } 180 | return costs; 181 | } 182 | 183 | }; 184 | 185 | VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(vrp, "input/rr_ta.xml"); 186 | vraBuilder.addCoreConstraints(); 187 | vraBuilder.setStateAndConstraintManager(stateManager, constraintManager); 188 | vraBuilder.addDefaultCostCalculators(); 189 | vraBuilder.setObjectiveFunction(costCalculator); 190 | VehicleRoutingAlgorithm vra = vraBuilder.build(); 191 | 192 | vra.addListener(new AlgorithmSearchProgressChartListener("output/search")); 193 | 194 | // 195 | Collection solutions = vra.searchSolutions(); 196 | 197 | SolutionPrinter.print(vrp, Solutions.bestOf(solutions), Print.VERBOSE); 198 | 199 | new Plotter(vrp,Solutions.bestOf(solutions)).setLabel(Label.ID).plot("output/jsprit_vrpnc1_13_21_inSameRoute", "jsprit: 13 and 21 in same route"); 200 | } 201 | 202 | } 203 | -------------------------------------------------------------------------------- /src/stackoverflow/Stackoverflow_RelatedJobs_13_and_21_inSameRoute_13_immediatelyAfter_21.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2013 Stefan Schroeder 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 3.0 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library. If not, see . 16 | ******************************************************************************/ 17 | 18 | package stackoverflow; 19 | 20 | import java.util.Collection; 21 | 22 | import jsprit.analysis.toolbox.AlgorithmSearchProgressChartListener; 23 | import jsprit.analysis.toolbox.Plotter; 24 | import jsprit.analysis.toolbox.Plotter.Label; 25 | import jsprit.core.algorithm.VehicleRoutingAlgorithm; 26 | import jsprit.core.algorithm.VehicleRoutingAlgorithmBuilder; 27 | import jsprit.core.algorithm.state.StateManager; 28 | import jsprit.core.algorithm.state.StateUpdater; 29 | import jsprit.core.problem.VehicleRoutingProblem; 30 | import jsprit.core.problem.constraint.ConstraintManager; 31 | import jsprit.core.problem.constraint.SoftActivityConstraint; 32 | import jsprit.core.problem.io.VrpXMLReader; 33 | import jsprit.core.problem.job.Job; 34 | import jsprit.core.problem.misc.JobInsertionContext; 35 | import jsprit.core.problem.solution.SolutionCostCalculator; 36 | import jsprit.core.problem.solution.VehicleRoutingProblemSolution; 37 | import jsprit.core.problem.solution.route.VehicleRoute; 38 | import jsprit.core.problem.solution.route.activity.ActivityVisitor; 39 | import jsprit.core.problem.solution.route.activity.TourActivity; 40 | import jsprit.core.problem.solution.route.activity.TourActivity.JobActivity; 41 | import jsprit.core.problem.solution.route.state.StateFactory; 42 | import jsprit.core.reporting.SolutionPrinter; 43 | import jsprit.core.reporting.SolutionPrinter.Print; 44 | import jsprit.core.util.Solutions; 45 | 46 | /** 47 | * http://stackoverflow.com/questions/24447451/related-jobs-in-jsprit 48 | * 49 | * @author schroeder 50 | * 51 | */ 52 | public class Stackoverflow_RelatedJobs_13_and_21_inSameRoute_13_immediatelyAfter_21 { 53 | 54 | static class JobsInRouteMemorizer implements StateUpdater, ActivityVisitor { 55 | 56 | private StateManager stateManager; 57 | private VehicleRoute route; 58 | 59 | 60 | public JobsInRouteMemorizer(StateManager stateManager) { 61 | super(); 62 | this.stateManager = stateManager; 63 | } 64 | 65 | @Override 66 | public void begin(VehicleRoute route) { 67 | this.route=route; 68 | } 69 | 70 | @Override 71 | public void visit(TourActivity activity) { 72 | if(activity instanceof JobActivity){ 73 | String jobId = ((JobActivity) activity).getJob().getId(); 74 | stateManager.putProblemState(StateFactory.createId(jobId), VehicleRoute.class, this.route); 75 | } 76 | 77 | } 78 | 79 | @Override 80 | public void finish() {} 81 | 82 | } 83 | 84 | static class ThirteenImmediatelyAfterTwentyOne implements SoftActivityConstraint { 85 | 86 | @Override 87 | public double getCosts(JobInsertionContext iFacts,TourActivity prevAct, TourActivity newAct,TourActivity nextAct, double prevActDepTime) { 88 | if(prevAct instanceof JobActivity && newAct instanceof JobActivity){ 89 | if(((JobActivity)prevAct).getJob().getId().equals("21") && ((JobActivity)newAct).getJob().getId().equals("13")){ 90 | return -500; 91 | } 92 | if(((JobActivity)newAct).getJob().getId().equals("13")){ 93 | return 500; 94 | } 95 | } 96 | if(newAct instanceof JobActivity && nextAct instanceof JobActivity){ 97 | if(((JobActivity)newAct).getJob().getId().equals("21") && ((JobActivity)nextAct).getJob().getId().equals("13")){ 98 | return -500; 99 | } 100 | if(((JobActivity)nextAct).getJob().getId().equals("13")){ 101 | return 500; 102 | } 103 | } 104 | return 0; 105 | } 106 | 107 | } 108 | 109 | static class RewardAndPenaltiesThroughSoftConstraints { 110 | private VehicleRoutingProblem vrp; 111 | 112 | public RewardAndPenaltiesThroughSoftConstraints(VehicleRoutingProblem vrp) { 113 | super(); 114 | this.vrp = vrp; 115 | } 116 | 117 | public double getCosts(VehicleRoute route) { 118 | boolean serves13 = route.getTourActivities().servesJob(getJob("13")); 119 | boolean serves21 = route.getTourActivities().servesJob(getJob("21")); 120 | if(serves13 && serves21) { 121 | TourActivity lastAct = route.getStart(); 122 | for(TourActivity act : route.getActivities()){ 123 | if(act instanceof JobActivity && lastAct instanceof JobActivity){ 124 | if(((JobActivity)act).getJob().getId().equals("21")){ 125 | if(((JobActivity)lastAct).getJob().getId().equals("13")){ 126 | return -500; 127 | } 128 | else{ 129 | return +500; 130 | } 131 | } 132 | } 133 | lastAct=act; 134 | } 135 | return 0.; 136 | } 137 | if(serves13 && !serves21) return +500; 138 | if(!serves13 && serves21) return +500; 139 | return 0; 140 | } 141 | 142 | private Job getJob(String string) { 143 | return vrp.getJobs().get(string); 144 | } 145 | 146 | } 147 | 148 | public static void main(String[] args) { 149 | 150 | VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); 151 | 152 | /* 153 | * A solomonReader reads solomon-instance files, and stores the required information in the builder. 154 | */ 155 | new VrpXMLReader(vrpBuilder).read("input/vrpnc1-jsprit.xml"); 156 | 157 | /* 158 | * Finally, the problem can be built. By default, transportCosts are crowFlyDistances (as usually used for vrp-instances). 159 | */ 160 | VehicleRoutingProblem vrp = vrpBuilder.build(); 161 | 162 | final StateManager stateManager = new StateManager(vrp.getTransportCosts()); 163 | stateManager.addStateUpdater(new JobsInRouteMemorizer(stateManager)); 164 | 165 | ConstraintManager constraintManager = new ConstraintManager(vrp,stateManager); 166 | constraintManager.addConstraint(new ThirteenImmediatelyAfterTwentyOne()); 167 | 168 | final RewardAndPenaltiesThroughSoftConstraints contrib = new RewardAndPenaltiesThroughSoftConstraints(vrp); 169 | SolutionCostCalculator costCalculator = new SolutionCostCalculator() { 170 | 171 | @Override 172 | public double getCosts(VehicleRoutingProblemSolution solution) { 173 | double costs = 0.; 174 | for(VehicleRoute route : solution.getRoutes()){ 175 | costs+=route.getVehicle().getType().getVehicleCostParams().fix; 176 | costs+=stateManager.getRouteState(route, StateFactory.COSTS, Double.class); 177 | costs+=contrib.getCosts(route); 178 | } 179 | return costs; 180 | } 181 | 182 | }; 183 | 184 | VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(vrp, "input/rr_ta.xml"); 185 | vraBuilder.addCoreConstraints(); 186 | vraBuilder.setStateAndConstraintManager(stateManager, constraintManager); 187 | vraBuilder.addDefaultCostCalculators(); 188 | vraBuilder.setObjectiveFunction(costCalculator); 189 | VehicleRoutingAlgorithm vra = vraBuilder.build(); 190 | 191 | vra.addListener(new AlgorithmSearchProgressChartListener("output/search")); 192 | 193 | Collection solutions = vra.searchSolutions(); 194 | 195 | SolutionPrinter.print(vrp, Solutions.bestOf(solutions), Print.VERBOSE); 196 | 197 | new Plotter(vrp,Solutions.bestOf(solutions)).setLabel(Label.ID).plot("output/jsprit_vrpnc1_13_rightAfter_21", "jsprit: 13 right after 21"); 198 | } 199 | 200 | } 201 | -------------------------------------------------------------------------------- /src/stackoverflow/Stackoverflow_RelatedJobs_13_and_21_inSameRoute_21_first.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2013 Stefan Schroeder 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 3.0 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library. If not, see . 16 | ******************************************************************************/ 17 | 18 | package stackoverflow; 19 | 20 | import java.util.Collection; 21 | 22 | import jsprit.analysis.toolbox.AlgorithmSearchProgressChartListener; 23 | import jsprit.analysis.toolbox.Plotter; 24 | import jsprit.analysis.toolbox.Plotter.Label; 25 | import jsprit.core.algorithm.VehicleRoutingAlgorithm; 26 | import jsprit.core.algorithm.VehicleRoutingAlgorithmBuilder; 27 | import jsprit.core.algorithm.state.StateManager; 28 | import jsprit.core.algorithm.state.StateUpdater; 29 | import jsprit.core.problem.VehicleRoutingProblem; 30 | import jsprit.core.problem.constraint.ConstraintManager; 31 | import jsprit.core.problem.constraint.SoftRouteConstraint; 32 | import jsprit.core.problem.io.VrpXMLReader; 33 | import jsprit.core.problem.job.Job; 34 | import jsprit.core.problem.misc.JobInsertionContext; 35 | import jsprit.core.problem.solution.SolutionCostCalculator; 36 | import jsprit.core.problem.solution.VehicleRoutingProblemSolution; 37 | import jsprit.core.problem.solution.route.VehicleRoute; 38 | import jsprit.core.problem.solution.route.activity.ActivityVisitor; 39 | import jsprit.core.problem.solution.route.activity.TourActivity; 40 | import jsprit.core.problem.solution.route.activity.TourActivity.JobActivity; 41 | import jsprit.core.problem.solution.route.state.StateFactory; 42 | import jsprit.core.reporting.SolutionPrinter; 43 | import jsprit.core.reporting.SolutionPrinter.Print; 44 | import jsprit.core.util.Solutions; 45 | 46 | /** 47 | * http://stackoverflow.com/questions/24447451/related-jobs-in-jsprit 48 | * 49 | * @author schroeder 50 | * 51 | */ 52 | public class Stackoverflow_RelatedJobs_13_and_21_inSameRoute_21_first { 53 | 54 | static class JobsInRouteMemorizer implements StateUpdater, ActivityVisitor { 55 | 56 | private StateManager stateManager; 57 | private VehicleRoute route; 58 | 59 | 60 | public JobsInRouteMemorizer(StateManager stateManager) { 61 | super(); 62 | this.stateManager = stateManager; 63 | } 64 | 65 | @Override 66 | public void begin(VehicleRoute route) { 67 | this.route=route; 68 | } 69 | 70 | @Override 71 | public void visit(TourActivity activity) { 72 | if(activity instanceof JobActivity){ 73 | String jobId = ((JobActivity) activity).getJob().getId(); 74 | stateManager.putProblemState(StateFactory.createId(jobId), VehicleRoute.class, this.route); 75 | } 76 | 77 | } 78 | 79 | @Override 80 | public void finish() {} 81 | 82 | } 83 | 84 | static class TwentyOneBeforeThirteenConstraint implements SoftRouteConstraint { 85 | 86 | private StateManager stateManager; 87 | 88 | public TwentyOneBeforeThirteenConstraint(StateManager stateManager) { 89 | super(); 90 | this.stateManager = stateManager; 91 | } 92 | 93 | @Override 94 | public double getCosts(JobInsertionContext insertionContext) { 95 | if(insertionContext.getJob().getId().equals("21")){ 96 | VehicleRoute route = stateManager.getProblemState(StateFactory.createId("13"), VehicleRoute.class); 97 | if(route==null){ 98 | return 0.; 99 | } 100 | if(route!=null){ 101 | if(route==insertionContext.getRoute()){ 102 | return -100.; 103 | } 104 | else return 0.; 105 | } 106 | } 107 | return 0; 108 | } 109 | } 110 | 111 | static class RewardAndPenaltiesThroughSoftConstraints { 112 | private VehicleRoutingProblem vrp; 113 | 114 | public RewardAndPenaltiesThroughSoftConstraints(VehicleRoutingProblem vrp) { 115 | super(); 116 | this.vrp = vrp; 117 | } 118 | 119 | public double getCosts(VehicleRoute route) { 120 | boolean serves13 = route.getTourActivities().servesJob(getJob("13")); 121 | boolean serves21 = route.getTourActivities().servesJob(getJob("21")); 122 | if(serves13 && serves21) { 123 | boolean first13 = false; 124 | for(TourActivity act : route.getActivities()){ 125 | if(act instanceof JobActivity){ 126 | if(((JobActivity) act).getJob().getId().equals("21") && !first13){ 127 | return -100; 128 | } 129 | if(((JobActivity) act).getJob().getId().equals("13")){ 130 | first13=true; 131 | } 132 | } 133 | } 134 | return 0.; 135 | } 136 | return 0; 137 | } 138 | 139 | private Job getJob(String string) { 140 | return vrp.getJobs().get(string); 141 | } 142 | 143 | } 144 | 145 | public static void main(String[] args) { 146 | 147 | VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); 148 | 149 | /* 150 | * A solomonReader reads solomon-instance files, and stores the required information in the builder. 151 | */ 152 | new VrpXMLReader(vrpBuilder).read("input/vrpnc1-jsprit.xml"); 153 | 154 | /* 155 | * Finally, the problem can be built. By default, transportCosts are crowFlyDistances (as usually used for vrp-instances). 156 | */ 157 | VehicleRoutingProblem vrp = vrpBuilder.build(); 158 | 159 | final StateManager stateManager = new StateManager(vrp.getTransportCosts()); 160 | stateManager.addStateUpdater(new JobsInRouteMemorizer(stateManager)); 161 | 162 | ConstraintManager constraintManager = new ConstraintManager(vrp,stateManager); 163 | constraintManager.addConstraint(new TwentyOneBeforeThirteenConstraint(stateManager)); 164 | 165 | // final SolutionCostCalculator basicCalculator = new VariablePlusFixedSolutionCostCalculatorFactory(stateManager).createCalculator(); 166 | final RewardAndPenaltiesThroughSoftConstraints contrib = new RewardAndPenaltiesThroughSoftConstraints(vrp); 167 | SolutionCostCalculator costCalculator = new SolutionCostCalculator() { 168 | 169 | @Override 170 | public double getCosts(VehicleRoutingProblemSolution solution) { 171 | double costs = 0.; 172 | for(VehicleRoute route : solution.getRoutes()){ 173 | costs+=route.getVehicle().getType().getVehicleCostParams().fix; 174 | costs+=stateManager.getRouteState(route, StateFactory.COSTS, Double.class); 175 | costs+=contrib.getCosts(route); 176 | } 177 | return costs; 178 | } 179 | 180 | }; 181 | 182 | VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(vrp, "input/rr_ta.xml"); 183 | vraBuilder.addCoreConstraints(); 184 | vraBuilder.setStateAndConstraintManager(stateManager, constraintManager); 185 | vraBuilder.addDefaultCostCalculators(); 186 | vraBuilder.setObjectiveFunction(costCalculator); 187 | VehicleRoutingAlgorithm vra = vraBuilder.build(); 188 | 189 | vra.addListener(new AlgorithmSearchProgressChartListener("output/search")); 190 | 191 | // 192 | Collection solutions = vra.searchSolutions(); 193 | 194 | SolutionPrinter.print(vrp, Solutions.bestOf(solutions), Print.VERBOSE); 195 | 196 | new Plotter(vrp,Solutions.bestOf(solutions)).setLabel(Label.ID).plot("output/jsprit_vrpnc1_21_first", "jsprit: 21 first"); 197 | } 198 | 199 | } 200 | -------------------------------------------------------------------------------- /src/stackoverflow/Stackoverflow_RelatedJobs_CapacityConstraints.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2013 Stefan Schroeder 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 3.0 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library. If not, see . 16 | ******************************************************************************/ 17 | 18 | package stackoverflow; 19 | 20 | import java.util.Collection; 21 | 22 | import jsprit.analysis.toolbox.AlgorithmSearchProgressChartListener; 23 | import jsprit.analysis.toolbox.Plotter; 24 | import jsprit.analysis.toolbox.Plotter.Label; 25 | import jsprit.core.algorithm.VehicleRoutingAlgorithm; 26 | import jsprit.core.algorithm.VehicleRoutingAlgorithmBuilder; 27 | import jsprit.core.algorithm.state.StateManager; 28 | import jsprit.core.problem.VehicleRoutingProblem; 29 | import jsprit.core.problem.constraint.ConstraintManager; 30 | import jsprit.core.problem.io.VrpXMLReader; 31 | import jsprit.core.problem.solution.VehicleRoutingProblemSolution; 32 | import jsprit.core.reporting.SolutionPrinter; 33 | import jsprit.core.reporting.SolutionPrinter.Print; 34 | import jsprit.core.util.Solutions; 35 | 36 | /** 37 | * http://stackoverflow.com/questions/24447451/related-jobs-in-jsprit 38 | * 39 | * @author schroeder 40 | * 41 | */ 42 | public class Stackoverflow_RelatedJobs_CapacityConstraints { 43 | 44 | 45 | public static void main(String[] args) { 46 | 47 | VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); 48 | 49 | /* 50 | * A solomonReader reads solomon-instance files, and stores the required information in the builder. 51 | */ 52 | new VrpXMLReader(vrpBuilder).read("input/vrpnc1-jsprit.xml"); 53 | 54 | /* 55 | * Finally, the problem can be built. By default, transportCosts are crowFlyDistances (as usually used for vrp-instances). 56 | */ 57 | VehicleRoutingProblem vrp = vrpBuilder.build(); 58 | 59 | final StateManager stateManager = new StateManager(vrp.getTransportCosts()); 60 | 61 | ConstraintManager constraintManager = new ConstraintManager(vrp,stateManager); 62 | 63 | VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(vrp, "input/rr_ta.xml"); 64 | vraBuilder.addCoreConstraints(); 65 | vraBuilder.setStateAndConstraintManager(stateManager, constraintManager); 66 | vraBuilder.addDefaultCostCalculators(); 67 | VehicleRoutingAlgorithm vra = vraBuilder.build(); 68 | 69 | vra.addListener(new AlgorithmSearchProgressChartListener("output/search")); 70 | 71 | // 72 | Collection solutions = vra.searchSolutions(); 73 | 74 | SolutionPrinter.print(vrp, Solutions.bestOf(solutions), Print.VERBOSE); 75 | 76 | new Plotter(vrp,Solutions.bestOf(solutions)).setLabel(Label.ID).plot("output/jsprit_vrpnc1_capConstraints", "jsprit: capacityConstraints"); 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /src/stackoverflow/Stackoverflow_RelatedJobs_noConstraints.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2013 Stefan Schroeder 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 3.0 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library. If not, see . 16 | ******************************************************************************/ 17 | 18 | package stackoverflow; 19 | 20 | import java.util.Collection; 21 | 22 | import jsprit.analysis.toolbox.AlgorithmSearchProgressChartListener; 23 | import jsprit.analysis.toolbox.Plotter; 24 | import jsprit.analysis.toolbox.Plotter.Label; 25 | import jsprit.core.algorithm.VehicleRoutingAlgorithm; 26 | import jsprit.core.algorithm.VehicleRoutingAlgorithmBuilder; 27 | import jsprit.core.algorithm.state.StateManager; 28 | import jsprit.core.problem.VehicleRoutingProblem; 29 | import jsprit.core.problem.constraint.ConstraintManager; 30 | import jsprit.core.problem.io.VrpXMLReader; 31 | import jsprit.core.problem.solution.VehicleRoutingProblemSolution; 32 | import jsprit.core.reporting.SolutionPrinter; 33 | import jsprit.core.reporting.SolutionPrinter.Print; 34 | import jsprit.core.util.Solutions; 35 | 36 | /** 37 | * http://stackoverflow.com/questions/24447451/related-jobs-in-jsprit 38 | * 39 | * @author schroeder 40 | * 41 | */ 42 | public class Stackoverflow_RelatedJobs_noConstraints { 43 | 44 | 45 | public static void main(String[] args) { 46 | 47 | VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); 48 | 49 | /* 50 | * A solomonReader reads solomon-instance files, and stores the required information in the builder. 51 | */ 52 | new VrpXMLReader(vrpBuilder).read("input/stackoverflow/vrpnc1-jsprit.xml"); 53 | 54 | /* 55 | * Finally, the problem can be built. By default, transportCosts are crowFlyDistances (as usually used for vrp-instances). 56 | */ 57 | VehicleRoutingProblem vrp = vrpBuilder.build(); 58 | 59 | final StateManager stateManager = new StateManager(vrp.getTransportCosts()); 60 | 61 | ConstraintManager constraintManager = new ConstraintManager(vrp,stateManager); 62 | 63 | VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(vrp, "input/stackoverflow/rr_ta.xml"); 64 | vraBuilder.setStateAndConstraintManager(stateManager, constraintManager); 65 | vraBuilder.addDefaultCostCalculators(); 66 | VehicleRoutingAlgorithm vra = vraBuilder.build(); 67 | 68 | vra.addListener(new AlgorithmSearchProgressChartListener("output/search")); 69 | 70 | // 71 | Collection solutions = vra.searchSolutions(); 72 | 73 | SolutionPrinter.print(vrp, Solutions.bestOf(solutions), Print.VERBOSE); 74 | 75 | new Plotter(vrp,Solutions.bestOf(solutions)).setLabel(Label.ID).plot("output/jsprit_vrpnc1_noConstraints", "jsprit: noConstraints"); 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /stackoverflow/jsprit_vrpnc1_13_21_inSameRoute.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jsprit/playground/e42858e70a42c4614ae55a5baff87e654a8cde4b/stackoverflow/jsprit_vrpnc1_13_21_inSameRoute.png -------------------------------------------------------------------------------- /stackoverflow/jsprit_vrpnc1_13_rightAfter_21.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jsprit/playground/e42858e70a42c4614ae55a5baff87e654a8cde4b/stackoverflow/jsprit_vrpnc1_13_rightAfter_21.png -------------------------------------------------------------------------------- /stackoverflow/jsprit_vrpnc1_21_first.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jsprit/playground/e42858e70a42c4614ae55a5baff87e654a8cde4b/stackoverflow/jsprit_vrpnc1_21_first.png -------------------------------------------------------------------------------- /stackoverflow/jsprit_vrpnc1_capConstraints.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jsprit/playground/e42858e70a42c4614ae55a5baff87e654a8cde4b/stackoverflow/jsprit_vrpnc1_capConstraints.png -------------------------------------------------------------------------------- /stackoverflow/jsprit_vrpnc1_noConstraints.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jsprit/playground/e42858e70a42c4614ae55a5baff87e654a8cde4b/stackoverflow/jsprit_vrpnc1_noConstraints.png -------------------------------------------------------------------------------- /test/sschroeder/TestTimeWindowConstraintWithDriver.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2013 Stefan Schroeder 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 3.0 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library. If not, see . 16 | ******************************************************************************/ 17 | package sschroeder; 18 | 19 | import static org.mockito.Mockito.mock; 20 | import static org.mockito.Mockito.when; 21 | import static org.junit.Assert.assertEquals; 22 | 23 | import jsprit.core.algorithm.state.StateManager; 24 | import jsprit.core.problem.constraint.HardActivityStateLevelConstraint.ConstraintsStatus; 25 | import jsprit.core.problem.cost.VehicleRoutingTransportCosts; 26 | import jsprit.core.problem.driver.Driver; 27 | import jsprit.core.problem.job.Job; 28 | import jsprit.core.problem.misc.JobInsertionContext; 29 | import jsprit.core.problem.solution.route.VehicleRoute; 30 | import jsprit.core.problem.solution.route.activity.TourActivity; 31 | import jsprit.core.problem.vehicle.Vehicle; 32 | import jsprit.core.util.Coordinate; 33 | import jsprit.core.util.CrowFlyCosts; 34 | import jsprit.core.util.Locations; 35 | 36 | import org.junit.Before; 37 | import org.junit.Test; 38 | 39 | public class TestTimeWindowConstraintWithDriver { 40 | 41 | VehicleRoute route; 42 | 43 | Job job; 44 | 45 | Driver newDriver; 46 | 47 | VehicleRoutingTransportCosts routingCosts; 48 | 49 | TourActivity prevAct; 50 | 51 | TourActivity nextAct; 52 | 53 | StateManager states; 54 | 55 | @Before 56 | public void doBefore(){ 57 | 58 | job = mock(Job.class); 59 | newDriver = mock(Driver.class); 60 | routingCosts = new CrowFlyCosts(new Locations(){ 61 | 62 | @Override 63 | public Coordinate getCoord(String id) { 64 | return Coordinate.newInstance(Double.valueOf(id.split(",")[0].trim()), Double.valueOf(id.split(",")[1].trim())); 65 | } 66 | 67 | }); 68 | prevAct = getMockedActivity("0,10",10.,20.); 69 | nextAct = getMockedActivity("0,20",0.,20.); 70 | states = new StateManager(routingCosts); 71 | states.putTypedActivityState(prevAct, StateIds.LATEST_ACTIVITY_START, Double.class, 20.); 72 | states.putTypedActivityState(nextAct, StateIds.LATEST_ACTIVITY_START, Double.class, 20.); 73 | 74 | } 75 | 76 | @Test 77 | public void whenNewActNeedsToBeServedBeforePrevAct_returnNotFulfilledBreak(){ 78 | Vehicle newVehicle = getMockedVehicle("0,0","0,0",0.,100.); 79 | JobInsertionContext iContext = getInsertionContext(newVehicle,0.); 80 | double maxDriverTime = 100; 81 | TimeWindowConstraintWithDriverTime c = new TimeWindowConstraintWithDriverTime(states, routingCosts, maxDriverTime); 82 | TourActivity newAct = getMockedActivity("0,10",0.,9.); 83 | 84 | assertEquals(ConstraintsStatus.NOT_FULFILLED_BREAK,c.fulfilled(iContext, prevAct, newAct, nextAct, 10.)); 85 | } 86 | 87 | @Test 88 | public void whenNewActNeedsToBeServedAfterNextAct_returnNotFulfilled(){ 89 | Vehicle newVehicle = getMockedVehicle("0,0","0,0",0.,100.); 90 | JobInsertionContext iContext = getInsertionContext(newVehicle,0.); 91 | double maxDriverTime = 100; 92 | TimeWindowConstraintWithDriverTime c = new TimeWindowConstraintWithDriverTime(states, routingCosts, maxDriverTime); 93 | TourActivity newAct = getMockedActivity("0,10",25.,30.); 94 | 95 | assertEquals(ConstraintsStatus.NOT_FULFILLED,c.fulfilled(iContext, prevAct, newAct, nextAct, 10.)); 96 | } 97 | 98 | @Test 99 | public void whenNewActNeedsToBeServedAfterLatestNextAct_returnNotFulfilled(){ 100 | Vehicle newVehicle = getMockedVehicle("0,0","0,0",0.,100.); 101 | JobInsertionContext iContext = getInsertionContext(newVehicle,0.); 102 | states.putTypedActivityState(nextAct, StateIds.LATEST_ACTIVITY_START, Double.class, 15.); 103 | double maxDriverTime = 100; 104 | TimeWindowConstraintWithDriverTime c = new TimeWindowConstraintWithDriverTime(states, routingCosts, maxDriverTime); 105 | TourActivity newAct = getMockedActivity("0,10",10.,15.); 106 | /* 107 | * arrTime@Next=20 > latestArrTime@Next=15 108 | */ 109 | assertEquals(ConstraintsStatus.NOT_FULFILLED,c.fulfilled(iContext, prevAct, newAct, nextAct, 10.)); 110 | } 111 | 112 | @Test 113 | public void whenVehicleArrTimeIsNotEnough_returnNotFulfilledBreak(){ 114 | Vehicle newVehicle = getMockedVehicle("0,0","0,0",0.,19.); 115 | JobInsertionContext iContext = getInsertionContext(newVehicle,0.); 116 | 117 | states.putTypedActivityState(prevAct, StateIds.LATEST_ACTIVITY_START, Double.class, 9.); 118 | states.putTypedActivityState(nextAct, StateIds.LATEST_ACTIVITY_START, Double.class, 19.); 119 | 120 | double maxDriverTime = 100; 121 | TimeWindowConstraintWithDriverTime c = new TimeWindowConstraintWithDriverTime(states, routingCosts, maxDriverTime); 122 | TourActivity newAct = getMockedActivity("0,10",10.,15.); 123 | 124 | assertEquals(ConstraintsStatus.NOT_FULFILLED_BREAK,c.fulfilled(iContext, prevAct, newAct, nextAct, 10.)); 125 | } 126 | 127 | @Test 128 | public void whenMaxDriverTimeIsNotEnough_returnNotFulfilledBreak(){ 129 | Vehicle newVehicle = getMockedVehicle("0,0","0,0",0.,100.); 130 | JobInsertionContext iContext = getInsertionContext(newVehicle,0.); 131 | 132 | states.putTypedActivityState(prevAct, StateIds.LATEST_ACTIVITY_START, Double.class, 9.); 133 | states.putTypedActivityState(nextAct, StateIds.LATEST_ACTIVITY_START, Double.class, 19.); 134 | 135 | double maxDriverTime = 19; 136 | TimeWindowConstraintWithDriverTime c = new TimeWindowConstraintWithDriverTime(states, routingCosts, maxDriverTime); 137 | TourActivity newAct = getMockedActivity("0,10",10.,15.); 138 | 139 | assertEquals(ConstraintsStatus.NOT_FULFILLED_BREAK,c.fulfilled(iContext, prevAct, newAct, nextAct, 10.)); 140 | } 141 | 142 | @Test 143 | public void whenMaxDriverTimeIsNotEnoughv2_returnNotFulfilledBreak(){ 144 | Vehicle newVehicle = getMockedVehicle("0,0","0,0",0.,100.); 145 | JobInsertionContext iContext = getInsertionContext(newVehicle,0.); 146 | 147 | states.putTypedActivityState(prevAct, StateIds.LATEST_ACTIVITY_START, Double.class, 10.); 148 | states.putTypedActivityState(nextAct, StateIds.LATEST_ACTIVITY_START, Double.class, 20.); 149 | 150 | double maxDriverTime = 30; 151 | TimeWindowConstraintWithDriverTime c = new TimeWindowConstraintWithDriverTime(states, routingCosts, maxDriverTime); 152 | TourActivity newAct = getMockedActivity("0,10",10.,15.); 153 | 154 | assertEquals(ConstraintsStatus.NOT_FULFILLED_BREAK,c.fulfilled(iContext, prevAct, newAct, nextAct, 10.)); 155 | } 156 | 157 | 158 | 159 | 160 | private JobInsertionContext getInsertionContext(Vehicle newVehicle, double newDepartureTime) { 161 | return new JobInsertionContext(route, job, newVehicle, newDriver, newDepartureTime); 162 | } 163 | 164 | private Vehicle getMockedVehicle(String startLoc, String endLoc, double earliestStart, double latestArr) { 165 | Vehicle vehicle = mock(Vehicle.class); 166 | when(vehicle.getStartLocationId()).thenReturn("0,0"); 167 | when(vehicle.getEndLocationId()).thenReturn("0,0"); 168 | when(vehicle.getEarliestDeparture()).thenReturn(earliestStart); 169 | when(vehicle.getLatestArrival()).thenReturn(latestArr); 170 | return vehicle; 171 | } 172 | 173 | public TourActivity getMockedActivity(String locationId, double earliestStart, double latestStart){ 174 | TourActivity act = mock(TourActivity.class); 175 | when(act.getLocationId()).thenReturn(locationId); 176 | when(act.getTheoreticalEarliestOperationStartTime()).thenReturn(earliestStart); 177 | when(act.getTheoreticalLatestOperationStartTime()).thenReturn(latestStart); 178 | return act; 179 | } 180 | 181 | } 182 | --------------------------------------------------------------------------------