IBM ILOG Solver User's Manual > The Basics > Using Arrays and Basic Search: Changing Money > Suggested answers > Exercise 3 |
Exercise 3 |
INDEX
![]() |
Assume that you want to pay for an item that costs 1.23 euros. You have a mixture of coins: 1 euro cent, 2 euro cents, 5 euro cents, 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, 5 coins of 2 euro cents, and 10 coins of 5 euro cents. You must also use at least 1 coin of 1 euro (100 cents).
The code that has changed from money.cpp
follows. You can view the complete program online in the file YourSolverHome/examples/src/money_ex3.cpp
.
The coefficients change as follows:
IloInt nCoins = 6, Sum = 123; IloIntArray coeffs(env, nCoins, 1, 2, 5, 10, 20, 100); |
These additional constraints are added to the model:
model.add(coins[1] <= 5); model.add(coins[2] <= 10); model.add(coins[5] >= 1); |
You should obtain the following results:
© Copyright IBM Corp. 1987, 2009. Legal terms. | PREVIOUS NEXT |