Optimization: principles and algorithms, by Michel Bierlaire
twoOpt.m
Go to the documentation of this file.
1 %> \file
2 %> Perform a 2-opt operation of a list of cities
3 %>
4 %> @note Called by \ref twoOptNeighborhood
5 %> @note Called by \ref twoOptRandomNeighbor
6 %>
7 %> @author Michel Bierlaire
8 %> @date Tue Apr 14 15:30:42 2015
9 %> @ingroup Algorithms
10 %> @ingroup chap27
11 
12 %> Perform a 2-opt operation of a list of cities
13 %> @param cities
14 %> @param c1 index of the first city
15 %> @param c2 index of the second city
16 %> @return new list of cities
17 function newlist = twoOpt(cities,c1,c2)
18  if (c1 > c2)
19  t = c1 ;
20  c1 = c2 ;
21  c2 = t ;
22  endif
23  if (c1 == 1)
24  error('Cannot perform a 2-opt with the depot')
25  else
26  c1 = c1 - 1 ;
27  endif
28  newlist = cities(1:c1);
29  newlist = [newlist ; flipud(cities(c1+1:c2))];
30  newlist = [newlist ; cities(c2+1:end)];
31 endfunction
32 
function twoOpt(in cities, in c1, in c2)
Perform a 2-opt operation of a list of cities.
function twoOptNeighborhood(in cities)
Generate the 2-opt neightborhood for the TSP.
function twoOptRandomNeighbor(in cities)
Generate one random 2-opt neighbor for the TSP.
Copyright 2015-2016 Michel Bierlaire