Reservoir : Onstream and Offstream Optimal Reservoir Management

Reference

  • Neculai Andrei, Nonlinear Optimization Applications Using the GAMS Technology,Springer Optimization and Its Applications, Model Reservoir (10.2) in chapter Water Management in River Systems , 2013

Category : GAMS NOA library


Mainfile : reservoir.gms

$onText
Onstream and offstream optimal reservoir management.

Adapted from:
McKinney, D.C., Savitsky, A.G., Basic optimization models for water and
energy management. June 1999 (revision 6, February 2003).
http://www.ce.utexas.edu/prof/mckynney/ce385d/papers/GAMS-Tutorial.pdf

Andrei, N., Optimal management of system of two reservoirs.
Revista Romana de Informatica si Automatica, vol.16, no.1, 2006, pp.15-18.
$offText

sets n reservoirs /res1, res2/;

sets t time /ian, feb, mar, apr, mai, jun, jul,
             aug, sep, oct, nov, dec, enda /

tt(t) /ian/;

table q(n,t) inflow water in the first reservoir rez1 (mil.m3)
      ian  feb  mar  apr  mai  jun  jul  aug  sep  oct  nov  dec  enda
res1  128  125  234  360  541  645  807  512  267  210  981  928  250;

table r(n,t) required released water from the first reservoir rez1 (mil.m3)
      ian  feb  mar  apr  mai  jun  jul  aug  sep  oct  nov  dec  enda
res1  100  150  200  500  222  700  333  333  300  250  250  250  200;

variables q2(t),
          r2(t),
          s(n,t),
          obj;

equation
bal1(n,t)   water balance in reservoir S1
bal2(n,t)   water balance in reservoir S2
dec(n,t)    decisions of filling the reservoirs
objf        objective function ;

bal1(n,t)$(not tt(t))..
   s('res1',t)-s('res1',t-1) =E= Q('res1',t)+r2(t)-
       q2(t)-r('res1',t);

bal2(n,t)$(not tt(t))..
   s('res2',t)-s('res2',t-1) =E= q2(t)-r2(t);

dec(n,t)$(not tt(t))..
   (s('res2',t)-s('res1',t)) -
   (s('res2',t)-s('res1',t)) * (1.0-q2(t)/(q2(t)+0.000001)) =E=
       0.0;

objf.. obj =E= sum(t$(not tt(t)),r2(t));

* Bounds
s.lo('res1',t)=1150;
s.up('res1',t)=4590;
s.fx('res1','ian')=1200;

s.lo('res2',t)=100;
s.up('res2',t)=4590;
s.fx('res2','ian')=1200;

r2.up(t)=1500;
r2.lo(t)=0.0;

q2.up(t)=1500;
q2.lo(t)=0.0;
q2.l(t)=0.00001;

*option optcr =0.000001;

parameter a(t);
  a(t)=(1-(q2.l(t)/(abs(q2.l(t))+0.00000001)));

model reservoir /all/;

solve reservoir using nlp minimizing obj;

* Visualisation of the solution
* -----------------------------

$ifThenI x%mode%==xbook
file res /rezerv.txt/
put res;
put "objective = ", obj.l:10:5; put /;
put /"======================================================"/;
put /"          a     q-res1    r-res1   q2(t)  r2(t)   s-res1   ds-res1    s-res2   ds-res2     "/;

loop (t $(ord(t) ne card(t)),
  put t.tl:7, a(t):5:2, q('res1',t):10:2, r('res1',t):10:2,
      q2.l(t):7:1, r2.l(t):7:1,
      s.l('res1',t):10:2, (s.l('res1',t)-s.l('res1',t-1)):10:2,
      s.l('res2',t):10:2, (s.l('res2',t)-s.l('res2',t-1)):10:2 /; );
put /"======================================================"/;


file stoc1 /s-res1.dat/;
put stoc1
loop(t, put s.l('res1',t):10:7, put/)

file stoc2 /s-res2.dat/;
put stoc2
loop(t, put s.l('res2',t):10:7, put/)

file flow1 /q2.dat/;
put flow1
loop(t, put q2.l(t):10:7, put/)

file flow2 /r2.dat/;
put flow2
loop(t, put r2.l(t):10:7, put/)

file flowq /q.dat/;
put flowq
loop(t, put q('res1',t):10:7, put/)

file flowr /r.dat/;
put flowr
loop(t, put r('res1',t):10:7, put/)
$endIf

* End of reservoir