How do I model predecessor/successor relations?

Frequently asked questions about GAMS

Moderator: aileen

Forum rules
Please ask questions in the other sub-forums
Locked
aileen
User
User
Posts: 136
Joined: 4 years ago

How do I model predecessor/successor relations?

Post by aileen »

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/successor relation between those x variables. E.g. I have to model the difference between two neighboring x variables like:

Code: Select all

delta(d,h) =e= x(d,h) - x(pred(d,h)); 
delta(d,h) =l= constant;
aileen
User
User
Posts: 136
Joined: 4 years ago

Re: How do I model predecessor/successor relations?

Post by aileen »

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 the 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:

Code: Select all

Set d / d1*d365 /
    h / h1*h24  /;
Now here is what you can do:

Code: Select all

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:

Code: Select all

Set h /h1*h24/, d /d1*d365/, dh(d,h) /#d.#h/
Set t /t1*t8760/, tdh(t,d,h) /#t:#dh/, dht /#dh:#t/;
. and : are called matching operators. Now I would have the variable x and delta over t and then the constraint looks simple:

Code: Select all

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:

Code: Select all

delta(t) =l= sum(tdh(t,d,h), maxdeviation(d,h));
Locked