Optimization: principles and algorithms, by Michel Bierlaire
tspTourLength.m
Go to the documentation of this file.
1 %> \file
2 %> Calculate the length of a tour of the TSP
3 %>
4 %> @note Called by \ref tspLocalSearch
5 %> @note Called by \ref tspVns
6 %> @note Called by \ref tspInsertionLocalSearch
7 %> @note Called by \ref tspSimulatedAnnealing
8 %>
9 %> @author Michel Bierlaire
10 %> @date Tue Apr 14 11:44:01 2015
11 %> @ingroup Algorithms
12 %> @ingroup chap27
13
14
15 %> Calculate the length of a tour for the TSP
16 %> @param tour list of cities
17 %> @param dist distance matrix
18 %> @return l tour length
19 function l = tspTourLength(tour,dist)
20  [n, shouldBeOne]= size(tour) ;
21  [dsn, dsm] = size(dist) ;
22  if (dsn != n)
23  error("Incompatible dimensions") ;
24  endif
25  if (dsm != n)
26  error("Incompatible dimensions") ;
27  endif
28  l = 0 ;
29  for i = 1:n-1
30  l += dist(tour(i),tour(i+1)) ;
31  endfor
32  l += dist(tour(end),tour(1)) ;
33 endfunction
function tspSimulatedAnnealing(in tour, in dist)
function tspInsertionLocalSearch(in dist, in subtourList)
function tspTourLength(in tour, in dist)
Calculate the length of a tour for the TSP.
function tspLocalSearch(in tour, in dist)
function tspVns(in tour, in dist)
Runs the VNS heuristic on the TSP.