Initializing help system before first use

Solving a quadratically constrained problem


Type: Programming
Rating: 2 (easy-medium)
Description: Solve a quadratically constrained problem
File(s): example_qcqp.py


example_qcqp.py
#!/bin/env python

#
# Test for the main features of the Xpress Python interface
#
# Adds a vector of N=5 variables and sets constraints and objective. The
# problem is a convex QCQP

from __future__ import print_function

import xpress as xp

N = 5
S = range(N)

v = [xp.var(name="y{0}".format(i)) for i in S]

m = xp.problem("problem 1")

print("variable:", v)

m.addVariable(v)

m.addConstraint(v[i] + v[j] >= 1 for i in range(N - 4) for j in range(i, i+4))
m.addConstraint(xp.Sum([v[i]**2 for i in range(N - 1)]) <= N**2 * v[N - 1]**2)

# Objective overwritten at each setObjective()
m.setObjective(xp.Sum([i*v[i] for i in S]) * (xp.Sum([i*v[i] for i in S])))

m.solve()

print("solution: ", m.getSolution())

© 2001-2019 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.