- java.lang.Object
-
- org.jgrapht.alg.tour.HamiltonianCycleAlgorithmBase<V,E>
-
- org.jgrapht.alg.tour.FarthestInsertionHeuristicTSP<V,E>
-
- Type Parameters:
V
- the graph vertex typeE
- the graph edge type
- All Implemented Interfaces:
HamiltonianCycleAlgorithm<V,E>
public class FarthestInsertionHeuristicTSP<V,E> extends HamiltonianCycleAlgorithmBase<V,E>
The farthest insertion heuristic algorithm for the TSP problem.The travelling salesman problem (TSP) asks the following question: "Given a list of cities and the distances between each pair of cities, what is the shortest possible route that visits each city exactly once and returns to the origin city?".
Insertion heuristics are quite straightforward, and there are many variants to choose from. The basics of insertion heuristics is to start with a partial tour of a subset of all cities, and then iteratively an unvisited vertex (a vertex whichis not in the tour) is chosen given a criterion and inserted in the best position of the partial tour. Per each iteration, the farthest insertion heuristic selects the farthest unvisited vertex from the partial tour. This algorithm provides a guarantee to compute tours no more than 0(log N) times optimum (assuming the triangle inequality). However, regarding practical results, some references refer to this heuristic as one of the best among the category of insertion heuristics. This implementation uses the longest edge by default as the initial sub-tour if one is not provided.
The description of this algorithm can be consulted on:
Johnson, D. S., & McGeoch, L. A. (2007). Experimental Analysis of Heuristics for the STSP. In G. Gutin & A. P. Punnen (Eds.), The Traveling Salesman Problem and Its Variations (pp. 369–443). Springer US. https://doi.org/10.1007/0-306-48213-4_9This implementation can also be used in order to augment an existing partial tour. See constructor
FarthestInsertionHeuristicTSP(GraphPath)
.The runtime complexity of this class is $O(V^2)$.
This algorithm requires that the graph is complete.
- Author:
- J. Alejandro Cornejo-Acosta
-
-
Constructor Summary
Constructors Constructor Description FarthestInsertionHeuristicTSP()
Constructor.FarthestInsertionHeuristicTSP(GraphPath<V,E> subtour)
Constructor Specifies an existing sub-tour that will be augmented to form a complete tour whengetTour(org.jgrapht.Graph)
is called
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description GraphPath<V,E>
getTour(Graph<V,E> graph)
Computes a tour using the farthest insertion heuristic.-
Methods inherited from class org.jgrapht.alg.tour.HamiltonianCycleAlgorithmBase
checkGraph, closedVertexListToTour, edgeSetToTour, getSingletonTour, requireNotEmpty, vertexListToTour
-
-
-
-
Constructor Detail
-
FarthestInsertionHeuristicTSP
public FarthestInsertionHeuristicTSP()
Constructor. By default a sub-tour is chosen based on the longest edge
-
FarthestInsertionHeuristicTSP
public FarthestInsertionHeuristicTSP(GraphPath<V,E> subtour)
Constructor Specifies an existing sub-tour that will be augmented to form a complete tour whengetTour(org.jgrapht.Graph)
is called- Parameters:
subtour
- Initial sub-tour, or null to start with longest edge
-
-
Method Detail
-
getTour
public GraphPath<V,E> getTour(Graph<V,E> graph)
Computes a tour using the farthest insertion heuristic.- Parameters:
graph
- the input graph- Returns:
- a tour
- Throws:
IllegalArgumentException
- if the graph is not undirectedIllegalArgumentException
- if the graph is not completeIllegalArgumentException
- if the graph contains no vertices
-
-