Try our new documentation site (beta).


GRBModel.setObjective()

Set the model objective equal to a linear or quadratic expression (for multi-objective optimization, see setObjectiveN).

Note that you can also modify the linear portion of a model objective using the Obj variable attribute. If you wish to mix and match these two approaches, please note that this method replaces the entire existing objective, while the Obj attribute can be used to modify individual linear terms.

void setObjective ( GRBExpr expr,
    int sense )
    Set the model objective, and the objective sense (GRB.MINIMIZE for minimization, GRB.MAXIMIZE for maximization).

    Arguments:

    expr: New model objective.

    sense: New optimization sense (GRB.MINIMIZE for minimization, GRB.MAXIMIZE for maximization).

void setObjective ( GRBExpr expr )

    Set the model objective. The sense of the objective is determined by the value of the ModelSense attribute.

    Arguments:

    expr: New model objective.

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