qiskit.optimization.applications.ising.knapsack¶
Convert knapsack parameters instances into Pauli list The parameters are a list of values a list of weights and a maximum weight of the knapsack.
In the Knapsack Problem we are given a list of objects that each has a weight and a value. We are also given a maximum weight we can carry. We need to pick a subset of the objects so as to maximize the total value without going over the maximum weight.
If we have the weights w[i], the values v[i] and the maximum weight W_max. We express the solution as a binary array x[i] where we have a 1 for the items we take in the solution set. We need to maximize sum(x[i]*v[i]) while respecting W_max >= sum(x[i]*w[i])
Functions
|
Generate Hamiltonian for the knapsack problem. |
|
Get the solution to the knapsack problem from the bitstring that represents to the ground state of the Hamiltonian |
|
Get the total wight and value of the items taken in the knapsack. |