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 improve the solution. Then, you use the function createAdditionalVisits
to add a visit to the model and the function addNewVisit
to dynamically add the visit to the routing plan without recomputing the solution from scratch. You print this solution and then remove the visit. 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(mdl.getSwapArray());
solver.printInformation("***Solution after improvements with nhood***");
IloVisit visit = mdl.createAdditionalVisits (argc, argv);
if (solver.addNewVisit (visit)) {
solver.printInformation("***Solution including new visit***");
mdl.removeVisit(visit);
if (solver.removeVisitAndResolve (visit)) {
solver.printInformation("***Solution after removing visit***");
}
}
}
} catch(IloException& ex) {
cerr << "Error: " << ex << endl;
}
env.end();
return 0;
}
|
Step 12
-
|
Compile and run the program
|
Compile and run the program. You will get results that show the routing plan and information for the first solution and the improved solution. You will also get results that show how the solution changes when you add an additional visit and then remove it.
First solution information
The first solution phase finds a solution using 2 vehicles with a total cost of 1012.11 units:
***First Solution***
Number of fails : 245
Number of choice points : 1057
Number of variables : 2064
Number of constraints : 348
Reversible stack (bytes) : 156804
Solver heap (bytes) : 892720
Solver global heap (bytes) : 132324
And stack (bytes) : 20124
Or stack (bytes) : 44244
Search Stack (bytes) : 4044
Constraint queue (bytes) : 11160
Total memory used (bytes) : 1261420
Elapsed time since creation : 1.593
Number of nodes : 51
Number of visits : 70
Number of vehicles : 10
Number of dimensions : 3
Number of accepted moves : 0
===============
Cost : 1012.11
Number of vehicles used : 2
|
Improved Solution Information
The solution improvement phase finds a solution using 2 vehicles with a total cost of 716.945 units after making 24 cost-decreasing moves:
***Solution after improvements with nhood***
Number of fails : 0
Number of choice points : 0
Number of variables : 2064
Number of constraints : 344
Reversible stack (bytes) : 156804
Solver heap (bytes) : 892720
Solver global heap (bytes) : 148404
And stack (bytes) : 20124
Or stack (bytes) : 44244
Search Stack (bytes) : 4044
Constraint queue (bytes) : 11160
Total memory used (bytes) : 1277500
Elapsed time since creation : 0.01
Number of nodes : 51
Number of visits : 70
Number of vehicles : 10
Number of dimensions : 3
Number of accepted moves : 24
===============
Cost : 716.945
Number of vehicles used : 2
|
Solution information including new visit
After including a new visit, the total cost is now 763.538:
Number of fails : 1
Number of choice points : 1049
Number of variables : 2091
Number of constraints : 345
Reversible stack (bytes) : 156804
Solver heap (bytes) : 892720
Solver global heap (bytes) : 559036
And stack (bytes) : 20124
Or stack (bytes) : 44244
Search Stack (bytes) : 4044
Constraint queue (bytes) : 11160
Total memory used (bytes) : 1688132
Elapsed time since creation : 1.462
Number of nodes : 52
Number of visits : 71
Number of vehicles : 10
Number of dimensions : 3
Number of accepted moves : 24
===============
Cost : 763.538
Number of vehicles used : 2
|
Solution information after removing visit
After removing the visit, the routing plan again has a total cost of 716.945:
***Solution after removing visit***
Number of fails : 0
Number of choice points : 0
Number of variables : 2068
Number of constraints : 345
Reversible stack (bytes) : 156804
Solver heap (bytes) : 892720
Solver global heap (bytes) : 559036
And stack (bytes) : 20124
Or stack (bytes) : 44244
Search Stack (bytes) : 4044
Constraint queue (bytes) : 11160
Total memory used (bytes) : 1688132
Elapsed time since creation : 1.482
Number of nodes : 52
Number of visits : 70
Number of vehicles : 10
Number of dimensions : 3
Number of accepted moves : 24
===============
Cost : 716.945
Number of vehicles used : 2
|
The complete program and output are listed in "Complete Program". You can also view it online in the YourDispatcherHome/examples/src/disjunct.cpp
file.