Interface TspMetric

  • All Known Implementing Classes:
    TspMetricMatchingAppx, TspMetricMSTAppx

    public interface TspMetric
    Metric Traveling Salesman Problem (TSP) algorithm.

    Given a list of points, the traveling salesman problem asking what is the shortest tour to visit all points. The metric version of TSP is a special case in which the distances satisfy the triangle inequality and the distances are symmetric.

    The problem itself is NP-hard, but various approximation algorithms exists.

    Author:
    Barak Ugav
    See Also:
    Wikipedia
    • Method Detail

      • computeShortestTour

        <V,​E> Path<V,​E> computeShortestTour​(Graph<V,​E> g,
                                                        WeightFunction<E> w)
        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 an IntGraph, a IPath object is returned. In that case, its better to pass a IWeightFunction as w to avoid boxing/unboxing.

        Type Parameters:
        V - the vertices type
        E - the edges type
        Parameters:
        g - a graph containing all the vertices the tour must visit, using its edges
        w - an edge weight function. In the metric world every three vertices \(u,v,w\) should satisfy \(w((u,v)) + w((v,w)) \leq w((u,w))$
        Returns:
        a result object containing the list of the \(n\) vertices ordered by the calculated path. If the graph contains no vertices, null is returned