IBM ILOG Solver User's Manual > More on Solving > Searching for Optimal Solutions: Replanning Warehouses > Storing solutions

In the previous section, you used the member function IloSolver::restartSearch to keep track of the best objective value found and to restart the search to find the one optimal solution again. Another way to find optimal solutions is to store them.

As discussed in the previous section, the minimization algorithm computes the best solution twice: it is first computed during a loop producing better and better solutions, and it is computed once more after that loop. In order to avoid this unnecessary computation, you can store intermediate solutions.

The process to do so is quite simple:

  1. Create an instance of IloSolution.
  2. Add the variables you want to store to the solution.
  3. Store the solution object.

Once a solution object is stored, you can restore the values contained within it by passing the function IloRestoreSolution to the solver.

For example, the following code uses stored solutions in an optimization procedure:

  IloSolver solver(model);
  solver.setOptimizationStep(0.1);

  IloSolution solution(env);
  solution.add(next);
  solution.add(length);

  solver.startNewSearch(IloGenerate(env,next) &&
                                      IloDichotomize(env,length) &&
                                      IloStoreSolution(env, solution));

  while (solver.next());
  solver.endSearch();

  solver.printInformation();

  solver.solve(IloRestoreSolution(env,solution));