IBM ILOG Solver User's Manual > More on Modeling > Using Table Constraints: Scheduling Teams > Solve

Now you create an instance of the class IloSolver to solve the problem expressed in the model.

Step 14   -  

Create an instance of IloSolver

Add the following code after the comment //Create an instance of IloSolver

      IloSolver solver(model);

Then you search for a solution using the member function IloSolver::solve. The solution is displayed using two nested for loops. For each period and week, the home team and the away team are displayed.

Step 15   -  

Search for a solution

Add the following code after the comment //Search for a solution

      if (solver.solve()) {
        cout << endl << "SOLUTION" << endl;
        for (p=0; p < nbPeriods; ++p) {
             cout << "period " << p << " : ";
               for (w=0; w < nbWeeks; ++w) {
               cout << solver.getValue(homeTeamVars[p][w]) << " vs "
                   << solver.getValue(awayTeamVars[p][w]) << " - " ;
             }
         cout << endl;
        }
        solver.printInformation();
          }
      else
        cout << "**** NO SOLUTION ****" << endl;

Step 16   -  

Compile and run the program

Compile and run the program. You should get the following results, though the information displayed by IloSolver::printInformation will vary depending on platform, machine, configuration, and so on:

%
* sports scheduling teams: 8 weeks: 7 periods: 4

SOLUTION
period 0 : 0 vs 1 - 0 vs 2 - 1 vs 2 - 3 vs 4 - 3 vs 5 - 4 vs 5 - 6 vs 7 -
period 1 : 2 vs 3 - 3 vs 6 - 4 vs 6 - 0 vs 7 - 0 vs 4 - 2 vs 7 - 1 vs 5 -
period 2 : 4 vs 7 - 5 vs 7 - 0 vs 5 - 1 vs 6 - 2 vs 6 - 1 vs 3 - 0 vs 3 -
period 3 : 5 vs 6 - 1 vs 4 - 3 vs 7 - 2 vs 5 - 1 vs 7 - 0 vs 6 - 2 vs 4 -
%

The first period (period 0) has the following schedule. In Week 1, Team 0 is home and Team 1 is away. In Week 2, Team 0 is home and Team 2 is away. In Week 3, Team 1 is home and Team 2 is away. In Week 4, Team 3 is home and Team 4 is away. In Week 5, Team 3 is home and Team 5 is away. In Week 6, Team 4 is home and Team 5 is away. In Week 7, Team 6 is home and Team 7 is away. You can follow the schedule for the other three periods.

The complete program is listed in "Complete program". You can also view it online in the file YourSolverHome/examples/src/sports_basic.cpp.