Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* problem 3. Giving away maximum weight of coins
- http://www.takingthefun.com/2013/04/john-graham-cunnings-minimum-coin.html
- Uses GNU Linear Programming Kit (glpk):
- glpsol -m prob3.txt -o /dev/fd/1 | egrep 'Objective|used\['
- */
- set COIN;
- param onhand {i in COIN} >= 0, integer; /* number of each coin on hand */
- param weight {i in COIN} >= 0, integer; /* weight of each coin in centigrams */
- var used {i in COIN} >= 0, integer; /* number of each coin used in solution */
- param target integer;
- maximize weightofcoins: sum{c in COIN} used[c] * weight[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;
- param weight :=
- 200 1200
- 100 950
- 50 800
- 20 500
- 10 650
- 5 325
- 2 713
- 1 356;
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement