|
2 | 2 | import random
|
3 | 3 |
|
4 | 4 | from neat.indexer import Indexer
|
5 |
| -from neat.six_util import iteritems, itervalues |
| 5 | +from neat.six_util import iteritems, iterkeys, itervalues |
6 | 6 |
|
7 | 7 | # TODO: Provide some sort of optional cross-species performance criteria, which
|
8 | 8 | # are then used to control stagnation and possibly the mutation rate configuration.
|
@@ -52,8 +52,8 @@ def create_new(self, genome_type, genome_config, num_genomes):
|
52 | 52 | return new_genomes
|
53 | 53 |
|
54 | 54 | def reproduce(self, config, species, pop_size):
|
55 |
| - # TODO: I don't like this modification of the species object, |
56 |
| - # because it requires internal knowledge of the object. |
| 55 | + # TODO: I don't like this modification of the species and stagnation objects, |
| 56 | + # because it requires internal knowledge of the objects. |
57 | 57 |
|
58 | 58 | # Filter out stagnated species and collect the set of non-stagnated species members.
|
59 | 59 | num_remaining = 0
|
@@ -148,6 +148,11 @@ def reproduce(self, config, species, pop_size):
|
148 | 148 | new_population[gid] = child
|
149 | 149 | self.ancestors[gid] = (parent1_id, parent2_id)
|
150 | 150 |
|
| 151 | + # Remove empty species from the stagnation tracking. |
| 152 | + keys = list(iterkeys(self.stagnation.stagnant_counts)) |
| 153 | + for sid in keys: |
| 154 | + if sid not in species.species: |
| 155 | + self.stagnation.remove(sid) |
151 | 156 |
|
152 | 157 | # Sort species by ID (purely for ease of reading the reported list).
|
153 | 158 | # TODO: This should probably be done by the species object.
|
|
0 commit comments