TSP using Two-Opt Heuristics
Version 1.0.2 (2.38 KB) by
Moreno, M.
Fast and simple TSP algorithm using 2-opt heuristics seeking for the 'best' solution.
Description
[idx,val] = tsp(x,arg1,arg2,~): Returns the best solution idx and its cost val to the travelling sales person problem in x (matrix or file name) using two-opt heuristics within the parameters arg1 and arg2. These parameters are, by default, the number of run cycles and the number of iterations per cycle, and are set to 1 and 1e3 each by default. If only arg1 was passed, it would be taken as the number of iterations for only one cycle. An empty function call produces sample values with a figure output. Passing a fourth input parameter would instead look for the 'worst' possible solution.
Miguel Moreno, July 2024
Examples
[idx,val] = tsp; % Test run
[idx,val] = tsp(rand(2e2,2)); % Medium problem
[idx,val] = tsp(rand(50,2),10,1e3) % Re-converged
[idx,val] = tsp(rand(20,3),[],[],-1); % Worst solution
Cite As
Moreno, M. (2024). TSP using Two-Opt Heuristics (https://www.mathworks.com/matlabcentral/fileexchange/169161-tsp-using-two-opt-heuristics), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Created with
R2024a
Compatible with any release
Platform Compatibility
Windows macOS LinuxTags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.