Defining Primitive Sets
To define a primitive set in a sets section, you specify:
• | the name of the set, |
• | optionally, its members (objects contained in the set), and |
• | optionally, any attributes the members of the set may have. |
A primitive set definition has the following syntax:
setname [/ member_list /] [: attribute_list];
Note: | The use of square brackets indicates an item is optional. In this particular case, a primitive set’s attribute_list and member_list are both optional. |
The setname is a name you choose to designate the set. It should be a descriptive name that is easy to remember. The set name must conform to standard LINGO naming conventions. In other words, the name must begin with an alphabetic character, which may be followed by up to 31 alphanumeric characters or the underscore (_). LINGO does not distinguish between upper and lowercase characters in names.
A member_list is a list of the members that constitute the set. If the set members are included in the set definition, they may be listed either explicitly or implicitly. If set members are not included in the set definition, then they may be defined subsequently in a data section of the model. For details on defining set members in a data section, refer to Introduction to the Data Section.
When listing members explicitly, you enter a unique name for each member, optionally separated by commas. As with set names, member names must also conform to standard naming conventions. In the Wireless Widgets model, we could have used an explicit member list to define the set WAREHOUSES in the sets section as follows:
WAREHOUSES / WH1 WH2 WH3 WH4 WH5 WH6/: CAPACITY;
When using implicit set member lists, you do not have to list a name for each set member. Use the following syntax when using an implicit set member list:
setname / member1..memberN / [: attribute_list];
where member1 is the name of the first member in the set and memberN is the name of the last member. LINGO automatically generates all the intermediate member names between member1 and memberN. While this can be a very compact and convenient method for building a primitive set, there is one catch in that only certain formats of names are accepted for the initial and terminal member names. The following table details the available options:
Implicit Member List Format |
Example |
Set Members |
1..n |
1..5 |
1, 2, 3, 4, 5 |
alpaM..alphaN |
a..g |
a, b, c, d, e, f, g |
stringM..stringN |
TRUCKS3..TRUCKS204 |
TRUCKS3, TRUCKS4, ..., TRUCKS204 |
dayM..dayN |
MON..FRI |
MON, TUE, WED, THU, FRI |
monthM..monthN |
OCT..JAN |
OCT, NOV, DEC, JAN |
monthYearM..monthYearN |
OCT2001..JAN2002 |
OCT2001, NOV2001, DEC2001, JAN2002 |
When using the 1..n format, n may be any positive integer value, and the initial member must always be a 1.
The stringM..stringN format allows you to use any string to start both the initial and terminal member names as long as the string conforms to standard LINGO naming conventions. M and N must be nonnegative and integer, such that M ≤ N. Also, you may pad the M value to the left with 0s in order to generate set member names of matching lengths. For example, TRUCKS003..TRUCKS204 would yield set members TRUCKS003, TRUCKS004, ..., TRUCKS204, so that all set members will be padded with 0s in order to contain 8 characters.
The dayM..dayN format allows you to choose the initial and terminal member names for the names of the days of the week. All names are abbreviated to three characters. Thus, the available options are: Mon, Tue, Wed, Thu, Fri, Sat, and Sun.
The monthM..monthN format allows you to select from the months of the year, where all names are abbreviated to three characters. The available options are: Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, and Dec.
The monthYearM..monthYearN option allows you to specify a month and a four digit year.
As further illustration, in the Wireless Widgets example, we could have also defined the WAREHOUSES set as:
WAREHOUSES / 1..6/: CAPACITY;
As an alternative, when using this 1..n form of implicit definition, you may also place the length of the set in a data section, and then reference this length in a subsequent sets section as we do here:
DATA:
NUMBER_OF_WH = 6;
ENDDATA
SETS:
WAREHOUSES / 1..NUMBER_OF_WH/: CAPACITY;
ENDSETS
Set members may have one or more attributes specified in the attribute_list of the set definition. An attribute is simply some property each member of the set displays. For instance, in the WAREHOUSES set above, there is a single attribute titled CAPACITY, which is used to represent the shipping capacity of the warehouses. Attribute names must follow standard naming conventions and be separated by commas.
For illustration, suppose our warehouses had additional attributes related to their location and the number of loading docks. These additional attributes could be added to the attribute list of the set declaration as follows:
WAREHOUSES / 1..6/: CAPACITY, LOCATION, DOCKS;
Set members may have one or more attributes specified in the attribute_list of the set definition. An attribute is simply some property each member of the set displays. For instance, in the WAREHOUSES set above, there is a single attribute titled CAPACITY, which is used to represent the shipping capacity of the warehouses. Attribute names must follow standard naming conventions and be separated by commas.
In addition to listing a primitive set's members in a model's sets section, primitive set members may also be listed in a model's data section. Some users may prefer this alternative approach in that a set's members are actually input data for the model. Therefore, listing set members in a model's data section, along with all other data, is a more natural approach that makes a model more readable. All the various techniques listed above for enumerating a primitive set's members are also valid in a data section. Some examples of defining primitive set members in a data section follow:
SETS:
WAREHOUSES: CAPACITY;
ENDSETS
DATA:
WAREHOUSES = WH1 WH2 WH3 WH4 WH5 WH6;
ENDDATA
Example 1: Listing a Primitive Set in a Data Section
SETS:
WAREHOUSES: CAPACITY;
ENDSETS
DATA:
NUMBER_OF_WH = 6;
WAREHOUSES = 1..NUMBER_OF_WH;
ENDDATA
Example 2: Listing a Primitive Set in a Data Section