The Data Section of a Model
The data section allows you to isolate data from the rest of your model. This is a useful practice in that it facilitates model maintenance and scaling of a model’s dimensions.
The data section begins with the keyword DATA: (including the colon) and ends with the keyword ENDDATA. In the data section, you can have statements to initialize set members and/or the attributes of the sets you declared in a previous sets section. These expressions have the syntax:
object_list = value_list;
The object_list contains the names of the attributes and/or a set whose members you want to initialize, optionally separated by commas. There can be no more than one set name in object_list, while there may be any number of attributes. If there is more than one attribute name in object_list, then the attributes must be defined on the same set. If there is a set name in object_list, then all attributes in object_list must be defined on this set.
The value_list contains the values you want to assign to the members of object_list, optionally separated by commas. As an example, consider the following model:
SETS:
SET1 /A, B, C/: X, Y;
ENDSETS
DATA:
X = 1, 2, 3;
Y = 4, 5, 6;
ENDDATA
We have two attributes, X and Y, defined on the SET1 set. The three values of X are set to 1, 2, and 3, while Y is set to 4, 5, and 6. We could have also used the following compound data statement to the same end:
SETS:
SET1 /A, B, C/: X, Y;
ENDSETS
DATA:
X, Y =
1, 4,
2, 5,
3, 6;
ENDDATA
Looking at this example, you might imagine X would be assigned the values 1, 4, and 2 because they are first in the values list, rather than the true values of 1, 2, and 3. When LINGO reads a data statement's value list, it assigns the first n values to the first position of each of the n attributes in the attribute list, the second n values to the second position of each of the n attributes, and so on. In other words, LINGO is expecting the input data in column form rather than row form.
As mentioned, we can also initialize the set members in the data section. Modifying our sample model to use this approach by moving the set members from the sets section to the data section we get:
SETS:
SET1: X, Y;
ENDSETS
DATA:
SET1, X, Y =
A 1 4
B 2 5
C 3 6;
ENDDATA
This final method is, perhaps, the most elegant in that all model data-attribute values and set members-are isolated within the data section.