| IBM ILOG Dispatcher User's Manual > The Basics > Minimizing the Number of Vehicles > Solve > Define the main function |
Define the main function |
INDEX
PREVIOUS
NEXT
|
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 Dispatcher finds a first solution, you print the information and then improve the solution. Then you close all empty vehicles. You use the function reduceActiveVehicles to search for the vehicle with the fewest number of visits and empty it. You try to find a new solution without using this vehicle. If you find a new solution, you improve it. After solution improvement, you empty the vehicle that now has the fewest number of visits. When you cannot empty any more vehicles and still find a solution, you have minimized the number of vehicles. This solution is then printed. The following code is provided for you:
Step 15 - | 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, the initial improved solution, and the solution found after reducing the number of active vehicles. The first solution uses 20 vehicles. The initial improved solution uses 17 vehicles. The solution found after reducing the number of active vehicles uses 16 vehicles.
The first solution phase finds a solution using 20 vehicles with a total cost of 2554.03 units:
The solution improvement phase finds a solution using 17 vehicles with a total cost of 2073.11 units-:
After solution improvement, vehicle 20 has the fewest number of visits. (See the section "Complete Output".) The reduceActiveVehicles function empties vehicle 20, assigns its visits to other vehicles, and improves the solution. Now, vehicle 7 has the fewest number of visits. The reduceActiveVehicles function empties vehicle 7, tries to assign its visits to other vehicles, but is not able to do so. The last solution found is restored. The solution after reducing active vehicles uses 16 vehicles with a total cost of 2072.93 units:
The complete program and output are listed in "Complete Program". You can also view it online in the YourDispatcherHome/examples/src/minvehcl.cpp file.
| © Copyright IBM Corp. 1987, 2009. Legal terms. | PREVIOUS NEXT |