NO FRAMES

Class IloObjective

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

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.

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 ILOG CPLEX Reference Manual, extracts the objective.

Multiple Objectives

You may create more than one objective in a model, for example, by creating more than one group. 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 objective 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:

Constructor Summary
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)
Method Summary
public IloNumgetConstant() const
public IloNumExprArggetExpr() const
public IloObjectiveI *getImpl() const
public IloObjective::SensegetSense() const
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 voidsetSense(IloObjective::Sense sense)
Inherited Methods from IloExtractable
asConstraint, asIntExpr, asModel, asNumExpr, asObjective, asVariable, end, getEnv, getId, getImpl, getName, getObject, isConstraint, isIntExpr, isModel, isNumExpr, isObjective, isVariable, setName, setObject
Inner Enumeration
IloObjective::Sense Specifies objective as minimization or maximization.
Constructor 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.

Method Detail

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.

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 for an explanation of how to use this operator in column-wise modeling.


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 for an explanation of how to use this operator in column-wise modeling.


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.


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.


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
Maximize