0
$\begingroup$

How to convert this one to a linear program:

if $x=1$ then $B=1$; otherwise, $B=0$.

If I use the Big M method: \begin{align}x&\ge1-M(1-B)\\x&\le1+M(1-B)\end{align}

A) with $B=1$: \begin{align}x&\ge1\\x&\le1\end{align} That is corresponding to $x=1$

B) with $B=0$: \begin{align}x&\ge1-M\\x&\le1+M\end{align} That is corresponding to any value of $x$ even $x=1$. How do I exclude $x=1$ when $B=0$?

$\endgroup$
4
  • 4
    $\begingroup$ What type of variable is $x$? $\endgroup$
    – RobPratt
    Commented Nov 25, 2022 at 18:20
  • $\begingroup$ If $x$ is continuous with constant bounds $-M \le x \le M$, see my answer here (take $b=1$, $L=-M$, and $U=M$): or.stackexchange.com/a/2632/500 $\endgroup$
    – RobPratt
    Commented Nov 25, 2022 at 18:46
  • $\begingroup$ Thanks! x is continuous $\endgroup$ Commented Nov 25, 2022 at 23:13
  • $\begingroup$ @RobPratt yes, it does. Thanks! $\endgroup$ Commented Nov 26, 2022 at 5:36

2 Answers 2

0
$\begingroup$

I think the two constraints put in there, lead to the same thing, just change the sign of one of those and then add the two constraints, it will lead to $M \ge 0$. Assuming $x$ is continuous, then you need:
C1 = $B \ E \ [0,1] \ and \ z \le 0$: B is binary.
Choose U such that it's the upper bound for x
C2 = $Uz \le x$: z is <0 for x=99, z will remain <0 for x=-99 as U is larger than x and when x=1, z=0
C3 = $Uz+L(z-1) \ge (1-x)*(L-U)$: if x=1 z is forced to 0 due to C2, if x=99, z remains <0, if x=-99, z is again <0
C4 = $B \ge z+1$: z <0, B can be 0 but when z=0, B =1
and Choose $M \gt \lvert {x} \rvert+1$, $L$ is lower bound of $x$ and should be <0 and $U$ is upper bound of $x$ and >0

$\endgroup$
7
  • $\begingroup$ x is continuous. Thanks for your trail of help, but that does not work. If x=0, then: C2 = M.B-M>=0: thus B=1 C3 = M.B-1<=M: thus, B is free. To satisfy C2 and C3, B will be 1. Thus your suggestion does not work. $\endgroup$ Commented Nov 26, 2022 at 1:09
  • $\begingroup$ Now? Does it solve? $\endgroup$ Commented Nov 26, 2022 at 1:44
  • $\begingroup$ Sorry no let assume 0<=x<=10 C2: Uz<=x with x=1: 10z<=1 z<=0.1 and z<=0 does not mean z==0 $\endgroup$ Commented Nov 26, 2022 at 4:22
  • $\begingroup$ But look at c3, z=-0.1, would make it infeasible, so solver will choose to make it 0. $\endgroup$ Commented Nov 26, 2022 at 4:54
  • $\begingroup$ I will double-check and let you know. Thank you. $\endgroup$ Commented Nov 26, 2022 at 4:59
-1
$\begingroup$

if x and B both are binary then x+B>=2 should work. this contriant is satisfactory only under one condition that is both x and B should be 1. for every other condition the constraint will be voilated.

$\endgroup$
2
  • 1
    $\begingroup$ If $x$ and $B$ are both binary, then $x=B$ is instead the correct constraint. $\endgroup$
    – RobPratt
    Commented Nov 25, 2022 at 20:26
  • $\begingroup$ That means the only solution is when x=1, but the optimal solution can be zero. By the way, the x variable is continuous $\endgroup$ Commented Nov 26, 2022 at 0:39

Not the answer you're looking for? Browse other questions tagged or ask your own question.