Initializing help system before first use

xpress.constraint

Description
Class representing linear, quadratic, and nonlinear constraints.
Attributes
name 
Name of the constraint.
type 
Type of the constraint, one of:
xpress.leq 
a ≤ constraint;
xpress.eq 
an equality constraint;
xpress.geq 
a ≥ constraint;
xpress.rng 
a range constraint;
xpress.nonbinding 
a free constraint.
rhs 
Right-hand side of the constraint.
rhsrange 
Right-hand side range value for the constraint.
index 
Index of the constraint in the Optimization problem. None for constraints that have not yet been added to a problem (and for unlinked constraints).
lb 
Lower bound on the constraint expression (read-only).
ub 
Upper bound on the constraint expression (read-only).
Constructors

Constructor detail

xpress.constraint
Synopsis
c = xpress.constraint(constraint=None, body=None, lb=-xpress.infinity, ub=xpress.infinity, type=None, rhs=None, name='', rhsrange=None)
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 type. It should not be used when constraint is defined. Example: 3 * x1 + x2
lb 
Lower bound on body.
ub 
Upper bound on body.
type 
Type of the constraint, one of:
xpress.leq 
for ≤ constraints;
xpress.eq 
for equality constraints;
xpress.geq 
for ≥ constraints;
xpress.rng 
for range constraints.
rhs 
Right-hand side of the constraint if type is defined. It may not be specified if lb or ub are.
name 
Name of the constraint.
rhsrange 
Right-hand side range of the constraint. rhs argument must also be specified. It may not be specified if lb or ub are.
Example
Constraint declared without the explicit constructor:
myconstr = x1 + x2 * (x2 + 1) <= 4
One or more constraints (or lists 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))
The constraint constructor argument is provided so that constraints defined with an inequality can be assigned a name:
myconstr = xp.constraint(x1 + x2 * (x2 + 1) <= 4, name='myconstr')
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])
See also


© 2001-2024 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.