Try our new documentation site (beta).


addMConstr ( A, x, sense, b, name="" )

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.


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.

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

Return value:

MConstr object.

Example usage:

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

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

Try Gurobi for Free

Choose the evaluation license that fits you best, and start working with our Expert Team for technical guidance and support.

Evaluation License
Get a free, full-featured license of the Gurobi Optimizer to experience the performance, support, benchmarking and tuning services we provide as part of our product offering.
Academic License
Gurobi supports the teaching and use of optimization within academic institutions. We offer free, full-featured copies of Gurobi for use in class, and for research.
Cloud Trial

Request free trial hours, so you can see how quickly and easily a model can be solved on the cloud.