示例#1
0
    def _learnStep(self):
        """ do one generation step """
        # evaluate fitness
        """ added by JPQ """
        if isinstance(self.fitnesses,dict):
            oldfitnesses = self.fitnesses
            self.fitnesses = dict()
            for indiv in self.currentpop:
                if tuple(indiv) in oldfitnesses:
                    self.fitnesses[tuple(indiv)] = oldfitnesses[tuple(indiv)]
                else:
                    self.fitnesses[tuple(indiv)] = self._oneEvaluation(indiv)
            del oldfitnesses
        else:
        # ---
            self.fitnesses = dict([(tuple(indiv), self._oneEvaluation(indiv)) for indiv in self.currentpop])

        if self.storeAllPopulations:
            self._allGenerations.append((self.currentpop, self.fitnesses))

        if self.elitism:
            self.bestEvaluable = list(non_dominated_front(list(map(tuple, self.currentpop)),
                                                          key=lambda x: self.fitnesses[x],
                                                          allowequality = self.allowEquality))
        else:
            self.bestEvaluable = list(non_dominated_front(list(map(tuple, self.currentpop))+self.bestEvaluable,
                                                          key=lambda x: self.fitnesses[x],
                                                          allowequality = self.allowEquality))
        self.bestEvaluation = [self.fitnesses[indiv] for indiv in self.bestEvaluable]

        self.produceOffspring()
示例#2
0
文件: nsga2.py 项目: DanSGraham/code
    def _learnStep(self):
        """ do one generation step """
        # evaluate fitness
        self.fitnesses = dict([(tuple(indiv), self._oneEvaluation(indiv)) for indiv in self.currentpop])
        if self.storeAllPopulations:
            self._allGenerations.append((self.currentpop, self.fitnesses))

        if self.elitism:
            self.bestEvaluable = list(non_dominated_front(map(tuple, self.currentpop),
                                                          key=lambda x: self.fitnesses[x],
                                                          allowequality = self.allowEquality))
        else:
            self.bestEvaluable = list(non_dominated_front(map(tuple, self.currentpop)+self.bestEvaluable,
                                                          key=lambda x: self.fitnesses[x],
                                                          allowequality = self.allowEquality))
        self.bestEvaluation = [self.fitnesses[indiv] for indiv in self.bestEvaluable]
        self.produceOffspring()
示例#3
0
    def _learnStep(self):
        """ do one generation step """
        # evaluate fitness
        self.fitnesses = dict([(tuple(indiv), self._oneEvaluation(indiv))
                               for indiv in self.currentpop])
        if self.storeAllPopulations:
            self._allGenerations.append((self.currentpop, self.fitnesses))

        if self.elitism:
            self.bestEvaluable = list(
                non_dominated_front(map(tuple, self.currentpop),
                                    key=lambda x: self.fitnesses[x],
                                    allowequality=self.allowEquality))
        else:
            self.bestEvaluable = list(
                non_dominated_front(map(tuple, self.currentpop) +
                                    self.bestEvaluable,
                                    key=lambda x: self.fitnesses[x],
                                    allowequality=self.allowEquality))
        self.bestEvaluation = [
            self.fitnesses[indiv] for indiv in self.bestEvaluable
        ]
        self.produceOffspring()