The Data Section

Typically, you will want to initialize the members of certain sets and assign values to certain set attributes. For this purpose, LINGO uses a second optional section called the data section. The data section allows you to isolate data from the equations of your model. This is a useful practice in that it leads to easier model maintenance and facilitates scaling up a model to larger dimensions.

Similar to the sets section, 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 the sets and/or attributes you defined in a sets section. These expressions have the syntax:

object_list = value_list;

The object_list contains the names of a set and/or attributes you want to initialize, optionally separated by commas. If there is more than one attribute name on in the object list, then all attributes must be defined on the same set. Furthermore, if a set name appears in the object list, then it must be the parent set of any attributes also in the object list. The value_list contains the values to assign to the objects in the object list, optionally separated by commas. For example, consider the following model:

MODEL:

SETS:

  SET1: X, Y;

ENDSETS

DATA:

  SET1 = A B C;

  X = 1 2 3;

  Y = 4 5 6;

ENDDATA

END

We have two attributes, X and Y, defined on the set SET1. 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:

MODEL:

SETS:

  SET1: X, Y;

ENDSETS

DATA:

  SET1 X Y = A 1 4

             B 2 5

             C 3 6;

ENDDATA

END

An important fact to remember is that when LINGO reads a compound data statement's value list, it assigns the first n values in the list to the first position of each of the n objects in the object list, the second n values to the second position of each of the n objects, and so on. In other words, LINGO is expecting the input data in column format rather than row format, which mirrors the flat file approach used in relational databases.

This section has served to give you a brief introduction into the use of the data section. In Data and Init Sections, you will learn more about the capabilities of the data section. You will learn data does not have to actually reside in the data section as shown in examples here. In fact, your data section can have OLE links to Excel, ODBC links to databases, and connections to text based data files.