DEAP / deap

Distributed Evolutionary Algorithms in Python
http://deap.readthedocs.org/
GNU Lesser General Public License v3.0
5.82k stars 1.13k forks source link

Survivor selection #477

Open thineswaran opened 4 years ago

thineswaran commented 4 years ago

Most of the examples given appear to be using generational replacement as the survivor selection strategy.

Could you please give some examples on how to use steady state replacement?

fmder commented 4 years ago

This should do the trick. It is a little rough, but it is a starting point.

pop = toolbox.population(2)
for gen in range(NGEN):
    c1, c2 = [toolbox.clone(c) for c in pop]
    c1, c2 = toolbox.mate([c1, c2])
    c1, = toolbox.mutate(c1)         # Mutation returns a list (note the comma)
    c2, = toolbox.mutate(c2)
    for c in [c1, c2]:
        c.fitness.values = toolbox.evaluate(c)
    pop = toolbox.select(pop + [c1, c2], 2)
thineswaran commented 4 years ago

Thanks a lot for the feedback. Really appreciate it. Will try it out.