IBM ILOG Solver User's Manual > The Basics > Using Arrays and Basic Search: Changing Money > Suggested answers > Exercise 3

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).

Suggested Answer

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:

[1, 2, 5, 10, 20, 100]
solution  1:    0 4 1 1 0 1
solution  2:    0 4 3 0 0 1
solution  3:    1 1 0 0 1 1
solution  4:    1 1 0 2 0 1
solution  5:    1 1 2 1 0 1
solution  6:    1 1 4 0 0 1
solution  7:    2 3 1 1 0 1
solution  8:    2 3 3 0 0 1
solution  9:    3 0 0 0 1 1
solution  10:   3 0 0 2 0 1
solution  11:   3 0 2 1 0 1
solution  12:   3 0 4 0 0 1
solution  13:   3 5 0 1 0 1
solution  14:   3 5 2 0 0 1
solution  15:   4 2 1 1 0 1
solution  16:   4 2 3 0 0 1
solution  17:   5 4 0 1 0 1
solution  18:   5 4 2 0 0 1