MODEL:
 ! Two level blending or pooling model(POOLING).
   Raw materials are selectively blended into pools,
   then pools are blended into finished products;
 ! Keywords: blending, pooling;
 SETS:
 ! Each raw material has an availability and cost/unit;
   RM : A, COST;

 ! There are a set of intermediate pools, e.g., storage tanks;
   POOL: BP ;
 ! Each finished good has a min required, max sellable,pro-
   fit contribution/unit and batch size to be determined;
   FG: D, E, PRICE, BF;

  ! There are a set of quality measures;
   QM;

  ! For each combo of RM and QM there is a quality level;
   RXQ( RM, QM): Q;

  ! For each combo QM, FG there are upper and lower limits
   on quality, and slack on upper quality to be determined;
   QXF( QM, FG): U, L, S;

  ! For each combination of Pool and quality level, there is
     a quality level to be determined;
   PXQ( POOL, QM): QP;

  ! Set of which RM can go into which POOL;
   RXP( RM, POOL): R2P;

  ! Set of which POOL can go into which FG;
   PXF( POOL, FG): P2F;
 ENDSETS

 DATA:

  RM=  RMA    RMB    RMC;  ! Set of raw materials;
  A = 9999   9999   9999;  ! Raw matl availabilities;
  COST = 6     16     10;  ! R. M. costs;

 QM = SULFUR;             ! Set of qualities;
  Q =  .03   .01    .02;  ! Quality by R.M.;
     

 FG =   FGX   FGY;
  D =    0,    0;       ! Min needed of each F.G.;
  E =   100   200;      ! Max sellable of each F.G;
  PRICE=  9     15;     ! Selling price of each F.G.;

  U =   .025  .015;     ! Upper limits on quality for each FG.;
  L =      0    0 ;     ! Lower limits on quality...;

 POOL  = POOLAB  POOLC; ! The names of the pools;
! Which R.M. can go into which POOLS;
 RXP=
     RMA   POOLAB
     RMB   POOLAB
     RMC   POOLC;
! Which pools go into which F.G.;
 PXF = POOLAB FGX  POOLAB FGY  POOLC FGX  POOLC FGY;
 ENDDATA
!---------------------------------------------------------------;
  ! The model;
   ! Max revenues - cost of raw materials;
       [PROFIT] MAX = @SUM( FG(K): PRICE(K) * BF(K)) -
           @SUM( RXP(I, J): COST( I)*R2P( I, J));

   ! Raw materials stage: raw material availabilities;
    @FOR( RM( I):
         [RMLIM] @SUM( RXP(I, K): R2P( I, K)) <= A( I);
        );

   ! Pools stage;
      @FOR( POOL(J):
   !  How much is in each pool;
      [INPOOLI]  BP(J) = @SUM( RXP(I,J): R2P(I,J));
      [INPOOLO]  BP(J) = @SUM( PXF(J,K): P2F(J,K));
   ! The quality level, QP(J,T), of each pool;
      @FOR( QM( T):
       [QPOOL] QP(J,T)*BP(J) = @SUM( RXP(I,J): Q(I,T)*R2P(I,J));
           );
          );

   ! Finished goods stage;
    @FOR( FG( K):
     ! Batch size computation;
          [BDEFO] BF( K) = @SUM( POOL( J): P2F( J, K));
     ! Batch size limits;
          [BLO] BF( K) >= D( K);
          [BHI] BF( K) <= E( K);
     ! Quality restrictions for each quality;
       @FOR( QM( T):
           [QUP] @SUM( POOL( J): QP( J, T) * P2F( J, K))
                   + S( T, K) = U( T, K) * BF( K);
           [QDN] S( T, K) <= ( U( T, K) - L( T, K)) * BF( K);
           );
        );
 END