if elseif+alias

I have a question and i would be appreciate if you can help me:
assume that I have 30 different sets in my model but I am not gonna use all of them. Depend on the value of one of the variables some of the sets must be use in constraints. I decided to use if-elseif+alias to solve my problem, but I dont know is that correct or which part of the program shall I write this code:
sets
g1 /1/
g2 /2/
g3 /3/
g4 /4/
g5 /5/
g6 /6/
g7 /7/
g8 /8/
g9 /9/
g10 /10/;

if (y1=1 and y2=1 and y3=1,
alias(g1,L1) and alias(g2,L2);
Elseif y1=1 and y2=1 and y4=1,
alias(g1,L1) and alias(g3,L2);
Elseif y1=1 and y4=1and y5=1,
alias(g3,L1) and alias(g6,L2));

Equation
const1(i)
const2(i);
const1(i)$L1… v(i)=g=epsilon;
const2(i)$L2… v(i)=g=0;

the If-elseif is longer than what I wrote and also i have much more constraints, I just wanna know this form of writing is correct?
I am new in gams and this is the first code I am going to write.
Thanks is advance.


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.

Hi Arman

Here is a way to do this (there might be more elegant ways). You are not allowed to use alias in a loop, therefore I defined an overall set with all the elements of all sets and then defined a dynamic set using “YES” (see the manual for this).
I introduced some values for y1 to y5 and a simple model to test the code (in your listing you can now see the sets as well as the (linearized) equations in the equation listing).
I hope this helps

Renger

sets
overall /1*10/,
g1 /1/
g2 /2/
g3 /3/
g4 /4/
g5 /5/
g6 /6/
g7 /7/
g8 /8/
g9 /9/
g10 /10/,

L1,L2;;

parameter y1 /1/, y2 /1/, y3 /1/, y4 /0/, y5 /0/;

if (y1=1 and y2=1 and y3=1,
L1(g1) = YES;
L2(g2) = YES;
Elseif y1=1 and y2=1 and y4=1,
L1(g1) = YES;
L2(g3) = YES;
Elseif y1=1 and y4=1and y5=1,
L1(g1) = YES;
L2(g6) = YES;);

Display L1, L2;
variable dummy,v(overall);

Equation
const1(overall)
const2(overall)
dummyeq;

const1(overall)$L1(overall)… v(overall)=g= EPS;

const2(overall)$L2(overall)… v(overall)=g=0;

dummyeq… dummy =E= 1;

model test /all/;

solve test minimizing dummy using NLP;

From: gamsworld@googlegroups.com [mailto:gamsworld@googlegroups.com] On Behalf Of Arman N
Sent: Sonntag, 3. Mai 2015 13:54
To: gamsworld@googlegroups.com
Subject: if elseif+alias

I have a question and i would be appreciate if you can help me:
assume that I have 30 different sets in my model but I am not gonna use all of them. Depend on the value of one of the variables some of the sets must be use in constraints. I decided to use if-elseif+alias to solve my problem, but I dont know is that correct or which part of the program shall I write this code:
sets
g1 /1/
g2 /2/
g3 /3/
g4 /4/
g5 /5/
g6 /6/
g7 /7/
g8 /8/
g9 /9/
g10 /10/;

if (y1=1 and y2=1 and y3=1,
alias(g1,L1) and alias(g2,L2);
Elseif y1=1 and y2=1 and y4=1,
alias(g1,L1) and alias(g3,L2);
Elseif y1=1 and y4=1and y5=1,
alias(g3,L1) and alias(g6,L2));

Equation
const1(i)
const2(i);
const1(i)$L1… v(i)=g=epsilon;
const2(i)$L2… v(i)=g=0;

the If-elseif is longer than what I wrote and also i have much more constraints, I just wanna know this form of writing is correct?
I am new in gams and this is the first code I am going to write.
Thanks is advance.

Dear Renger,
Thank you very much… You don’t know how much your trick helps me… I really appreciate you… :slight_smile:

Best Regards,
Arman Nedjati
Eastern Mediterranean University


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.