Lindo Systems

! Model "choose from a finite set" in LINGO. (FiniteChoice.lng)
 A common problem is that a certain variable 
 can only take on values chosen from a given
 finite set;
! Keywords: Choice, Finite choice, Multiple choice;
SETS:
  FINITESET: Z, DIAM, COST;
ENDSETS
DATA:
 ! The diameters from which we can choose;
  DIAM = 10  12  15  18;
 ! and their cost;
  COST = 3.5 3.6 3.8 6.9;
ENDDATA

 @FOR( FINITESET( d):
 ! Z(d) is a binary variable.
   We either choose diameter d, (Z(d) = 1), or not ( Z(d) = 0);
    @BIN( Z(d));
    );

! We must choose exactly one diameter;
 @SUM( FINITESET( d): Z(d)) = 1;

! Compute chosen diameter and cost;
   CDIAM = @SUM( FINITESET( d): DIAM(d) * Z(d));
   CCOST = @SUM( FINITESET( d): COST(d) * Z(d));
 
! Arbitrarily add a made-up objective.
  maximize diameter - cost;
  MAX = CDIAM - CCOST;