RosettaCodeData/Task/Knapsack-problem-Continuous/Ursala/knapsack-problem-continuous...

28 lines
785 B
Plaintext

#import flo
#import lin
items = # name: (weight,price)
<
'beef ': (3.8,36.0),
'pork ': (5.4,43.0),
'ham ': (3.6,90.0),
'greaves': (2.4,45.0),
'flitch ': (4.0,30.0),
'brawn ': (2.5,56.0),
'welt ': (3.7,67.0),
'salami ': (3.0,95.0),
'sausage': (5.9,98.0)>
system = # a function to transform the item list to the data structure needed by the solver
linear_system$[
lower_bounds: *nS ~&\0., # all zeros because we can't steal less than zero
upper_bounds: ~&nmlPXS, # can't steal more than what's in the shop
costs: * ^|/~& negative+ vid, # prices divided by weights, negated so as to maximize
equations: ~&iNC\15.+ 1.-*@nS] # 1 equation constraining the total weight to 15
#cast %em
main = solution system items