IBM ILOG Dispatcher User's Manual > The Basics > Multiple Tours per Vehicle > Solve > Define the insertCustomerVisits function

You use the insertCustomerVisits function to add the ordered visits from _orderedVisitArray to the first solution in the multitour model. As you remember, you already added the return visits to the first solution in the section "Define the insertAllReturnVisits function".

Step 20   -  

Add the ordered customer visits to the model

Add the following code after the comment
//Add the ordered customer visits to the model

bool RoutingSolver::insertCustomerVisits () {
  _solver.out() << "Inserting customer visits" << endl;
  for (IloInt i = 0; i < _orderedVisitArray.getSize(); i++) {
    IloVisit visit = _orderedVisitArray[i];
    _mdl.add(visit);

You insert the visit directly into the first solution 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. If the visit can be inserted, you use the function IloRoutingSolution::add to directly add the visit to the solution. The new solution is then stored.

Step 21   -  

Insert the ordered customer visits into the first solution

Add the following code after the comment
//Insert the ordered customer visits into the first solution

      IloGoal insert =
          IloInsertVisit(_env, visit, vehicle, _solution, _instantiateCost);
      if (!_solver.solve(insert)) {
        _solver.out() << "Cannot insert new visit in solution" << endl;
        _mdl.remove(visit);
      }
      else {
        _solution.add(visit);
        _solution.store(_solver);
      }
    }
  }
}