Try our new documentation site (beta).


Model.setMObjective()

setMObjective ( Q, c, constant, xQ_L=None, xQ_R=None, xc=None, sense=None )

Set the model objective equal to a quadratic (or linear) expression using matrix semantics.

Note that you will typically use overloaded operators to set the objective using matrix objects. The overloaded @ operator can be used to build a linear matrix expression or a quadratic matrix expression, which is then passed to setObjective.

Arguments:

Q: The quadratic objective matrix - a NumPy 2-D dense ndarray or a SciPy sparse matrix. This can be None if there are no quadratic terms.

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

constant: Objective constant.

xQ_L (optional): Decision variables for quadratic objective 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 (optional): Decision variables for quadratic objective terms; right multiplier for Q. The length of the argument must match the size of the second dimension of Q.

xc (optional): Decision variables for linear objective 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.

sense (optional): Optimization sense (GRB.MINIMIZE for minimization, GRB.MAXIMIZE for maximization). Omit this argument to use the ModelSense attribute value to determine the sense.

Example usage:

  c = np.full(10, 1.0)
  xc = model.addMVar(10)

  model.setMObjective(None, c, 0.0, None, None, xc, GRB.MAXIMIZE)

  Q = np.full((2, 3), 1.0)
  xL = model.addMVar(2)
  xR = model.addMVar(3)

  model.setMObjective(Q, None, 0.0, xL, xR, None, GRB.MINIMIZE)

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

Gurobi Optimization