Initializing lists
Lists are not commonly used in the standard formulation of Mathematical Programming problems. However, this data structure may be useful for the Mosel implementation of some more advanced solving and programming tasks.
Constant list
If the contents of a list are specified at the declaration of the list, such as
declarations L = [1,2,3,4,5,6,7,8,9,10] end-declarations
we have defined a constant list (its contents cannot be changed). If we want to be able to modify the list contents subsequently we need to separate the definition of the list contents from the declaration, resulting in a dynamic list:
declarations L: list of integer end-declarations L:= [1,2,3,4,5,6,7,8,9,10]
A two-dimensional array of lists may be defined thus (and higher dimensional arrays by analogy):
declarations M: array(range,set of integer) of list of string end-declarations M:: (2..4,1)[['A','B','C'], ['D','E'], ['F','G','H','I']]
List initialization from file
Similarly to what we have already seen for other data structures, the contents of lists may be initialized from file through initializations blocks. For example,
declarations K: list of integer N: array(range,set of integer) of list of string end-declarations initializations from "listinit.dat" K N end-initializations writeln("K: ", K) writeln("An entry of N: ", N(5,3))
Assuming the datafile listinit.dat contains these lines
K: [5 4 3 2 1 1 2 3 4 5] N: [(3 1) ['B' 'C' 'A'] (5 3) ['D' 'E'] (6 1) ['H' 'I' 'F' 'G']]
we obtain the following output from the model fragment above:
K: [5,4,3,2,1,1,2,3,4,5] An entry of N: [`D',`E']