Enforce constraints in nth visited node

28 Views Asked by At

I have a problem similar to the tsp problem where : $x_{i,j} \in \left\{0,1\right\}$, is 1 if I visit node $j$ immediately after node $i$.

Now suppose that I need to enforce constraints for the n-th visited node, how would I do that in an efficient way, given the fact that I do not know a-priori which node I will visit first, second etc?

To elaborate, this would be part of my program:

$min \sum_i \sum_j c_{i,j} y_{i,j}$

st. $ ~ y_{i,j} \le M ~ x_{i,j} ~~~ \forall ~ i,j $

$ ~ y_{i,j} \ge P_n~ x_{i,j} ~~~~ $ if $j$ is the n-th visited node

$ y \in \mathbb{R}_+ $

1

There are 1 best solutions below

0
On

The following may be more cumbersome than necessary, but I think it will work. (I do recommend checking it carefully, though.)

I'll assume that the starting point for your trip is a (possibly artificial) node with index 0, since you said you do not know which node is visited first. Start by adding the Miller-Tucker-Zemlin constraints. That adds (continuous) variables $u_i$ with domain $[1,\dots,m]$ (where $m$ is the number of nodes). Fix $u_0=0$ and constraints$$u_i - u_j + 1\le m(1-x_{ij})$$for all $i,j$ (including $i=0$ but excluding $j=0$ if this is a closed tour). The result is that $u_i$ will equal $k$ if and only if node $i$ is the $k$-th stop.

Now add binary variables $z_i\,(i=1,\dots,m)$ and add the constraint$$\sum_{i=1}^m z_i=1.$$Variable $z_i$ will be 1 if and only if node $i$ is the $n$-th node visited. To enforce this, add$$u_j \ge n z_j\,\forall j=1,\dots,m$$(which ensures that $z_j=1$ implies that node $j$ is visited no earlier than the $n$-th stop) and$$u_i\le n-1 + (m-n+1)(2-x_{ij}-z_j)\, \forall i,j\in\{0,\dots,m\},j\neq 0.$$This last constraint ensures that if $z_j=1$ and $x_{ij}=1$, $u_i \le n-1$. Combine those and you have that $z_j=1$ implies $j$ is at least stop $n$ and its predecessor was at most stop $n-1$, so node $j$ must be stop $n$.

Now you just have to frame your conditional constraints using $z$ as the indicator of which stop is stop $n$.