IBM ILOG Dispatcher User's Manual > Developing Dispatcher Applications > Developing Your Own Neighborhoods > Neighborhood Description > Creating the Solution Delta

You now create the structure representing the neighbor: the solution delta. This is done by creating an empty solution delta (an instance of IloSolution). You also create a routing solution rdelta from this delta, so that routing operations can be performed on delta. Note that the delta should not be created as an IloRoutingSolution as this also performs other operations, such as adding an objective to the routing solution, which is not appropriate here.

  IloSolution delta(getEnv());
  IloRoutingSolution rdelta(delta);
  rdelta.add(_here);
  rdelta.add(v);

You now perform the "swap." This is done in two stages. In the first stage, v is moved into the place of here, and in the second, here is moved into the former place of v. When you "insert" v into the place where here formerly was, you involve three visits: the visit preceding here in the current solution, the visit following here in the current solution, and v itself. The visit preceding here in the current solution will keep all its attributes in the delta, except that its following visit will be set to v, rather than here. A similar situation holds for the visit following here in the current solution. Most of the state of these visits is preserved in the delta. For this reason, their state is copied from the current solution. Then, the vehicle, previous visit, and next visit of v are set. The action of setting the next and previous visits of v also correctly sets the next and previous visits of the connected visits, so that consistency of the solution is maintained, and no explicit action is required for those visits. In the case where here is not performed, the "insertion" simply makes v unperformed.

  if (_perfHere) {
    rdelta.setVehicle(v, _vehHere);
    rdelta.add(_nextHere); delta.copy(_nextHere, _rsolution);
    rdelta.add(_prevHere); delta.copy(_prevHere, _rsolution);
    rdelta.setNext(v, _nextHere);
    rdelta.setPrev(v, _prevHere);
  }
  else
    rdelta.setUnperformed(v);

The symmetric "insertion" is almost identical. The only difference is that the current preceding and following visits, as well as the vehicle serving v, need to be retrieved from the current solution first.

  if (perfV) {
    rdelta.setVehicle(_here, _rsolution.getVehicle(v));
    IloVisit nextV = _rsolution.getNext(v);
    IloVisit prevV = _rsolution.getPrev(v);
    rdelta.add(nextV); delta.copy(nextV, _rsolution);
    rdelta.add(prevV); delta.copy(prevV, _rsolution);
    rdelta.setNext(_here, nextV);
    rdelta.setPrev(_here, prevV);
  }
  else
    rdelta.setUnperformed(_here);

Finally, the delta is returned, which concludes the definition of the LocalizedExchangeI class.

  return delta;
}