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.
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 'AB' will produce an error, because '' 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.
# 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)