User Tools

Site Tools


gams:model_predecessor_successor_relations

How do I model predecessor/successor relations?

Q: I have variables with two indices, e.g. x(d,h), where d and h are sets of days and hours. My problem is to make a predecessor/sucessor relation between those x variables. E.g. I have to model the difference between two neighboring x variables like: delta(d,h) =e= x(d,h) - x(pred(d,h)) ; delta(d,) =l= constant ;

The GAMS lingo for this is lag and lead operators: x(d,h-1) e.g. shows the previous hour. The '-' is not a numerical minus but a lag. Trouble is that the predecessor for x(d,'h1') is x(d-1,'h24'). You also have to decide what predecessor of 'd1','h1' is.

If you do a steady state model you could have 'd365','h24' or you can decide that there is no predecessor (meaning delta('d1','h1') = x('d1','h1)). I am assuming your sets look like this

set d / d1*d365 /
      h / h1*h24 /

Now here is what you can do: delta(d,h) =e= x(d,h) - x(d-(1$sameas('h1')),h–1)) ;

Not so elegant, but it will work. I prefer working with an additional set of all hours in the year and a map between d,h and all hours in the year:

sets h /h1*h24/, d /d1*d365/, dh(d,h) /#d.#h/
sets t /t1*t8760/, tdh(t,d,h) /#t:#dh/, dht/#dh:#t/

This matching operators (. and :) are new syntax and will work with 22.7 and higher. You can do the maps also with older GAMS statements. Now I would have the variable x and delta over t and then the constraint looks simple: delta(t) =e= x(t) - x(t-1) (or x(t–1) for steady state)

In case you have data by d,h you can use the map tdh, for example: delta(t) =l= sum(tdh(t,d,h), maxdeviation(d,h));

gams/model_predecessor_successor_relations.txt · Last modified: 2014/01/16 09:00 by admin