Use this file to discover all available pages before exploring further.
View on GitHub
Open this notebook in GitHub to run it yourself
Integer Linear Programming (ILP) seeks a vector of integer numbers that maximizes (or minimizes) a linear cost function under a set of linear equality or inequality constraints [1]. In other words, it is an optimization problem where the cost function to optimize and all the constraints are linear and the decision variables are integers.
The ILP problem can be formulated as follows: given an n-dimensional vector c=(c1,c2,…,cn), an m×n matrix A=(aij) with i=1,…,m and j=1,…,n, and an m-dimensional vector b=(b1,b2,…,bm), find an n-dimensional vector x=(x1,x2,…,xn) with integer entries that maximizes (or minimizes) the cost function:c⋅x=c1x1+c2x2+…+cnxnsubject to these constraints:Axxjxj≤b≥0,j=1,2,…,n∈Z,j=1,2,…,nThis tutorial guides you through the steps of solving the problem with the Classiq platform, using QAOA [2].The solution is based on defining a Pyomo model for the optimization problem to solve.
To solve the Pyomo model defined above, use the CombinatorialProblem quantum object.Under the hood it translates the Pyomo model to a quantum model of QAOA, with the cost Hamiltonian translated from the Pyomo model.Choose the number of layers for the QAOA ansatz using the num_layers argument.The penalty_factor is the coefficient of the constraints term in the cost Hamiltonian.
from classiq.execution import *execution_preferences = ExecutionPreferences( backend_preferences=ClassiqBackendPreferences(backend_name="simulator"),)
Solve the problem by calling the optimize method of the CombinatorialProblem object.For the classical optimization part of QAOA, define the maximum number of classical iterations (maxiter) and the α-parameter (quantile) for running CVaR-QAOA, an improved variation of QAOA [3]:
Examine the statistics of the algorithm.The optimization is always defined as a minimization problem, so the positive maximization objective is translated to negative minimization by the Pyomo-to-Qmod translator.To get samples with the optimized parameters, call the sample method:
from pyomo.opt import SolverFactorysolver = SolverFactory("couenne")solver.solve(ilp_model)classical_solution = [int(pyo.value(ilp_model.x[i])) for i in range(len(ilp_model.x))]print("Classical solution:", classical_solution)