Model.addMConstrs()

addMConstrs ( A, x, sense, b, names="" )

Add a set of linear constraints to the model using matrix semantics. The added constraints are <span>$</span>A x = b<span>$</span> (except that the constraint sense is determined by the sense argument). The A argument must be a NumPy dense ndarray or a SciPy sparse matrix.

Note that you will typically use overloaded operators to build and add constraints using matrix semantics. The overloaded @ operator can be used to build a linear matrix expression, which can then be used with an overloaded comparison operator to build a TempConstr object. This can then be passed to addConstr.

Arguments:

A: The constraint matrix - a NumPy 2-D dense ndarray or a SciPy sparse matrix.

x: Decision variables. Argument can be an MVar object, a list of Var objects, or None (None uses all variables in the model). The length of the argument must match the size of the second dimension of A.

sense: Constraint senses, provided as a NumPy 1-D ndarray or as a single character. Valid values are <span>$</span><<span>$</span>, <span>$</span>><span>$</span>, or <span>$</span>=<span>$</span>. The length of the array must be equal the size of the first dimension of A. A character will be promoted to an ndarray of the appropriate length.

b: Right-hand side vector, stored as a NumPy 1-D ndarray. The length of the array must be equal the size of the first dimension of A.

names: Names for new constraints. The given name will be subscripted by the index of the constraint in the matrix.

Return value:

List of Constr objects.

Example usage:

  A = np.full((5, 10), 1)
  x = model.addMVar(10)
  b = np.full(5, 1)

  model.addMConstrs(A, x, '=', b)