A Basic Mathematical Optimisation Problem With A Basic Boundary Condition To Demonstrate QUBO Formulation
This script demonstrates how to formulate the optimisation problem
up to a positive integer constant of 15.
The problem variable is expressed in binary manner to make it easier to express in the forms of 1's and 0's - those are the only allowed values in the QUBO formulation anyway. In the code, this is expressed as
expression_1 = (8x+4y+2z+q)
coefficients being the powers of 2. expression_1 is here just our variable x given in the minimization problem. The x in the expression itself is just a simpy symbol, and should not be confused with the one in the optimization problem.
Boundary condition is expressed in the same manner with a constant factor between 0 and 15 (4 bit's allowance span).
After the problem is created, coefficients of the variables are placed in the symmetrical cost matrix. We don't differentiate between quadratic expressions and singular experrions(such as
That's the big question!
The constant part in the problem definition (that would be e.g. 36, for the case of c=6 or 144, for the case of c=12) is the energy which can not be decreased with the manipulation of the variables. Hence, it stays in the problem. This energy is communicated with the quantum annealer via
e_offset=boundary.as_independent(x,y,z,q)[0]*langrange_hard
Since the Annealer returns back a vector of binary variables, one must translate it back to a readable answer. To do that, we just to binary to decimal conversation. smpl[0] is equivalent to our symbol x, and smpl[1] to our y etc.
answer = 8smpl[0] + 4smpl[1] + 2*smpl[2] + smpl[3]
Here are some helping functions for the sake of keeping the main script clean. Hopefully they are well commented by the time!