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.)

Note:

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
 
dvar int x in 0..20;
dvar int y in 0..20;
dvar int d;
dvar int s;
maximize (d);
   subject to
   {
      d==x-y;
      s==x+y;
      s<=15;
      s<=x-2*y;
      d>=2;
      d<=y+8;
      1<=d;
   }
dvar int x in 0..20;
dvar int y in 0..20;
dexpr int d=x-y;
dexpr int s=x+y;
maximize (d);
   subject to
   {
      s<=15;
      s<=x-2*y;
      d>=2;
      d<=y+8;
      1<=d;
}
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; 
}