IBM ILOG Solver User's Manual > More on Modeling > Using Set Variables: Crew Scheduling > Solve

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

Step 9   -  

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 predefined goal IloGenerate. You use a "for" loop to display the solution using the function Print.

Step 10   -  

Search for a solution

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

    if (solver.solve(IloGenerate(env, crews))){
      solver.out() << "Solution" << endl;
      for (IloInt j=0 ; j< crews.getSize() ; j++) {
        solver.out() << "Crew #" << (j+1) << ": " ;
        Print(solver, crews[j], Names);
      }
    }
    else
      solver.out() << "No solution" << endl;
    solver.printInformation();

You use the Print function to display the solution. You use an iterator to display the values in each set in the array of set variables crews. This code is provided for you:

void Print(IloSolver solver, IloNumSetVar crews, char** Names) {
  for(IloNumSet::Iterator iter(solver.getIntSetValue(crews));iter.ok();++iter){
    solver.out() << Names[(IloInt)*iter] << " ";
  }
  solver.out() << endl;
}

Step 11   -  

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:

Solution
Crew #1: Bill Bob Carol Cathy
Crew #2: Carolyn David Ed Fred Juliet
Crew #3: Heather Inez Janet Jeremy Joe
Crew #4: Bill Bob Carol Cathy Jean Marilyn
Crew #5: Carolyn David Ed Fred Juliet Mario Ron
Crew #6: Heather Inez Janet Jeremy
Crew #7: Bill Bob Carol Cathy Jean
Crew #8: Carolyn David Ed Fred Joe Juliet
Crew #9: Heather Inez Janet Jeremy Marilyn Mario
Crew #10: Bill Bob Carol Cathy Jean Ron Tom
Number of fails               : 8
Number of choice points       : 57
Number of variables           : 130
Number of constraints         : 232
Reversible stack (bytes)      : 20124
Solver heap (bytes)           : 112584
Solver global heap (bytes)    : 4044
And stack (bytes)             : 4044
Or stack (bytes)              : 4044
Search Stack (bytes)          : 4044
Constraint queue (bytes)      : 11152
Total memory used (bytes)     : 160036
Elapsed time since creation   : 0.09

As you can see, the crew members assigned to each flight are displayed. The complete program is listed in "Complete program". You can also view it online in the file YourSolverHome/examples/src/crews.cpp.