# 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? Commented Aug 3, 2019 at 21:42
• yes, you are right.
– ooo
Commented Aug 4, 2019 at 8:50
• In that case I will write it as an answer in case it is useful to future readers. Commented Aug 5, 2019 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$$)
{"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 1, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 21, "wp-katex-eq": 0, "align": 1, "equation": 0, "x-ck12": 0, "texerror": 0}