当前位置: 首页>>代码示例>>Python>>正文


Python Population.tournamentParentSelection方法代码示例

本文整理汇总了Python中population.Population.tournamentParentSelection方法的典型用法代码示例。如果您正苦于以下问题:Python Population.tournamentParentSelection方法的具体用法?Python Population.tournamentParentSelection怎么用?Python Population.tournamentParentSelection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在population.Population的用法示例。


在下文中一共展示了Population.tournamentParentSelection方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from population import Population [as 别名]
# 或者: from population.Population import tournamentParentSelection [as 别名]
class EA:

    def __init__(self ,numOfGenerations, numOfChildren, numOfAdults, numOfParents, bitsInGenotypes, fitnessMethod, adultSelectionMethod, parentSelectionMethod):

        self.numOfGenerations = numOfGenerations
        self.numOfChildren = numOfChildren
        self.numOfAdults = numOfAdults
        self.numOfParents = numOfParents
        self.pop = Population(bitsInGenotypes)
        self.adultSelectionMethod = adultSelectionMethod
        self.parentSelectionMethod = parentSelectionMethod

        self.pop.initializeChildPopulation(self.numOfChildren)

        self.startEvolution()

    def startEvolution(self):
        for generation in range(self.numOfGenerations):
            self.pop.developGenotypePopulation()
            self.pop.testPopulation()

            fitnessSum = 0
            for c in self.pop.developedChildren:
                fitnessSum += c.testScore
            print(generation)
            print(fitnessSum)

            self.adultSelection()
            self.parentSelection()
            self.pop.mateSelectedParents(self.numOfChildren)

    def adultSelection(self):
        if self.adultSelectionMethod == 0:
            self.pop.fullGenerationalReplacement()
        if self.adultSelectionMethod == 1:
            self.pop.overProduction(self.numOfAdults)
        if self.adultSelectionMethod == 2:
            self.pop.generationalMixing(self.numOfAdults)

    def parentSelection(self):
        if self.parentSelectionMethod == 0:
            self.pop.fitnessProportonateParentSelection(self.numOfParents)
        if self.parentSelectionMethod == 1:
            self.pop.sigmaScalingParentSelection(self.numOfParents)
        if self.parentSelectionMethod == 2:
            self.pop.tournamentParentSelection(self.numOfParents)
        if self.parentSelectionMethod == 3:
            self.pop.boltzmannParentSelection(self.numOfParents)
开发者ID:kittleik,项目名称:subsymaiaiai,代码行数:50,代码来源:ea.py


注:本文中的population.Population.tournamentParentSelection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。