Reputation: 515
I understand the important parts of genetic algorithms e.g. fitness, selection methods, mutation, crossover etc. but I haven't ever been shown an example showing how the next generation is kept the same size as the previous generation.
Probably as a result, everything I've tried to code has resulted in my solutions getting stuck at local minima.
So for example, let's say the initial population is size 100. Can someone show me a specific breakdown of how the next generation is kept at size 100? (I know there are many ways of doing this but one way should put me on the right track).
e.g.
1. Choose 20 best solutions using roulette wheel selection
2. ...
...
k. You now have 100 solutions. Use this as your new population and repeat from step 1
Many thanks.
Upvotes: 0
Views: 1083
Reputation: 93
A very simple and easy to implement method is called the Microbial Genetic Algorithm which will ensure that the population size remains constant.
Upvotes: 1
Reputation: 372
There are several strategies to keep population size at a fixed value. For example, you can first add the offspring to the whole population, evaluate the new individuals, then sort the population by fitness value and keep killing the worst individuals until you reach the desired size. This approach is called "mu+lambda" in literature (because mu is often use to indicate population size, and lambda the size of the offspring produced at each generation).
In pseudocode:
1. Generate initial population (size mu)
2. Evaluate initial population
3. Choose parent individuals and produce offspring (size lambda)
4. Evaluate offspring, then add offspring to population
5. Sort population (now of size mu+lambda) by fitness value
6. Kill the worst individuals until population is again of size mu
7. Unless a termination condition is satisfied, goto 3
There are other solutions in literature: another popular option is "mu,lambda", where a fixed part of the population is replaced by the offspring, no matter what their value, but in my opinion is better to start with a "mu+lambda" strategy and then see if it fits your problem.
Upvotes: 2