0 1 knapsack using ga

17
Genetic Algorithm (0-1 Knapsack problem ) Guided by : Prof. Kinjal Mistree GA

description

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

Transcript of 0 1 knapsack using ga

Page 1: 0 1 knapsack using ga

Genetic Algorithm(0-1 Knapsack problem )

Guided by : Prof. Kinjal Mistree

GA

Page 2: 0 1 knapsack using ga

Content

1. What is knapsack problem?

2. Knapsack problem using GA

3. Idea behind GA

4. Implementation flow

5. Conclusion

6. References

Page 3: 0 1 knapsack using ga

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.

Page 4: 0 1 knapsack using ga

Different approach to solve 0-1KP

1. Dynamic programming

2. Backtracking

3. Branch & bound

4. Genetic algorithm

Page 5: 0 1 knapsack using ga

0-1 Knapsack using GA

Page 6: 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

Page 7: 0 1 knapsack using ga

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

Page 8: 0 1 knapsack using ga

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

Page 9: 0 1 knapsack using ga

• 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

Page 10: 0 1 knapsack using ga

• Mutation(Optional)-Perform mutation with 0.1234% probability

• Termination condition -The population converges when either 85% of chromosomes in population have same fitness

Page 11: 0 1 knapsack using ga

Results Using Roulette-wheel

Page 12: 0 1 knapsack using ga
Page 13: 0 1 knapsack using ga
Page 14: 0 1 knapsack using ga

Termination of GA

Page 15: 0 1 knapsack using ga

Drawback of Roulette Wheel

Page 16: 0 1 knapsack using ga

Results using Rank selection

Page 17: 0 1 knapsack using ga

Conclusion