I have three variables : A, B, C.
I want to write a linear equation such that
X = 1 if atleast 2 of A,B,C are ones.
X= 0 if only one of A,B,C is one.
A,B and C are binary (0,1).
Kindly suggest a linear equation for this.
Thank you.
I have three variables : A, B, C.
I want to write a linear equation such that
X = 1 if atleast 2 of A,B,C are ones.
X= 0 if only one of A,B,C is one.
A,B and C are binary (0,1).
Kindly suggest a linear equation for this.
Thank you.
Hi, i think this could work. Please check it.
if atleast 2 of A,B,C are ones then X = 1
X + 1 - A + 1 - B =g= 1;
X + 1 - A + 1 - C =g= 1;
X + 1 - B + 1 - C =g= 1;
if X = 1 then 2 of A,B,C are ones
1 - X + A + B =g= 1
1 - X + A + C =g= 1
1 - X + A + B + C =g= 1
1 - X + B + C =g= 1
if only one of A,B,C is one then X=0
1 - A + B + C + 1-x =g= 1
1 - B + A + C + 1-x =g= 1
1 - C + B + A + 1-x =g= 1
if X = 0 then one of A,B,C are ones
X + A + B + C =g= 1
X + A + 1-B + 1-C =g= 1
X + 1-A + 1-B =g= 1
X + 1-A + 1-B + C =g= 1
X + 1-A + 1-B + 1-C =g= 1
X + 1-B + 1-C =g= 1
X + 1-A + 1-C =g= 1
X + 1-A + B + 1-C =g= 1
X + 1-B + 1-C =g= 1
best
Thank you for your reply.
But I only want a one set of equations which will satisfy the conditions
If you put them together, they are a single set of equations. I don’t think you will achieve your goal with a single equation.
best
binary variable
X,A,B,C
;
equation
eq1,eq2,eq3,eq4,eq5,eq6,eq7,eq8,
eq9,eq10,eq11,eq12,eq13,eq14,eq15,eq16
eq17,eq18,eq19,eq20
;
variable
z
;
eq1.. X + 1 - A + 1 - B =g= 1;
eq2.. X + 1 - A + 1 - C =g= 1;
eq3.. X + 1 - B + 1 - C =g= 1;
eq4.. 1 - X + A + B =g= 1 ;
eq5.. 1 - X + A + C =g= 1 ;
eq6.. 1 - X + A + B + C =g= 1 ;
eq7.. 1 - X + B + C =g= 1 ;
eq8.. 1 - A + B + C + 1-x =g= 1 ;
eq9.. 1 - B + A + C + 1-x =g= 1 ;
eq10.. 1 - C + B + A + 1-x =g= 1 ;
eq11.. X + A + B + C =g= 1 ;
eq12.. X + A + 1-B + 1-C =g= 1 ;
eq13.. X + 1-A + 1-B =g= 1 ;
eq14.. X + 1-A + 1-B + C =g= 1 ;
eq15.. X + 1-A + 1-B + 1-C =g= 1 ;
eq16.. X + 1-B + 1-C =g= 1 ;
eq17.. X + 1-A + 1-C =g= 1 ;
eq18.. X + 1-A + B + 1-C =g= 1 ;
eq19.. X + 1-B + 1-C =g= 1 ;
eq20.. z=e=1;
model test /All/
solve test using mip max z;