Fast 2-Opt Travelling Salesman Problem (TSP)
- x: An N-by-M matrix representing the coordinates of N-nodes (cities) in M-dimensions.
- iter (optional): Iteration count, specified as a scalar or a vector. If scalar, it represents the number of iterations. If vector, the first element specifies the number of attempts. If (any) negative, the non-symmetric TSP is solved. Default: max(10, ceil(n/10))
- N/A (optional): If passed, flag to query for the longest possible route. Default: none
- path: A vector containing the indices of the nodes in the order they are visited in the optimized path.
- dist: The total distance of the computed path.
Cite As
Moreno, M. (2026). Fast 2-Opt Travelling Salesman Problem (TSP) (https://www.mathworks.com/matlabcentral/fileexchange/169161-fast-2-opt-travelling-salesman-problem-tsp), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxTags
Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
| Version | Published | Release Notes | |
|---|---|---|---|
| 1.0.9 | Final version: optimal 2-opt implementation given an iteration number |
||
| 1.0.8 | Problem-based default iteration count
|
||
| 1.0.7 | - Added non-symmetric problem (TSP2OPT1)
|
||
| 1.0.6 | Fully-optimized code via test functions. |
||
| 1.0.5 | Separated first segment from the FOR loop to accelerate the calculation.
|
||
| 1.0.4 | Corrected a small error in the final distance calculation |
||
| 1.0.3 | Increased speed of the function and grouped inputs more intuitively. |
||
| 1.0.2 | Logo change. |
||
| 1.0.1 | Includes 'worst' possible solution upon an additional input parameter call |
||
| 1.0.0 |
