Help in writing linear equations based on conditionality in GAMS (9 variables) Topic is solved

Problems with modeling
Post Reply
parag_patil
User
User
Posts: 30
Joined: 3 years ago
Location: Ahmedabad
Contact:

Help in writing linear equations based on conditionality in GAMS (9 variables)

Post by parag_patil »

I have tried following problem, but I could not solve it. Can you please help me in this?

I have 8 binary variables :

Code: Select all

 a,b,c,d,e,f,g,h
I want to define a variable (x) with the help of linear equations with following conditions:

Code: Select all

x=0, if a+b+c+d+e+f+g+h≤1
x=1, if a+b+c+d+e+f+g+h>1
Further, in my problem, these variables can be more or less than 8. Thus, can you help me in finding a general set of linear equations with n binary variables satisfying the following:

Code: Select all

x=0, if a+b+c+d+e+f+g+h+…≤1
x=1, if a+b+c+d+e+f+g+h+…>1
Thank you.
Manassaldi
User
User
Posts: 118
Joined: 7 years ago
Location: Rosario - Argentina

Re: Help in writing linear equations based on conditionality in GAMS (9 variables)

Post by Manassaldi »

hi, i think i'd better index the variables.

x=0, if a+b+c+d+e+f+g+h≤1 => x=0, if sum(i,z(i)) ≤ 1
x=1, if a+b+c+d+e+f+g+h>1 => x=1, if sum(i,z(i)) > 1

so maybe a "bigM" decomposition can work. M is a large enough parameter

eq1.. sum(i,z(i)) =l= 1 + M*x;
eq2.. sum(i,z(i)) =g= 2 - M*(1-x);

best
parag_patil
User
User
Posts: 30
Joined: 3 years ago
Location: Ahmedabad
Contact:

Re: Help in writing linear equations based on conditionality in GAMS (9 variables)

Post by parag_patil »

I appreciate your help ( suggesting big M method), but it is giving wrong answer, when applied to 2 binary variable problem
Manassaldi
User
User
Posts: 118
Joined: 7 years ago
Location: Rosario - Argentina

Re: Help in writing linear equations based on conditionality in GAMS (9 variables)

Post by Manassaldi »

sure, I misunderstood.
the above takes x as the main variable.
parag_patil
User
User
Posts: 30
Joined: 3 years ago
Location: Ahmedabad
Contact:

Re: Help in writing linear equations based on conditionality in GAMS (9 variables)

Post by parag_patil »

Hi, still I did not understand. If it is possible, can you write the correct answer please? I'm trying it since few days. I'm not able to get it done.

Thanks
Manassaldi
User
User
Posts: 118
Joined: 7 years ago
Location: Rosario - Argentina

Re: Help in writing linear equations based on conditionality in GAMS (9 variables)

Post by Manassaldi »

Hi, I don't know if I have the correct answer. I only try to help you based on what you comment. There is no single way to solve problems.
try adding these restrictions

eq1.. sum(i,z(i)) =l= 1 + M*x;
eq2.. sum(i,z(i)) =g= 2 - M*(1-x);
eq3.. sum(i,z(i)) + 1 - x =g= 1;
eq4(i).. 1 - z(i) + sum(j$(ord(j) ne ord(i)),z(j)) + 1 - x =g= 1;

I hope you can solve your problem, regards!
User avatar
dirkse
Moderator
Moderator
Posts: 215
Joined: 7 years ago
Location: Fairfax, VA

Re: Help in writing linear equations based on conditionality in GAMS (9 variables)

Post by dirkse »

How about this?

Code: Select all

* find binary variables y_i, x, such that
*  x=0  if sum_y <= 1
*  x=1  if sum_y > 1
set i / i1 * i8 /;
scalar M 'big-M of card(i) is enough' / [card(i)] /;
binary variable y(i);
binary variable x;

equation smallsum '(1-x) should be 1 if ysum is small-ish';
smallsum.. (1-x) * 2 + sum{i, y(i)} =G= 2;

equation bigsum 'x should be 1 if ysum is not small-ish';
bigsum.. sum{i, y(i)} =L= 1 + M * x;
Post Reply