# How to add Binary Variable with condition in LP

### Notation

• $$\text{src}_{h,s},\text{dst}_{h,s},\text{ch}_{h,s}$$ are constants.

• $$a_{h,s},x_{i,j,s}$$ are binary variables.

• $$\text{wt}_{h,s}$$ are continuous variables.

### Problem

\begin{align}\min.&\qquad\sum_{h \in H}\sum_{s\in S}(\text{src}_{h,s}+\text{ch}_{h,s}+\text{dst}_{h,s}+\text{wt}_{h,s})\times a_{h,s}\\\text{s.t.}&\qquad{\forall i,j\in H,\,\forall s\in S}:\text{wt}_{j,s}\geq((\text{src}_{i,s}+\text{ch}_{i,s}+\text{wt}_{i,s})-\text{src}_{j,s})\times x_{i,j,s}\end{align}

Now $$x_{i,j,s} = 1$$ only when vehicle $$i$$ charges before vehicle $$j$$. (Finding minimum time for vehicle to reach to its destination) for reference.

Vehicle $$i$$ charges before $$j$$ only when $$\text{src}_{i,s} < \text{src}_{j,s}$$ so how could I force $$x_{i,j,s} = 1$$ when this condition meets?

• If $src$ are constants, then you know in advance whether $i$ charges before $j$, and you can just force $x_{ijs} = 1$ in this case (via a constraint or via treating it like a constant) — or am I missing something? – LarrySnyder610 Aug 3 '19 at 21:42
• yes, you are right. – ooo Aug 4 '19 at 8:50
• In that case I will write it as an answer in case it is useful to future readers. – LarrySnyder610 Aug 5 '19 at 0:41

Since the $$\text{src}$$ are constants, you know in advance whether $$i$$ charges before $$j$$, and you can just force $$x_{ijs}=1$$ in this case (via a constraint or by treating it like a constant).
• when $$x_{i,j,s} = 1$$, the condition must be true ($$i$$ charges before $$j$$)
• when $$x_{i,j,s} = 0$$, the condition must be false ($$i$$ charges after $$j$$)