python - 如何在基于DEAP的Python遗传算法中加入淘汰机制

标签 python algorithm genetic-algorithm deap

这是我的问题。
我正在使用 DEAP 处理一个优化问题。

现在,我使用 toolbox.register("select", tools.selNSGA2) 来选择一些最适合生存的个体。

但我想通过用户定义的函数添加一些阈值。

算法能否实现两步选择?

  1. Select several individuals by the tournament or selNSGA2 method

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

相关文章:

algorithm - 如何为每个 n 构造一个算术自由排列?

language-agnostic - 基因编程在线学习

machine-learning - 通过遗传算法进行特征选择

python - 使用单纯形和遗传算法最小化非常嘈杂的 6 参数函数 - Python 语言

python - 在 sklearn.preprocessing 模块中,我得到 ValueError : Found array with 0 feature(s)

python - 特里?在python中匹配带有尾随字符的单词

algorithm - 使用 2^n 步来获得房间中每个可能的人组合

algorithm - 在整数列表中找出非奇偶校验反转的数量

python - Scrapy/Python从 yield 请求中获取项目

python - 使用 Groupby Pandas 描述函数 (Python 3.5.1)