IBM ILOG Dispatcher User's Manual > Field Service Solutions > CARP: Visiting Arcs Using Multiple Vehicles > Solve |
Solve |
INDEX
![]() |
The solving section of this example introduces metaheuristics. In previous lessons, heuristics terminated when no cost-reducing move could be found at a local minimum. Metaheuristics allow the search to continue by allowing neighborhood moves that degrade the current solution and allow the search to move from the current position. This degradation must be carefully controlled, however, to prevent the search from moving to very poor solutions. This control is provided by various types of metaheuristics. The type used in this lesson is based on guided local search (GLS).
Guided local search works by making a series of greedy searches, each to a local minimum. However, it reduces a different cost function from the original. If the original cost function is represented by c, then guided local search attempts to reduce the cost c+wp, where p is a penalty term that is adjusted every time a local minimum is reached, and w is a constant. So, in essence, guided local search tries to minimize a combination of the true cost and a penalty term. The weighting constant w is an important search parameter that determines how important the penalty term is with respect to the true cost.
Guided local search is constructed so that the penalty term is higher when the search moves to solutions that resemble previous ones. This is done by recording certain arcs as "bad" each time a local minimum is reached. When these arcs appear in a solution, the penalty term is increased. Guided local search determines which arcs are bad based upon the cost of the arc in the solution and how often that arc has previously appeared at local minima.
More complete details of the use of metaheuristics can be found in ïtò^ C Predefined Search Heuristics and Metaheuristics and in the IBM ILOG Dispatcher Reference Manual.
The first step in the solving section is to create the RoutingSolver
function.
Step 10 - | Create the RoutingSolver function |
//Create the RoutingSolver function.
The function improveWithFastGLS
uses the metaheuristic IloDispatcherGLS
to get out of the local minimum solution to find a better one.
Two new functions appear in the class RoutingSolver
for this lesson: modifyFilterLevelAndRestore
and restoreSolution
.
Step 11 - | Modify filter level and restore solution |
Add the following code after the comment //Modify filter level and restore solution
.
This function changes the filter level of the propagation before restoring the solution. IlcMedium
is the highest level of propagation, and takes considerably longer than IlcLow
. This function is called to have better propagation of the cumul variables and to have a better display of the solution.
Step 12 - | Add the restoreSolution function |
void RoutingSolver::restoreSolution() { _solver.solve(_restoreSolution && _instantiateCost); _solution.store(_solver); _solver.out() << "Modified cost: " << _dispatcher.getTotalCost() << endl; } |
//Add the restoreSolution function.
This function is called by main
to restore the solution after modifyGraphArcCost
has been called to modify the original arc cost data.
The next function, improveWithFastGLS
, uses the metaheuristic IloDispatcherGLS
to get out of the local minimum solution to find a better one.
Step 13 - | Add the metaheuristic function |
//Add the metaheuristic function.
IloDispatcherGLS
tries to penalize "bad" arcs--arcs with a high cost. However, if an arc has been penalized a number of times, the importance of cost reduces. This is due to the fact that if an arc has been penalized a large number of times and is still in the solution, there may be no better arc with which to replace it and it is probably best to start looking elsewhere to place penalties.
The functions IloCouple
and IloDecouple
connect and disconnect a neighborhood to a metaheuristic. The neighborhood must be coupled to an instance of IloDispatcherGLS
, otherwise an exception is thrown.
Step 14 - | The display paths function |
Locate the following code after the comment //The display paths function.
The function displayPaths
is used to display the route of each vehicle following the actual paths on the road network. An instance of IloIterator<IloVehicle>
is used to iterate over the vehicles, and an instance of IloDispatcher::RouteIterator
is used to iterate over the visits of each vehicle. IloDispatcherGraph::PathIterator
is used to iterate over the nodes present on the shortest path between visits.
Finally, main
calls these functions.
Step 15 - | Add the main function |
Add the following code after the comment //Add the main function
.
Note that three sets of results are displayed: a set before and a set after the first modifyFilterLevelAndRestore
function is called to change the propagation to IlcMedium
, and one set after modifyGraphArcCost
is called, increasing the cost of certain arcs.
Step 16 - | Compile and run the program |
The complete program and output are presented in "Complete Program".
The first solution phase, before improveWithNHood(250)
and modifyFilterLevelAndRestore
have been called, finds a solution using 3 vehicles with a cost of 8100.14 units:
The first solution is improved with improveWithNHood(250)
and modifyFilterLevelAndRestore
:
Improving solution Improving with first-accept GLS --- Cost = 7781.68 Cost = 7712.67 Cost = 7616.17 Cost = 7592.99 --- |
The solution improvement phase continues lowering the cost until it finds a solution using 3 vehicles with a cost of 7413.03 units:
Now the problem is solved a second time. The cost is modified with modifyGraphArcCost
and then reoptimized with improveWithNHood(50)
. Note that the modified cost is large until the solution is improved.
Modified cost: 8311.26 Improving solution Improving with first-accept GLS --- Cost = 7506.89 Cost = 7482.83 --- |
This solution improvement phase continues lowering the cost until it finds a solution using 3 vehicles with a cost of 7459.55 units:
© Copyright IBM Corp. 1987, 2009. Legal terms. | PREVIOUS NEXT |