After you finish creating the RoutingModel
and RoutingSolver
classes and the printInformation
function, you use them in the main
function. You can use command line syntax to pass the names of input files to the model. If you do not specify input files, the defaults will be used. In the main
function, you first create an environment. Then you create an instance of the RoutingModel
class, which takes the environment and input files as parameters. You create an instance of the RoutingSolver
class. This takes one parameter, the model. You use an if
loop to find a solution. If Solver finds a first solution, you print the information and then improve the solution. When Solver finds a solution that cannot be improved any further by the first accept search heuristic, Solver prints that solution. The following code is provided for you:
int main(int argc, char * argv[]) {
IloEnv env;
try {
RoutingModel mdl(env, argc, argv);
RoutingSolver solver(mdl);
if (solver.findFirstSolution()) {
solver.printInformation("***First Solution***");
solver.improveWithNhood();
solver.printInformation("***Improved Solution***");
}
} catch(IloException& ex) {
cerr << "Error: " << ex << endl;
}
env.end();
return 0;
}
|
Step 10
-
|
Compile and run the program
|
Compile and run the program. You will get results that show the routing plan and information for both the first solution and the improved solution. The first solution has a cost of 417.834 units. The improved solution has a cost of 366.447 units. During the improvement phase, Dispatcher made 11 moves and lowered the cost of the routing plan by 51.387 units. Both routing plans use four vehicles.
First Solution Information
The first solution phase finds a solution with a total cost of 417.834 units:
***First Solution***
Number of fails : 76
Number of choice points : 1051
Number of variables : 869
Number of constraints : 153
Reversible stack (bytes) : 92484
Solver heap (bytes) : 478660
Solver global heap (bytes) : 50860
And stack (bytes) : 20124
Or stack (bytes) : 44244
Search Stack (bytes) : 4044
Constraint queue (bytes) : 11160
Total memory used (bytes) : 701576
Elapsed time since creation : 0.06
Number of nodes : 21
Number of visits : 30
Number of vehicles : 5
Number of dimensions : 3
Number of accepted moves : 0
===============
Cost : 417.834
Number of vehicles used : 4
|
Improved Solution Information
The solution improvement phase finds a solution with a total cost of 366.447 units after making 11 cost-decreasing moves:
Improving solution
***Improved Solution***
Number of fails : 0
Number of choice points : 0
Number of variables : 869
Number of constraints : 149
Reversible stack (bytes) : 92484
Solver heap (bytes) : 478660
Solver global heap (bytes) : 62920
And stack (bytes) : 20124
Or stack (bytes) : 44244
Search Stack (bytes) : 4044
Constraint queue (bytes) : 11160
Total memory used (bytes) : 713636
Elapsed time since creation : 0
Number of nodes : 21
Number of visits : 30
Number of vehicles : 5
Number of dimensions : 3
Number of accepted moves : 11
===============
Cost : 366.447
Number of vehicles used : 4
|
First Solution Routing Plan
During the first solution phase, Dispatcher found the following routing plan using four vehicles:
Solution :
Unperformed visits : None
vehicle1 :
-> depot weight[0] time[0..2.76114] distance[0..Inf) -> visit18 weight[0..87]
time[15.8114..18.5725] distance[15.8114..Inf) -> visit7 weight[12..99]
time[35.8114..38.5725] distance[25.8114..Inf) -> visit19 weight[17..104]
time[56.9917..59.7529] distance[36.9917..Inf) -> visit11 weight[34..121]
time[74.0628..76.8239] distance[44.0628..Inf) -> visit10 weight[46..133]
time[95.2431..98.0043] distance[55.2431..Inf) -> visit20 weight[62..149]
time[121.055..123.816] distance[71.0545..Inf) -> visit3 weight[71..158]
time[153.415..156.176] distance[93.4152..Inf) -> visit12 weight[84..171]
time[174.596..177.357] distance[104.596..Inf) -> visit1 weight[103..190]
time[201.239..204] distance[121.239..Inf) -> depot weight[113..200]
time[226.47..230] distance[136.47..Inf)
vehicle2 :
-> depot weight[0] time[0..49.4126] distance[0..Inf) -> visit6 weight[0..114]
time[11.1803..60.5929] distance[11.1803..Inf) -> visit5 weight[3..117]
time[31.1803..80.5929] distance[21.1803..Inf) -> visit8 weight[29..143]
time[95..104.521] distance[35.1087..Inf) -> visit17 weight[38..152]
time[118.928..128.45] distance[49.0371..Inf) -> visit16 weight[40..154]
time[140.109..149.63] distance[60.2175..Inf) -> visit14 weight[59..173]
time[161.289..170.81] distance[71.3978..Inf) -> visit2 weight[79..193]
time[192.479..202] distance[92.5874..Inf) -> depot weight[86..200]
time[220.479..230] distance[110.587..Inf)
vehicle3 :
-> depot weight[0] time[0..40.5862] distance[0..Inf) -> visit15 weight[0..173]
time[61..71] distance[30.4138..Inf) -> visit4 weight[8..181] time[149..159]
distance[59.5686..Inf) -> depot weight[27..200] time[184..230]
distance[84.5686..Inf)
vehicle4 :
-> depot weight[0] time[0..74.9844] distance[0..Inf) -> visit9 weight[0..161]
time[97..107] distance[32.0156..Inf) -> visit13 weight[16..177] time[159..169]
distance[75.0272..Inf) -> depot weight[39..200] time[180.18..230]
distance[86.2076..Inf)
vehicle5 : Unused
|
Here is how to interpret this program output:
vehicle1 :
-> depot weight[0] time[0..2.76114] distance[0..Inf) -> visit18 weight[0..87] time[15.8114..18.5725] distance[15.8114..Inf)
indicates that the truck (vehicle1
) leaves the depot at 0 time units. At this point, the truck has traveled 0 distance units and delivered 0 weight units. Next, the truck arrives at customer 18, not earlier than 15.8114 time units, and not later than 18.5725 time units. At this point, the truck has traveled at least 15.8114 distance units. The weight delivered at this point is still 0 weight units. Remember that weight is delivered after arrival.
Improved Solution Routing Plan
During the solution improvement phase, Dispatcher found the following routing plan:
Solution :
Unperformed visits : None
vehicle1 :
-> depot weight[0] time[0..25.8217] distance[0..Inf) -> visit10 weight[0..112]
time[25.4951..51.3168] distance[25.4951..Inf) -> visit11 weight[16..128]
time[67..72.4972] distance[36.6754..Inf) -> visit19 weight[28..140]
time[84.0711..89.5683] distance[43.7465..Inf) -> visit7 weight[45..157]
time[105.251..110.749] distance[54.9268..Inf) -> visit18 weight[50..162]
time[125.251..130.749] distance[64.9268..Inf) -> visit6 weight[62..174]
time[146.432..151.929] distance[76.1072..Inf) -> visit13 weight[65..177]
time[163.503..169] distance[83.1783..Inf) -> depot weight[88..200]
time[184.683..230] distance[94.3586..Inf)
vehicle2 :
-> depot weight[0] time[0..60.4561] distance[0..Inf) -> visit5 weight[0..124]
time[20.6155..81.0716] distance[20.6155..Inf) -> visit8 weight[26..150]
time[95..105] distance[34.5439..Inf) -> visit17 weight[35..159]
time[118.928..144.639] distance[48.4723..Inf) -> visit16 weight[37..161]
time[140.109..165.82] distance[59.6526..Inf) -> visit14 weight[56..180]
time[161.289..187] distance[70.833..Inf) -> depot weight[76..200]
time[203.305..230] distance[102.849..Inf)
vehicle3 :
-> depot weight[0] time[0..30] distance[0..Inf) -> visit2 weight[0..166]
time[18..48] distance[18..Inf) -> visit15 weight[7..173] time[61..71]
distance[31..Inf) -> visit4 weight[15..181] time[149..159]
distance[60.1548..Inf) -> depot weight[34..200] time[184..230]
distance[85.1548..Inf)
vehicle4 :
-> depot weight[0] time[0..45.8197] distance[0..Inf) -> visit12 weight[0..133]
time[15..60.8197] distance[15..Inf) -> visit3 weight[19..152] time[36.1803..82]
distance[26.1803..Inf) -> visit9 weight[32..165] time[97..107]
distance[41.1803..Inf) -> visit20 weight[48..181] time[118.18..177.508]
distance[52.3607..Inf) -> visit1 weight[57..190] time[144.673..204]
distance[68.8531..Inf) -> depot weight[67..200] time[169.904..230]
distance[84.0846..Inf)
vehicle5 : Unused
|
As you can see, the improved solution still uses four vehicles, but with a lower cost. This solution also better balances the visits between the trucks. In the first solution routing plan, vehicle 1 makes nine visits, vehicle 2 makes six visits, and vehicles 3 and 4 each make two visits. In the improved solution routing plan, vehicle 1 makes seven visits, vehicles 2 and 4 each make five visits, and vehicle 3 makes three visits.
The complete program and output are listed in "Complete Program". You can also view it online in the YourDispatcherHome/examples/src/vrp.cpp
file.