Hello,

I have just started to work with GAMS. I have already programmed a storage optimization tool, which is working fine. It optimizes the revenue at the spot market minus costs of storage and volume.

But now I want to extend my model (I want to include self discharge). The self discharge depends on State of Charge (SOC - variable in my model) and of course the storage type (sto1, sto2, sto3 - set u_S).

I have the following parameters:

      sel_Dis1(u_S) self discharge rate per day SOC > 80%
     / sto1 0.999928762
       sto2 0.999943304
       sto3 0.999957696 /

    sel_Dis2(u_S) self discharge rate per day SOC < 80%
     / sto1 0.999971941
       sto2 0.999986041
       sto3 0.999986041 /

Depending on the level of my variable SOC - the self discharge differs. But I need just one SelDis variable(?), thats why I build the following if else term:

 Variables 
  x
  y etc.

  SOC(t,u_S)

  SelDis(t,u_S)
  LOOP(u_S,LOOP(t,
  if((SOC(t,U_S)gt 0.8),
      SelDis(t,u_S)=Sel_Dis1(u_S)
  else
      SelDis(t,u_S)=Sel_Dis2(u_S)););

But unfortunately it is not working. Is my "if else" term wrong? Where do I have to put it? Under equations? Do you need more information?

Thank you very much in advance!

asked 29 Apr '14, 04:23

banolli's gravatar image

banolli
1113
accept rate: 0%

edited 29 Apr '14, 04:52


I'm not a GAMS "expert" ...but if I understand you right, you need to express your conditional statement using constraints and a (binary) auxiliary variable:

VARIABLES
  ...
  z(t,u_S) ;

BINARY VARIABLE
  z ;

EQUATIONS
  SelDis(t,u_S).lo = Sel_Dis1(u_S)
  SelDis(t,u_S).up = Sel_Dis2(u_S)
  SelfDischargeRate1(t,u_S)        test if SOC(t,u_S) geq 0.8
  SelfDischargeRate2(t,u_S)        ^ using z(t,u_S) as indicator
  SelfDischargeRate3(t,u_S)        set SOC(t,u_S) eq Sel_Dis1(u_S) if z(t,u_S) eq 1, else eq Sel_Dis2(u_S) ;

SelfDischargeRate1(t,u_S)..
  SOC(t,u_S) - 0.7999999 =L= z(t,u_S) ;
SelfDischargeRate2(t,u_S)..
  SOC(t,u_S) =G= 0.8 * z(t,u_S) ;
SelfDischargeRate3(t,u_S).. 
  SelDis(t,u_S) =E= Sel_Dis1(u_S) + ( Sel_Dis2(u_S) - Sel_Dis1(u_S) ) * ( 1 - z(t,u_S) ) ;

IINM, LOOP is a control flow statement that can't be used as part of the model definition, and if-conditions involving variables make your model nonlinear (this might work for you if you're using a MINLP solver, though).

link

answered 29 Apr '14, 07:13

fbahr's gravatar image

fbahr ♦
4.6k716
accept rate: 13%

edited 30 Apr '14, 05:10

P.S.: BTW, there's also a Google group, dedicated to "all things GAMS" https://groups.google.com/forum/#!forum/gamsworld

(29 Apr '14, 07:16) fbahr ♦

Hey, thanks for your help. It's working! But now I have another linearity problem :/ I try to figure it out and write here again, when it is fixed :)

Thanks again!

(29 Apr '14, 12:12) banolli
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×51
×4

Asked: 29 Apr '14, 04:23

Seen: 3,539 times

Last updated: 30 Apr '14, 05:10

OR-Exchange! Your site for questions, answers, and announcements about operations research.