sasoptpy.Model.add_constraints

Model.add_constraints(self, argv, name)[source]

Adds a set of constraints to the model

Parameters
argvGenerator-type object

List of constraints as a generator-type Python object

namestring

Name for the constraint group and individual constraint prefix

Returns
cgConstraintGroup

Reference to the ConstraintGroup

Examples

>>> x = m.add_variable(name='x', vartype=so.INT, lb=0, ub=5)
>>> y = m.add_variables(3, name='y', vartype=so.CONT, lb=0, ub=10)
>>> c = m.add_constraints((x + 2 * y[i] >= 2 for i in [0, 1, 2]),
                          name='c')
>>> print(c)
Constraint Group (c) [
  [0:  2.0 * y[0]  +  x  >=  2]
  [1:  2.0 * y[1]  +  x  >=  2]
  [2:  2.0 * y[2]  +  x  >=  2]
]
>>> t = m.add_variables(3, 4, name='t')
>>> ct = m.add_constraints((t[i, j] <= x for i in range(3)
                           for j in range(4)), name='ct')
>>> print(ct)
Constraint Group (ct) [
  [(0, 0):  -  x  +  t[0, 0]  <=  0]
  [(0, 1):  t[0, 1]  -  x  <=  0]
  [(0, 2):  -  x  +  t[0, 2]  <=  0]
  [(0, 3):  t[0, 3]  -  x  <=  0]
  [(1, 0):  t[1, 0]  -  x  <=  0]
  [(1, 1):  t[1, 1]  -  x  <=  0]
  [(1, 2):  -  x  +  t[1, 2]  <=  0]
  [(1, 3):  -  x  +  t[1, 3]  <=  0]
  [(2, 0):  -  x  +  t[2, 0]  <=  0]
  [(2, 1):  t[2, 1]  -  x  <=  0]
  [(2, 2):  t[2, 2]  -  x  <=  0]
  [(2, 3):  t[2, 3]  -  x  <=  0]
]