Comp Sci Genetic algorithm knapsack problem

  • Thread starter Thread starter shivajikobardan
  • Start date Start date
  • Tags Tags
    Algorithm
AI Thread Summary
The discussion revolves around the confusion regarding the implementation of a genetic algorithm for the knapsack problem, particularly the selection and mutation processes in successive generations. Participants question the rationale behind selecting specific individuals for the second and third generations, noting that the explanation provided is unclear and lacks coherence. The importance of randomness in mating and mutation is emphasized, suggesting that relying solely on the fittest individuals may not be efficient. Additionally, key parameters such as survival rates and mutation rates need to be established in advance to guide the algorithm effectively. The conversation highlights the need for clarity in understanding genetic algorithms and the challenges faced when seeking reliable resources for learning.
shivajikobardan
Messages
637
Reaction score
54
Homework Statement
want 2 iterations solved by hand
Relevant Equations
genetic algorithm
kluAEmyiH63Z4BsXKT5Xr7X7mLxOwbR1L0y3ttoLitS6bOnwz-.png


Here is a solution, part of which doesn’t make any sense to me-:


->Why did we select c3,c1 and c3,c2 for 2nd generation?
-> why did we select os1,os2,c3,c2 for 3rd generation? (And what the heck is happening here? We are already in 3rd generation when even 2nd one is not complete?
-> then we mutate. Why are we mutating c1 lol. It doesn’t make any sense. We need to mutate one of the os1,os2,c3 or c2 according to my logic.

Anyway i have tried solving 2 iterations of it. If you can help me with 2 iterations of this problem, please do so.
Also test out my 2 iterations of this algorithm. What is right and wrong. I have used 1 point crossover.
AVBciQqBMkom-eP6coHtimC9hbzpfWkovo5U9W1pjGfcNncNNM.png

pHHSJyNapyFQWvhYGXTBs9tklfEX-0IwFg8O9xnOzEVA59dp0s.png

7ABdhqdHlCbBA67Qshvybt6WAEAM8ZHM13OX0Hj9BvREEaCwDy.png

CybhNAD643FTzy4f2b7Za1tFcQV2r9srNDZafZ69cr2c4EaCUn.png


I just want 2 iterations of this and know when to stop and check if I am right or wrong..And understand that first solved example video that I shared above.. this is getting confusing more and more I see it. Is this something where I can do anything randomly and get marks in exam lol...I feel like so looking at it. And the internet. Internet sucks. 1 easy thing then there are 5 lakhs of posts explaining the same thing. 1 hard thing and suddenly there is no one even remotely trying to explain it. Few explanations are there but they are very contradictory to each other.
 
Physics news on Phys.org
shivajikobardan said:
->Why did we select c3,c1 and c3,c2 for 2nd generation?
The selection is random with a probability based on the relative fitness (roulette wheel).

shivajikobardan said:
-> why did we select os1,os2,c3,c2 for 3rd generation? (And what the heck is happening here? We are already in 3rd generation when even 2nd one is not complete?
It is a very bad explanation. Normally, you would call it a generation after the offspring have been generated.

shivajikobardan said:
-> then we mutate. Why are we mutating c1 lol. It doesn’t make any sense. We need to mutate one of the os1,os2,c3 or c2 according to my logic.
I think this was just to show an example of a mutation.

shivajikobardan said:
Anyway i have tried solving 2 iterations of it. If you can help me with 2 iterations of this problem, please do so.
It is hard to follow all you are doing, but you seem to have too little randomness. Choosing to mate the fittest individuals is not efficient.

There are different parameters that need to be decided in advance. For instance, do any individuals survive to the next generation, or what is the mutation rate.

If some individuals survive to the next generation, you can either take the fittest, or use a roulette wheel. Then, you create offspring, choosing the parents by roulette wheel, and pick a crossover point randomly. Then, when you have your pool of individuals for the next generation, you determine for each one if there will be a mutation (randomly chosen following the mutation rate). You now have your new generation.

When to stop is also a choice. You can for instance stop when there has been a certain number of generations with no increase in fitness.
 

Similar threads

Back
Top