Let us first discuss the interface for managing multiple objectives.
An empty model starts with one objective function, which is initially
just 0.0. We'll refer to this as the primary objective. You
can modify the primary objective in two ways: you can set the
Obj attribute, or you can use the
setObjective method from your language API (e.g.,
Python). For models with a single objective, this primary objective
can be linear, quadratic, or piecewise-linear. In general, attributes
and methods that aren't specific to multi-objective optimization will
work with the primary objective function.
To provide additional objectives, use the
from your language API (e.g.
in Python). Objectives are numbered
The order of the objectives is arbitrary, but you must provide a
unique index for each one (specified using the
setObjectiveN). You can query the number of objectives in
your model using the NumObj attribute.
Note that all objectives, including the primary one, must be linear
for multi-objective models.
You can query and modify information about multiple objectives using
the ObjNumber parameter, in
conjunction with several model and variable attributes. For example,
to retrieve the coefficient for variable
x in objective ,
you'd set the
ObjNumber parameter to , then query the
ObjN attribute for
querying the ObjNName attribute after
ObjNumber to would give the name of objective .
We should note that there is one important exception to our statement
above that the order of objectives is arbitrary: objective is
treated as the primary objective. One consequence is that the
original objective automatically becomes objective when you add a
second objective. Another is that querying the
is equivalent to querying the Obj attribute
ObjNumber is .
Note that a model has a single objective sense (controlled by the ModelSense attribute). This means that you can't maximize the first objective and minimize the second. However, you can achieve the same result with a simple trick. Each objective has a weight, and these weights are allowed to be negative. Minimizing an objective function is equivalent to maximizing the negation of that function.
You can change the number of objectives in your model as many times as you like (by modifying the NumObj attribute). When you increase the objective count, the new objectives and their associated attributes are set to 0. When you decrease the count, objectives beyond the new count are discarded. If you set the number of objectives to zero, the model becomes a pure feasibility problem.
We have extended the LP and MPS file formats, so writing a model with multiple objectives to a file will capture those objectives. Similarly, if you read a model file that contains multiple objectives, then NumObj and ObjN will capture the objectives stored in the file. See the file format section for details.