IBM ILOG Solver User's Manual > The Basics > Using Objectives: Map Coloring with Minimum Colors > Suggested answers > Exercise 3 |
Exercise 3 |
INDEX
![]() |
Add an objective to the changing money problem you worked on in Chapter 3, Using Arrays and Basic Search: Changing Money. Assume that you want to pay for an item that costs 1.23 euros. You have a mixture of coins of the following types: 1 euro cent, 10 euro cents, 20 euro cents, and 1 euro. To make the problem more interesting, assume that you have only 5 coins of 1 euro cent. You prefer to pay for the item using as many of your lower denomination coins as possible. Create an objective that uses the following coefficients to represent the importance of using each type of coin: 1000 (1 euro cent), 800 (10 euro cents), 300 (20 euro cents), and 10 (1 euro). Change the code so that you only search for one maximized solution.
The code that has changed from money.cpp
follows. You can view the complete program online in the file YourSolverHome/examples/src/colormin_ex3.cpp
.
You add the objective:
IloObjective obj = IloMaximize(env, (1000 * (coins[0])) + (800 * (coins[1])) + (300 * (coins[2])) + (10 * (coins[3]))); model.add(obj); |
You change the following code to display the solution:
You should get the following results:
[1, 10, 20, 100] Optimal Solution Objective = 12600 3 12 0 0 |
© Copyright IBM Corp. 1987, 2009. Legal terms. | PREVIOUS NEXT |