Create an shifting index gap

Hi everyone,

I’m fairly new to gams and I have a problem that I’d appreciate your input on: I have a set I which includes hours in a year so 1 to 8760. I have a variable g(h) which is index by hour h. I want to write an equation to satisfy these constraints:
g(1) + g(2) + g(3) + g(4) = 0
g(3) + g(4) + g(5) + g(6) = 0
g(5) + g(6) + g(7) + g(8) = 0

So starting at hour 1, the sum of the first 4 consecutive variables is zero, after that there is a shifting window of 2 indices then the sum of the next 4 indices are zero, and so on and so on until the end of the year. I can’t think of how to do this. Any help is greatly appreciated! Thanks.

Read about ordered set including lag and leeds at https://www.gams.com/latest/docs/UG_OrderedSets.html.

set h / 1*8760 /, gh(h,h);
scalar i;
for (i=0 to 3,
  gh(h,h+i)$mod(ord(h),2)= yes;
)

alias (h,hh);
variable g(h);
equation e(h);
e(h)$mod(ord(h),2).. sum(gh(h,hh), g(hh)) =e= 0;

-Michael

My colleague Alex Meeraus had an even better suggestion:

set h / 1*8760 /, hh(h) / 1*4 /;
variable g(h);
equation e(h);
e(h)$mod(ord(h),2).. sum(hh, g(h+hh.off)) =e= 0;

He also pointed out that one as a modeler always has to think about the boundaries of the set. So what should happen for the last elements of h? Should the sequence be just shorter or do you want circular behavior (then use h**++**hh.off).

-Michael