Hi Renger,
Thank you very much for your help, it really helps a lot.
Best regards,
Dylan
在 2014å¹´10月16日星期四UTC+8下åˆ2æ—¶18分54秒,Renger van Nieuwkoop写é“:
Hi Dylan
You almost have the solution. The only thing to do is introducing aliases, so you can loop without running into your problem
Here is the idea (it might not be exactly what you want, but the idea might help you to exactly do what you want)
Parameters
a(i) ,ar(r);
a(i) = 0 ;
ar(r) = 0;
Equations
EQ3(r,i) Equation 3 ;
EQ3(r,i)$(a(i) and ar(r))… sum(j, x(i,j)) =l= 10000 ;
Model M2 / EQ1, EQ2, EQ3, OBJ / ;
alias(i,ii),(j,jj),(r,rr);
loop(rr,
loop(ii,
a(i) = 0;
ar(r) = 0;
loop(jj,
if(x.l(ii,jj) >= 500,
a(i)$(ord(i) = ord(ii)) = 1 ;
ar(r)$(ord(rr) = ord(r)) = 1;
) ;
Solve M2 using LP minimizing z ;
);
) ;
) ;
Cheers
Renger
Modelworks
Gewerbestrasse 15
3600 Thun – Switzerland
+41 79 818 53 73
In…@modelworks.ch
blog.modelworks.ch
From: gams...@googlegroups.com [mailto:gams...@googlegroups.com] On Behalf Of Dylan Lan
Sent: Thursday, October 16, 2014 4:15 AM
To: gams...@googlegroups.com
Subject: Equation index involved in loops
Dear all,
I am trying to formulate a model that can add new constraints after each solution, but the GAMS seems to forbid solving model in which equations’ index are involved in loops. The example is shown in the follow, and it is just to show the idea and may not be feasible.
Sets
i / i1*i100 /
j / j1*j100 / ;
Positive variables
x(i,j)
y(i) ;
Variable
z ;
Equations
EQ1(i,j) Equation 1
EQ2(i) Equation 2
OBJ Objective ;
EQ1(i,j) … y(i) =l= 100 ;
EQ2 (i) … sum(j$(ord(j)=2ord(i)), x(i,j)) + y(i) =g= 3000 ;
OBJ … z =e= 2sum((i,j), x(i,j)) + sum(i, y(i)) ;
Model M1 / EQ1, EQ2, OBJ / ;
Solve M1 using LP minimizing z ;
Set
r / r1*r10 / ;
Parameters
a(i) ;
a(i) = 0 ;
Equations
EQ3(r,i) Equation 3 ;
EQ3(r,i)$a(i) … sum(j, x(i,j)) =l= 10000 ;
Model M2 / EQ1, EQ2, EQ3, OBJ / ;
loop(r,
loop(i,
loop(j,
if(x.l(i,j) >= 500,
a(i) = 1 ;
) ;
) ;
) ;
Solve M2 using LP minimizing z ;
) ;
–
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+...@googlegroups.com.
To post to this group, send email to gams...@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.
–
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.