Initializing arrays
The recommended method is to use a generic indexed array.
In most cases, the recommended method for indexing a set
of data within an array is to use a generic indexed array, as shown
in the example transp4.mod.
Initializing data within a generic indexed array (transp4.mod)
float Cost[Routes] = [ <t.p,<t.o,t.d>>:t.cost | t in TableRoutes ];
Alternatively, you can use IBM® ILOG Script and write an execute block,
as shown in the following example.
Initializing data within an execute block
float Cost[Routes];
execute INITIALIZE {
for( var t in TableRoutes ) {
Cost[Routes.get(t.p,Connections.get(t.o,t.d))] = t.cost;
}
}
The get method throws an exception
on non-existing tuples to allow you to use the result directly and
continue processing instead of checking for non-null values.
Note:
You don't need to initialize your array elements to zero as OPL does that for you by default.