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

After you have found a first solution, you create the neighborhoods you will use in the solution improvement phase. You use the constructor IloNHoodArray to create an array of six neighborhoods called nhoodArray. Five of these neighborhoods are the predefined neighborhoods IloRelocate, IloExchange, IloCross, IloTwoOpt, and IloOrOpt. The neighborhood nhoodArray[2] is created using the function IloConcatenate to join together the array of swap neighborhoods you created in the section "Define the createVisits function". You also use the function IloConcatenate to join together all the neighborhoods in nHoodArray and create nhood.

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

Step 9   -  

Create the neighborhoods

Add the following code after the comment //Create the neighborhoods

void RoutingSolver::improveWithNhood(IloNHoodArray swap) {
  IloNHoodArray nhoodArray(_env, 6);
  nhoodArray[0] = IloTwoOpt(_env);
  nhoodArray[1] = IloOrOpt(_env);
  nhoodArray[2] = IloConcatenate(_env, swap);
  nhoodArray[3] = IloExchange(_env);
  nhoodArray[4] = IloRelocate(_env);
  nhoodArray[5] = IloCross(_env);
  IloNHood nhood = IloConcatenate(_env, nhoodArray);

The rest of the function is defined as in Chapter 3, Solving a Vehicle Routing Problem. You use the function IloSingleMove to return a goal that makes a single local move as defined by a neighborhood and a search heuristic. The following code is provided for you:

  _solver.out() << "Improving solution" << endl;
  IloGoal improve = IloSingleMove(_env,
                                  _solution,
                                  nhood,
                                  IloImprove(_env),
                                  _instantiateCost);
  while (_solver.solve(improve)) {
  }
  _solver.solve(_restoreSolution);
}