Traveling Salesman Problem
Traveling Salesman Problem
The Traveling Salesman Problem consists in solving the following:
Given a complete graph, with
The following elements come into play:
the complete graph with nodes, where is the set of nodes and cost associated with link decision variable - equals 1 if link is used in the solution, 0 otherwise - Objective: find an Hamiltonian circuit of minimum cost when the cost of a circuit is the sum of the costs of the links defining the circuit
Formulation of the TSP
There exist several formulations for the TSP.
Basic TSP formulation
A basic formulation of the [[#Traveling Salesman Problem]] is the following:
subject to:
where:
if link is used in the solution, 0 otherwise
DEGREE CONSTRAINTS:
The degree constraints are needed to ensure that every node has only one link entering it and one exiting it.
More specifically:
set of all links entering node set of all links exiting node
This formulation is not sufficient to define the problem. In fact, a possible solution with this formulation could give something like this:
In the solution shown above, we can see that every link is only visited once, and the cost was minimized. We can easily see thoug that many subtours were made in place of a single tour.
TSP formulation with subtours breaking constraints
In order to avoid subtours like the one originating from the [[#Basic TSP formulation]], a new constraint is added to the formulation:
subject to:
$
\begin{align}
\text{Degree constraints:} &\begin{cases}
\sum\limits_{j \in A^{+}(i)} x_{ij} = 1, \qquad \forall i \in V \
\sum\limits_{j \in A^{-}(i)} x_{ij} = 1, \qquad \forall i \in V \
x_{ij} \in {0,1}, \qquad \forall (i,j) \in V
\end{cases} \ \
\text{Subtour breaking constraint:} &\sum\limits_{i\in S, j \in S} x_{ij} \le |S| - 1, \qquad \forall S \ne 0, \quad S\subset V
\end{align}
$
where:
if link is used in the solution, 0 otherwise
is a subset of all the nodes ( )
Remember:
set of all links entering node set of all links exiting node
SUBTOUR BREAKING COSTRAINT:
The subset breaking constraint does the following: for any subset of nodes, the number of links connecting these nodes has to be lower or equal the number of nodes in the subset minus 1. With this constraint, if
Despite this constraint being theoretically acturate, and it would allow to come to the right solution to the problem, given a network with
conditions. These, is way too many for any computer when
TSP formulation with weak subtour breaking constraints
Since, as we've seen in [[#TSP formulation with subtours breaking constraints]], the formulation of the breaking constrains is highly impractical when it comes to solving the problem with a computer, we hereby propose an alternative formulation.
subject to:
where:
if link is used in the solution, 0 otherwise
Remember:
set of all links entering node set of all links exiting node
Explanation of the WEAK SUBTOUR BREAKING CONSTRAINT
The figure above shoes the same network with 2 different solutions to the TSP. Keep in mind only the links in the solution are shown, the network is supposed to be complete.
On the left, the solution breaks the the weak subtour breaking constraints. In fact,
On the write, a unique cycle where the only occasion where the constraint is broken is when it is actually allowed, at
Solving the TSP
Solving the [[Traveling Salesman Problem]] is no easy task. That is why the problem is most often approached through [[Heuristic]] methods.
These are methods that are not proven to be mathematically optimised (as a matter of fact, they are not), but rather use an intuitive approach to reach a solution that is, at the very least, good enough. They won't guarantee to approach the exact solution, but should be able to provide a solution that is not far from it.
We will see the following:
- [[#Nearest neighbour heuristic]]
- [[#Nearest neighbour insertion heuristic]]
- [[#Spanning tree heuristic]]
- [[#Christofides heuristic]]
- [[#Improvement heuristics]]
For any of the following method, a cost matrix is going to be needed. This is a matrix that, for each link, gives the cost of traveling on that link.
Nearest neighbour heuristic
The nearest neighbour heuristic is considered a [[greedy heuristic]].
To approach a solution this is how we proceed:
- Select a node
in the network. Label this node as to remember that has already been visited; - Look at all the links leaving node
and select the one with the lowest cost; - Follow the selected link to
and label it too; - Keep going like this until all nodes have been labeled.
We can think of labelling a node as to add it to a set
When all nodes are in
Nearest neighbour insertion heuristic
The nearest neighbour insertion heuristic is considered a [[greedy heuristic]].
- Select any initial subtour. The nodes in the subtour will go into a set
- For every
node not in the subtour, create a set, containing all costs from and to that node to every node in the subtour ( ) - we will have something like:
for each node
- we will have something like:
- Select the minimum cost of each set
: - Select the minimum of all the costs found in step 3
- Add the selected link to the subtour and repeat the steps
Spanning tree heuristic
To apply the spanning tree heuristic, a complete graph is needed:
- Find a minimum spanning tree of
--> - Double all arcs in
, generating an auxiliary graph: - Since each node has even degree, an Eulerian cycle exists
- Determine an Eulerian cycle:
- Assign an orientation to
- Select a starting node
- Determine an Eulerian cycle:
- Make a Hamiltonian cycle following the nodes in the order of the Eulerian cycle. whenever a node already visited should be selected, jump to the first available node in the Eulerian cycle
- Stop when the Hamiltonian cycle is complete
Finding a Minimum Spanning Tree - Prim's Algorithm
- Select an arbitrary node in the network
- Select the arc with the minimum cost among those that connect any node already in the ST to any node not yet in the spanning tree
- Repeat until the Spanning Tree contains all nodes in the network
Christofides heuristic
- Determine a Minimum Spanning Tree
of - Find all nodes with odd degree and find a Minimum Perfect Matching,
- Make a new graph,
, out of all the edges in and - Form an Eulerian cycle in
and orient it arbitrarily - Make a Hamiltonian cycle following the nodes in the order of the Eulerian cycle. whenever a node already visited should be selected, jump to the first available node in the Eulerian cycle
Stop when all nodes are part of the Hamiltonian cycle.
Improvement heuristics
In the heuristics described above, it is rare to find an optimal solution. They are, in general, of moderate quality. Therefore, we pose the question of how we can improve a Hamiltonian cycle found in one of the previous heuristic.
We will see the [[#Exchange Heuristic]]. This is quite intuitive to understand if we're looking at an Euclidean problems. In a Euclidean problem, the distance between 2 nodes is given simply by the Euclidean distance between the nodes (basically, the real distance in any geometric space).
In this case, whenever a Hamiltonian cycle crosses itself, there must exist a better path, without crossings. What we will do is to unfold the path where it crosses itself in order to have a lower cost.
In a general problem (not euclidean), we can't really think in terms of unfolding a crossing, but the concept stays the same. We'll try to exchange some links in order to bring the cost between 2 nodes down. This is what we do in the [[#Exchange Heuristic]]
Exchange Heuristic
Suppose we have a Hamiltonian cycle like the following:
We are interested in links:
The heuristic goes as follow:
- Choose any vertex
- Pick a pair of links such that they fall into the set
:
which means any pair of links such that they have at least one other link in between them.
3. For each pair in
then remove links
Repeat for every node in the network.
In the example we compare the cost of having the green links in place of the red ones. Since the cost is lower for the green pair, then we exchange them. Notice how we also need to switch the direction of the dashed links in order to keep the directed hamiltonian cycle.
In case of asymmetric graphs, we also need to check and compare the costs of the links we do not intend to exchange but that we need to reverse. It would become:
where the orange costs are the total costs to go from node