IBM ILOG Solver User's Manual > More on Solving > Searching for Optimal Solutions: Replanning Warehouses > Multiphase search: Replanning warehouses

In Chapter 13, Controlling the Search: Locating Warehouses, you learned how to model and solve a locating warehouses problem. In this chapter, you will model this same problem using multiphase search and stored solutions. The problem is modeled the same as in Chapter 15, Searching for Optimal Solutions: Replanning Warehouses.

First, you fix the suppliers of the first four stores by creating a solution object for the variables you do not want to change:

    IloSolution solution(env);
    solution.add(supplier[0]);
    solution.add(supplier[1]);
    solution.add(supplier[2]);
    solution.add(supplier[3]); // we fix the suppliers of the first 4 stores

Next, you search for a solution to the whole problem using searchGoal and the stored solution solution:

    if (solver.solve(searchGoal && IloStoreSolution(env, solution)))

This initial solution is displayed:

      {
        solver.out() << "------------------------------" << endl;
        solver.out() << "Initial Solution:  " << endl;
        for (i = 0; i < nStores; i ++)
          solver.out() << "Store  " << i << " " << "Warehouse:  "
                       << Suppliers[(IloInt)solver.getValue(supplier[i])]
                       << " " << endl;
        solver.out() << endl;
        for (j = 0; j < nStores ; j ++)
          solver.out() << "Store  " << j << " " << "Cost:  "
                       << solver.getValue(cost[j]) << " " << endl;
        solver.out() << endl;
        solver.out() << "Total cost:  " << solver.getValue(totalCost)
                     << endl;
        solver.out() << solution << endl;
        solver.out() << "------------------------------" << endl;

You add an objective to minimize totalCost and search for an optimal solution using the restored solution:

        model.add(IloMinimize(env, totalCost));
        solver.solve(IloRestoreSolution(env, solution) && searchGoal);

Finally, you display the optimal solution:

        solver.out() << "------------------------------" << endl;
        solver.out() << "Final Solution:  " << endl;
        for (i = 0; i < nStores; i ++)
          solver.out() << "Store  " << i << " " << "Warehouse:  "
                       << Suppliers[(IloInt)solver.getValue(supplier[i])]
                       << " " << endl;
        solver.out() << endl;
        for (j = 0; j < nStores ; j ++)
          solver.out() << "Store  " << j << " " << "Cost:  "
                       << solver.getValue(cost[j]) << " " << endl;
        solver.out() << endl;
        solver.out() << "Total cost:  " << solver.getValue(totalCost)
                     << endl;
        solver.out() << "------------------------------" << endl;

      }
    else {
      solver.out() << "No solution" << endl;
    }
    solver.printInformation();

You can view the complete program online in the file YourSolverHome/examples/src/replan_store.cpp.