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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

ArraysArrays are fundamental in many applications.One-dimensional arraysOne-dimensional arrays are the simplest arrays in <strong>OPL</strong> and vary according to the type of theirelements and index sets. A declaration of the formint a[1..4] = [10, 20, 30, 40];declares an array of four integers a[1],...,a[4] whose values are 10, 20, 30, and 40.It is of course possible to define arrays of other basic types. For instance, the instructionsint a[1..4] = [10, 20, 30, 40];float f[1..4] = [1.2, 2.3, 3.4, 4.5];string d[1..2] = [“Monday”, “Wednesday”];declare arrays of natural numbers, floats, and strings, respectively.The index sets of arrays in <strong>OPL</strong> are very general and can be integer ranges and arbitrary finitesets. In the examples so far, index sets were given explicitly, but it is possible to use apreviously defined range, as inrange R = 1..4;int a[R] = [10, 20, 30, 40];The declaration:int a[Days] = [10, 20, 30, 40, 50, 60, 70];describes an array indexed by a set of strings; its elements are a[“Monday”],...,a[“Sunday”].Arrays can also be indexed by finite sets of arbitrary types. This feature is fundamental in<strong>OPL</strong> to exploit sparsity in large linear programming applications, as discussed in detail inExploiting sparsity in the <strong>Language</strong> User’s <strong>Manual</strong>.For example, the declaration:tuple Edges {int orig;int dest;}24I 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!