SHARE
TWEET

Minimum Coin Problem #2

kh444n Apr 23rd, 2013 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* problem 2. ending up with the minimum number of coins when change is optionally given
  2.         http://www.takingthefun.com/2013/04/john-graham-cunnings-minimum-coin.html
  3.         Uses GNU Linear Programming Kit (glpk):
  4.         glpsol -m prob2.txt -o /dev/fd/1 | egrep 'Objective|used\['
  5. */
  6.  
  7. set COIN;
  8. param onhand {i in COIN} >= 0, integer; /* number of each coin on hand */
  9. var used {i in COIN} >= 0, integer; /* number of each coin used in solution */
  10. param target integer;
  11. maximize ncoinsused: sum{c in COIN} used[c];
  12. s.t. valid{c in COIN}: used[c] <= onhand[c];
  13. s.t. total: sum{c in COIN} c * used[c] >= target;
  14. s.t. totalminusonecoin {d in COIN}: (sum{c in COIN} c * used[c]) - d <= target - 1;
  15.  
  16. data;
  17. param target := 170;
  18. set COIN := 200 100 50 20 10 5 2 1;
  19. param onhand :=
  20. 200 1
  21. 100 2
  22. 50 2
  23. 20 3
  24. 10 1
  25. 5 2
  26. 2 2
  27. 1 2;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top