$TITLE  RESEVOIR PROBLEM
$OFFUPPER
* This problem finds the maximum flow through a resevoir
* network.
*
*  References: 
*        The problem is taken from the book on Linear Programming
*        in Infinite Dimensional Spaces. 

  SETS
       I   resevoirs   / R1*R3 /
       T   time periods  / T1, T2 / ;

PARAMETERS

  S(I)  initial amount of water in Ri
   / R1  100
     R2  150
     R3  130 /

  C(I)  capacity of Ri
   /R1   200
    R2   300
    R3   250 /

  D(T)  demand at time t
    /T1  190
     T2  210 /

  F(I)   capacity of flow from Ri to demand
   / R1  15
     R2  25
     R3  50 /  ;

  TABLE RT(I,T)  rate of flow into Ri at time t
        T1   T2
    R1  20   25
    R2  30   35
    R3  45   45 ;

VARIABLES

  X(I,T)    rate of water flow from Ri at time t
  W(I,T)    rate of spillage from Ri at time t 
  Z         objective function; 

 POSITIVE VARIABLES
  X
  W ;

X.UP(I,T) = F(I)   ;

EQUATIONS
  LH1(I,T)  left hand side 1
  RH1(I,T)
  LH2(I)
  RH2(I) 
  COST   ;

RH1(I,T) .. RT(I,T) - X(I,T)-W(I,T)+S(I) =L= C(I) ;
LH1(I,T) .. RT(I,T) - X(I,T)-W(I,T)+S(I) =G= 0 ;
RH2(I) .. SUM(T,RT(I,T) - X(I,T)-W(I,T))+S(I) =L= C(I) ;
LH2(I) .. SUM(T,RT(I,T) - X(I,T)-W(I,T))+S(I) =G= 0 ;

COST ..   Z =E= SUM((I,T),X(I,T));



  MODEL RESEVOIR /ALL/ ;

  SOLVE RESEVOIR USING LP MAXIMIZING Z ;

  DISPLAY X.L, X.M ;
