Overview | Group | Tree | Graph | Deprecated | Index | Concepts |
An objective consists of its sense (specifying whether it is a minimization or maximization) and an expression. The expression may be a constant, a numeric expression or a multiple criteria expression.
An objective belongs to the environment that the variables in its expression belong to. Generally, you will create an objective, add it to a model, and extract the model for an algorithm.
Most member functions in this class contain
assert
statements. For an
explanation of the macro NDEBUG
(a way to turn on or turn off these
assert
statements), see the concept
Assert and NDEBUG.
What Is Extracted
All the variables (that is, instances of
IloNumVar
or one of its subclasses) in the
objective (an instance of IloObjective
)
will be extracted when an algorithm such as IloCplex
,
documented in the CPLEX C++ API Reference Manual,
extracts the objective.
Multiple Objectives
For some optimization problems, a single objective function is not sufficient:
several criteria are required to express precisely the problem. The different
criteria are generally contradictory and a tradeoff between the different criteria
must be found. Concert Technology allows the user to define a multi-criterion
objective, and to specify which kind of tradeoff between the criteria he wants.
Basically, a multi-criterion objective is constructed with 3 elements: an array of expressions
representing the different criteria, the sense of the optimization, specifying whether
the criteria are to be minimized or maximized, a policy to find the tradeoff between
the criteria. Concert Technology uses instances of the class IloMultiCriterionExpr
for regrouping the array of criteria and the tradeoff policy. An instance of
IloMultiCriterionExpr
is created by a function like IloStaticLex
and can be given as parameter to a function like IloMaximize
that specifies
the sense of optimization and build a multi-criterion objective.
Multicriteria objectives are available in both IloCP
and
IloCplex
.
You may create more than one objective in a model, for example,
using an IloMultiCriterionExpr
. However, certain
algorithms, such as an instance of IloCplex
, will throw an
exception (on a platform that supports C++ exceptions, when exceptions
are enabled) if you attempt to extract more than one
IloObjective
at a time.
Also see the functions IloMaximize
and
IloMinimize
for “short cuts” to create objectives.
Normalizing Linear Expressions: Reducing the Terms
Normalizing is sometimes known as reducing the terms of a linear expression.
Linear expressions consist of terms made up of constants and variables related by arithmetic operations; for example, x + 3y is a linear expression of two terms consisting of two variables. In some linear expressions, a given variable may appear in more than one term, for example, x + 3y +2x. Concert Technology has more than one way of dealing with linear expressions in this respect, and you control which way Concert Technology treats linear expressions from your application.
In one mode (the default mode), Concert Technology
analyzes expressions that your
application passes it and attempts to reduce them
so that a given variable appears in
only one term in the expression.
You set this mode with the member function
IloEnv::setNormalizer
.
Certain constructors and member functions in this class check this setting in the model and behave accordingly: they attempt to reduce expressions. This mode may require more time during preliminary computation, but it avoids the possibility of an assertion failing for certain member functions of this class in case of duplicates.
In the other mode, Concert Technology assumes
that no variable appears in more than
one term in any of the linear expressions
that your application passes to Concert
Technology. We call this mode assume no duplicates.
You set this mode with the member function
IloEnv::setNormalizer
.
Certain constructors and member functions in this class
check this setting in the model and behave accordingly:
they assume that no variable appears in more than one
term in an expression. This mode may save time during computation,
but it entails the risk that an expression may contain one or more
variables, each of which appears in one or more terms.
This situation will cause certain assert
statements in
Concert Technology to fail if you do not compile with the
flag -DNDEBUG
.
See Also:
IloMaximize, IloMinimize, IloModel, IloObjective::Sense
Method Summary | |
---|---|
public IloNum | getConstant() const |
public IloNumExprArg | getExpr() const |
public IloObjectiveI * | getImpl() const |
public IloExpr::LinearIterator | getLinearIterator() const |
public IloExpr::QuadIterator | getQuadIterator() const |
public IloObjective::Sense | getSense() const |
public | IloObjective() |
public | IloObjective(IloObjectiveI * impl) |
public | IloObjective(const IloEnv env, IloNum constant=0.0, IloObjective::Sense sense=Minimize, const char * name=0) |
public | IloObjective(const IloEnv env, const IloNumExprArg expr, IloObjective::Sense sense=Minimize, const char * name=0) |
public | IloObjective(const IloEnv env, IloMultiCriterionExpr moExpr, IloObjective::Sense sense, const char * name=0) |
public IloAddValueToObj | operator()(IloNum value) |
public IloAddValueToObj | operator()() |
public void | setConstant(IloNum constant) |
public void | setExpr(const IloNumExprArg) |
public void | setLinearCoef(const IloNumVar var, IloNum value) |
public void | setLinearCoefs(const IloNumVarArray vars, const IloNumArray values) |
public void | setQuadCoef(const IloNumVar var1, const IloNumVar var2, IloNum value) |
public void | setSense(IloObjective::Sense sense) |
Inherited Methods from IloExtractable |
---|
asConstraint, asIntExpr, asModel, asNumExpr, asObjective, asVariable, end, getEnv, getId, getImpl, getName, getObject, IloExtractable, isConstraint, isIntExpr, isModel, isNumExpr, isObjective, isVariable, removeFromAll, setLocation, setName, setObject |
Inner Enumeration | |
---|---|
IloObjective::Sense | Specifies objective as minimization or maximization. |
Method Detail |
---|
This constructor creates an objective
consisting of a constant
and
belonging to env
. The sense of the objective (whether it is a
minimization or maximization) is specified by sense
;
by default, it is a minimization.
You may supply a name
for the objective; by default, its
name
is the empty string.
This constructor is useful when you want to
create an empty objective and fill it later by column-wise modeling.
This constructor creates an objective to add to a model from
expr
.
After you create an objective from an expression with this constructor,
you must use the member function add
explicitly to add your
objective to your model or to a group in order for the objective to be taken
into account.
This constructor creates an objective to add to a model from
moExpr
.
After you create an objective from multiple criteria expressed as
an instance of IloMultiCriterionExpr with this constructor,
you must use the member function add
explicitly to add your
objective to your model or to a group in order for the objective to be taken
into account.
This member function returns the constant term from the expression of the invoking objective.
This member function returns the expression of the invoking
IloObjective
object.
This member function creates and returns an iterator to traverse linear expressions in the invoking objective.
This member function creates and returns an iterator to traverse quadratic expressions in the invoking objective.
This member function returns the sense of the invoking objective,
specifying whether the objective is a minimization (Minimize
)
or a maximization (Maximize
).
This casting operator uses a floating-point value
to create an
instance of IloAddNumVar
or one of its subclasses and to add that
value
to that instance. See the concept Column-Wise Modeling in CPLEX
for an explanation of how to use this operator in column-wise modeling.
Not for use with CP Optimizer.
This casting operator uses a floating-point value
to create an
instance of IloAddNumVar
or one of its subclasses and to add that
value
to that instance. If no argument is given, it assumes 1.0. See the
concept Column-Wise Modeling in CPLEX
for an explanation of how to use this operator in column-wise modeling.
Not for use with CP Optimizer.
This member function sets constant
as the constant term in the
invoking objective, and it creates the appropriate instance of the undocumented class
IloChange
to notify algorithms about this change of an extractable object
in the model.
setConstant
notifies Concert Technology algorithms
about this change of this invoking object.
This member function sets the expression of the invoking
IloObjective
object.
setExpr
notifies
Concert Technology algorithms
about this change of this invoking object.
This member function sets value
as the linear coefficient of the
variable var
in the invoking objective, and it creates the appropriate
instance of the undocumented class IloChange
to notify algorithms about
this change of an extractable object in the model.
setLinearCoef
notifies Concert Technology algorithms
about this change of this invoking object.
If you attempt to use setLinearCoef
on a nonlinear expression, it will
throw an exception on platforms that support C++ exceptions when exceptions are
enabled.
For each of the variables in vars
, this member function sets the
corresponding value of values
(whether integer or floating-point) as its
linear coefficient in the invoking objective, and it creates the appropriate instance
of the undocumented class IloChange
to notify algorithms about this
change of an extractable object in the model.
setLinearCoefs
notifies Concert Technology algorithms
about this change of this invoking object.
If you attempt to use setLinearCoef
on a non linear expression,
Concert Technology will throw an exception on platforms that support C++ exceptions
when exceptions are enabled.
This member function assigns value
as the quadratic coefficient of the
term var1*var2
in the invoking objective,
and it creates the appropriate
instance of the undocumented class IloChange
to notify algorithms about
this change of an extractable object in the model.
setQuadCoef
notifies Concert Technology algorithms
about this change of this invoking object.
If you attempt to use setQuadCoef
on a
general nonlinear expression, it will throw an
exception on platforms that support C++ exceptions when exceptions are
enabled.
This member function sets sense
to specify whether the invoking
objective is a maximization (Maximize
) or minimization
(Minimize
), and it creates the appropriate instance
of the undocumented
class IloChange
to notify algorithms
about this change of an extractable object in the model.
setSense
notifies Concert Technology algorithms about
this change of this invoking object.
Inner Enumeration Detail |
---|
An instance of the class IloObjective
represents an objective in a model. This nested enumeration is limited
in scope to that class, and its values specify the sense of an
objective; that is, whether it is a minimization
(Minimize
) or a maximization (Maximize
).
See Also:
Fields |
---|
Minimize = 1 | |
Maximize = -1 |