IBM ILOG Dispatcher User's Manual > Transportation Industry Solutions > Pickup and Delivery by Multiple Vehicles from Multiple Depots > Solve > Define the main function

After you finish creating the Depot, RoutingModel, and RoutingSolver classes, 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 and parse the input files. You create the model for the whole problem with the member function RoutingModel::createModel. You create an instance of the RoutingSolver class. You find a first solution and then use iterative improvement to improve the depots and the routing plan. You synchronize the final solution and print this solution. The following code is provided for you:

int main(int argc, char* argv[]) {
  IloEnv env;
  try {
    RoutingModel routingModel(env);
    routingModel.parse(argc, argv);
    routingModel.createModel();

    RoutingSolver rsolver(routingModel);
    if ( rsolver.findFirstSolution() ) {
      IloBool improved = IloTrue;
      do {
        improved =
          rsolver.improveDepots() && rsolver.improvePlan();
      } while ( improved );
    }
    rsolver.syncSolution();
    rsolver.printInformation();
  } catch (IloException& ex) {
    env.out() << "Error: " << ex << endl;
  }
  env.end();
  return 0;
}

Step 18   -  

Compile and run the program

Compile and run the program. The first solution has a cost of 1397.52 units. After three improvement loops, the solution has a cost of 983.385 units. The solution uses 15 vehicles:

Number of fails               : 0
Number of choice points       : 0
Number of variables           : 7354
Number of constraints         : 1280
Reversible stack (bytes)      : 944724
Solver heap (bytes)           : 2509244
Solver global heap (bytes)    : 2446204
And stack (bytes)             : 20124
Or stack (bytes)              : 44244
Search Stack (bytes)          : 4044
Constraint queue (bytes)      : 20176
Total memory used (bytes)     : 5988760
Elapsed time since creation   : 0.461
Number of nodes               : 103
Number of visits              : 260
Number of vehicles            : 30
Number of dimensions          : 3
Number of accepted moves      : 141
===============
Cost         : 983.385
Number of vehicles used : 15
First solution with cost: 1397.52

Improvement loop
================
  Optimizing depot Depot 0 509.991 ---> 411.418
  Optimizing depot Depot 1 385.144 ---> 351.056
  Optimizing depot Depot 2 502.382 ---> 345.504
Optimizing plan 1107.98 ---> 1073.71

Improvement loop
================
  Optimizing depot Depot 0 412.393 ---> 391.898
  Optimizing depot Depot 1 325.838 ---> 323.948
  Optimizing depot Depot 2 335.482 ---> 310.54
Optimizing plan 1026.39 ---> 992.007

Improvement loop
================
  Optimizing depot Depot 0 385.09 ---> 378.142
  Optimizing depot Depot 1 323.948 ---> 323.948
  Optimizing depot Depot 2 282.968 ---> 281.295
  Optimizing plan 983.385 ---> 983.385

The complete program and output are listed in "Complete Program". You can also view it online in the YourDispatcherHome/examples/src/mdpdp.cpp file.