12.07.2015 Views

ILOG OPL Development Studio Language Reference Manual

ILOG OPL Development Studio Language Reference Manual

ILOG OPL Development Studio Language Reference Manual

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

As generic arrays<strong>OPL</strong> also supports generic arrays, that is, arrays whose items are initialized by an expression.These generic arrays may significantly simplify the modeling of an application. The declaration:int a[i in 1..10] = i+1;declares an array of 10 elements such that the value of a[i] is i+1. Generic arrays can ofcourse be multidimensional, as in:int m[i in 0..10][j in 0..10] = 10*i + j;which initializes element m[i][j] to 10*i + j. Generic arrays are useful in performingsome simple transformations. For instance, generic arrays can be used to transpose matricesin a simple way, as in:int m[Dim1][Dim2] = ...;int t[j in Dim2][i in Dim1] = m[i][j];More generally speaking, generic arrays can be used to permute the indices of arrays in simpleways.As generic indexed arraysTo have more flexibility when initializing arrays in a generic way, <strong>OPL</strong> enables you to controlthe index value in addition to the item value, as described earlier in As generic arrays. Toillustrate the syntax, the same examples can be expressed as follows:int a[1..10] = [ i-1 : i | i in 2..11 ];int m[0..10][0..10] = [ i : [ j : 10*i+j ] | i,j in 0..10 ];This syntax is close to the syntax used for initializing arrays in .dat files by means of indices,delimited by #[ and ] #, as explained in Specifying pairs. Using this syntax is an efficientmeans of initializing arrays used to index data.The oilDB.mod example contains an execute block that performs initialization. Insteadof:GasType gas[Gasolines];execute {for(var g in gasData) {gas[g.name] = g44I L O G O P L D E V E L O P M E N T S T U D I O L A N G U A G ER E F E R E N C E M A N U A L

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!