> Discrete Optimization > Cutting Stock: Column Generation > Solving the Problem: Using More than One Algorithm

This example does not solve the problem to optimality. It only generates a good feasible solution. It does so by first solving a linear relaxation of the problem. In other words, the decision variables Cut[j] are relaxed (not required to be integers). This linear relaxation of the problem then generates columns. While generating columns, the application keeps the variables generated so far, changes their type to integer, and resolves the problem.

As you've seen, this example effectively builds two models of the problem, cutOpt and patGen. Likewise, it uses two algorithms (that is, two instances of IloCplex) to arrive at a good feasible solution.

Here's how to create the first algorithm cutSolver and extract the initial model cutOpt:

    IloCplex cutSolver(cutOpt);

And here is how to create the second algorithm and extract patGen:

    IloCplex patSolver(patGen);

The heart of the example is here, in the column generation and optimization over current patterns:

    IloNumArray price(env, nWdth);
    IloNumArray newPatt(env, nWdth);

    for (;;) {
      /// OPTIMIZE OVER CURRENT PATTERNS ///

      cutSolver.solve();
      report1 (cutSolver, Cut, Fill);

      /// FIND AND ADD A NEW PATTERN ///

      for (i = 0; i < nWdth; i++)
        price[i] = -cutSolver.getDual(Fill[i]);
      ReducedCost.setCoef(Use, price);

      patSolver.solve();
      report2 (patSolver, Use, ReducedCost);

      if (patSolver.getValue(ReducedCost) > -RC_EPS) break;

      patSolver.getValues(newPatt, Use);
      Cut.add( IloNumVar(RollsUsed(1) + Fill(newPatt)) );
    }
    cutOpt.add(IloConversion(env, Cut, ILOINT));
    cutSolver.solve();

Those lines solve the current subproblem cutOpt by calling cutSolver.solve. Then they copy the values of the negative dual solution into the array price. They use that array to set objective coefficients in the model patGen. Then they solve the right pattern generation problem.

If the objective value exceeds the negation of the optimality tolerance (-RC_EPS), then the application has proved that the current solution of the model cutOpt is optimal within the given optimality tolerance (RC_EPS). Otherwise, the application copies the solution of the current pattern generation problem into the array newPatt and uses that new pattern to build the next column to add to the model cutOpt. Then it repeats the procedure.