Overview | Group | Tree | Graph | Index | Concepts |
An instance of this class represents an expression in a model. An
instance of IloExpr
is a handle.
Expressions in Environments
The variables in an expression must all belong to the same environment as the expression itself. In other words, you must not mix variables from different environments within the same expression.
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.
Programming Hint: Creating Expressions
In addition to using a constructor of this class to create an expression,
you may also initialize an instance of IloExpr
as a C++
expression built from variables of a model. For example:
IloNumVar x; IloNumVar y; IloExpr expr = x + y;
Programming Hint: Empty Handles and Null Expressions
This statement creates an empty handle:
IloExpr e1;
You must initialize it before you use it. For example, if you attempt to use it in this way:
e1 += 10; // BAD IDEA
Without the compiler option -DNDEBUG
, that line will cause
an assert
statement to fail because you are attempting to use
an empty handle.
In contrast, the following statement
IloExpr e2(env);
creates a handle to a null expression. You can use this handle to build up an expression, for example, in this way:
e2 += 10; // OK
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 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 expressions from your application.
In one mode, Concert Technology analyzes linear expressions that your
application passes it and attempts to reduce them so that a given variable
appears in only one term in the linear expression. This is the default
mode. You set this mode with the member function IloEnv::setNormalizer(IloTrue)
.
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 normalized linear
expressions. You set this mode with the member function IloEnv::setNormalizer(IloFalse)
.
Certain constructors and member functions in this class check this
setting in the environment and behave accordingly: they assume that no
variable appears in more than one term in a linear expression. This mode may
save time during computation, but it entails the risk that a linear
expression may contain one or more variables, each of which appears in one
or more terms. Such a case may cause certain assertions in member functions
of this class to fail if you do not compile with the flag
-DNDEBUG
.
Certain constructors and member functions in this class check this setting in the environment and behave accordingly: they attempt to reduce expressions. This mode may require more time during preliminary computation, but it avoids of the possibility of a failed assertion in case of duplicates.
See Also:
Constructor Summary | |
---|---|
public | IloExpr() |
public | IloExpr(IloNumExprI *) |
public | IloExpr(const IloNumLinExprTerm) |
public | IloExpr(const IloIntLinExprTerm) |
public | IloExpr(IloNumExprArg) |
public | IloExpr(const IloEnv, IloNum) |
Method Summary | |
---|---|
public IloNum | getConstant() |
public IloNumLinTermI * | getImpl() |
public IloExpr::LinearIterator | getLinearIterator() |
public IloBool | isNormalized() |
public IloInt | normalize() |
public IloExpr & | operator *=(IloNum) |
public IloExpr & | operator+=(const IloIntLinExprTerm) |
public IloExpr & | operator+=(const IloNumLinExprTerm) |
public IloExpr & | operator+=(const IloIntVar) |
public IloExpr & | operator+=(const IloNumVar) |
public IloExpr & | operator+=(const IloNumExprArg) |
public IloExpr & | operator+=(IloNum) |
public IloExpr & | operator-=(const IloIntLinExprTerm) |
public IloExpr & | operator-=(const IloNumLinExprTerm) |
public IloExpr & | operator-=(const IloIntVar) |
public IloExpr & | operator-=(const IloNumVar) |
public IloExpr & | operator-=(const IloNumExprArg) |
public IloExpr & | operator-=(IloNum) |
public IloExpr & | operator/=(IloNum) |
public void | remove(const IloNumVarArray) |
public void | setConstant(IloNum) |
public void | setLinearCoef(const IloNumVar, IloNum) |
public void | setLinearCoefs(const IloNumVarArray, IloNumArray) |
public void | setNumConstant(IloNum) |
Inherited Methods from IloNumExpr |
---|
getImpl, operator *=, operator+=, operator+=, operator-=, operator-=, operator/= |
Inherited Methods from IloNumExprArg |
---|
getImpl |
Inherited Methods from IloExtractable |
---|
end, getEnv, getId, getImpl, getName, getObject, setName, setObject |
Inner Class | |
---|---|
IloExpr::LinearIterator | An iterator over the linear part of an expression. |
Constructor Detail |
---|
This constructor creates an empty handle. You must initialize it before you use it.
This constructor creates an expression from a pointer to the implementation class
of numeric expressions IloNumExprI*
.
This constructor creates an integer expression with linear terms using the
undocumented class IloNumLinExprTerm
.
This constructor creates an integer expression with linear terms using the
undocumented class IloIntLinExprTerm
.
This constructor creates an expression using the undocumented class
IloNumExprArg
.
This constructor creates an expression in the environment indicated by
env
. It may be used to build other expressions from variables
belonging to env
. You must not mix variables of different
environments within an expression.
Method Detail |
---|
This member function returns the constant term in the invoking expression.
This member function returns the implementation object of the invoking enumerated variable.
This methods returns a linear iterator on the invoking expression.
This member function returns IloTrue
if the invoking expression
has been normalized using IloExpr::normalize
.
This member function normalizes the invoking linear expression. Normalizing is sometimes known as reducing the terms of a linear expression. That is, if there is more than one linear term using the same variable in the invoking linear expression, then this member function merges those linear terms into a single term expressed in that variable. The return value indicates the number of merged terms.
For example, 1*x + 17*y - 3*x
becomes 17*y - 2*x
,
and the member function returns 1 (one).
If you attempt to use this member function on a nonlinear expression, it throws an exception.
This operator is recommended for building a Concert Technology expression
in a loop. It is more efficient than x = x * ...
This operator is recommended for building a Concert Technology expression
in a loop. It is more efficient than x = x + ...
This operator is recommended for building a Concert Technology expression
in a loop. It is more efficient than x = x + ...
This operator is recommended for building a Concert Technology expression
in a loop. It is more efficient than x = x + ...
This operator is recommended for building a Concert Technology expression
in a loop. It is more efficient than x = x + ...
This operator is recommended for building a Concert Technology expression
in a loop. It is more efficient than x = x + ...
This operator is recommended for building a Concert Technology expression
in a loop. It is more efficient than x = x + ...
This operator is recommended for building a Concert Technology expression
in a loop. It is more efficient than x = x - ...
This operator is recommended for building a Concert Technology expression
in a loop. It is more efficient than x = x - ...
This operator is recommended for building a Concert Technology expression
in a loop. It is more efficient than x = x - ...
This operator is recommended for building a Concert Technology expression
in a loop. It is more efficient than x = x - ...
This operator is recommended for building a Concert Technology expression
in a loop. It is more efficient than x = x - ...
This operator is recommended for building a Concert Technology expression
in a loop. It is more efficient than x = x - ...
This operator is recommended for building a Concert Technology expression
in a loop. It is more efficient than x = x / ...
This member function removes all occurrences of all variables listed in
the array vars
from the invoking expression. For linear
expressions, the effect of this member function is equivalent to setting the
coefficient for all the variables listed in vars
to 0 (zero).
This member function assigns cst
as the constant term in the
invoking expression.
This member function assigns value
as the coefficient of
var
in the invoking expression if the invoking expression is
linear. This member function applies only to linear expressions. In other
words, you can not use this member function to change the coefficient of a
non linear expression. An attempt to do so will cause Concert Technology to
throw an exception.
For each of the variables in vars
, this member function
assigns the corresponding value of values
as its linear
coefficient if the invoking expression is linear. This member function
applies only to linear expressions. In other words, you can not use this
member function to change the coefficient of a nonlinear expression. An
attempt to do so will cause Concert Technology to throw an exception.
This member function assigns cst
as the constant term in the
invoking expression.