8 lines
638 B
Text
8 lines
638 B
Text
%Knapsack problem/Unbounded. Nigel Galloway, August 13th., 2021
|
|
enum Items ={panacea,ichor,gold};
|
|
array[Items] of float: weight =[0.3,0.2,2.0]; constraint sum(n in Items)(take[n]*weight[n])<=25.0;
|
|
array[Items] of int: value =[3000,1800,2500];
|
|
array[Items] of float: volume =[0.025,0.015,0.002]; constraint sum(n in Items)(take[n]*volume[n])<=0.25;
|
|
array[Items] of var 0..floor(25.0/min(weight)): take;
|
|
solve maximize sum(n in Items)(value[n]*take[n]);
|
|
output(["Take "++show(take[panacea])++" vials of panacea\nTake "++show(take[ichor])++" ampules of ichor\nTake "++ show(take[gold])++" bars of gold\n"])
|