Upcoming SlideShare
×

# 0 1 knapsack using ga

3,262 views
2,914 views

Published on

Knapsack problem is solved using genetic algorithm and other comparison are shown to prove best result of GA

2 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

Views
Total views
3,262
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
144
0
Likes
2
Embeds 0
No embeds

No notes for slide

### 0 1 knapsack using ga

1. 1. Genetic Algorithm (0-1 Knapsack problem ) Guided by : Prof. Kinjal Mistree GA
2. 2. Content 1. What is knapsack problem? 2. Knapsack problem using GA 3. Idea behind GA 4. Implementation flow 5. Conclusion 6. References
3. 3. Knapsack problem(KP) • Let, Xi – no. of copies of items i are to be placed in knapsack in such a way that, maximize ∑ BiXi for i=1..N subject to constraints ∑ ViXi ≤ W • There are Qi copies of item i available where, Qi positive integer satisfying 1 ≤ Qi ≤ ∞ and 0 ≤ Xi ≤ Qi . • If Qi is infinite ,KP is unbounded otherwise bounded. The bounded KP can be 0-1 Knapsack Problem or multiconstraint KP. • If Qi=1 for i=1,2,...N the problem is bounded 0-1 knapsack problem.
4. 4. Different approach to solve 0-1KP 1. Dynamic programming 2. Backtracking 3. Branch & bound 4. Genetic algorithm
5. 5. 0-1 Knapsack using GA
6. 6. Implementation Flow 1.Initialize array items with data(benefit & volume) and population size 2.Randomly generate initial population 3.calculate fitness function • For each item if it is included in knapsack(bit=1) – Add volume and benefits to total benefits and total volume – If total volume > W Remove item from the knapsack & change the bit=0 else return total items with volume and benefit and stop 4.Check which chromosome having same fitness • If 80% have same fitness then stop else reproduction, cross over, mutation and go to step 3. 5.Termination Condition
7. 7. Implementation of 0-1 KP Using GA • Representation of items: -2 dimension array which called Cell E.g. Item[benefit][volume] Items 0 1 2 3 • Random Initial population(N=3): 20 30 5 10 10 20 40 50 0 1 0 1 1 1 0 1 1 0 1 1
8. 8. Implementation of 0-1 KP Using GA • Encoding of chromosomes: -Binary Encoding 0 1 2 3 20 30 5 10 10 20 40 50 1 0 0 1
9. 9. • Fitness Function if wixi <=W then item is added in to knapsack else fitness of chromosome is zero. • Selection • Crossover -The crossover point is determined randomly by generating a n random number between 0 and num_items - 1. -Perform crossover with certain probability -crossover probability-0.90
10. 10. • Mutation(Optional) -Perform mutation with 0.1234% probability • Termination condition -The population converges when either 85% of chromosomes in population have same fitness
11. 11. Results Using Roulette-wheel
12. 12. Termination of GA
13. 13. Drawback of Roulette Wheel
14. 14. Results using Rank selection
15. 15. Conclusion