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

APPLICATION OF KNAPSACK ALGORITHM

Ramarajan S, Jayaraman R
Computer Science and Engineering Shanmuganathan Engineering College , Arasampatti, Tamil Nadu, India.
ramarajanengg@gmail.com, 9500482418

Abstract Using Knapsack Algorithm (Greedy Method) we present an innovative thinking on how to get maximum energy from a meal by finding the food measures. Usually, if we take the energetic foods daily, we can gain more calories. But if you are given only a limited number of recipes, we not sure to get maximum energy. So in this paper we are giving a way to reach maximum energy from meals by finding the food measures using fractional knapsack algorithm. The measures of foods are taken using the weights and total calories are taken as the weights and total calories are taken as the profits for the knapsack algorithm. The optimal solution found out gives the ratio of foods to take to eat.

Greedy Method: Application-Knapsack Problem: Input: A weight capacity C, and n items of weights W[1:n] and monetary value P[1:n].

Problem: Determine which items to take and how much of each item, so that

Introduction: The knapsack problem can be used to find the optimal solution to fill the knapsack with maximum profit. Likewise, we can apply the same technique to obtain the optimal solution for eating a meal. So that, we can get maximum calories by using the optimal solution. Before entering into the problem, it becomes must to know about the Greedy method and knapsack problem, That is why, here, a brief introduction on Greedy method and knapsack problem using Greedy method are given.

The total weight is <= C, and


The total value (Profit) is

maximized. Formulation of the problem: Let x[i] be the fraction taken from item i.

0 <= x[i] <= 1. The weight of the part taken from item i is x[i]*w[i] The corresponding profit is x[i]*P[i] The problem is then to find the values of the array x [1: n] So that X[1]P[1]+x[2]P[2]+.+x[n]P[n] is maximized subject to the constraint that
1

x[1]w[1]+X[2]w[2] +x[n]w[n] <= C

+.. policy: Three

is the capacity that is constraint for this problem. This condition suits for this problem, since a healthy young persons stomach can consume 1.5 liters without any troubles. i.e, m = 1.5 liters. We give six numbers of objects. i.e., n=6 The below. 1. Rice (cooked) (2 cups) 2. Drumstick sambar (1 cups) 3. Cabbage Curry (1/3 cup) 4. Baked eggs (2/3 cup) 5. Butter milk gravy (1 cup)
6. Payasam (2 cups)

Greedy Selection natural possibilities

Policy 1: Choose the lightest remaining item, and take as much of it as can fit. Policy 2: Choose the most profitable remaining item, and take as much of it as can fit. Policy 3: Choose the item with the highest price per unit weight (P[i]/W[i]) and take as much of it as can fit. According to knapsack problem using greedy Technique we can calculate or find which is the best way to earn maximum energy per a time. Here Humans stomach is considered as a knapsack or bag. The capacity of

objects

are

listed

stomach is taken as a constraint for this problem. The capacity of stomach may vary according to the person who takes the food. Because Gents, ladies, a person who affected by disease, etc. can eat differently. Even though, in this paper we are taken 1.5 liters

The measures of the objects are given in cups. Using the standard kitchen conversion units we can calculate the measures in milliliters. The objects measure in milliliters. 1) Rice (cooked) (2 cups) = 590 ml

2) Drumstick sambar (1 cups)= 354 ml 3) Cabbage Curry (1/3 cup) 4) Baked eggs (2/3 cup) = 79 ml =158 ml

3) Cabbage curry = 36 calories 4) Baked eggs = 211 calories 5) Butter milk gravy =98 calories Payasam (Sugar, Cream,

5) Butter milk gravy (1 cup)= 237 ml 6) Payasam (2 cups) = 473 ml

Vermicelli) = 300 calories Profits are Pi = (P1, P2, P3, P4, P5, P6)
Pi = (800, 224, 36, 211, 98, 300) Where 1 i n and n=6

These objects are to be loaded into the stomach while lunch or dinner. So, these are taken as objects similar to weights in knapsack problem. i.e., wi = (w1 , w2 , w3 , w4 , w5 ,w6 ) = (Rice, Sambar, Cabbage curry, Baked eggs, Buttermilk gravy, Payasam ) (w1, w2, w3, w4, w5, w6) = (590, 354, 79, 158, 237, 473) units are in ml. Then we have to set profits. As this point of view, total can set as profit. So that nutritional information is collected for each recipe. The calories per each recipe are given below: 1) Rice (Cooked) = 800 calories
2) Drumstick

The

possible

feasible

and

objective solutions are calculated using the expressions WiXi and PiXi respectively. Where Xi is the possible assumptions we made based on which recipe are taken by the person. The following table gives the feasible and objective solutions in which we can choose the optimal solution that solution should have the maximum profit in calories. Wi = (590, 354, 79, 158, 237, 473) Pi = (800, 224, 36, 211, 98, 300)

Sambar = 8224

calories

Xi

WiXi

PiXi
(Objective Solutions)
800+224+36+211+98 1369 800+126.5+36+211+300 1429.7 800+36+211+82.7+300 1429.7 800+63.276+36+211+41.35+300 1451.266 800+224+211+98+102.114 1435.114 800+224+36+211+98+300x82/473 1421 800+224+0+110.84+0+300 1434.841 800+224+36+0+1.654+300 1361.654 800+224+0+0+83/237x98+300 1358.32 800+224+61/79x36+211+98+10/473x300 1424.22

(Feasible Solutions)
590+354+79+158+237+473 1418 590+200+79+158+0+473 1500 590+0+79+158+200+473 1500 590+100+79+158+100+473 1500 590+354+158+237+161 1500 590+354+79+158+237+82 1500 590+354+0+83+0+473 1500 590+354+79+0+4+473 1500 590+354+0+0+83+473 1500 590+354+61+158+237+100 150

1) (1,1 ,1,1,1,0) 2) 1,200/354,1,1,0,1) 3) 1,0,1,1,,200/237,1) 4) (1,100/354,1,1,100/237) 5) 1,1,0,1,1,161/473)

6) 1,1,1,1,1, 82/473

7) (1,1,0, 83/158,0,1) 8) (1,1,1,0,4/237,1)

9) (1,1,0,0,83/237,1)

10) (1,1,61/79,1,1,100/473)

The ten solutions of possible solutions are in the table. The first solution is calculated by straight forward technique. This solution gives us the profit 1369 calories only. Also, it doesnt satisfy the constraint exactly. Then in another objects are arranged in knapsack in the form of weights have maximum profit than others. We are tried to get optimal solution if the ratio Pi / Xi has high value this trick yields us the solution similar to the above solution said. When we compare all the

Conclusion: If we eat foods that have high nutrition we can attain the good profit. But, if you have only 6 items from that only you take nutrition. When this situation arises, we can use this method and we can reach maximum profit we should remember a fact that is 1200 calories is the calorie limit for a good healthy person per a time. ********* References: 1. Ellis Horowitz, Sartaj Sahni and Sanguthevar Rajasekaran, Computer Algorithms / C++, 2nd Edition, Universities Press, 2007. 2. Easwarakumar, K.S., Object Oriented Data Structures Using C++, Vikas Publishing House, 2000. 3. Cormen, T.H., Leiserson, C.E., Rivest, R.L. and Stein, C., Introduction to Algorithms, 2nd Edition, Prentice Hall of India Pvt. Ltd, 2003

objective solutions, solution - 2 has the high profit in calories (1473.55 calories). So we can take this solution on optimal solution. If we take the foods based on this solution we can attain the maximum energy.

Похожие интересы