Practical guides to AI, computing, modelling, simulation, optimization and quantum computing, featuring hands-on tutorials, experiments and research.

Optimization Problems Explained: Traveling Salesman, Job Shop Scheduling, and the Knight’s Tour

Combinatorial Optimization · 2026

Optimization Problems Explained: TSP, Job Shop Scheduling, and the Knight’s Tour

Three classic combinatorial problems, one shared story: search spaces that explode faster than brute force can follow, and the greedy heuristics engineers reach for instead.

The Knight’s Tour walkthrough on this blog treats the problem as a coding exercise: implement Warnsdorff’s heuristic, watch a knight visit every square exactly once, move on. But the Knight’s Tour belongs to a much larger family — combinatorial optimization problems, where the challenge isn’t computing an answer, it’s searching an astronomically large space of candidate answers for a good one. The Traveling Salesman Problem and Job Shop Scheduling are the two most-cited members of that family, and putting all three side by side makes clear why certain techniques keep reappearing across logistics, manufacturing, and chessboard puzzles alike.


1  ·  What Makes a Problem “Combinatorial”

A combinatorial optimization problem asks for the best arrangement, ordering, or assignment out of a finite but enormous set of possibilities. “Finite” is the misleading part — finite doesn’t mean small. The number of ways to order 20 cities is 20! (roughly 2.4 × 1018), and it only grows from there. Checking every possibility, brute force, is correct but useless: even a supercomputer evaluating a trillion arrangements per second would need decades for a 25-city tour.

This is the shared root of all three problems below. Each has a small, easily-stated rule for what counts as a valid solution, and a combinatorial explosion of candidates that satisfy the rule. The interesting work isn’t defining the problem — it’s finding a good answer without enumerating the haystack.

A useful vocabulary distinction: a problem is NP-complete if it’s among the hardest problems whose solutions can at least be verified quickly, and NP-hard if it’s at least as hard as those, whether or not verification is fast. TSP’s decision version (“is there a tour under length L?”) is NP-complete; its optimization version (“find the shortest tour”) is NP-hard. Job Shop Scheduling is NP-hard. The Knight’s Tour is a special case that, unusually, isn’t — more on that in Section 4.

2  ·  The Traveling Salesman Problem

Given a list of cities and the distances between each pair, find the shortest possible route that visits every city exactly once and returns to the start. First studied formally in the 1930s, TSP is the problem most people picture when they hear “NP-hard” — partly because it maps so cleanly onto real logistics: delivery routing, PCB drilling paths, DNA sequencing fragment assembly, even warehouse pick-path optimization all reduce to some variant of TSP.

The number of distinct tours for n cities is (n−1)!⁄2 — for just 15 cities, that’s over 43 billion routes. Exact solvers exist (branch-and-bound, cutting planes, integer linear programming) and can handle surprisingly large instances — the Concorde TSP solver has certified optimal tours for problems with tens of thousands of cities — but they can take unbounded time in the worst case. In practice, most applications use heuristics instead:

HeuristicIdeaTypical gap from optimal
Nearest neighborAlways jump to the closest unvisited city~25%
2-opt local searchRepeatedly uncross pairs of edges that improve total length~5%

Beyond hand-designed heuristics, a large body of research applies metaheuristics — genetic algorithms, ant colony optimization, bee colony optimization — to push closer to optimal on large instances. One example: Choong, Wong, Low & Chong, “A Bee Colony Optimization Algorithm with a Sequential-Pattern-Mining-based Pruning Strategy for the Traveling Salesman Problem,” International Journal of Bio-Inspired Computation, 15(4), 239–253 (2020), which uses sequential pattern mining to prune the search space a bee colony algorithm explores, improving both solution quality and runtime over earlier bee colony variants on standard TSP benchmarks. Section 7 below lists the full line of TSP research this paper builds on.

Most of the field trades a provable worst-case guarantee away for speed, accepting “probably close to optimal, verified empirically on benchmark instances” instead — which is exactly the trade-off metaheuristic approaches like the one above are built around.

3  ·  Job Shop Scheduling

A set of jobs, each made of an ordered sequence of operations, must run on a shared set of machines. Each machine can only process one operation at a time, and each job’s operations must run in their specified order. The goal is usually to minimize makespan — the total time until every job finishes. This is the workhorse problem behind semiconductor fab scheduling, shipyard and manufacturing floor planning, and container terminal crane assignment — anywhere shared, expensive resources have to be sequenced across competing demands.

Even the deceptively small “3 jobs × 3 machines” instance can take meaningful compute time to solve exactly, and general Job Shop Scheduling is NP-hard — confirmed by Garey, Johnson, and Sethi in 1976. The search space is every valid interleaving of operations across machines respecting precedence constraints, which grows combinatorially with both job count and machine count simultaneously, faster than TSP’s single-dimension city count.

Common approaches: dispatching rules (simple greedy priorities like “shortest processing time first” or “earliest due date first”), genetic algorithms (evolve a population of candidate schedules via mutation and crossover), simulated annealing (accept occasional worse moves to escape local optima), and constraint programming solvers for smaller, high-stakes instances where near-optimality genuinely matters. Neural network approaches are also an active research direction: Sim, Low, Chong & Shakeri, “Job Shop Scheduling Problem Neural Network Solver with Dispatching Rules,” IEEM 2020, 14–17 December 2020, Singapore, trains a neural network to select which dispatching rule to apply at each decision point, rather than committing to a single fixed rule for the whole schedule. Section 7 lists the earlier bee-colony-based JSSP work this line of research follows from.

Unlike TSP, there’s no single dominant heuristic with a well-known worst-case bound — the field leans heavily on metaheuristics, learned dispatching policies, and problem-specific rules tuned empirically to the shop floor in question.

4  ·  The Knight’s Tour — the Odd One Out

A knight on a chessboard must visit every square exactly once using only legal knight moves. As covered in the Codex CLI walkthrough, this is a special case of the Hamiltonian path problem: model each square as a graph node, connect two nodes if a knight can move between them in one hop, and a Knight’s Tour is exactly a Hamiltonian path through that graph.

Finding a Hamiltonian path in an arbitrary graph is NP-complete — it belongs in the same hardness class as TSP’s decision version. But the knight’s-move graph on a chessboard isn’t arbitrary; it has enough regular structure that a simple greedy rule, Warnsdorff’s rule (always move to the unvisited square with the fewest onward moves), finds a complete tour almost every time on boards 5×5 and larger, in linear time, with no backtracking needed in the overwhelming majority of cases.

The general Hamiltonian-circuit problem — not restricted to a knight’s-move graph — is itself a live research target for the same metaheuristic techniques used on TSP: Wong, Low & Chong, “Finding the Shortest Hamiltonian Circuit of Selected Places in Penang Using a Generic Bee Colony Optimization Framework,” BIC-TA 2011, 51–57 applies a bee colony framework to find the shortest Hamiltonian circuit connecting real-world locations — the same underlying graph-theory object the Knight’s Tour is a highly structured special case of.

Why this matters: the Knight’s Tour is a working example of a problem that sits inside an NP-complete family in general, yet becomes tractable once you exploit the specific structure of the instance. It’s a reminder that “NP-hard in general” doesn’t mean “hard for every input” — structured sub-cases can be much friendlier than the worst case the complexity class describes.

5  ·  What the Three Have in Common

ProblemComplexityDominant heuristicReal-world domain
TSPNP-hardNearest neighbor, 2-optLogistics, routing
Job Shop SchedulingNP-hardDispatching rules, genetic algorithmsManufacturing, semiconductor fabs
Knight’s TourTractable special case of Hamiltonian path (NP-complete in general)Warnsdorff’s rulePuzzle design, graph theory pedagogy

The pattern across all three: a greedy, locally-informed rule — go to the nearest city, dispatch the shortest job first, move to the most-constrained square — gets surprisingly close to optimal, surprisingly fast, with no guarantee it always will. Exact methods (branch-and-bound, ILP, constraint solvers) remain necessary when the application genuinely needs a certified optimum or a worst-case bound, but for most production systems, a well-tuned greedy heuristic plus local-search refinement is the pragmatic default.

6  ·  When to Reach for Which Tool

  • Small instance, need the true optimum: exact solvers — branch-and-bound, integer linear programming, or off-the-shelf constraint solvers (OR-Tools, Gurobi, CPLEX).
  • Large instance, “good enough” is genuinely good enough: a simple greedy heuristic, ideally with a known worst-case bound if one exists for the problem.
  • Large instance, need better than greedy but exact is too slow: metaheuristics — simulated annealing, genetic algorithms, tabu search — layered on top of a greedy starting solution.
  • Your instance has exploitable structure (like the knight’s-move graph’s regularity): look for a problem-specific rule before reaching for general-purpose machinery. The cheapest algorithm is the one that exploits structure the general theory doesn’t assume.

7  ·  Related Publications from the Author

The full line of the author’s own published research on TSP and Job Shop Scheduling, drawn from the Publications page, spans nearly two decades of bee-colony and neural-network approaches to both problems:

Traveling Salesman Problem

Job Shop Scheduling

Full author bibliography, including book chapters and the remaining 130+ conference and journal papers spanning simulation, crowd modeling, and manufacturing systems, is available on the Publications page.

None of these three problems has been “solved” in the sense of a fast, exact, general algorithm — and for TSP and Job Shop Scheduling, complexity theory says no such algorithm exists unless P = NP. What they share instead is a body of heuristics, decades deep, that trade a small, usually-acceptable gap from optimal for a massive reduction in compute time. The Knight’s Tour is the outlier that got lucky: enough structure in its specific graph that a two-line greedy rule does the job outright.


Combinatorial Optimization · 2026

✦ This article was assembled with the assistance of Claude by Anthropic

Comments

Leave a comment