Friday, July 18, 2008

Lags and day/hour time representation

> 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,g) =l= constant ;
> Are there any ideas how to make this in an easy and elegant way?

In general it is much easier to work with one time index. I.e. use a single index t instead of two indices (d,h). This will make your model much simpler and easier to maintain.

If you want to print in the final reports in terms of (d,h) then use:

d / d1*d10 /
h / h1*h24 /
t / t1 * t240 /

variable delta(t),x(t);
equation e(t);
e(t).. delta(t)$(ord(t)>1) =e= x(t) - x(t-1) ;

set mapper(d,h,t);
mapper(d,h,t)$([ord(d)-1]*card(h)+ord(h) = ord(t)) = yes;
display mapper;

x.l(t) = uniform(0,1);
parameter xreport(d,h);
xreport(d,h) = sum(mapper(d,h,t),x.l(t));
display xreport;