Optimization: principles and algorithms, by Michel Bierlaire
twoOptRandomNeighbor.m
Go to the documentation of this file.
1 %> \file
2 %> Generate one random 2-opt neighbor for the TSP
3 %>
4 %> @note Called by \ref tspSimulatedAnnealing
5 %> @note Calls \ref twoOpt
6 %> @note Calls \ref randomFromAtoB
7 %>
8 %> @author Michel Bierlaire
9 %> @date Sun Apr 19 13:37:59 2015
10 %> @ingroup Algorithms
11 %> @ingroup chap27
12
13 %> Generate one random 2-opt neighbor for the TSP
14 %> @param cities current tour
15 %> @return neighbor the selected neighbor
16 function neighbor = twoOptRandomNeighbor(cities)
17  first = 1 ;
18  i = randomFromAtoB(2,size(cities)-1) ;
19  j = randomFromAtoB(i+1,size(cities)) ;
20  neighbor = twoOpt(cities,i,j) ;
21 endfunction
22
function tspSimulatedAnnealing(in tour, in dist)
function twoOpt(in cities, in c1, in c2)
Perform a 2-opt operation of a list of cities.
function randomFromAtoB(in A, in B)
Compute a random integer between A and B.
function twoOptRandomNeighbor(in cities)
Generate one random 2-opt neighbor for the TSP.