Você está na página 1de 5

APPLICATION OF KNAPSACK ALGORITHM

Author

: S Ramarajan

Year

: III BE CSE

College : Shanmuganathan Engineering


College, Arasampatti.
Introduction:
ABSTRACT
Using Knapsack Algorithm (Greedy
Method) we are giving an innovative
thinking on how to get maximum energy
from a meal. 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 a meals 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.

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.
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
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 capacity of
stomach is taken as a constraint
for this problem. The capacity of

The weight of the part taken from


item i is x[i]*w[i]

stomach may vary according to

The corresponding profit is x[i]*P[i]

Because Gents, ladies, a person

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
x[1]w[1] +X[2]w[2] +
+x[n]w[n] <= C
Greedy Selection policy: Three
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 person who takes the food.


who affected by disease, etc. can
eat differently. Even though, in
this paper we are taken 1.5 liters
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 objects are listed
below.
Rice (cooked) (2 cups)
1)
2)
3)
4)
5)

Drumstick sambar (1 cups)


Cabbage Curry (1/3 cup)
Baked eggs (2/3 cup)
Butter milk gravy (1 cup)
Payasam (2 cups)

The measures of the objects are


given in cups. Using the standard kitchen

conversion units we can calculate the


measures in milliliters.

The calories per each recipe are


given below:

The objects measure in milliliters.

1) Rice (Cooked) = 800 calories


2) Drumstick Sambar = 8224

1) Rice (cooked) (2 cups) = 590 ml

calories
3) Cabbage curry = 36 calories
4) Baked eggs = 211 calories
5) Butter milk gravy =98 calories

2) Drumstick sambar (1 cups)= 354 ml


3) Cabbage Curry (1/3 cup)= 79 ml

Payasam (Sugar, Cream,


4) Baked eggs (2/3 cup)

= 158 ml

5) Butter milk gravy (1 cup)= 237 ml


6) Payasam (2 cups)

= 473 ml

These objects are to be loaded

Vermicelli) = 300 calories


Profits are
Pi = (P1, P2, P3, P4, P5, P6)
Pi = (800, 224, 36, 211, 98, 300)

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 )

Where 1 i n and n=6

The possible feasible and


objective solutions are calculated using

= (Rice, Sambar, Cabbage curry, Baked

the expressions WiXi and PiXi

eggs, Buttermilk gravy, Payasam )

respectively. Where Xi is the possible


assumptions we made based on which

(w1, w2, w3, w4, w5, w6) = (590, 354,

recipe are taken by the person.

79, 158, 237, 473) units are in ml.


The following table gives the
Then we have to set profits. As

feasible and objective solutions in which

this point of view, total can set as profit.

we can choose the optimal solution that

So that nutritional information is

solution should have the maximum profit

collected for each recipe.

in calories.
Wi = (590, 354, 79, 158, 237, 473)

Pi = (800, 224, 36, 211, 98, 300)

WiXi

Xi

PiXi

(Objective Solutions)

(Feasible Solutions)
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)

590+354+79+158+237+473

800+224+36+211+98

1418

1369

590+200+79+158+0+473

800+126.5+36+211+300

1500
590+0+79+158+200+473

1429.7
800+36+211+82.7+300

1500
590+100+79+158+100+473

1429.7
800+63.276+36+211+41.35+300

1500
590+354+158+237+161

1451.266
800+224+211+98+102.114

1500
590+354+79+158+237+82

1435.114

1500
590+354+0+83+0+473

800+224+36+211+98+300x82/473
1421
800+224+0+110.84+0+300

1500
590+354+79+0+4+473

1434.841
800+224+36+0+1.654+300

1500

1361.654

590+354+0+0+83+473

800+224+0+0+83/237x98+300

1500

1358.32

10)

590+354+61+158+237+100

800+224+61/79x36+211+98+10/473x300

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

150

1424.22

8) (1,1,1,0,4/237,1)

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

The ten solutions of possible solutions


are in the table.

The first solution is calculated by

If we eat foods that have high

straight forward technique. This solution

nutrition we can attain the good profit.

gives us the profit 1369 calories only.

But, if you have only 6 items from that

Also, it doesnt satisfy the constraint

only you take nutrition. When this

exactly.

situation arises, we can use this method

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
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.

Conclusion:

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.
*********

Você também pode gostar