Knapsack problem/Continuous: Difference between revisions
Content added Content deleted
m (changed a comment) |
|||
Line 379: | Line 379: | ||
We might as well leave this one to the experts by setting it up as a |
We might as well leave this one to the experts by setting it up as a |
||
[http://en.wikipedia.org/wiki/Linear_programming linear programming] problem and handing it off to an external library (which will be either [http://sourceforge.net/projects/lpsolve lpsolve] or |
[http://en.wikipedia.org/wiki/Linear_programming linear programming] problem and handing it off to an external library (which will be either [http://sourceforge.net/projects/lpsolve lpsolve] or |
||
[http://www.gnu.org/software/glpk/glpk.html |
[http://www.gnu.org/software/glpk/glpk.html glpk] depending on the run-time system configuration). |
||
<lang Ursala>#import std |
<lang Ursala>#import std |
||
Line 403: | Line 403: | ||
lower_bounds: *nS ~&\0., # all zeros because we can't steal less than zero |
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 |
upper_bounds: ~&nmlPXS, # can't steal more than what's in the shop |
||
costs: * ^|/~& negative+ vid, # |
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 |
equations: ~&iNC\15.+ 1.-*@nS] # 1 equation constraining the total weight to 15 |
||