IBM ILOG Solver User's Manual > Local Search > Combining Complete and Local Search: Locating Warehouses > Solve > Use complete search for optimization

If the option to use complete search has been selected, we first set the upper bound for the search. If local search has been run first, the best objective value obtained in local search is used as the upper bound. Thus, local search provides a method for pruning the search tree used by the complete search method.

We create a standard optimization goal to solve the problem. If local search has not been performed, we extract the model for the solver. We also add code to output information about how the solution is found:

    if (proof) {
      cost.setUb(upperBound - 1);
      g = IloGenerate(env, open) &&
          generateOffer &&
          IloStoreSolution(env, whole);
      g = IloSelectSearch(env, g, IloMinimizeVar(env, cost, 1));
  
      // Optimization loop
      if (!local) solver.extract(m);
      if (solver.solve(g)) {
        solver.out() << "Complete search found solution of cost "
                     << solver.getValue(cost) << endl;
        solver.out() << solver.getIntVarArray(offer) << endl;
        if (local) {
          solver.out() << "Better solution found by complete search" << endl;
          solver.out() << "Local search was "
                       << 100.0 * (upperBound / whole.getObjectiveValue() - 1)
                       << "% above optimal" << endl;
        }
      }
      else {
        if (local) solver.out() << "No better solution found" << endl;
        else       solver.out() << "No solution" << endl;
      }
    }

After the search is complete, the best solution is restored and displayed.