Model.addMQConstr()

addMQConstr ( Q, c, sense, rhs, xQ_L=None, xQ_R=None, xc=None, name="" )

Add a quadratic constraint to the model using matrix semantics. The added constraint is <span>$</span>x_{Q_L}' Q x_{Q_R} + c' x_c = \mbox{rhs}<span>$</span> (except that the constraint sense is determined by the sense argument). The Q argument must be a NumPy 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 or quadratic matrix expression. An overloaded comparison operator can then be used to build a TempConstr object, which is then passed to addConstr.

Arguments:

Q: The quadratic constraint matrix - a NumPy 2-D ndarray or a SciPy sparse matrix.

c: The linear constraint vector - a NumPy 1-D ndarray. This can be None if there are no linear terms.

sense: Constraint sense. Valid values are <span>$</span><<span>$</span>, <span>$</span>><span>$</span>, or <span>$</span>=<span>$</span>.

rhs: Right-hand-side value.

xQ_L: Decision variables for quadratic terms; left multiplier for Q. 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 first dimension of Q.

xQ_R: Decision variables for quadratic terms; right multiplier for Q. The length of the argument must match the size of the second dimension of Q.

xc: Decision variables for linear terms. 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 length of c.

name: Name for new constraint.

Return value:

The QConstr object.

Example usage:

  Q = np.full((2, 3), 1)
  xL = model.addMVar(2)
  xR = model.addMVar(3)
  model.addMQConstr(Q, None, '<', 1.0, xL, xR)

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.

Search