Decision variables

Shows how to declare and use decision variables in the OPL language.

A decision variable is an unknown in an optimization problem. It has a domain, which is a compact representation of the set of all possible values for the variable. Decision variable types are references to objects whose exact nature depends on the underlying optimizer of a model. A decision variable can be instantiated only in the context of a given model instance.

The purpose of an OPL model is to find values for the decision variables such that all constraints are satisfied or, in optimization problems, to find values for the variables that satisfy all constraints and optimize a specific objective function. Variables in OPL are thus essentially decision variables and differ fundamentally from variables in programming languages such as Java, and ILOG Script.

Note:

OPL decision variables are noted with the dvar keyword while the keyword var denotes ILOG Script variables.

A decision variable declaration in OPL specifies the type and set of possible values for the variable. Once again, decision variables can be of different types (integer, float) and it is possible to define multidimensional arrays of decision variables. The declaration


dvar int transp[Orig][Dest] in 0..100; 

declares a two-dimensional array of integer variables. The decision variables are constrained to take their values in the range 0..100 ; i.e., any solution to the model containing this declaration must assign values between 0 and 100 to these variables. Note that all integer variables need a finite range in OPL. Arrays of decision variables can be constructed using the same index sets as arrays of data. In particular, it is also possible, and desirable for larger problems, to index arrays of decision variables by finite sets. For example, the excerpt:


tuple Route {
     City orig; 
     City dest
} 
{Route} routes = ...; 
dvar int transp[routes] in 0..100; 

declares an array of decision variables transp that is indexed by the finite set of tuples routes. Genericity can be used to initialize the domain of the variables. For example, the excerpt:


tuple Route { 
       City orig; 
       City dest; 
}
{Route} routes = ...; 
int capacity[routes] = ...; 
dvar int transp[r in routes] in 0..capacity[r]; 

declares an array of decision variables indexed by the finite set routes such that variable transp[r] ranges over 0..capacity[r]. The array capacity is also indexed by the finite set routes. Note that decision variables can be declared to range over a user-defined range. For example, the excerpt:


range Capacity = 0..limitCapacity; 
dvar int transp[Orig][Dest] in Capacity; 

declares an array of integer variables ranging over Capacity.

Decision variables can of course be declared individually, as in:


dvar int averageDelay in 0..maxDelay; 

For convenience, OPL proposes the types float+, int+ and boolean to define the domain of a decision variable. The declarations


dvar int+ x; // non negative integer decision variable
dvar float+ y; // non-negative decision variable
dvar boolean z; // boolean decision variable

are therefore equivalent to


dvar int x in 0..maxint;
dvar float y in 0..infinity;
dvar int z in 0..1;

Decision variables in an array can be assigned item-specific ranges, as in


dvar float transp[o in Orig][d in Dest] in 0..cap[o][d]; 

which declares a two-dimensional array of float variables, where variable transp[o][d] ranges over the set 0..cap[o][d].