SOS Variables

LINGO supports SOS (Special Ordered Sets) variables of Type 1, 2 and 3 via the @SOS1, @SOS2 and @SOS3 functions, respectively.  The properties of the three SOS types are:

SOS Type

Property

SOS1

At most, only one variable belonging to an SOS1 set will be greater than 0.

SOS2

At most, only two variables in an SOS2 set can be different from 0.  If two variables are nonzero, then the variables will be adjacent to one another.  SOS2 sets are particularly useful for implementing piecewise-linear functions in models.

SOS3

Exactly one variable from a given SOS3 set will be equal to 1.  All remaining variables will be equal to 0.

Note:Any variables added to an SOS set will count against the integer variable limit imposed in limited versions of LINGO.

The syntax for the @SOS declarations is as follows:

@SOS{1|2|3}( 'set_name', variable_reference);

The set_name argument is a unique label, or name, for the particular set of SOS variables.  You add additional variables to an SOS set by making subsequent calls to the @SOS function using the same set name.

Some examples of SOS sets are:

Example 1:        @SOS3( 'SUM_TO_1', X); @SOS3( 'SUM_TO_1', Y); @SOS3( 'SUM_TO_1', Z);

In this example, an SOS Type 3 set forces either X, Y or Z to be equal to 1.  The remaining variables will be equal to 0.

Example 2:        @FOR( CUST( J): @FOR( PLANTS( I): @SOS1( 'SNGSRC_' + CUST( J), SHIP( I, J))));

Here, multiple SOS Type 1 sets force each customer to receive shipments from only one plant.  There is one SOS1 set created for each customer, each bearing the name SNGSRC_customer_name.

An example of using Type 2 sets follows in the next section.