Traveling Salesman Problem & Utility Functions

Understanding Optimization through Tour Planning

Find the shortest route visiting all cities exactly once
Back to SE444 Course

The Traveling Salesman Problem (TSP)

The Traveling Salesman Problem is a classic optimization problem where a salesman must visit n cities exactly once and return to the starting city, minimizing the total travel distance.

Problem Components:

  • Goal: Find the shortest tour connecting all cities
  • Starting Point: City A (green) - where the tour begins and ends
  • State Space: All possible tours (permutations)
  • State Representation: Sequence of cities to visit
  • Constraints: Visit each city exactly once, return to start
Key Insight: With n cities, there are (n-1)!/2 possible tours, making exhaustive search impractical for large problems. Local search helps find good solutions efficiently.
5
Cities in Demo
12
Possible Tours
2-opt
Local Move

Interactive TSP Solver

Explore different tour configurations and see how distance affects the utility function!
Green city (A) is both start and destination • The dashed green line shows the return journey

Start City (A)
Return to Start
Other Cities
Tour Path
123
Distance
Current Tour: A → B → C → D → E → A
Path Cost: 1234 units Utility: -1234
Tour starts and ends at City A (complete circuit)

Utility Function for TSP

For the Traveling Salesman Problem, we want to minimize the total tour length. Our utility function reflects this optimization goal:

Our Utility Function:

Utility = -Tour Length
Higher utility = Shorter tour = Better solution
  • Tour Length: Sum of distances between consecutive cities
  • Best Tour: Highest utility (least negative value)
  • Worst Tour: Lowest utility (most negative value)
  • Key Principle: Shorter distances = higher utility
Why Negative Utilities?

Negative values represent the cost of the tour.
Higher utility corresponds to lower cost (better solution).
This formulation aligns with maximization-based optimization algorithms.

-856
Current Utility
Tour breakdown: Loading...
Total length: 856 units
856
Tour Length
5
Cities Visited

Local Search & Neighborhood Moves

2-Opt Move

The most common local move for TSP is the 2-opt operation:

  • Select two edges in the current tour
  • Remove these edges and reconnect in a different way
  • This reverses the order of cities in a segment
  • Accept the move if it improves the tour length
Example: Tour A→B→C→D→E→A
Reverse segment C→D→E becomes C→E→D
New tour: A→B→C→E→D→A

Optimization Landscape

The TSP creates a complex optimization landscape:

  • Many Local Optima: Tours that can't be improved by 2-opt
  • Global Optimum: The shortest possible tour
  • Neighborhood Size: Each tour has O(n²) 2-opt neighbors
  • Search Challenge: Avoid getting stuck in poor local optima
Local Search Insight: Simple hill climbing often gets stuck, but algorithms like simulated annealing can escape local optima.

Tour Examples & Utilities

Compare different tours and their utility values:

Ready for TSP Local Search!

Now that you understand the TSP and its utility function, you're prepared to explore local search algorithms like Hill Climbing with 2-opt moves, Simulated Annealing, and Genetic Algorithms for solving large-scale TSP instances.