Class TspMetricMatchingAppx

  • All Implemented Interfaces:
    TspMetric

    public class TspMetricMatchingAppx
    extends Object
    TSP \(3/2\)-approximation using maximum matching.

    The running of this algorithm is \(O(n^3)\) and it achieve \(3/2\)-approximation to the optimal TSP solution.

    Based on 'Worst-Case Analysis of a New Heuristic for the Travelling Salesman Problem' by Nicos Christofides (1976).

    Author:
    Barak Ugav
    • Constructor Detail

      • TspMetricMatchingAppx

        public TspMetricMatchingAppx()
        Create a new TSP \(3/2\)-approximation algorithm.
    • Method Detail

      • computeShortestTour

        public <V,​E> Path<V,​E> computeShortestTour​(Graph<V,​E> g,
                                                               WeightFunction<E> w)
        Description copied from interface: TspMetric
        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.

        Specified by:
        computeShortestTour in interface TspMetric
        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