## SUBSET USAGE IN CONSTRAINT Topic is solved

Problems with syntax of GAMS
Kadir
User
Posts: 6
Joined: 1 month ago

### SUBSET USAGE IN CONSTRAINT

Dear all,
I have a problem about subset usage in constraints,
my set and subsets are following;

Code: Select all

``````sets
i aircraft /1*16/
heavy(i) /2,6,10,14/;
set medium (i);
medium (i)= NOT heavy (i);

alias (i,p);

I created a separation parameter like;

parameter SEP(i,p);
SEP(medium,medium)=70;
SEP(medium,heavy)=60;
SEP(heavy,heavy)=82;
SEP(heavy,medium)=118;

and my seperation constaints;

constraint3(i,p,medium(i),heavy(i))\$(ord(i)<>ord(p) and R(i)=R(p)and PM(i)=PM(p)and [SEP(i,p) and SEP(medium,medium) and SEP(medium,heavy)and SEP(heavy,medium) and SEP(heavy,heavy)])..
D(i)-D(p)=g= SEP(p,i)-M*E(i,p);

constraint4(i,p,medium(i),heavy(i))\$(ord(i)<>ord(p) and R(i)=R(p)and PM(i)=PM(p)and [SEP(i,p) and SEP(medium,medium) and SEP(medium,heavy)and SEP(heavy,medium) and SEP(heavy,heavy)])..
D(p)-D(i)=g= SEP(i,p) -M*(1-E(i,p));``````
this constraints not working and seperation between aircrafts is not provided.
But code is running and solution is founded.

How can I express the subsets in the constraints? Thanks in advance.

abhosekar
Moderator
Posts: 92
Joined: 3 months ago

### Re: SUBSET USAGE IN CONSTRAINT

From your code, it is difficult to tell what you are trying to achieve. There are a bunch of undeclared equations, variables.
Also, since medium(i) and heavy(i) are complementary sets, I don't know why you would include it in constraint definition at once.

I assume you want to use constraint3 for 'i' that are only in subset medium(i) or subset heavy(i).

constraint3(i, p)\$(medium(i))..
would define this constraint only for i that is included in medium(i) (i.e. 2,6,10,14)

Similarly
constraint3(i, p) \$(heavy(i)) would include all i that are included in subset heavy.

Within the constraint, you can simply use 'i' as the \$ condition can take care of including correct i.

Hope this helps.

- Atharv

Kadir
User
Posts: 6
Joined: 1 month ago

### Re: SUBSET USAGE IN CONSTRAINT

Hi abhosekar, first of all thank you.

I did not share all part of code but precisely I am trying to achieve making a separation between all type of aircraft, i.e. if leading aircraft is medium and trailing aircraft is heavy separation must be 60 sec. or i.e. if leading aircraft is heavy and trailing aircraft is heavy separation must be 82 sec.

In constraint 3 and 4, D(i) and D(p) are times when aircraft passes from a determined point. E(i,p) is binary variable which is 1 if i assigned before p. These constraints is working if I determined SEP=60 as a scalar but I need to determine different separation conditions changing depending on leading and trailing aircraft type. Actually in these constraints heavy and medium aircraft must be included. Because SEP(i,p) need to equal one of the SEP(medium,heavy) or SEP(medium,medium) or SEP(heavy,medium) or SEP(heavy, heavy) depending on i and p. remember that i alias p. I am waiting your help. thank you again.

abhosekar
Moderator
Posts: 92
Joined: 3 months ago

### Re: SUBSET USAGE IN CONSTRAINT

Okay, I think I get your problem.
First of all, any given i should either be heavy or medium based on your definition.
Looking at the long list of if conditions with your constraints, I don't understand why the following conditions are needed (I think these should be removed)
[SEP(i,p) and SEP(medium,medium) and SEP(medium,heavy)and SEP(heavy,medium) and SEP(heavy,heavy)]

I think indexing your constraints with just i and p is enough since there are only 4 possibilities, you can just include 4 constraints (m, m), (m, h), (h, m), (h, h)

Finally, I assume that if E(i, p) is 1, i passes a point before p. Therefore D(i) is less than D(p)
Also, I assume SEP(i, p) indicates separation when i passes a point before p.

I would go about it as follows:

Code: Select all

``````constraint1(i, p)\$([b]medium(i) and medium(p)[/b] and ord(i)<>ord(p) and R(i)=R(p)and PM(i)=PM(p)).. D(p)-D(i)=g= SEP(i,p)-M*E(i,p);
constraint2(i, p)\$([b]medium(i) and heavy(p)[/b] and R(i)=R(p)and PM(i)=PM(p)).. D(p)-D(i)=g= SEP(i,p)-M*E(i,p);
constraint3(i, p)\$([b]heavy(i) and medium(p)[/b] and R(i)=R(p)and PM(i)=PM(p)).. D(p)-D(i)=g= SEP(i,p)-M*E(i,p);
constraint4(i, p)\$([b]heavy(i) and heavy(p)[/b] and ord(i)<>ord(p) and R(i)=R(p)and PM(i)=PM(p)).. D(p)-D(i)=g= SEP(i,p)-M*E(i,p);``````
Please note that constraint 2 and 3 do not require ord(i)<>ord(p) since medium and heavy sets do not overlap.
Please also note that all constraints are same. The only difference is \$ conditions.

Hope this helps.

- Atharv

Kadir
User
Posts: 6
Joined: 1 month ago

### Re: SUBSET USAGE IN CONSTRAINT

Thank you very much Atharv,
I figure it out thanks to you.
Last edited by Kadir 1 month ago, edited 2 times in total.

abhosekar
Moderator
Posts: 92
Joined: 3 months ago

### Re: SUBSET USAGE IN CONSTRAINT

condition1 and condition2

implies that both conditions need to be satisfied in order for this to be true.

similarly, condition1 or condition2 implies that any one of the two condition needs to be satisfied for this to be true.

Hope it is clear now.

- Atharv