IBM ILOG Dispatcher User's Manual > The Basics > Adding Visit Disjunctions > Solve > Define the addNewVisit function

Once new visits have been added to an existing routing plan using the function createAdditionalVisits, they can be inserted into the existing solution using the function addNewVisit. This function uses IloRoutingSolution::add to directly add the new visit to the solution. When it is added, its saved state is unperformed. To make the visit performed, you create a goal using IloInsertVisit, which eliminates the need to recompute the routing plan from scratch. If the visit cannot be inserted in the solution, the goal fails. If the visit is inserted, the new solution is stored.

Step 10   -  

Add a new visit

Add the following code after the comment //Add a new visit

IloBool RoutingSolver::addNewVisit (IloVisit visit) {
  IloGoal insert = IloInsertVisit(_env, visit, _solution, _instantiateCost);
  if (!_solver.solve(insert)) {
    _solver.out() << "Cannot insert new visit in solution" << endl;
    return IloFalse;
  }
  _solution.add(visit);
  _solution.store(_solver);
  return IloTrue;
}