Skip to main content
FRAMES NO FRAMES

Class IloObjective

Definition file: ilconcert/ilolinear.h
Map of IloObjectiveIloObjectiveIloObjectiveIloExtractable
An instance of this class is an objective in a model.

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:

Method Summary
public IloNumgetConstant() const
public IloNumExprArggetExpr() const
public IloObjectiveI *getImpl() const
public IloExpr::LinearIteratorgetLinearIterator() const
public IloExpr::QuadIteratorgetQuadIterator() const
public IloObjective::SensegetSense() 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 IloAddValueToObjoperator()(IloNum value)
public IloAddValueToObjoperator()()
public voidsetConstant(IloNum constant)
public voidsetExpr(const IloNumExprArg)
public voidsetLinearCoef(const IloNumVar var, IloNum value)
public voidsetLinearCoefs(const IloNumVarArray vars, const IloNumArray values)
public voidsetQuadCoef(const IloNumVar var1, const IloNumVar var2, IloNum value)
public voidsetSense(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

IloObjective

public IloObjective()
This constructor creates an empty handle. You must initialize it before you use it.

IloObjective

public IloObjective(IloObjectiveI * impl)
This constructor creates a handle object from a pointer to an implementation object.

IloObjective

public IloObjective(const IloEnv env, IloNum constant=0.0, IloObjective::Sense sense=Minimize, const char * name=0)

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.


IloObjective

public IloObjective(const IloEnv env, const IloNumExprArg expr, IloObjective::Sense sense=Minimize, const char * name=0)

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.

Note
When it accepts an expression as an argument, this constructor checks the setting of IloEnv::setNormalizer to determine whether to assume the expression has already been reduced or to reduce the expression before using it.

IloObjective

public IloObjective(const IloEnv env, IloMultiCriterionExpr moExpr, IloObjective::Sense sense, const char * name=0)

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.


getConstant

public IloNum getConstant() const

This member function returns the constant term from the expression of the invoking objective.


getExpr

public IloNumExprArg getExpr() const

This member function returns the expression of the invoking IloObjective object.


getImpl

public IloObjectiveI * getImpl() const
This member function returns a pointer to the implementation object of the invoking handle.

getLinearIterator

public IloExpr::LinearIterator getLinearIterator() const

This member function creates and returns an iterator to traverse linear expressions in the invoking objective.


getQuadIterator

public IloExpr::QuadIterator getQuadIterator() const

This member function creates and returns an iterator to traverse quadratic expressions in the invoking objective.


getSense

public IloObjective::Sense getSense() const

This member function returns the sense of the invoking objective, specifying whether the objective is a minimization (Minimize) or a maximization (Maximize).


operator()

public IloAddValueToObj operator()(IloNum value)

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.


operator()

public IloAddValueToObj operator()()

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.


setConstant

public void setConstant(IloNum constant)

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.

Note
The member function setConstant notifies Concert Technology algorithms about this change of this invoking object.

setExpr

public void setExpr(const IloNumExprArg)

This member function sets the expression of the invoking IloObjective object.

Note
The member function setExpr notifies Concert Technology algorithms about this change of this invoking object.

setLinearCoef

public void setLinearCoef(const IloNumVar var, IloNum value)

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.

Note
The member function 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.


setLinearCoefs

public void setLinearCoefs(const IloNumVarArray vars, const IloNumArray values)

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.

Note
The member function 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.


setQuadCoef

public void setQuadCoef(const IloNumVar var1, const IloNumVar var2, IloNum value)

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.

Note
The member function 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.


setSense

public void setSense(IloObjective::Sense sense)

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.

Note
The member function setSense notifies Concert Technology algorithms about this change of this invoking object.

Inner Enumeration Detail

Enumeration Sense

Definition file: ilconcert/ilolinear.h
Specifies objective as minimization or maximization.

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