IBM ILOG Solver User's Manual > The Basics > Using Objectives: Map Coloring with Minimum Colors > Solve

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.

      {
      solver.out() << solver.getStatus() << " Solution" << endl;
      solver.out() << "Objective = " << solver.getValue(obj) << endl;
      print(solver, "Belgium:     ", Belgium);
      print(solver, "Denmark:     ", Denmark);
      print(solver, "France:      ", France);
      print(solver, "Germany:     ", Germany);
      print(solver, "Netherlands: ", Netherlands);
      print(solver, "Luxembourg:  ", Luxembourg);
    }

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.

More on metaconstraints

Metaconstraints are created by combining constraints or placing constraints on other constraints. Metaconstraints are based on the idea that constraints have value. Solver handles constraints not only as if they have a Boolean value, such as true or false, but effectively as if the value is 0 or 1. This allows you to combine constraints into expressions or impose constraints on constraints, as you have done in this lesson.

Constraints can be combined using arithmetic operators. You can also use the following logical operators to combine constraints: