Hi Deniz
You are not allowed to use if statements in equations. A way to solve this would be
const4(t,p)… (1 - z1(t-1,p)) * (1 - z2(t-1,p)) * (z3(t-1,p) - 0) * lambda(p,t) - Lambda(P,t-1)*A +
z1(t-1,p) * (lambda(p,t) - Lambda(P,t-1)*B1) +
z2(t-1,p) * (lambda(p,t) - Lambda(P,t-1)*B2) +
z3(t-1,p) * (lambda(p,t) - Lambda(P,t-1)*B3) =E= 0;
If z1, z2, z3 are binary variables, this seems to do the trick.
Be aware, that you B1 is defined as B1(t,“budget“), so you should correct this, as well as introduce the parameters B2 and B3.
Hope this helps
Renger
From: gamsworld@googlegroups.com [mailto:gamsworld@googlegroups.com] On Behalf Of deniz
Sent: Donnerstag, 21. Mai 2015 17:24
To: gamsworld@googlegroups.com
Subject: Re: error code 119 for loop including several if else statements
Dear Renger,
Here is my gams model file along with data table.
Model work till if statement and after that it gives me error code.
Since if statements contains variable, can be this a problem?
I appreciate your help very much.
Sincerely.
On Thursday, May 21, 2015 at 12:47:03 AM UTC-5, Renger van Nieuwkoop wrote:
Hi Deniz
If you send code, this should at least run without errors until the error you mention appears. Your code is incomplete and raises error far before the if statements.
Renger
From: gams...@googlegroups.com [mailto:gams...@googlegroups.com] On Behalf Of deniz
Sent: Mittwoch, 20. Mai 2015 18:37
To: gams...@googlegroups.com
Subject: Re: error code 119 for loop including several if else statements
Dear Ranger,
First of all, I would like to thank you for your help.
If it helps, I posted my model.
I define the sets and parameters. But when it comes to if statement. it gives me error code 119.
I am putting variables inside if statement. Is this error because of that or do I need to use other constraint to define my if then statement. I do not know how to fix this error code.
I really do appreciate your help very much and your helps mean a lot.
Regards.
Sets
p component/P1*P4/
T periods in the planning horizon / 0*4/
t0(t)/0/
;
SCALAR K1 correction factor /0.5/ ;
SCALAR K2 correction factor /0.3/ ;
SCALAR K3 correction factor /0.2/ ;
SCALAR A degradation constant /1.01/ ;
PARAMETERS
b(t) budget
EN(t) en need
ENP(p) eny production of each productat time t
U1(t) maintenance costs at time t
U2(t) mid-level cost at time t
U3(t) high-level cost at time t
R1 improvement level 1
R2 improvement level 2
R3 r improvement level 3
RS(t)
Rmin(T) min
Rmax(T) max
;
U1(t)=OMNN1(t,“OMNN”);
U2(t)=OMLR1(t,“OMLR”);
U3(t)=OMHR1(t,“OMHR”);
b(t)= b1(t,“budget”);
EN(t)= EN1(t,“energy”);
ENP(p)=ENP1(p,“ENPS”);
R1=0.3;
R2=0.6 ;
R3=0.8 ;
Rmin(T)=0.1 ;
Rmax(T)=0.9 ;
parameter
Lambdazero(P) given for time period zero
/P1 0.6
P2 0.7
P3 0.1
P4 0.1
/
;
variable
Lambda(p,t) lambda for component p at time t
h
;
binary variables
Z1(T,P)
Z2(T,P)
Z3(T,P)
;
Equations
objective
const1(T,P)
const1a(T,P)
const2(T,P)
Const3(T0,P)
Const3a(T,P)
const4(T,P)
const5(T,P)
const6(T,P)
const7(T)
const8(T)
const8a(T)
;
ALIAS (T,J);
const1(t,p) …sum((j),ENP1(P,“ENPS”)*lambda(P,t))=g=EN1(T,“energy”);
ALIAS (T,J);
const2(t,p) … sum((J),OMNN1(J,“OMNN”)*Z1(J,P))+ sum((J),OMLR1(J,“OMLR”)*Z2(J,P))
- sum((J),OMHR1(J,“OMHR”)*Z3(J,P))=l=b1(T,“budget”);
const3(t0,p) …lambda(p,t-1)=e= Lambdazero(P);
const3a(T,P)…lambda(p,t)=e=Lambda(P,t-1)*A+Lambda(P,t-1)B1Z1(t-1,p)+Lambda(P,t-1)B2Z2(t-1,p)+Lambda(P,t-1)B3Z3(T-1,P);
const4(t+1,p)…loop(t,
if((z1(t,p)=0)and (z2(t,p)=0) and (z3(t,p)=0), lambda(p,t+1)= Lambda(P,t)*A);
elseif ((z1(t,p)=1), lambda(p,t+1)= Lambda(P,t)*B1);
elseif ((z2(t,p)=1), lambda(p,t+1)= Lambda(P,t)*B2);
elseif ((z3(t,p))=1, lambda(p,t+1)= Lambda(P,t)*B3);
);
Const5(T,P) …Z1(T,P)+ Z2(T,P)+Z3(T,P)=e=1;
const6(T,P) … loop (t,
If ((lambda(p,t+1) l R1),
z1(t,p)=0;
z2(t,p)=0;
elseif ((lambda(p,t+1)gt R1 and (lambda(p,t+1)l R2),
z1(t,p)=0;
z3(t,p)=0;
elseif ((lambda(p,t+1)gt R2 and (lambda(p,t+1)l R3),
z2(t,p)=0;
z3(t,p)=0;
elseif ((lambda(p,t+1)gt R3),
z1(t,p)=0;
z2(t,p)=0;
z3(t,p)=0;
);
Const7(T)… RS(t)=E=1-prod(p,(1-exp(-lambda(p,t)*ord(T))));
Const8(T)… Rmin(T)=l= RS(t) ;
Const8a(T)…RS(t) =g= Rmax(T);
objective…h=e=sum((T,P),OMNN1(T,“OMNN”)*Z1(T,P))+ sum((T,P),OMLR1(T,“OMLR”)*Z2(T,P))+ sum((T,P),OMLR1(T,“OMHR”)*Z3(T,P));
model DEN /all/;
solve DEN using minlp minimizing h;
display z1.l;
display z2.l;
display z3.l;
On Tuesday, May 19, 2015 at 1:04:51 AM UTC-5, deniz wrote:
Dear All,
I have been trying to code if then, if else by using loop but some how I am struggling a great deal.
I keep getting error code 119 and I do not know how to fix it. I have searched all the old questions and asnwers but so far no luck.
If possible could you please let me know how can I fix the problem. Thank you in advance.
PARAMETERS
R1=0.3;
R2=0.6 ;
R3=0.8 ;
binary variables
Z1(T,P)
Z2(T,P)
Z3(T,P)
const4(t+1,p)…loop(t,
if((z1(t,p)=0)and (z2(t,p)=0) and (z3(t,p)=0), lambda(p,t+1)= Lambda(P,t)*A);
elseif ((z1(t,p)=1), lambda(p,t+1)= Lambda(P,t)*B1);
elseif ((z2(t,p)=1), lambda(p,t+1)= Lambda(P,t)*B2);
elseif ((z3(t,p))=1, lambda(p,t+1)= Lambda(P,t)*B3);
);
const6(T,P) … loop (t,
If ((lambda(p,t+1) l R1),
z1(t,p)=0;
z2(t,p)=0;
elseif ((lambda(p,t+1)gt R1 and (lambda(p,t+1)l R2),
z1(t,p)=0;
z3(t,p)=0;
elseif ((lambda(p,t+1)gt R2 and (lambda(p,t+1)l R3),
z2(t,p)=0;
z3(t,p)=0;
elseif ((lambda(p,t+1)gt R3),
z1(t,p)=0;
z2(t,p)=0;
z3(t,p)=0;
);
\
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.
–
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.