Class TravelingSalesman

java.lang.Object
io.openml.gearbox.TravelingSalesman

public final class TravelingSalesman extends Object
Solves the Traveling Salesman Problem (TSP) using the Held-Karp algorithm, which employs dynamic programming with bitmasking.

At its heart, the Traveling Salesman Problem asks a simple question: "Given a list of cities and the distances between each pair, what is the shortest possible route that visits each city exactly once and returns to the origin city?"

This implementation finds the exact optimal solution and is suitable for a small number of cities (e.g., up to ~22) due to its O(n^2 * 2^n) time complexity.

The class is marked as `final` to signify that its algorithmic implementation is complete and not designed for extension, ensuring its logical integrity.

Other references on traveling salesman problem include:

  • Constructor Details

    • TravelingSalesman

      public TravelingSalesman(double[][] distanceMatrix)
      Constructor.

      Prepares the solver for a given set of cities and their distances.

      Parameters:
      distanceMatrix - A square matrix where matrix[i][j] represents the distance from city i to city j.
      Throws:
      IllegalArgumentException - if distanceMatrix is null, or empty, or non-squarely shaped
  • Method Details

    • solve

      public TravelingSalesman.Tour solve()
      Executes the dynamic programming algorithm to find the optimal tour.
      Returns:
      A Tour record containing the minimum cost and the sequence of cities in the optimal path.