Overview | Group | Tree | Graph | Deprecated | Index | Concepts |
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
a failure at execution time 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:
Method Summary | |
---|---|
public void | clear() |
public IloNum | getConstant() const |
public IloNumLinTermI * | getImpl() const |
public IloExpr::LinearIterator | getLinearIterator() const |
public IloExpr::QuadIterator | getQuadIterator() const |
public | IloExpr() |
public | IloExpr(IloNumExprI * expr) |
public | IloExpr(const IloNumLinExprTerm term) |
public | IloExpr(const IloIntLinExprTerm term) |
public | IloExpr(const IloNumQuadExprTerm term) |
public | IloExpr(const IloIntQuadExprTerm term) |
public | IloExpr(IloNumExprArg) |
public | IloExpr(const IloEnv env, IloNum val=0) |
public IloBool | isNormalized() const |
public IloInt | normalize() const |
public IloExpr & | operator*=(IloNum val) |
public IloExpr & | operator+=(const IloIntQuadExprTerm term) |
public IloExpr & | operator+=(const IloNumQuadExprTerm term) |
public IloExpr & | operator+=(const IloIntLinExprTerm term) |
public IloExpr & | operator+=(const IloNumLinExprTerm term) |
public IloExpr & | operator+=(const IloIntVar var) |
public IloExpr & | operator+=(const IloNumVar var) |
public IloExpr & | operator+=(const IloNumExprArg expr) |
public IloExpr & | operator+=(IloNum val) |
public IloExpr & | operator-=(const IloIntQuadExprTerm term) |
public IloExpr & | operator-=(const IloNumQuadExprTerm term) |
public IloExpr & | operator-=(const IloIntLinExprTerm term) |
public IloExpr & | operator-=(const IloNumLinExprTerm term) |
public IloExpr & | operator-=(const IloIntVar var) |
public IloExpr & | operator-=(const IloNumVar var) |
public IloExpr & | operator-=(const IloNumExprArg expr) |
public IloExpr & | operator-=(IloNum val) |
public IloExpr & | operator/=(IloNum val) |
public void | remove(const IloNumVarArray vars) |
public void | setConstant(IloNum cst) |
public void | setLinearCoef(const IloNumVar var, IloNum value) |
public void | setLinearCoefs(const IloNumVarArray vars, IloNumArray values) |
public void | setNumConstant(IloNum constant) |
public void | setQuadCoef(const IloNumVar var1, const IloNumVar var2, IloNum value) |
Inherited Methods from IloNumExpr |
---|
getImpl, IloNumExpr, IloNumExpr, IloNumExpr, IloNumExpr, IloNumExpr, IloNumExpr, IloNumExpr, IloNumExpr, IloNumExpr, operator*=, operator+=, operator+=, operator-=, operator-=, operator/= |
Inherited Methods from IloNumExprArg |
---|
getImpl, IloNumExprArg, IloNumExprArg |
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 Class | |
---|---|
IloExpr::LinearIterator | An iterator over the linear part of an expression. |
IloExpr::QuadIterator | An iterator over quadratic terms in a linear expression. |
Method 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 a general numeric 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 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 initialized to the value
val
in the environment specified by env
.
This constructor may be used to build other expressions from variables
belonging to env
. You must not mix variables of different
environments within an expression.
This member function removes all terms from the invoking expression, leaving a 0 expression behind.
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 methods returns an iterator over the quadratic terms of 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 or quadratic expression. Normalizing is sometimes known as reducing the terms of an expression. Concert Technology will analyze the linear expressions and will attempt to reduce them so that a given variable appears in only one term in the linear expression.
If there is more than one linear term using the same variable in an invoking linear expression, this member function merges those linear terms into a single term expressed in that variable. For linear expressions, the return value specifies 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).
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 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.
This member function changes the coefficient of a pair of variables in a quadratic expression.