IBM ILOG Solver User's Manual > The Basics > Modeling and Solving a Simple Problem: Map Coloring > Suggested answers > Exercise 4 |
Exercise 4 |
INDEX
![]() |
Change the original code to include Switzerland in the map. Switzerland shares borders with France and Germany. No neighboring countries are the same color.
The code that has changed from color.cpp
follows. You can view the complete program online in the file YourSolverHome/examples/src/color_ex4.cpp
.
The declaration of the variables is changed as follows:
IloIntVar Belgium(env, 0, 3), Denmark(env, 0, 3), France(env, 0, 3), Germany(env, 0, 3), Luxembourg(env, 0, 3), Netherlands(env, 0, 3), Switzerland(env, 0, 3); |
These additional constraints are added to the model
model.add(France != Switzerland); model.add(Germany != Switzerland); |
This code is added to the solution display:
solver.out() << "Switzerland: " << Names[(IloInt)solver.getValue(Switzerland)] << endl; |
You should obtain the following results:
FEASIBLE Solution Belgium: blue Denmark: blue France: white Germany: yellow Luxembourg: green Netherlands: white Switzerland: blue |
© Copyright IBM Corp. 1987, 2009. Legal terms. | PREVIOUS NEXT |