I have written the following code:
How to interpret auxiliary constraints and sub tour elimination constraints in the following formulation?
The interpretation of the MTZ subtour elimination approach is actually quite simple. Assign numbers u(i)
to each node in the order in which they are visited. The constraint
u(i) - u(j) + n x(i,j) <= n - 1
can be interpreted as
u(j) >= u(i) + 1 - M*(1-x(i,j))
or
x(i,j) = 1 ==> u(j) >= u(i) + 1
If you have a subtour say 2-3-2 this cannot hold:
2-3 means u(3) >= u(2)+1
3-2 means u(2) >= u(3)+1
As the whole tour should be allowed, we just drop the first node from this check.