Class Salesman

Direct Known Subclasses:
SalesmanPruning

public class Salesman extends HamiltonianAll

Traveling Salesman

Extends HamiltonianAll to find the global minimum cost cycle. Unlike the base class, it stores bestCost and updates it whenever a shorter Hamiltonian cycle is discovered.

  • Field Details

    • bestPath

      protected final int[] bestPath
    • bestCost

      protected int bestCost
  • Constructor Details

    • Salesman

      public Salesman(int n, int source, int[][] weights)
  • Method Details

    • backtrack

      protected void backtrack(int current)
      Description copied from class: HamiltonianAll
      Core backtracking logic following the Choose-Explore-Unchoose paradigm.
      Overrides:
      backtrack in class HamiltonianAll
      Parameters:
      current - The current node being visited.
    • getBestCost

      public int getBestCost()
    • getBestPath

      public String getBestPath()