Knapsack Problem #33
-
|
Hi everyone, Any comments or help is welcomed. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 8 replies
-
|
Hi there, Thank you for reaching out. The In the context of reframing combinatorial optimization problems into Ising models, ancillary spins are additional spins introduced to embed interractions that would require terms of degree higher than 2. Here is the interpration of the hamiltonian Note: SB is an approximation algorithm so the output does not necessarily achieve the minimal energy. Since the constraints are embedded by ensuring that the energy of a spin vector violating the constraints cannot be minimal, the output can still violate the constraints. I am not really sure I understood your question properly, please let me know if you need further explanations. |
Beta Was this translation helpful? Give feedback.
-
|
Hi @Kashyapaman2812, Here is a quick note in addition to @BusyBeaver-42's answer. About Lucas' paperIn the case of the Knapsack problem, the In the following, we denote the weights of the items Thus, we need to introduce 6 ancillary binary variables
Then, setting
A good way to know if the solution found by SB is admissible is to check whether the objective function is negative (success) or positive (fail). Knapsack problem implementationThe good news is that the Integer-Weights Knapsack problem is already implemented in the repository. It is not part of the last PyPI release (1.2.0) because it was added pretty recently. If you wish to use our implementation, please consider downloading the dev version of SB with Then, you can use the Knapsack model from the from simulated_bifurcation.models import Knapsack
knapsack_problem = Knapsack(weights=[5, 2, 3, 4, 8, 1], costs=[4, 12, 3, 4, 15, 5], max_weight=10)
knapsack_problem.minimize() # We seek to minimize the Ising energy of the Lucas' Knapsack Hamiltonian
print(knapsack_problem.summary)Running this code snippet on my computer I got
I hope this answer helped you. Please feel free to ask any further question and we will be happy to help. |
Beta Was this translation helpful? Give feedback.


Oh I understand the question now. You just put everything in the same vector and matrix and read the output only at locations corresponding to$X$ .
For instance, let's say you pack your variable spins and your ancillary spins in a vector as follows.
Let$A$ be the matrix embedding the interactions between your variable spins, let $B$ be the matrix embedding the interactions between your ancillary spins, let $C$ be the matrix embedding the interactions between your variable spins and your ancillary spins, and let $C_1$ , $C_2$ be two matrices such that $C = C_1 + C_2$ . Usually $C_2 = 0$ or $C_2 = C_1$ depending on what is the easiest to generate.…