LINGO allows the user to isolate data within the data section of the model. In our Wireless Widget example, we have the following data section:

DATA:

  !set members;

  WAREHOUSES = WH1 WH2 WH3 WH4 WH5 WH6;

  VENDORS = V1 V2 V3 V4 V5 V6 V7 V8;

 

  !attribute values;

  CAPACITY = 60 55 51 43 41 52;

  DEMAND = 35 37 22 32 41 32 43 38;

  COST = 6 2 6 7 4 2 5 9

         4 9 5 3 8 5 8 2

         5 2 1 9 7 4 3 3

         7 6 7 3 9 2 7 1

         2 3 9 5 7 2 6 5

         5 5 2 2 8 1 4 3;

ENDDATA

The data section begins with the keyword DATA: on a line by itself and ends with ENDDATA on a line by itself.

Next, we input the list of warehouses and vendors.  Had we preferred, we could have also used the following shorthand notation to the same end:

!set members;

WAREHOUSES = WH1..WH6;

VENDORS = V1..V8;

LINGO interprets the double-dots to mean that it should internally generate the six warehouses and eight vendors.

Both the CAPACITY attribute of the set WAREHOUSES and DEMAND attribute of the set VENDORS are initialized in a straightforward manner. The COST attribute of the two-dimensional set LINKS is a little bit trickier, however. When LINGO is initializing a multidimensional array in a data section, it increments the outer index the fastest. Thus, in this particular example, COST( WH1, V1) is initialized first, followed by COST( WH1, V2) through COST (WH1, V8). Then, the next one to be initialized with be COST(WH2, V1), and so on.

In this particular example, we have isolated all the model’s data within a single data section.  Given that the data is the most likely feature to change from one run of a model to the next, isolating data, as we have done here, makes modifications considerably easier.  Contrast this to how difficult it would be to track down and change the data in a large, scalar model where data is spread throughout all the constraints of the model.

In order to facilitate data management further, LINGO has the ability to import data from external sources. More specifically, a LINGO model can import data from external text files, establish real-time OLE links to Excel, and/or create ODBC links to databases.

Putting together the data section, the sets section, the objective, and the constraints, the completed model is as follows:

MODEL:

! A 6 Warehouse 8 Vendor Transportation Problem;

SETS:

  WAREHOUSES: CAPACITY;

  VENDORS: DEMAND;

  LINKS( WAREHOUSES, VENDORS): COST, VOLUME;

ENDSETS

! Here is the data;

DATA:

  !set members;

  WAREHOUSES = WH1 WH2 WH3 WH4 WH5 WH6;

  VENDORS = V1 V2 V3 V4 V5 V6 V7 V8;

 

  !attribute values;

  CAPACITY = 60 55 51 43 41 52;

  DEMAND = 35 37 22 32 41 32 43 38;

  COST = 6 2 6 7 4 2 5 9

         4 9 5 3 8 5 8 2

         5 2 1 9 7 4 3 3

         7 6 7 3 9 2 7 1

         2 3 9 5 7 2 6 5

         5 5 2 2 8 1 4 3;

ENDDATA

! The objective;

  MIN = @SUM( LINKS( I, J):

   COST( I, J) * VOLUME( I, J));

! The demand constraints;

  @FOR( VENDORS( J):

   @SUM( WAREHOUSES( I): VOLUME( I, J)) =

    DEMAND( J));

! The capacity constraints;

  @FOR( WAREHOUSES( I):

   @SUM( VENDORS( J): VOLUME( I, J)) <=

    CAPACITY( I));

END

Model: WIDGETS

Note that we have again added comments to improve the readability of the model. The model is named WIDGETS, and can be found in the SAMPLES subdirectory off the main LINGO directory.