9.3 Constraints

Linear equality and inequality constraints of the form

f(x1,...,xn) = 0,   f(x1,...,xn) ≼ 0,

where f is a convex function, are represented by constraint objects. Equality constraints are created by expressions of the form

f1 == f2.

Here f1 and f2 can be any objects for which the difference f1-f2 yields an affine function. Inequality constraints are created by expressions of the form

f1 <= f2, f2 >= f1,

where f1 and f2 can be any objects for which the difference f1-f2 yields a convex piecewise-linear function. The comparison operators first convert the expressions to f1-f2 == 0, resp. f1-f2 <= 0, and then return a new constraint object with constraint function f1-f2.

In the following example we create three constraints

0 ≼ x ≼ 1,  1T x = 2,

for a variable of length 5.

>>> x = variable(5,’x’)  
>>> c1 = (x <= 1)  
>>> c2 = (x >= 0)  
>>> c3 = (sum(x) == 2)

The built-in function len() returns the dimension of the constraint function.

Constraints have four public attributes.

type()

Returns ’=’ if the constraint is an equality constraint, and ’<’ if the constraint is an inequality constraint.

value()

Returns the value of the constraint function.

multiplier

For a constraint c, c.multiplier is a variable object of dimension len(c). It is used to represent the Lagrange multiplier or dual variable associated with the constraint. Its value is initialized as None, and can be modified by making an assignment to c.multiplier.value.

name

The name of the constraint. Changing the name of a constraint also changes the name of the multiplier of c. For example, the command c.name = ’newname’ also changes c.multiplier.name to ’newname_mul’.