コード例 #1
0
ファイル: population.py プロジェクト: fractal13/python-neat
    def speciate(self):
        comporg = None
        counter = 0

        #//Step through all existing organisms
        for curorg in self.organisms:
            
            #//For each organism, search for a species it is compatible to
            cur_species_i = 0
            found = False
            while (cur_species_i < len(self.species)) and (not found):
                comporg = self.species[cur_species_i].first()
                if comporg is None:
                    #//Keep searching for a matching species
                    cur_species_i += 1
                elif curorg.gnome.compatibility(comporg.gnome) < neat.compat_threshold:
                    #//Found compatible species, so add this organism to it
                    self.species[cur_species_i].add_Organism(curorg)
                    curorg.species = self.species[cur_species_i]
                    found = True
                else:
                    #//Keep searching for a matching species
                    cur_species_i += 1

            #//If we didn't find a match, create a new species
            if not found:
                newspecies = Species()
                counter += 1
                newspecies.SetFromId(counter)
                self.species.append(newspecies)
                newspecies.add_Organism(curorg)
                curorg.species = newspecies
            # end species search conditions

        # end organism loop
        self.last_species = counter
        return True