示例#1
0
    def ChooseBestIndividal(self):
        phenotype = Phenotype(self.bodySize)
        indexBest = -1
        adaptationBest = 0.0

        for i in range(self.muValue):
            phenotype.UseGenotype(self.population[i])
            if phenotype.GetAdaptation() > adaptationBest:
                indexBest = i
                adaptationBest = phenotype.GetAdaptation()

        self.lastAdaptationValue = self.currentAdaptationValue
        self.currentAdaptationValue = adaptationBest
        print("#" + str(self.lastAdaptationValuesBelowDelta) +
              "\tCurrent best: " + str(adaptationBest))

        self.view.UpdateData(self.population[indexBest])
示例#2
0
    def CreateRouletteWheel(self, individualsToChoose):
        sum = 0.0

        adaptationValue = []

        for i in range(len(individualsToChoose)):
            phenotype = Phenotype(self.bodySize)
            phenotype.UseGenotype(individualsToChoose[i])
            adaptation = phenotype.GetAdaptation()

            adaptationValue.append(math.exp(adaptation))
            sum += math.exp(adaptation)

        rouletteWheel = []
        for i in range(len(individualsToChoose)):
            rouletteWheel.append(adaptationValue[i] / sum)

        for i in range(1, len(individualsToChoose)):
            rouletteWheel[i] += rouletteWheel[i - 1]

        return rouletteWheel