问题
Here is my question.
I'm dealing with one optimization problem using DEAP.
For now, I use toolbox.register("select", tools.selNSGA2)
to select some fittest indivual to survive.
But I want to add some threshold by user-defined function.
Can the algorithm achieve two step of selection?
Select several individuals by the tournament or selNSGA2 method
Eliminate several individuals by pre-defined thresholds.
回答1:
This should work.
def myselect(pop, k, check):
return [ind for in in tools.selNSGA2(pop, k) if check(ind)]
def mycheck(ind):
return True
toolbox.register("select", myselect, check=mycheck)
However, you will end up selecting <= k offspring.
来源:https://stackoverflow.com/questions/41661637/how-to-add-elimination-mechanism-in-python-genetic-algorithm-based-on-deap