Try our new documentation site (beta).


Model.setObjectiveN()

setObjectiveN ( expr, index, priority=0, weight=1, abstol=0, reltol=0, name="" )

Set an alternative optimization objective equal to a linear expression.

Please refer to the discussion of Multiple Objectives for more information on the use of alternative objectives.

Note that you can also modify an alternative objective using the ObjN variable attribute. If you wish to mix and match these two approaches, please note that this method replaces the entire existing objective, while the ObjN attribute can be used to modify individual terms.

Arguments:

expr (LinExpr): New alternative objective.

index (int): Index for new objective. If you use an index of 0, this routine will change the primary optimization objective.

priority (int, optional): Priority for the alternative objective. This initializes the ObjNPriority attribute for this objective.

weight (float, optional): Weight for the alternative objective. This initializes the ObjNWeight attribute for this objective.

abstol (float, optional): Absolute tolerance for the alternative objective. This initializes the ObjNAbsTol attribute for this objective.

reltol (float, optional): Relative tolerance for the alternative objective. This initializes the ObjNRelTol attribute for this objective.

name (string, optional): Name of the alternative objective. This initializes the ObjNName attribute for this objective. Note that name will be stored as an ASCII string. Thus, a name like 'A<span>$</span>{\rightarrow}<span>$</span>B' will produce an error, because '<span>$</span>{\rightarrow}<span>$</span>' can not be represented as an ASCII character. Note also that names that contain spaces are strongly discouraged, because they can't be written to LP format files.

Example usage:

  # Primary objective: x + 2 y
  model.setObjectiveN(x + 2*y, 0, 2)
  # Alternative, lower priority objectives: 3 y + z and x + z
  model.setObjectiveN(3*y + z, 1, 1)
  model.setObjectiveN(x + z, 2, 0)

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