Package com.jgalgo.alg.shortestpath
Class TspAbstract
java.lang.Object
com.jgalgo.alg.shortestpath.TspAbstract
- All Implemented Interfaces:
Tsp
- Direct Known Subclasses:
TspMetricMatchingAppx
,TspMetricMstAppx
Abstract class for computing the shortest tour that visit all vertices in a graph.
The class implements the interface by solving the problem on the index graph and then maps the results back to the original graph. The implementation for index graphs is abstract and left to the subclasses.
- Author:
- Barak Ugav
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptioncomputeShortestTour
(Graph<V, E> g, WeightFunction<E> w) Compute the shortest tour that visit all vertices.
-
Constructor Details
-
TspAbstract
public TspAbstract()Default constructor.
-
-
Method Details
-
computeShortestTour
Description copied from interface:Tsp
Compute the shortest tour that visit all vertices.Note that this problem is NP-hard and therefore the result is only the best approximation the implementation could find.
If
g
is anIntGraph
, an optional ofIPath
is returned. In that case, its better to pass aIWeightFunction
asw
to avoid boxing/unboxing.- Specified by:
computeShortestTour
in interfaceTsp
- Type Parameters:
V
- the vertices typeE
- the edges type- Parameters:
g
- a graph containing all the vertices the tour must visit, using its edgesw
- an edge weight function- Returns:
- an optional of the tour calculated, or an empty optional if no such path was found
-