sasoptpy.ConstraintGroup¶
-
class
ConstraintGroup
(**kwargs)[source]¶ Bases:
sasoptpy.core.group.Group
Creates a group of
Constraint
objects- Parameters
- argvGenerator-type object
A Python generator that includes
Expression
objects- namestring, optional
Name (prefix) of the constraints
Notes
Use
sasoptpy.Model.add_constraints()
when working with a single model.Examples
>>> var_ind = ['a', 'b', 'c', 'd'] >>> u = so.VariableGroup(var_ind, name='u') >>> t = so.Variable(name='t') >>> cg = so.ConstraintGroup((u[i] + 2 * t <= 5 for i in var_ind), name='cg') >>> print(cg) Constraint Group (cg) [ [a: 2.0 * t + u['a'] <= 5] [b: u['b'] + 2.0 * t <= 5] [c: 2.0 * t + u['c'] <= 5] [d: 2.0 * t + u['d'] <= 5] ]
>>> z = so.VariableGroup(2, ['a', 'b', 'c'], name='z', lb=0, ub=10) >>> cg2 = so.ConstraintGroup((2 * z[i, j] + 3 * z[i-1, j] >= 2 for i in [1] for j in ['a', 'b', 'c']), name='cg2') >>> print(cg2) Constraint Group (cg2) [ [(1, 'a'): 3.0 * z[0, 'a'] + 2.0 * z[1, 'a'] >= 2] [(1, 'b'): 2.0 * z[1, 'b'] + 3.0 * z[0, 'b'] >= 2] [(1, 'c'): 2.0 * z[1, 'c'] + 3.0 * z[0, 'c'] >= 2] ]