Optimization: principles and algorithms, by Michel Bierlaire
ksRandomNeighbor.m
Go to the documentation of this file.
1 %> \file
2 %> Algorithm 27.5: neighborhood for the knapsack problem. Implementation of algorithm 27.5 of \cite Bier15-book
3 %>
4 %> @note Called by \ref ksLocalSearchRandom
5 %> @note Called by \ref ksSimulatedAnnealing
6 %>
7 %> @author Michel Bierlaire
8 %> @date Tue Apr 14 13:06:01 2015
9 %> @ingroup Algorithms
10 %> @ingroup chap27
11 %>
12 %> Generate a random neighbor in a neighborhood of a given size for the knpasack problem
13 %> @param x0 current solution
14 %> @param s size of the neighborhood
15 %> @return x generated neighbor
16 function x = ksRandomNeighbor(x0,s)
17  order = randperm(size(x0)) ;
18  if (s > size(x0))
19  error("Size %d is larger than the size of the problem %d",size,size(x0))
20  endif
21  x = x0 ;
22  for i=1:s
23  x(order(i)) = 1-x0(order(i)) ;
24  endfor
25 endfunction
function ksRandomNeighbor(in x0, in s)
function ksSimulatedAnnealing(in u, in w, in c, in x0)
function ksLocalSearchRandom(in u, in w, in c, in x0, in s, in maxiter)
Copyright 2015-2018 Michel Bierlaire