Nearest Neighbor algorithm for the Travelling Salesman Problem

Version 1.1.0.0 (2.51 KB) by ajevtic
Computes and plots the shortest path for the random 10-city Travelling Salesman Problem.
3.3K Downloads
Updated 12 Aug 2014

View License

The 2-column vector contains cities' coordinates. The algorithm generates the optimal path to visit all the cities exactly once, and return to the starting city.
Do for all the cities:
1. select a city as current city.
2. find out the shortest edge connecting the current city and an unvisited city.
3. set the new city as current city.
4. mark the previous current city as visited.
5. if all the cities are visited, then terminate.
6. Go to step 2.

The algorithm has its limitations, and based on the cities' distribution on the map it may or may not give the optimal solution.

It resolves the problem of the equally distant cities, that some other submitted files had.

Cite As

ajevtic (2024). Nearest Neighbor algorithm for the Travelling Salesman Problem (https://www.mathworks.com/matlabcentral/fileexchange/25542-nearest-neighbor-algorithm-for-the-travelling-salesman-problem), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2008b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.1.0.0

The algoritm implementation logic added in the description.

1.0.0.0