How to add elimination mechanism in Python genetic algorithm based on DEAP

99封情书 提交于 2019-12-11 02:42:06

问题


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?

  1. Select several individuals by the tournament or selNSGA2 method

  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!