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

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

I have 8 binary variables :

 a,b,c,d,e,f,g,h

I want to define a variable (x) with the help of linear equations with following conditions:

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:

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.

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 + Mx;
eq2… sum(i,z(i)) =g= 2 - M
(1-x);

best

I appreciate your help ( suggesting big M method), but it is giving wrong answer, when applied to 2 binary variable problem

sure, I misunderstood.
the above takes x as the main variable.

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

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 + Mx;
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!

How about this?

* 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;