这是我的问题。
我正在使用 DEAP 处理一个优化问题。
现在,我使用 toolbox.register("select", tools.selNSGA2)
来选择一些最适合生存的个体。
但我想通过用户定义的函数添加一些阈值。
算法能否实现两步选择?
Select several individuals by the tournament or selNSGA2 method
Eliminate several individuals by pre-defined thresholds.
最佳答案
这应该有效。
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)
但是,您最终会选择 <= k 个后代。
关于python - 如何在基于DEAP的Python遗传算法中加入淘汰机制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41661637/