2 %> Algorithm 27.5: VNS
for the knapsack problem. Implementation of algorithm 27.5 of \cite Bier15-book
4 %> @note Tested with \ref run2702vns.m
7 %> @author Michel Bierlaire
8 %> @date Wed Apr 15 09:21:56 2015
12 %> VNS algorithm
for the knapsack problem.
13 %> @param u utility of each item
14 %> @param w weight of each item
15 %> @param c capacity of the knapsack
16 %> @param x0 current solution
17 %> @
return x local optimum
18 %> @
return The file \c ksIters.dat is also created, containing the details of the iterations.
19 function best =
ksVns(u,w,c,x0)
20 [fff,msg] = fopen(
"ksIters.dat",
"w") ;
21 fprintf(fff,
"Neighborhood\Candidate\tBest\n") ;
24 error(
"Vectors of incompatible sizes: %d and %d\n",n,size(w))
30 fprintf(fff,
"%d\t%f\t%f\n",s,u
'*candidate,u'*best) ;
31 if (u
'*candidate > u'*best)
function ksVns(in u, in w, in c, in x0)
function ksLocalSearchRandom(in u, in w, in c, in x0, in s, in maxiter)