is_valid_tsp_tour

is_valid_tsp_tour(bitstring, n_cities)[source]

Check if a bitstring represents a valid TSP tour.

A valid tour has the assignment matrix (reshaped from the bitstring) as a permutation matrix: every row and column sums to exactly 1.

Parameters:
  • bitstring (str) – Binary string of length (n_cities - 1)².

  • n_cities (int) – Total number of cities (including the fixed start city).

Return type:

bool

Returns:

True if the bitstring encodes a valid permutation.