• $\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.


\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?

  • 3
    $\begingroup$ 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? $\endgroup$ – LarrySnyder610 Aug 3 '19 at 21:42
  • $\begingroup$ yes, you are right. $\endgroup$ – ooo Aug 4 '19 at 8:50
  • 1
    $\begingroup$ In that case I will write it as an answer in case it is useful to future readers. $\endgroup$ – 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).


Add two indicator constraints:

  • 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$)

Most commercial solvers have simple APIs that allow you to add indicator constraints directly, without reformulation. For example, here's the documentation for Gurobi's addGenConstrIndicator function.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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