- Type Parameters:
V
- the graph vertex typeE
- the graph edge type
- All Implemented Interfaces:
HamiltonianCycleAlgorithm<V,
E>
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?".
The Greedy heuristic gradually constructs a tour by repeatedly selecting the shortest edge and adding it to the tour as long as it doesn’t create a cycle with less than N edges, or increases the degree of any node to more than 2. We must not add the same edge twice of course.
The implementation of this class is based on:
Nilsson, Christian. "Heuristics for the traveling salesman problem." Linkoping University 38
(2003)
The runtime complexity of this class is $O(V^2 log(V))$.
This algorithm requires that the graph is complete.
- Author:
- Peter Harman
-
Constructor Summary
-
Method Summary
Methods inherited from class org.jgrapht.alg.tour.HamiltonianCycleAlgorithmBase
checkGraph, closedVertexListToTour, edgeSetToTour, getSingletonTour, requireNotEmpty, vertexListToTour
-
Constructor Details
-
GreedyHeuristicTSP
public GreedyHeuristicTSP()
-
-
Method Details
-
getTour
Computes a tour using the greedy 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
-