![]() |
![]() ![]() ![]() ![]() ![]() |
![]() ![]() |
![]() |
![]() |
![]() ![]() |
Author | Message | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
gita
Newbie ![]() Joined: 08Apr2007 Online Status: Offline Posts: 19 |
![]() ![]() ![]() Posted: 08Apr2007 at 10:51pm |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5.2 General Knapsack problem:
Greedy
method is best suited to solve more complex problems such as a knapsack
problem. In a knapsack problem there is a knapsack or a container of
capacity M n items where, each item i is of weight wi and is associated with a profit pi.
The problem of knapsack is to fill the available items into the
knapsack so that the knapsack gets filled up and yields a maximum
profit. If a fraction xi of object i is placed into the knapsack, then a profit pixi is earned. The constrain is that all chosen objects should sum up to M
Illustration
Consider a knapsack problem of finding the optimal solution where,
M=15, (p1,p2,p3…p7) = (10, 5, 15, 7, 6, 18, 3) and (w1, w2, …., w7) =
(2, 3, 5, 7, 1, 4, 1).
In order to find the solution, one can follow three different srategies.
Strategy 1 : non-increasing profit values
Let (a,b,c,d,e,f,g) represent the items with profit
(10,5,15,7,6,18,3) then the sequence of objects with non-increasing
profit is (f,c,a,d,e,b,g).
(This means that the objects are considered in decreasing order of the ratio Pi/wI) a: P1/w1 =10/2 = 5 b: P2/w2 =5/3=1.66 c: P3/w3 =15/5 = 3 d: P4/w4 =7/7=1 e: P5/w5 =6/1=6 f: P6/w6 =18/4 = 4.5 g: P7/w7 =3/1=3 Hence, the sequence is (e,a,f,c,g,b,d)
The solution set is (1,2/3,1,0,1,1,1). In the above problem it can be observed that, if the sum of all the weights is £ M then all xi = 1, is an optimal solution. If we assume that the sum of all weights exceeds M, all xi’s cannot be one. Sometimes it becomes necessary to take a fraction of some items to completely fill the knapsack. This type of knapsack problems is a general knapsack problem.click here for more details: http://www.vyomworld.com/gate/cs/ada/5.2.asp Post Resume: Click here to Upload your Resume & Apply for Jobs |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() ![]() |
||
Forum Jump |
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |
|
© Vyom Technosoft Pvt. Ltd. All Rights Reserved.