dexpr
OPL keyword to express decision variables.
Purpose
OPL keyword to express decision variables in a more compact way.
context |
---|
Model files (.mod) |
Syntax
LocalVar: Type VariableDeclarator | "dvar" Type VariableDeclarator DecisionVarRange_opt | "dexpr" Type VariableDeclarator "=" Expression | Type VariableDeclarator "=" Expression | Type VariableDeclarator "=" "..."
Description
Use this keyword to express decision variables in a more compact way. This keyword modifies the number of variables, constraints, and nonzeros at execution time and, therefore, affects both the solving time and the memory consumption.
Using dexpr
is
particularly recommended to write objectives to be used with ODM Enterprise.
See the documentation for ODM Enterprise.
In constraint programming
models, you can use the dexpr
keyword to declare
floating point expressions. (The CP Optimizer engine supports only
integer decision variables.)
Manipulation of dexpr
may
lead to slower performance than direct manipulation of dvar
.
For example, adding dexpr
to a set of int
in
post-processing causes slower performance than adding dvar
to
a set of int
.
Example 1
Compare the following two code extracts.
Without dexpr | With dexpr | |
---|---|---|
|
|
|
Effect | 7 constraints 5 variables 14 non zeros |
5 constraints 3 variables 9 non zeros |
Example 2
using CP;
dvar int i in 1..100;
dvar int j in 1..100;
dvar int k in 1..99;
dexpr float kf = k/100;
dexpr float ar[l in 1..10] = k/l;
minimize kf + sum(l in 1..10)ar[l];
constraints {
i*(1+kf) == j;
}