What is the TSP?
The Travelling Salesman Problem asks: given a list of cities and distances between them, what is the shortest route that visits each city exactly once and returns to the origin? TSP is NP-hard — no polynomial-time exact algorithm exists for arbitrary instances. At scale (hundreds of cities), heuristic solvers are the only practical option.
TSP appears in logistics route planning, circuit board drilling, DNA sequencing, telescope scheduling, and warehouse pick-path optimization. Even a 1% improvement in tour length translates directly to fuel savings and delivery time at scale.
Solving TSP with NEROX
import nerox
import numpy as np
# Build or load your distance matrix (n x n symmetric, zero diagonal)
n = 200
rng = np.random.default_rng(42)
coords = rng.random((n, 2)) * 1000
dist = np.linalg.norm(coords[:, None] - coords[None, :], axis=-1)
client = nerox.Client()
job = client.optimize.tsp(
distance_matrix=dist,
solver="gpu", # gpu | tabu | hybrid
n_runs=512, # independent annealing chains
time_limit_s=60, # stop after 60 wall-clock seconds
)
result = job.wait()
print(f"Tour length: {result.objective:.1f}")
print(f"Tour order: {result.solution}") # list of city indicesLarge-scale TSP (1,000+ cities)
For instances over ~2,000 cities, switch to the Hybrid Solver which automatically decomposes the problem into GPU-sized subproblems and reconstructs the global tour.
job = client.optimize.tsp(
distance_matrix=dist,
solver="hybrid",
n_passes=3, # number of decomposition rounds
)
result = job.wait(timeout=600)Streaming real-time progress
For interactive applications, stream solver progress as the GPU annealer improves the tour. Each event includes the current best tour length so you can update a live map.
for event in job.stream():
print(f"Iter {event.iteration:6d} best={event.best_energy:.1f}")Asymmetric TSP
Supply a non-symmetric distance matrix (where distance from A→B ≠ B→A) for problems like directed road networks with one-way streets. NEROX handles asymmetric instances natively — no reformulation needed.
