本文介绍了如何在基于DEAP的Python遗传算法中添加消除机制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的问题.
我正在使用DEAP处理一个优化问题.
Here is my question.
I'm dealing with one optimization problem using DEAP.
目前,我使用toolbox.register("select", tools.selNSGA2)
选择一些最适合自己的人生存.
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?
-
通过锦标赛或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个后代.
However, you will end up selecting <= k offspring.
这篇关于如何在基于DEAP的Python遗传算法中添加消除机制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!