FICO Xpress Optimization Examples Repository
 FICO Optimization Community FICO Xpress Optimization Home

Solving a nonconvex quadratic problem

Description
Solve a nonconvex quadratic problem

Further explanation of this example: 'Xpress Python Reference Manual'

 QCQP_nonconvex_python.zip [download all files]

Source Files
By clicking on a file name, a preview is opened at the bottom of this page.
 example_quadnonconvex.py [download]

example_quadnonconvex.py

# Test problem on a dot product between matrices of scalars and/or of
# variables. Note that the problem cannot be solved by the Optimizer
# as it is nonconvex.
#
# (C) Fair Isaac Corp., 1983-2021

from __future__ import print_function

import xpress as xp
import numpy as np

a = 0.1 + np.arange(21).reshape(3, 7)

# Create NumPy vectors of variables
y = xp.vars(3, 7, name='')
x = xp.vars(7, 5, name='')

p = xp.problem()
p.addVariable(x, y)

p.addConstraint(xp.Dot(y, x) <= 0)
p.addConstraint(xp.Dot(a, x) == 1)

p.setObjective(x[0][0])

p.write("test6-nonconv", "lp")
p.optimize()