CPSolver.Examples.Knapsack (Fixpoint v0.5.12)
The 'knapsack' problem is mathematically formulated in the following way. Given n items to choose from, each item i ∈ 0 ...n − 1 has a value v[i] and a weight w[i]. The knapsack has a limited capacity K. Let x[i] be a variable that is 1 if you choose to take item i and 0 if you leave item i behind. Then the knapsack problem is formalized as the following optimization problem:
Maximize sum(x[i]v[i]), i = 0 ... n - 1 subject to sum(x[i] w[i]) <= K
Input data: First line: "n K" Next lines: "value weight"
Summary
Functions
Link to this function
model(input)
Link to this function