Records
Records group Mosel objects of different types. They may be used, for instance, to structure the data of a large-scale model by collecting all information relating to the same object.
Defining records
The definition of a record has some similarities with the declarations block: it starts with the keyword record, followed by a list of field names and types, and the keyword end-record marks the end of the definition. The definition of records must be placed in a declarations block. The following code extract defines a record with two fields (`name' and `values').
declarations R = 1..10 D: record name: string values: array(R) of real end-record end-declarations
We need to define a name (e.g., `mydata') for the record if we want to be able to refer to it elsewhere in the model—note that we declare this record as public in order to make all its fields public (so in particular, visible in output display), alternatively, individual fields can be declared as public. For example:
declarations R = 1..10 mydata = public record name: string values: array(R) of real end-record D: mydata A: array(range) of mydata end-declarations
The fields of a record are accessed by appending .fieldname to the record, for instance:
D.name:= "D" forall(i in R) D.values(i):= i writeln("Values of ", D.name, ": ", D.values) writeln("An entry of A: ", A(1)) writeln("'name' of an entry of A: ", A(4).name) writeln("'values' of an entry of A: ", A(3).values) writeln("First entry of 'values': ", A(3).values(1))
Note: if a record field is an array, the index set(s) of the array must be either constant or be declared outside of the record definition. So, these are valid record definitions:
declarations R: range P: record values: array(R) of real end-record Q: record values: array(1..10) of real end-record end-declarations
whereas this form can not be used:
Q: record values: array(range) of real end-record
Initialization of records from file
The contents of a record may be assigned fieldwise within a model as shown above or else be read in from file using initializations. The data file must contain the data entries for the different record fields in their order of occurrence in the record definition. An array A of the record type mydata defined in the previous section is initialized with data from file in the obvious way (model recorddef.mos):
declarations A: dynamic array(T:range) of mydata end-declarations initializations from "recorddef.dat" A end-initializations writeln(A(1)) forall(i in T | exists(A(i))) writeln(A(i).name)
If the data file recorddef.dat has these contents:
A: [(1) ['A1' [(2) 2 (3) 3 (4) 4] ] (3) ['A3' [(3) 6 (6) 9] ] (4) ['A4' [5 6 7 8] ] (7) ['A7'] ! Define just the first field (6) [* [(6) 6] ] ! Skip the first field ]
we obtain the following output (the entry with index 6 is defined but has no name, which accounts for the empty line between 'A4' and 'A7'):
[name=`A1' values=[0,2,3,4,0,0,0,0,0,0]] A1 A3 A4 A7
An example of the use of records is the encoding of arcs and associated information such as for representing the network in Figure Network with costs on arcs.

Figure 10.2: Network with costs on arcs
A data file with the network data may look as follows (file arcs.dat):
ARC: [(1) ["A" "B" 2] (2) ["A" "D" 4] (3) ["A" "C" 7] (4) ["B" "F" 4] (5) ["B" "D" 3] (6) ["C" "B" 5] (7) ["C" "D" 1] (8) ["C" "E" 1] (9) ["D" "F" 2] (10) ["D" "E" 5] (11) ["E" "F" 8] ]
We may then write our model arcs.mos thus
model "Arcs" declarations NODES: set of string ! Set of nodes ARC: array(ARCSET:range) of record ! Arcs: Source,Sink: string ! Source and sink of arc Cost: real ! Cost coefficient end-record end-declarations initializations from 'arcs.dat' ARC end-initializations ! Calculate the set of nodes NODES:=union(a in ARCSET) {ARC(a).Source, ARC(a).Sink} writeln(NODES) writeln("Average arc cost: ", sum(a in ARCSET) ARC(a).Cost / getsize(ARCSET) ) end-model
The record definition may contain additional fields (e.g., decision variables) that are not to be initialized from file. In this case we need to specify in the initializations block which record fields are to be filled with data.
declarations NODES: set of string ! Set of nodes ARC: array(ARCSET:range) of record ! Arcs: flow: mpvar ! Flow quantity Source,Sink: string ! Source and sink of arc Cost: real ! Cost coefficient end-record end-declarations initializations from 'arcs.dat' ARC(Source,Sink,Cost) end-initializations
This functionality can also be used to read separately, and possibly from different sources, the contents of the record fields. For instance, the 'Cost' field of our record ARC could be initialized as follows:
initializations from 'arcs.dat' ARC(Cost) as "COST" end-initializations
where the data array 'COST' is given as
COST: [(1) 2 (2) 4 (3) 7 (4) 4 (5) 3 (6) 5 (7) 1 (8) 1 (9) 2 (10) 5 (11) 8]
© 2001-2019 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.