Knapsack problem/Unbounded: Difference between revisions

Realize in MiniZinc
(Realize in MiniZinc)
Line 2,223:
end</lang>
 
=={{header|MiniZinc}}==
<lang MiniZinc>
%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"])
</lang>
{{out}}
<pre>
Take 0 vials of panacea
Take 15 ampules of ichor
Take 11 bars of gold
----------
==========
Finished in 159msec
</pre>
=={{header|M4}}==
A brute force solution:
2,171

edits