Вы находитесь на странице: 1из 3

Fractional KnapSack Problem: In this Greedy approach is used to solve

the Problem.Items are divisible i.e you can take fraction of the item.

Steps to solve the Problem


A) Calculate the ratio Value per Weight for each item.
B) Sort the Items in the Descending Order on the basis of above
calculated ratio.
C) Start Filling the Knapsack with items arranged in above sorted order.
D) Take as much Item as possible not already taken in the Knapsack.

Example:
Let us consider that the capacity of the knapsack’ W ’= 60 kg and the list
of provided items are shown in the following table −
Item Weight Profit
A 40 280
B 10 100
C 20 120
D 24 120

1) Calculate the ratio Profit(Value)per Weight for each item.

Item Weight Profit/Value Ratio =Value/Weight


A 40 280 7
B 10 100 10
C 20 120 6
D 24 120 5
2) Sort the Items in the Descending Order on the basis of above
calculated ratio.
Item Weight Profit/Value Ratio =Value/Weight
B 10 100 10
A 40 280 7
C 20 120 6
D 24 120 5
3) Start Filling the Knapsack with items arranged in above sorted order

Capacity of the Knapsack-Weight of the Item Item Added Profit in


added Knapsack
60 -0 = 60 0 0
60 - 10 = 50 B 100
50-40 = 10 B,A 100 + 280 = 380
10 -( Fraction of C * Weight of Added Item) B,A,C
10 -(1/2 * 20) = 10 - 10 =0

Now here the Remaining capacity of the Knapsack after adding item B
and item A is 10.
Next Item to be added according to the sorted order in the Knapsack is ‘C’
having weight 20 with Profit 120.

The Item Weight is greater than the remaining Capacity of the Knapsack
so we cannot take the C as a complete item but we consider only the
fraction of ‘C’ .

Question: How much part or Fraction of C should be considered for


adding in the Knapsack such that the profit will be maximum with in
limit of the Knapsack Capacity.

Fraction of an Item can be calculated as:


Remaining Capacity of the Knapsack/ Weight of the chosen Item
= 10/20= 1/2

Profit in the Knapsack = 100 + 280 + Profit of C * Fraction of C


= 100 +280 + 120 * (1/2)
= 100 +280 +60 = 440
Total Weight of the Selected Items = 10 + 40 + 20 (1/2) = 60

Вам также может понравиться