2 %> Algorithm 27.1: nearest neighbor heuristic
for TSP. Implementation of algorithm 27.1 of \cite Bier15-book
4 %> @note Tested with \ref run2703nearestNeighbor.m
6 %> @author Michel Bierlaire
7 %> @date Tue Apr 14 11:36:13 2015
11 %> Compute an halmitonian path
using the nearest neighbor heuristic
12 %> @param dist distance matrix
13 %> @
return permutation of the cities
16 if (columns(dist) != n)
17 error(
"Distance matrix must be square") ;
19 # First city is the depot 21 pi = [ currentCity ] ;
23 distances = dist(:,currentCity) ;
24 [s,i] = sort(distances) ;
26 if (s(j) != 0.0 && !any(pi==i(j)))
28 pi(end+1,1) = currentCity ;
function tspNearestNeighbor(in dist)
Compute an halmitonian path using the nearest neighbor heuristic.