Professional Documents
Culture Documents
Fractional Knapsack Problem
Fractional Knapsack Problem
Knapsack (w, v, W) { Create array x[] having length n for (i=1 to n) X[i] =0 Weight = 0 i=0 while (weight < W && i<=n) { if (weight+ w[i] <=W) { x[i] = 1 weight = weight + w[i] } else { X[i] = (W-weight)/w[i] weight = W } } return x }
Optimal solution set Solution (s, n, w, W) { i=n k= W Create array x [1n] initialize its elements with zero While (i>0 and k>0) { if (s[i, k] != s[i-1, k]) { x[i] = 1 k = k w[i] } i = i-1 } return x }