IBM ILOG Solver User's Manual > More on Modeling > Using Set Variables: Crew Scheduling > Suggested answers > Exercise 3

Using the crews example as a starting point, extend the example to deal with a new crew requirement. Each flight crew must have at least one Italian speaker, except for Flight #4, which must have at least two Italian speakers. The following flight attendants speak Italian: Bob, Carol, Janet, Marilyn, and Tracy.

Suggested Answer

The code that has changed from crews.cpp follows. You can view the complete program online in the file YourSolverHome/examples/src/crews_ex3.cpp.

You change the number of attributes:

    const IloInt nAttributes = 6;

You create an array of Italian speakers:

    IloNumArray ItalianArray(env, 5, Bob, Carol, Janet, Marilyn, Tracy);

You add an element to dataArrays:

    dataArrays[5] = ItalianArray;

You create an Italian set of variables:

    IloNumSetVar Italian(env, ItalianArray, ItalianArray);

You add this set of variables to the array of sets of variables and add the requirement that a default flight has one Italian speaker:

    IloNumSetVarArray attributeSets(env, nAttributes, Senior, Junior,
                                    French, German, Spanish, Italian);

    enum CrewRequirementsElements {SeniorSet, JuniorSet, FrenchSet,
                                   GermanSet, SpanishSet, ItalianSet};

   IloArray<IloNumArray> crewRequirements(env, nCrews);
   for (i =0; i < nCrews; i++)
     crewRequirements[i] = IloNumArray(env, nAttributes,
                                       1, 1, 1, 1, 1, 1);


You add the requirements that Flight #4 have two Italian speakers:

     crewRequirements[3][ItalianSet] = 2;

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 Juliet Marilyn
Crew #3: Fred Heather Inez Janet Jeremy
Crew #4: Bill Bob Carol Cathy Jean Joe
Crew #5: Carolyn David Ed Juliet Marilyn Mario Ron
Crew #6: Fred Inez Janet Jeremy
Crew #7: Bill Bob Carol Cathy Heather
Crew #8: Carolyn David Ed Jean Juliet Marilyn
Crew #9: Fred Inez Janet Jeremy Joe Mario
Crew #10: Bill Bob Carol Cathy Heather Ron Tom
Number of fails               : 44
Number of choice points       : 94
Number of variables           : 152
Number of constraints         : 273
Reversible stack (bytes)      : 24144
Solver heap (bytes)           : 128664
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)     : 180136
Elapsed time since creation   : 0.07


Privacy Policy