IBM ILOG Solver User's Manual > The Basics > Using Objectives: Map Coloring with Minimum Colors > Solve |
Solve |
INDEX
![]() |
Solving the problem consists of finding a value for each variable that satisfies the constraints and maximizes the objective containing the relaxed constraints.
Step 7 - | Create an instance of IloSolver |
Add the following code after the comment //Create an instance of IloSolver
IloSolver solver(model); |
You now use the member function IloSolver::solve
, which solves a problem by using a default goal to launch the search.
Step 8 - | Search for a solution |
Add the following code after the comment //Search for a solution
if (solver.solve()) |
You use the member functions and streams IloAlgorithm::getStatus
, IloSolver::getValue
, and the function print
to display the solution. These are already provided for you in the exercise code.
Step 9 - | Compile and run the program |
Compile and run the program. You should get the following results:
Optimal Solution Objective = 9611 Belgium: white Denmark: blue France: blue Germany: yellow Netherlands: blue Luxembourg: blue |
As you can see, only three colors are used. The "unrelaxed" constraints are all satisfied. The objective is maximized. The relaxed constraint Luxembourg != Germany
is satisfied. This adds 9043 to the expression. The relaxed constraint Luxembourg != Belgium
is also satisfied. This adds 568 to the expression. This gives a value of 9611 to the objective. The only way that the value of this objective expression could be greater would be if the relaxed constraint Luxembourg != France
were also satisfied. However, this is not a possible solution since it would mean that "unrelaxed" constraints would not be satisfied.
The complete program is listed in "Complete program". You can also view it online in the file YourSolverHome/examples/src/colormin.cpp
.
© Copyright IBM Corp. 1987, 2009. Legal terms. | PREVIOUS NEXT |