Cardinality

Related to the SOS capability discussed above, LINGO also supports cardinality sets of variables via the @CARD function.  The cardinality feature allows you  to specify a set of variables with a cardinality of N, meaning that, at most, N of the variables in the set will be allowed to be nonzero.

As with SOS sets, cardinality sets help the integer solver branch more efficiently, and they reduce the number of variables and constraints in your models.  Also, as with SOS sets, each variable added to a cardinality set will count against any integer variable limits imposed on your installation of LINGO.

The syntax for the @CARD declarations is as follows:

@CARD( 'set_name', variable_reference|set_cardinality);

The set_name argument is a unique label, or name, for the particular cardinality set.  You add additional variables to an SOS set by making subsequent calls to the @CARD function using the same set name with a different variable_reference.  In addition to calling @CARD once for each variable in a set, you will need to call @CARD once for each set passing an integer value as the second argument.  This integer argument is the set_cardinality, and may be either an actual integer number or a variable set to an integer value in either a data or calc section.

Some examples of @CARD sets are:

Example 1:        @CARD( 'PICK2', 2); @CARD( 'PICK2', X); @CARD( 'PICK2', Y); @CARD( 'PICK2', Z);

In this example, at most, two out of the three variable X, Y, and Z will be nonzero.

Example 2:        @FOR( PLANT( I): @CARD( 'OPENLIM', OPEN( I))); @CARD( 'OPENLIM', NCARD);

Here,  we limit the maximum number of open plants to NCARD, where NCARD must be set beforehand to an integer value in either a data or calc section.