values of sets in binary variable

Problems with syntax of GAMS
Post Reply
Yildirim
User
User
Posts: 1
Joined: 2 years ago

values of sets in binary variable

Post by Yildirim »

Why can't I increase or subtract sets in binary variable? I shared my problem below to be more descriptive.
I have defined x(i,j,t) as binary variable in my model. I want to write x(i,j,t-1) in the constraints section but I get an error. some part of my model is below:

binary variable x(i,j,t) if cell (i.j) is visited at t'th move of AGV;
equations
c3(i,j).. sum(t,x(i,j,t+1)) =e= 1;

I also defined v(m) and h(m) parameters in my model, I want to bring the values in these parameters to x(i,j,t) values, but I couldn't write them. You can see the part I want to write below.

Code: Select all

sets
i /1*10/ 
j /1*10/
m /1*12/
t /0*100/;
parameters
v(m)    coordinate i vaalue of machine m 
/
1        1
2        6
3        2
4        2
5        2
6        8
7        4
8        7
9        3
10       3
11       3
12       8
/
h(m)   coordinate j vaalue of machine m  
/
1        10
2        1
3        2
4        10
5        9
6        3
7        5
8        1
9        7
10       8
11       8
12       8
/;

[b]binary variable [/b]x(i,j,t) if cell (i.j) is visited at t'th move of AGV;

c1(m).. sum(t,x(v(m),h(m),t)) =e= 1;

how can i write constraint c1?
Thanks for your help

[b]all model:[/b]
sets
i /1*10/ 
j /1*10/
m /1*12/
t /0*100/;
parameters
v(m)    coordinate i vaalue of machine m 
/
1        1
2        6
3        2
4        2
5        2
6        8
7        4
8        7
9        3
10       3
11       3
12       8
/

h(m)   coordinate j vaalue of machine m  
/
1        10
2        1
3        2
4        10
5        9
6        3
7        5
8        1
9        7
10       8
11       8
12       8
/;

variable Z;
    binary variable x(i,j,t) if cell (i.j) is visited at t'th move of AGV;
positive variables
bi(t)
bj(t)
;

equations
obj
c1(m) all mach.s are visited once
c2(t) AGV is at one cell at one time
c3(i,j) No cell is visited twice
c4(t) AGV can only move to adjacent squares
c5 AGV start at cell(10-5)
c6 AGV ends at cell S (10-5)
c7(t)
c8(t);


c1(m).. sum(t,x(v(m),h(m),t)) =e= 1;
c2(t).. sum(i,sum(j,x(i,j,t))) =e= 1;
c3(i,j).. sum(t,x(i,j,t+1)) =e= 1;
c4(t).. x(bi(t)-1,bj(t),t+1)+ x(bi(t)+1,bj(t),t+1)+x(bi(t),bj(t)-1,t+1)+x(bi(t),bj(t)+1,t+1)=e=1;
c5.. x('10','5','0')=e=1;
c6.. sum(t,x('10','5',t) * t)=g=35;
c7(t).. bi(t) =e= sum(i,sum(j,i*x(i,j,t)));
c8(t).. bj(t) =e= sum(i,sum(j,j*x(i,j,t)));
obj.. Z =e= sum(t,x('10','5',t)*t.l);
model s1 /all/;
option optcr=0;
solve s1 using  MINLP min Z;
abhosekar
Moderator
Moderator
Posts: 295
Joined: 3 years ago

Re: values of sets in binary variable

Post by abhosekar »

I see the problem. You are trying to access variables by parameters. x(v(m)) makes no sense to GAMS as v(m) is not even set. Just because v(m) is 1, does not mean it is 1 that is contained in the set i. One easy way to see why this is flawed is following: If you rename the set i /1*10/ to be i /i1*i10/, you will never have v(m) to be anything inside set i. This would mean your equation doesn't make sense. It is often beneficial to think of elements of sets like strings and not numbers.

Now the solution:

Code: Select all

c1(i, j, m)$((ord(i)=v(m)) and (ord(j) = h(m))).. sum(t,x(i,j,t)) =e= 1;
Here instead of defining c1 over m, I am defining it over (i, j, m) and I am saying I want only those i and j where (ord(i) = v(m)) and (ord(j) = h(m)).

Your second problem. in constraint c3, you have t + 1.
sum(t, x(i, j, t + 1)).
Do you need t + 1 to ensure that this constraint is not valid for t = 0?
So a cleaner way to do that would be as follows:

Code: Select all

c3(i, j).. sum(t$(t.val =0), x(i, j, t)) =e= 1;
- Atharv
scholar.furquan
User
User
Posts: 3
Joined: 2 years ago

Re: values of sets in binary variable

Post by scholar.furquan »

c1(i, j, m)$((ord(i)=v(m)) and (ord(j) = h(m))).. sum(t,x(v(m),h(m),t)) =e= 1;

This equation is showing an error after following the said modificaitons !!
abhosekar
Moderator
Moderator
Posts: 295
Joined: 3 years ago

Re: values of sets in binary variable

Post by abhosekar »

Fixed the typo. It should be x(i,j,t).
- atharv
scholar.furquan
User
User
Posts: 3
Joined: 2 years ago

Re: values of sets in binary variable

Post by scholar.furquan »

sets
i /i1*i10/
j /j1*j10/
m /1*12/
t /t0*t100/;
parameters
v(m) coordinate i vaalue of machine m
/
1 1
2 6
3 2
4 2
5 2
6 8
7 4
8 7
9 3
10 3
11 3
12 8
/

h(m) coordinate j vaalue of machine m
/
1 10
2 1
3 2
4 10
5 9
6 3
7 5
8 1
9 7
10 8
11 8
12 8
/;

variable Z;
binary variable x(i,j,t) if cell (i.j) is visited at t'th move of AGV;
positive variables
bi(t)
bj(t)
;

equations
obj
c1(i,j,m) all mach.s are visited once
c2(t) AGV is at one cell at one time
c3(i,j) No cell is visited twice
c4(t) AGV can only move to adjacent squares
c5 AGV start at cell(10-5)
c6 AGV ends at cell S (10-5)
c7(t)
c8(t);

c1(i,j,m)$((ord(i)=v(m)) and (ord(j) = h(m))).. sum(t,x(i,j,t)) =e= 1;
*c1(m).. sum(t,x(v(m),h(m),t)) =e= 1;
c2(t).. sum(i,sum(j,x(i,j,t))) =e= 1;
c3(i, j).. sum(t$(t.val =0), x(i, j, t)) =e= 1;
*c3(i,j).. sum(t,x(i,j,t+1)) =e= 1;
c4(t).. x(bi(t)-1,bj(t),t+1)+ x(bi(t)+1,bj(t),t+1)+x(bi(t),bj(t)-1,t+1)+x(bi(t),bj(t)+1,t+1)=e=1;
c5.. x('10','5','0')=e=1;
c6.. sum(t,x('10','5',t) * t)=g=35;
c7(t).. bi(t) =e= sum(i,sum(j,i*x(i,j,t)));
c8(t).. bj(t) =e= sum(i,sum(j,j*x(i,j,t)));
obj.. Z =e= sum(t,x('10','5',t)*t.l);
model s1 /all/;
option optcr=0;
solve s1 using MINLP min Z;
abhosekar
Moderator
Moderator
Posts: 295
Joined: 3 years ago

Re: values of sets in binary variable

Post by abhosekar »

Hi,

I suggest using .val only if set elements are numbers. So now in your code, I see set t/t0*t100/ and you are using t.val. This does not make sense. Please keep your set t to be /0*100/ if you want to use .val.

Besides, the errors you see now are just the repeat of your previous errors. The variable x is defined over "sets" i, j ,and t. In equation c4, you are trying to access x(bi(t)-1,..)
Note that bi(t) -1 is not a set nor is it an element of the set i. Therefore, you get this error. I don't know what you intend to do here so I cannot suggest anything. I would just add one point for you to think about. bi(t) can also be a fraction when a solve progresses in which case x(bi(t)-1,..) would make even less sense.

Also, what I showed you in my previous reply is just one of the ways to make your code work without changing much. The real clean way would be to define a 2D set to map set m and sets i and j.

Code: Select all

set mi(m, i), mj(m, j);
mi(m, i)$(ord(i) = v(m)) = yes;
mi(m, j)$(ord(j) = h(m)) = yes;
You can then use these sets for defining your equations.

HTH.

- Atharv
scholar.furquan
User
User
Posts: 3
Joined: 2 years ago

Re: values of sets in binary variable

Post by scholar.furquan »

Thank you for your valuable reply.

This code is not of mine, but i was learning how to debug the GAMS for various errors (like the ones above).TQ
Post Reply