2 %> Algorithm 27.3: local search
for the TSP. Implementation of algorithm 27.3 of \cite Bier15-book
4 %> @note Tested with \ref run2703localSearch.m
8 %> @author Michel Bierlaire
9 %> @date Tue Apr 14 15:27:43 2015
10 %> @ingroup Algorithms
13 %> Local search based on the 2-OPT neighborhood.
14 %> @param tour initial solution
15 %> @param dist the distance matrix
16 %> @
return betterTour local optimum
17 %> Perform a local search
for the TSP with a 2-OPT neighborhood
22 printf(
"%d\t",current) ;
23 printf(
"|%.2f\n",bestLength) ;
30 for i =1:columns(neighborhood)
33 betterTour = neighborhood(:,i) ;
40 printf(
"%d\t",betterTour) ;
41 printf(
"|%.2f\t%d\t%d\n",bestLength,city1(bestindex),city2(bestindex)) ;
42 current = betterTour ;
function tspTourLength(in tour, in dist)
Calculate the length of a tour for the TSP.
function twoOptNeighborhood(in cities)
Generate the 2-opt neightborhood for the TSP.
function tspLocalSearch(in tour, in dist)