Cookie Settings

Try our new documentation site (beta).

Filter Content By
Version
Table of contents
Filter by Language
C API Details
C++ API Details
GRBModel +
Java API Details
GRBModel +
.NET API Details
GRBModel +
Python API Details
Model
Attributes
Parameters
Parameter Descriptions +


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)