xpress.constraint
Purpose
Class for linear, quadratic, and nonlinear constraints.
Synopsis
c = xpress.constraint (constraint=None, body=None, lb=-xpress.infinity, ub=xpress.infinity, sense=None, rhs=None, name='')
Arguments
|
constraint
|
The constraint, written as a
==,
<=, or
>= condition between two expressions. Variables can appear on either or both sides of the sign. Example: x1 + 2 * x2 <= 4 |
|
body
|
An expression indicating the function to be constrained between
lb and
ub or by
rhs with an assigned
sense. It should not be used when
constraint is defined. Example: 3 * x1 + x2
|
|
lb
|
Lower bound on
body.
|
|
ub
|
Upper bound on
body.
|
|
sense
|
Sign of the constraint: one of
xpress.leq,
xpress.eq,
xpress.geq, or
xpress.range.
|
|
rhs
|
Right-hand side of the constraint if
sense is defined. It may not be specified if
lb or
ub are.
|
|
name
|
Name of the constraint (string).
|
Example
Constraint declared without the explicit constructor:
myconstr = x1 + x2 * (x2 + 1) <= 4
One or more constraints (or vectors of constraints) can be added to a problem via the addConstraint method:
m.addConstraint(myconstr) m.addConstraint(v1 + v2 <= 3) m.addConstraint(x[i] + y[i] <= 2 for i in range (10))
In order to help formulate compact problems, the Sum operator of the xpress module can be used to express sums of expressions. Its argument is a list of expressions (linear or quadratic):
m.addConstraint(xp.Sum ([y[i] for i in range (10)]) <= 1) m.addConstraint(xp.Sum ([x[i]**2 for i in range (9)]) <= x[9])
Further information
1. Parameters lb, ub, and rhs must be constant.
2. A constraint can be specified more naturally as a condition on a linear or quadratic expression:
3. When handling variables or expressions, it is advised to use the Sum operator in the Xpress module rather than the native Python operator, for reasons of efficiency.
Related topics
© 2001-2021 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.
