TSP Neighbor Generation

Comparing City Swaps vs 2-Opt Moves

Understand why 2-opt is superior for TSP optimization

Original Tour

Current Tour: A → B → C → D → E → A

Total Distance: 0

What is a Neighbor?

Neighbor: A tour that can be reached by making a small change to the current tour.

  • Simple: Swap two cities in the tour
  • Better: Use 2-opt (reverse a segment)

Method Comparison

Method 1: City Swaps

How it works:

  1. Pick any two cities in the tour
  2. Swap their positions
  3. Keep all other connections

Problem: Often creates crossing edges and poor tours!

Method 2: 2-Opt

How it works:

  1. Remove 2 edges from the tour
  2. Reconnect in the only other valid way
  3. This reverses a segment of the tour

Advantage: Eliminates crossing edges and finds better tours!

Why 2-Opt is Better

❌ City Swaps Problems:
  • Often creates crossing edges
  • Breaks local connectivity
  • Many neighbors are worse than original
  • Less likely to find improvements
✅ 2-Opt Advantages:
  • Eliminates crossings systematically
  • Maintains tour connectivity
  • More neighbors are improvements
  • Standard in TSP algorithms
Key Insight:

2-opt moves are designed specifically for TSP geometry. By systematically removing crossing edges, they're much more likely to find tour improvements than random city swaps.