2 %> Solves the knapsack problem
using the greedy heuristic described in section 27.1.1 of \cite Bier15-book
4 %> @note Tested by run2702greedy.m
6 %> @author Michel Bierlaire
7 %> @date Tue Apr 14 11:22:01 2015
12 [n,shouldBeOne] = size(u) ;
14 error(
"A column vector is expected for u") ;
16 [nw,shouldBeOne] = size(w) ;
18 error(
"A column vector is expected for w") ;
21 error(
"The two vectors must have the same size")
27 [ sorted, index] = sort(ratio) ;
33 if (totalWeight + w(elem) <= capacity)
35 totalWeight += w(elem) ;
function knapsackGreedy(in u, in w, in capacity)