diff --git a/choosing_boxes_problem/index.html b/choosing_boxes_problem/index.html index 0c364a5..68f4577 100644 --- a/choosing_boxes_problem/index.html +++ b/choosing_boxes_problem/index.html @@ -13,14 +13,28 @@ div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;} ul.task-list{list-style: none;} + +
-The problem “Choosing Boxes” is described in the D-Wave problem formulation guide in chapt. 4.4.
Choosing Boxes Problem
We’re given three boxes with different weights. We want to choose the two boxes with the smallest sum.
This is a simple problem – we know that the answer is to choose boxes 15 and 20. But how do we phrase this problem as a BQM?
-Objective: We are looking for the smallest sum, so our objective is “minimize the sum of the boxes chosen”.
Constraint: We are allowed to choose two boxes, so our constraint is “choose exactly two boxes”.
Binary Variables. First, we need to define our binary variables. The answer that we are looking for is which boxes we should choose. For each box, we can ask “do we choose this box?”. This points us to how we should define our binary variables.
QUBO | -xi = 1 | -xi = 0 | +\(x_i = 1\) | +\(x_i = 0\) |
Ising | -si = + 1 | -si = − 1 | +\(s_i = +1\) | +\(s_i = −1\) |
Once we have defined our binary variables, we can convert our objective and constraint into math expressions.
Objective. We consider our objective for both QUBO and Ising forms.
-QUBO: To figure out the sum of the boxes that are chosen, we can use a weighted sum: 15x1 + 20x2 + 25x3. In this sum, the boxes that are chosen will have xi = 1 and the boxes that are not chosen will have xi = 0. In other words, the value of boxes that are not chosen will be multiplied by zero and so we will only be adding up the value of the boxes that are chosen. Our objective function becomes:
-
min(15x1 + 20x2 + 25x3)
QUBO: To figure out the sum of the boxes that are chosen, we can use a weighted sum: \(15x_1 + 20x_2 + 25x_3\). In this sum, the boxes that are chosen will have \(x_i = 1\) and the boxes that are not chosen will have \(x_i = 0\). In other words, the value of boxes that are not chosen will be multiplied by zero and so we will only be adding up the value of the boxes that are chosen. Our objective function becomes:
+\[ +min(15x_1 + 20x_2 + 25x_3) +\]
Ising: Using our binary variables, we can convert our +1/-1 to 1/0 using the Ising to QUBO translation shown earlier, which maps +1 7→ 1 and −1 7→ 0. Our objective function can then be written as:
-\[
min \left (
15 \left ( \frac{s_1 + 1}{2} \right ) +
20 \left ( \frac{s_2 + 1}{2} \right ) +
25 \left ( \frac{s_3 + 1}{2} \right )
\right )
-$$
$$
+
Constraint. We consider our constraint for both QUBO and Ising forms.
QUBO: Our constraint “choose exactly two boxes” means that we need exactly two of our binary variables to have value 1, and the remaining binary variable will have value 0. In other words, our constraint can be written as:
-
x1 + x2 + x3 = 2
\[x_1 + x_2 + x_3 = 2\]
Ising: Our constraint “choose exactly two boxes” means that we need exactly two of our binary variables to have value +1, and the remaining binary variable will have value -1. In other words, our constraint can be written as:
-
s1 + s2 + s3 = 1
\[s_1 + s_2 + s_3 = 1\]
+Our objective function is fine as written, so we only need to modify our constraint.
-QUBO: To modify our constraint, we need to use the method for equalities. Original constraint:
x1 + x2 + x3 = 2
Move everything to one side:
x1 + x2 + x3 − 2 = 0
Square the expression:
(x1 + x2 + x3 − 2)2
Ising: Following the same method, we can rewrite our constraint as follows.
(s1 + s2 + s3 − 1)2
QUBO: To modify our constraint, we need to use the method for equalities. Original constraint: \[x_1 + x_2 + x_3 = 2\] Move everything to one side: \[x_1 + x_2 + x_3 − 2 = 0\] Square the expression: \[(x_1 + x_2 + x_3 − 2)^2\]
+Ising: Following the same method, we can rewrite our constraint as follows. \[(s_1 + s_2 + s_3 − 1)^2\]
+Now that we have written our objective and constraint in BQM form, we can combine them together to make our final model using addition and adding in a Lagrange parameter. Both of these can be expanded and simplified to prepare for input to an Ocean python program.
-QUBO:
min((15x1+20x2+25x3)+γ(x1+x2+x3−2)2)
QUBO: \[ +min \left ( + (15 x_1 + 20 x_2 + 25 x_3) + + γ (x_1 + x_2 + x_3 − 2)^2 +\right ) +\]
Ising:
-\[
min \left (
15 \left ( \frac{s_1 + 1}{2} \right ) +
20 \left ( \frac{s_2 + 1}{2} \right ) +
25 \left ( \frac{s_3 + 1}{2} \right ) +
γ (s_1 + s_2 + s_3 − 1)^2
\right )
-$$
$$
+
Also see: https://github.com/dwave-training/choosing-boxes
-The code for the problem is in choosing_boxes.ipynb
which can be viewed at nbviewer.org or opened in the D-Wave Leap IDE
The eigenspectrum and eigenvector for this problem are visualized for different Lagrange multipliers γ: