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;} + + -

Choosing Boxes

-

Problem

+ +

1 Choosing Boxes

+

1.0.1 Problem

The problem “Choosing Boxes” is described in the D-Wave problem formulation guide in chapt. 4.4.

Choosing Boxes Problem

-

Example: Choosing Boxes

+

1.0.1.1 Example: Choosing Boxes

We’re given three boxes with different weights. We want to choose the two boxes with the smallest sum.

@@ -41,10 +55,10 @@

Example: Choosing Boxes

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?

-
Step 1: Write Objective and Constraints
+
1.0.1.1.1 Step 1: Write Objective and Constraints

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”.

-
Step 2: Convert Objective and Constraints into Binary Math Expressions
+
1.0.1.1.2 Step 2: Convert Objective and Constraints into Binary Math Expressions

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.

@@ -57,54 +71,61 @@
S
- - + + - - + +
QUBOxi = 1xi = 0\(x_i = 1\)\(x_i = 0\)
Isingsi =  + 1si =  − 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

-
Step 3: Transform Math Expressions into a BQM
+

\[s_1 + s_2 + s_3 = 1\]

+
1.0.1.1.3 Step 3: Transform Math Expressions into a BQM

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

-
Step 4: Combine Expressions
+

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\]

+
1.0.1.1.4 Step 4: Combine Expressions

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

-

Code

+

1.0.2 Code

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

-

Visualization

+

1.0.3 Visualization

The eigenspectrum and eigenvector for this problem are visualized for different Lagrange multipliers γ:

@@ -253,15 +274,16 @@

Visualization

  • choosing-boxes-4-eigenvectors-dt50
  • -

    Sitemap Markdowns

    +

    1.1 Sitemap Markdowns

    -

    Sitemap HTMLs

    +

    1.2 Sitemap HTMLs