IBM ILOG Dispatcher User's Manual > The Basics > Multiple Tours per Vehicle > Solve > Define the insertAllReturnVisits function |
Define the insertAllReturnVisits function |
INDEX
![]() |
Next, you define the insertAllReturnVisits
function which does the following:
You loop on each vehicle and create two return visits to the depot for each vehicle. This allows each vehicle to perform three tours. During the solution improvement phase, the number of tours can be rebalanced between vehicles.
Step 8 - | Create the return visits |
Add the following code after the comment //Create the return visits
Now, you use IloVisit::setPenaltyCost
to set a negative penalty cost on the return visit. By default, the penalty cost for not performing a visit is IloInfinity
, which forces the visit to be performed. If the return visit is performed, there is no additional cost added to the solution. If the return visit is not performed, then there is a small negative penalty cost. This makes not performing the return visit a slightly more favorable decision than performing the return visit, since you are minimizing the total cost. However, the negative penalty is so small that not performing the visit does not greatly affect the overall cost of the solution.
Step 9 - | Set the return visit negative penalty cost |
Add the following code after the comment //Set the return visit negative penalty cost
visit.setPenaltyCost(-0.1);
Next, you add the return visit to the model using IloModel::add
.
Step 10 - | Add the return visit to the model |
Add the following code after the comment //Add the return visit to the model
_mdl.add (visit);
You insert the return visit directly into the route of the vehicle by creating a goal using IloInsertVisit
. This function makes visit
performed without the need to recompute the routing plan from scratch. If the visit cannot be inserted, the goal fails and the visit is removed from the model. If the visit is inserted in the vehicle route, you use the function IloRoutingSolution::add
to directly add the return visit to the solution. The new solution is then stored.
Step 11 - | Insert the return visits into the first solution |
Add the following code after the comment //Insert the return visits into the first solution
© Copyright IBM Corp. 1987, 2009. Legal terms. | PREVIOUS NEXT |