Genetic Algorithm(0-1 Knapsack problem )
Guided by : Prof. Kinjal Mistree
GA
Content
1. What is knapsack problem?
2. Knapsack problem using GA
3. Idea behind GA
4. Implementation flow
5. Conclusion
6. References
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.
Different approach to solve 0-1KP
1. Dynamic programming
2. Backtracking
3. Branch & bound
4. Genetic algorithm
0-1 Knapsack using GA
Implementation Flow1.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
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
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
• 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
• Mutation(Optional)-Perform mutation with 0.1234% probability
• Termination condition -The population converges when either 85% of chromosomes in population have same fitness
Results Using Roulette-wheel
Termination of GA
Drawback of Roulette Wheel
Results using Rank selection
Conclusion
Top Related