Hi Peter,
I forgot to define the variables because I wrote them fast in the browser without checking them in GAMS.
xpos(tp,t) and ypos(tp,t) are binary variable
For example,
if xpos(‘1’,‘4’)=1 this mean thats the first time of x it happen in the fouth order (tp=1 and t=4)
if xpos(‘2’,‘10’)=1 this mean thats the second time of x it happen in the tenth order (tp=2 and t=10)
.
.
.
if xpos(‘50’,‘1000’)=1 this mean thats the fiftieth time of x it happen in the thousandth order (tp=50 and t=1000)
But, if for the rest of restriction x it happen only 50 time, the rest of the variables xpos take a values of 0
( xpos(‘51’,t)=xpos(‘52’,t)=xpos(‘53’,t)=…=xpos(‘1440’,t)=0 )
For the previusly example, xpos(‘1’,‘4’)=1 (tp=1 and t=4)
eq1(t,tp)… sum(tpp$(ord(tpp) le ord(t)),x(tpp)) =l= ord(tp) + (1-xpos(tp,t))*1440;
eq2(t,tp)… sum(tpp$(ord(tpp) le ord(t)),x(tpp)) =g= ord(tp) - (1-xpos(tp,t))*1440;
replacing and expanding
eq1(‘4’,‘1’)… x(‘1’) + x(‘2’) + x(‘3’) + x(‘4’) =l= 1 + (1-1)*1440;
eq2(‘4’,‘1’)… x(‘1’) + x(‘2’) + x(‘3’) + x(‘4’) =g= 1 - (1-1)*1440;
and
x(‘1’) + x(‘2’) + x(‘3’) + x(‘4’) = 1
if xpos(‘1’,‘4’)=1 the rest of xpos(‘1’,t) (t ne 4) take a value of 0, so
eq1(t,‘1’)… sum(tpp$(ord(tpp) le ord(t)),x(tpp)) =l= 1 + (1-0)*1440;
eq2(t,‘1’)… sum(tpp$(ord(tpp) le ord(t)),x(tpp)) =g= 1 - (1-0)*1440;
finally
eq1(t,‘1’)… sum(tpp$(ord(tpp) le ord(t)),x(tpp)) =l= 1441;
eq2(t,‘1’)… sum(tpp$(ord(tpp) le ord(t)),x(tpp)) =g= 1441;
eq1 and eq2 always be satisfied in this case
Analyzing your questions, I noted that you must to aggregate the eq7 and eq8
I think that this equations can represent all your problem. This focus is so-called “BigM relaxation”
Anyway, only you know all the problem and you must to vericated all equations.
I hope this can help you
bye!
set
t /1*1440/
;
alias(t,tp,tpp);
binary variable
x(t)
y(t)
xpos(tp,t)
ypos(tp,t)
;
variable
z
;
equation
eq1,eq2,eq3,eq4,eq5,eq6,eq7,eq8,eqobj
;
eq1(t,tp).. sum(tpp$(ord(tpp) le ord(t)),x(tpp)) =l= ord(tp) + (1-xpos(tp,t))*1440;
eq2(t,tp).. sum(tpp$(ord(tpp) le ord(t)),x(tpp)) =g= ord(tp) - (1-xpos(tp,t))*1440;
eq3(tp).. sum(t,xpos(tp,t)) =l= 1;
*same for y
eq4(t,tp).. sum(tpp$(ord(tpp) le ord(t)),y(tpp)) =l= ord(tp) + (1-ypos(tp,t))*1440;
eq5(t,tp).. sum(tpp$(ord(tpp) le ord(t)),y(tpp)) =g= ord(tp) - (1-ypos(tp,t))*1440;
eq6(tp).. sum(t,ypos(tp,t)) =l= 1;
eq7(tp,t).. 1-xpos(tp,t) + x(t) =g= 1;
eq8(tp,t).. 1-ypos(tp,t) + y(t) =g= 1;
eqobj.. z =e= sum(tp, sum(t,xpos(tp,t)*ord(tp)) - sum(t,ypos(tp,t)*ord(tp)));