-1

Suppose $i$ varies from $0$ to $4$.

$A_i$, $S_i$, $E_i$ are binary variables.

Now, if $S_1=1$ and $E_3=1$, then how to make $A_1=A_2=A_3=1$ and $A_0=A_4=0$ using linear equations?

creative
  • 3,539
Dr.PB
  • 143
  • Those... are linear equations? If they don't work for you, can you clarify what more you want from them? – Misha Lavrov Mar 27 '17 at 06:41
  • How to represent them in linear equation? sum of (Ai)=3 but this does not guarantee A4 will be 0... – Dr.PB Mar 27 '17 at 06:44
  • What I mean is, $A_0 = 0$ and $A_1 = 1$ and $A_2 = 1$ and so on are all linear equations already. – Misha Lavrov Mar 27 '17 at 06:46
  • S[1]=1. E[3]=1, Then for which linear equation(s) make A[1to3]=1. 3E[3]-1xS[1]+1=3, terms of A[i] will be 1. so sum of A[i]=3; S[1]=A[1] and E[1]=A[1] is also okay. But to forcefully make all middle A[i] =1? – Dr.PB Mar 27 '17 at 06:53
  • If the $A$ are known,what's the point including them in the equations ? They aren't unknowns, they are constants. –  Mar 27 '17 at 07:03
  • "for all i between Si and Ei on Ai": what the hell does that mean ? –  Mar 27 '17 at 07:05

1 Answers1

0

If you add a constraint $$A_i = \sum_{j \le i} S_j - \sum_{j < i} E_j$$ for each value of $i$ then I think that does what you want.

Assuming there is some starting index $a$ for which $S_a = 1$ and some ending index $b$ for which $E_b = 1$, and all other $S$ and $E$ variables are $0$, the first sum in this constraint will be $1$ if $i \ge a$, and the second sum will be $1$ if $i > b$. So we'll have $0-0$ for $i<a$, $1-0$ for $a \le i \le b$, and $1-1$ for $i>b$.

You probably also want the constraints $$\sum_{i=0}^n S_i = \sum_{i=0}^n E_i = 1,$$ so that there's exactly one starting index and exactly one ending index.

Misha Lavrov
  • 142,276