2 %> Implementation of a variant of the local search algorithm with random neighbors
for the knapsack problen.
4 %> @note Tested with \ref run2702localSearchRandom.m
6 %> @note Called by \ref
ksVns 8 %> @author Michel Bierlaire
9 %> @date Wed Apr 15 09:02:29 2015
10 %> @ingroup Algorithms
13 %> Perform a variant of the local search
for the knapsack problem with a neighborhood of a given size, where neighbord are selected randomly, and accepted
if hey improve the objective
function.
14 %> @param u utility of each item
15 %> @param w weight of each item
16 %> @param c capacity of the knapsack
17 %> @param x0 current solution
18 %> @param s size of the neighborhood
19 %> @param maxiter number of candidates being evaluated (Default: 1000)
20 %> @
return x local optimum
26 error("The initial solution is infeasible. Total weight: %f. Capacity %f.",totalWeight,c)
28 currentValue = u'*x0 ;
30 while (iter <= maxiter)
33 if (w'*candidate <= c)
34 if (u'*candidate > currentValue)
36 currentValue = u'*candidate ;
function ksVns(in u, in w, in c, in x0)
function ksRandomNeighbor(in x0, in s)
function ksLocalSearchRandom(in u, in w, in c, in x0, in s, in maxiter)