Set Looping Functions

Set looping functions operate over an entire set and, with the exception of the @FOR function, produce a single result. The syntax for a set looping function is:

@function( setname [ ( set_index_list)

  [ | conditional_qualifier]] : expression_list);

@function corresponds to one of the set looping functions listed below. setname is the name of the set you want to loop over. The set_index_list is optional and is used to create a list of indices, which correspond to the parent primitive sets that form the setname set. As LINGO loops through the members of the setname set, it will set the values of the indices in the set_index_list to correspond to the current member of the setname set.

The conditional_qualifier is optional and may be used to limit the scope of the set looping function. When LINGO is looping over each member of the setname set, it evaluates the conditional_qualifier. If the conditional_qualifier evaluates to true, then @function is performed for the set member. Otherwise, it is skipped.

The expression_list is a list of expressions to be applied to each member of the setname set. When using the @FOR function, the expression_list may contain multiple expressions, separated by semicolons. These expressions will be added as constraints to the model. When using the remaining three set looping functions (@SUM, @MAX, and @MIN), the expression_list must contain one expression only. If the set_index_list is omitted, all attributes referenced in the expression_list must be defined on the setname set.

The available set looping functions are listed below:

@FOR( setname [ ( set_index_list) [ | cond_qualifier]]: exp_list)

This generates the expressions contained in exp_list for all members of the setname set.  @FOR is used to generate constraints over all the members of a set, and is one of the most powerful features of LINGO.

@MAX( setname [ ( set_index_list) [ | cond_qualifier]]: expression)

This returns the maximum value of expression taken over the setname set.

@MIN( setname [ ( set_index_list) [ | cond_qualifier]]: expression)

This returns the minimum value of expression taken over the setname set.

@PROD( setname [ ( set_index_list) [ | cond_qualifier]]: expression)

This returns the product of an expression over the setname set.

@SUM( setname [ ( set_index_list) [ | cond_qualifier]]: expression)

This returns the sum of an expression over the setname set.

Set looping functions are discussed in more detail in section Set Looping Functions in Chapter 2.