IBM ILOG Dispatcher User's Manual > Transportation Industry Solutions > Pickup and Delivery by Multiple Vehicles from Multiple Depots > Solve > Define the RoutingSolver::findFirstSolution function

The function findFirstSolution searches for a solution using the goals _fsGoal and _instantiateCost. If successful, the solution is stored. If no first solution is found, the program reports that it was unsuccessful in finding a first solution. All other parts of the program remain unchanged. The following code is provided for you:

IloBool RoutingSolver::findFirstSolution() {
  if (!_solver.solve(_fsGoal && _instantiateCost)) {
    _solver.error() << "Infeasible Routing Plan" << endl;
    return IloFalse;
  }
  _solution.store(_solver);
  _solver.out() << "First solution with cost: "
                << _solution.getObjectiveValue()
                << endl;
  return IloTrue;
}

You do not need one solution per depot. One solution to the whole problem is sufficient. You will simply extract the part of it that you wish to work on. This is possible for two reasons. First, operations such as store and restore on solutions ignore parts of the solution that are not extracted. Therefore, a solution can cover more variables than have been extracted with no problems. Second, Dispatcher's neighborhoods (such as IloRelocate) ignore nonextracted parts of the solution and only generate neighbors for extracted parts. The result is that you can perform local search over an extracted part of the routing solution, while the remainder remains unchanged.

Note
There is one part of the solution that will always be extracted, regardless of the part of the solution being optimized: the objective. Thus, if you extract a submodel and restore the corresponding part of a routing solution, the stored value of the objective reflects only the cost of the submodel and not the whole solution. This is a situation where the cost value of a solution must be treated with care. The function syncSolution ensures that the cost value is consistent with that computed from the extracted model.