# Summary of Exercises with Solutions¶

Below you will find solutions to the exercises included in this “Learn to Formulate Problems” guide. For further discussion of these solutions, please visit our community forum in Leap.

## Introduction¶

Split the following problem into an objective and constraints.

A business is trying to figure out the best way to pack a box full of items. There are five items, with values 1, 5, 3, 4, and 2 dollars. These items have weights 2, 4, 4, 1, and 3 lbs, respectively. The contents of the box must weigh exactly 6 lbs. What is the best way to pack the box so that the box has the highest total value?

Solution

This problem can be split into an objective and constraints as follows.

Objective

• Maximize total value

Constraint

• Total weight of contents is exactly 6 lbs

## Definitions¶

### QUBO¶

Put the following QUBO into matrix form.

$x_1+x_1x_2-3x_3+5$

Solution

$\begin{split}\left[ \begin{array}{ccc} 1 & 1 & 0 \\ 0 & 0 & 0 \\ 0 & 0 & -3 \\ \end{array} \right]\end{split}$

### Ising¶

Put the following Ising model into matrix form.

$s_1+s_1s_2-3s_3+5$

Solution



Linear

$\begin{split}h = \left[ \begin{array}{cccc} 1 & 0 & -3 \\ \end{array} \right]\end{split}$

$\begin{split}J = \left[ \begin{array}{cccc} 0 & 1 & 0 \\ 0 & 0 & 0 \\ 0 & 0 & 0 \\ \end{array} \right]\end{split}$

### Converting Between QUBO and Ising¶

QUBO to Ising:

$-2s_2-6s_3+4s_1s_2+8$

Ising to QUBO:

$\frac{3}{4}x_1+\frac{1}{4}x_2-\frac{3}{2}x_3+\frac{1}{4}x_1x_2+\frac{17}{4}$

## Small Problems with Two Variables¶

QUBO:

Convert the following QUBO model to an Ising model.

$x_1+x_1x_2-3x_3+5$

Solution

$x_1-x_1x_2$

Ising:

Convert the following Ising model to a QUBO model.

$s_1+s_1s_2-3s_3+5$

Solution

$\frac{1}{4}s_1-\frac{1}{4}s_2-\frac{1}{4}s_1s_2+\frac{1}{4}$

## Problems with Multiple Constraints¶

Write a BQM for the following problem.

A business is trying to figure out the best way to pack a box full of items. There are five items, with values 1, 5, 3, 4, and 2 dollars. These items have weights 2, 4, 4, 1, and 3 lbs, respectively. The contents of the box must weigh exactly 6 lbs. What is the best way to pack the box so that the box has the highest total value?

Solution

QUBO:

$(x_1+5x_2+3x_3+4x_4+2x_5)+\gamma (2x_1+4x_2+4x_3+x_4+3x_5-6)^2$

Ising:

$(2s_1+10s_2+6s_3+8s_4+4s_5-15)+\gamma (4s_1+8s_2+8s_3+2s_4+6s_5-20)^2$