Or statements in equations

Problems with syntax of GAMS
Post Reply
User avatar
makro2005
User
User
Posts: 2
Joined: 6 years ago

Or statements in equations

Post by makro2005 »

Hi everyone,
I'm new at GAMS and i'm try to write a code with some knownlage of code writing with other languages like java. Anyway i want to write a code that gives me cordinates of departments in a fabric. I should add to my code some constrains to block overlapping departments and I thought I can add those equations to my code;
-----------------------------------------------------------------------

Code: Select all

sets
i         departmants
alias(i,j)
;
variables
x(i)      x cord of dep i
y(i)      y cord of dep i
w(i)      width of dep i
l(i)      lenght of dep i
;
Equations
eq13(i,j) .. (x(j)-(w(j)/2))=g=(x(i)+(w(i)/2)) or (x(j)+(w(j)/2))=l=(x(i)-(w(i)/2));
eq14(i,j) .. (y(j)-(l(j)/2))=g=(y(i)+(l(i)/2)) or (y(j)+(l(j)/2))=l=(y(i)-(l(i)/2));
-------------------------------------------------------------------------
What i want is that;
department j should not be on department i so department j should not between on x(i)-w(i) and x(i)+w(i)
but gams says me you can't use or statement like that so can you help me?

(p.s.: If anyone wants, i can show full of my code)
A simple Industrial Engineer as known as the panda that loves coding :ugeek:
User avatar
makro2005
User
User
Posts: 2
Joined: 6 years ago

Re: Or statements in equations

Post by makro2005 »

Accually I fixed it today 8-) with these equations, 2 binary variables and M (big m method) constant

Code: Select all

Eq17(i,j).. ij(i,j)*0.5*(w(i)+w(j))=l= x(i)-x(j) + M *(bin1(i,j)+bin2(i,j))  ;
Eq18(i,j).. ij(i,j)*0.5*(w(i)+w(j))=l= -(x(i)-x(j)) + M *bin1(i,j)+ M *(1-bin2(i,j))  ;
Eq19(i,j).. ij(i,j)*0.5*(l(i)+l(j))=l= y(i)-y(j) + M *(1-bin1(i,j)) + M *bin2(i,j)  ;
Eq20(i,j).. ij(i,j)*0.5*(l(i)+l(j))=l= -(y(i)-y(j)) + M *(1-bin1(i,j)) + M *(1-bin2(i,j))  ;
( ij(i,j) is a table I create to provide i<j condition. Where i<j table returns 1 otherwise 0. And M should be very large like 10000 )
A simple Industrial Engineer as known as the panda that loves coding :ugeek:
Post Reply