Visit each city once, return to the start 1 Istanbul 2 Izmir 3 Antalya 4 Ankara 5 Kayseri 6 Samsun 7 Erzurum 8 Van 9 Diyarbakır 10 Gaziantep
The map has 10 Turkish cities; the number inside each circle is the city's number. The salesman leaves the brass city, visits every city once and returns to where he started. The goal is the shortest total distance. Distances are straight-line distances in kilometres.
Trying every tour 1 Istanbul 2 Izmir 3 Antalya 4 Ankara 5 Kayseri 6 Samsun 7 Erzurum 8 Van 9 Diyarbakır 10 Gaziantep
With the first city fixed, the other 9 cities can be visited in 9! orders. Every tour is counted in both directions, so there are 181,440 different tours. A computer tries them in under a second. With 20 cities the number of tours passes 60 quadrillion; as cities are added, trying every tour becomes impossible. That is why methods that find a good tour fast are used.
Go to the nearest neighbour 1 Istanbul 2 Izmir 3 Antalya 4 Ankara 5 Kayseri 6 Samsun 7 Erzurum 8 Van 9 Diyarbakır 10 Gaziantep Length: 293 km
A simple rule: from where you are, go to the nearest city not visited yet. The nearest city to the start is 293 km away, and the salesman moved there.
The rule is applied again 1 Istanbul 2 Izmir 3 Antalya 4 Ankara 5 Kayseri 6 Samsun 7 Erzurum 8 Van 9 Diyarbakır 10 Gaziantep Length: 539 km
From the new city the nearest unvisited city was chosen again; this edge is 246 km. The path is 539 km so far.
The tour is complete 1 Istanbul 2 Izmir 3 Antalya 4 Ankara 5 Kayseri 6 Samsun 7 Erzurum 8 Van 9 Diyarbakır 10 Gaziantep Length: 3,931 km
The rule went on until every city was visited, then the salesman returned to the start. The tour is 3,931 km. Nearest neighbour is fast but greedy: the cities left for the end are often far apart and the way back gets long.
2-opt: swap two edges 1 Istanbul 2 Izmir 3 Antalya 4 Ankara 5 Kayseri 6 Samsun 7 Erzurum 8 Van 9 Diyarbakır 10 Gaziantep Length: 3,661 km
Removing two edges and reversing the part between them creates two new edges. 2-opt tries every pair of edges and applies the one that shortens the tour the most. The two brass edges are new; the tour got 269 km shorter and is now 3,661 km. Two crossing edges can always be shortened this way.
2-opt, step 2 1 Istanbul 2 Izmir 3 Antalya 4 Ankara 5 Kayseri 6 Samsun 7 Erzurum 8 Van 9 Diyarbakır 10 Gaziantep Length: 3,473 km
Another pair that shortens the new tour was found. The tour got 188 km shorter and is now 3,473 km.
2-opt, step 3 1 Istanbul 2 Izmir 3 Antalya 4 Ankara 5 Kayseri 6 Samsun 7 Erzurum 8 Van 9 Diyarbakır 10 Gaziantep Length: 3,318 km
Another pair that shortens the new tour was found. The tour got 155 km shorter and is now 3,318 km.
The shortest tour is reached 1 Istanbul 2 Izmir 3 Antalya 4 Ankara 5 Kayseri 6 Samsun 7 Erzurum 8 Van 9 Diyarbakır 10 Gaziantep Length: 3,318 km
The tour is 3,318 km and no swap of two edges makes it shorter. It is the same as the shortest tour found by trying every tour. From this start the local search found the best one, but there is no guarantee; try another starting city.