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

After you have created a first solution by inserting the return visits and ordered visits from the submodel into the first solution, you create the neighborhoods you will use in the solution improvement phase. As in Chapter 3, Solving a Vehicle Routing Problem, you use the predefined neighborhoods IloRelocate, IloExchange, IloCross, IloTwoOpt, and IloOrOpt. Additionally, you use two other predefined neighborhoods: IloMakePerformed and IloMakeUnperformed. The function IloMakePerformed returns a neighborhood that modifies a solution by inserting an unperformed visit after a performed one. The function IloMakeUnperformed returns a neighborhood that modifies a solution by causing a performed visit to be unperformed. These neighborhoods are used to improve a solution by making return visits performed and unperformed.

For more information about how predefined neighborhoods work, see ïtò^ B Predefined Neighborhoods.

This code is provided for you:

void RoutingSolver::improveWithNhood() {
  IloNHood nhood = IloRelocate(_env)
                     + IloTwoOpt(_env)
                     + IloOrOpt(_env)
                     + IloCross(_env)
                     + IloExchange(_env)
                     + IloMakeUnperformed(_env)
                     + IloMakePerformed(_env);
  _solver.out() << "Improving solution" << endl;
  IloGoal improve = IloSingleMove(_env,
                                  _solution,
                                  nhood,
                                  IloImprove(_env),
                                  _instantiateCost);
  while (_solver.solve(improve)) {
  }
   _solver.solve(_restoreSolution);
}