Preprocessing of data
Provides an overview of preprocessing operations in OPL.
You can preprocess data before the optimization model is created
by using IBM ILOG Script/JavaScript syntax encapsulated in execute blocks.
OPL provides script integration with the modeling language. All declared model elements are available for scripting via their name.
The functionality available for an element depends on its type.
All elements can be read, but modifications are possible only for
primitive types (int, float, string)
and primitive items of arrays and tuples. See the intro to the Reference Manual of IBM ILOG Script
Extensions for OPL about these limitations.
You can change the domain boundaries for decision variables, as well as their priority, in the preprocessing phase.
You can also use preprocessing to change CPLEX or CP Optimizer parameter settings (see Changing option values in the Language User’s Manual).
Elements of a range or constraint type are immutable.
Example:
int n = ...;
range R = 1..n;
int A[R] = ...
execute {
for(r in R) {
if ( A[r]<0 ) {
A[r] = 0;
}
}
}
Initialization and processing order
Preprocessing items are processed according to their category, not in absolute declaration order.
Within categories, the order is:
-
External data, in the order in which the data sources are added to the OPL model
-
All
executeblocks andassertstatements, in declaration order
Internal data is initialized as encountered during external data initialization, in execute blocks and in assert statements. The following examples use internal data.
If you write:
{int} s1={1,2};
{int} s2={ i | i in s1};
execute
{
writeln(s2);
s1.add(3);
writeln(s1,s2);
}
the result is:
{1 2}
{1 2 3} {1 2}
whereas if you write:
{int} s1={1,2};
{int} s2={ i | i in s1};
execute
{
//writeln(s2);
s1.add(3);
writeln(s1,s2);
}
the result is:
{1 2 3} {1 2 3}
The order in which you use the internal data is important. The order in which you use external data is not important because it is all created, or initiated, at the beginning of the run.
See also Pitfall of lazy initialization of data.
Use the profiler feature to inspect the instantiation sequence of your model. See Profiling the execution of a model in IDE Tutorials.
See IBM ILOG Script for OPL for details on the scripting language and its extensions for OPL.
Lazy initialization
It is important to be aware that, during processing, declared data elements are initialized on demand when referenced for the first time.