Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* problem 2. ending up with the minimum number of coins when change is optionally given
- http://www.takingthefun.com/2013/04/john-graham-cunnings-minimum-coin.html
- Uses GNU Linear Programming Kit (glpk):
- glpsol -m prob2.txt -o /dev/fd/1 | egrep 'Objective|used\['
- */
- set COIN;
- param onhand {i in COIN} >= 0, integer; /* number of each coin on hand */
- var used {i in COIN} >= 0, integer; /* number of each coin used in solution */
- param target integer;
- maximize ncoinsused: sum{c in COIN} used[c];
- s.t. valid{c in COIN}: used[c] <= onhand[c];
- s.t. total: sum{c in COIN} c * used[c] >= target;
- s.t. totalminusonecoin {d in COIN}: (sum{c in COIN} c * used[c]) - d <= target - 1;
- data;
- param target := 170;
- set COIN := 200 100 50 20 10 5 2 1;
- param onhand :=
- 200 1
- 100 2
- 50 2
- 20 3
- 10 1
- 5 2
- 2 2
- 1 2;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement