$
$ Coin application in Essence'.
$
$ From "The ECLiPSe Book" pages 99f and 234 ff
$ The solution in ECLiPSe is at page 236.
$ """
$ What is the minimum number of coins that allows one to pay _exactly_
$ any amount smaller than one Euro? Recall that there are six different
$ euro cents, of denomination 1, 2, 5, 10, 20, 50
$ """
$ Model created by Hakan Kjellerstrand, hakank@gmail.com
$ See also my Essence'/Savile Row page: http://www.hakank.org/savile_row/
$
language ESSENCE' 1.0
letting n be 6
letting range be domain int(1..n)
letting coins be domain int(1..99)
letting variables = [1, 2, 5, 10, 25, 50]
find x: matrix indexed by [ range ] of int(0..99)
find tmp: matrix indexed by [coins, range] of int(0..99)
find num_coins: int(0..n*99)
minimising num_coins
such that
num_coins = sum(x),
$ Checks that all changes from 1 to 99 can be made
forAll j: coins .
(sum i: range . tmp[j,i]*variables[i]) = j
/\
forAll i: range . tmp[j,i] <= x[i]
$ , num_coins = 8 $ testing all solution (_many_ optimal solutions)