Minor changes and fixes
__iter__ has to return an iter
This commit is contained in:
@ -57,17 +57,17 @@ class Chromosome:
|
||||
|
||||
def __iter__(self):
|
||||
"""Returns an iterable of the gene list"""
|
||||
return self.gene_list
|
||||
return iter(self.gene_list)
|
||||
|
||||
|
||||
def __getitem__(self, k):
|
||||
"""Returns the k-th gene"""
|
||||
return self.get_gene(k)
|
||||
def __getitem__(self, index):
|
||||
"""Returns the indexed gene"""
|
||||
return self.gene_list[index]
|
||||
|
||||
|
||||
def __setitem__(self, k, gene):
|
||||
"""Sets the k-th gene value"""
|
||||
self.set_gene(gene, k)
|
||||
def __setitem__(self, index, gene):
|
||||
"""Sets the indexed gene value"""
|
||||
self.gene_list[index] = gene
|
||||
|
||||
|
||||
def __len__(self):
|
||||
|
||||
@ -21,18 +21,18 @@ class Population:
|
||||
|
||||
|
||||
def remove_chromosome(self, index):
|
||||
"""Removes a chromosome from the indicated index from the population"""
|
||||
del self.chromosome_list[index]
|
||||
"""Removes and returns a chromosome from the indicated index from the population"""
|
||||
return self.chromosome_list.pop(index)
|
||||
|
||||
|
||||
def remove_parent(self, index):
|
||||
"""Removes a parent from the indicated index from the mating pool"""
|
||||
del self.mating_pool[index]
|
||||
"""Removes and returns a parent from the indicated index from the mating pool"""
|
||||
return self.mating_pool.pop(index)
|
||||
|
||||
|
||||
def remove_child(self, index):
|
||||
"""Removes a child from the indicated index from the next population"""
|
||||
del self.next_population[index]
|
||||
"""Removes and returns a child from the indicated index from the next population"""
|
||||
return self.next_population.pop(index)
|
||||
|
||||
|
||||
def reset_mating_pool(self):
|
||||
@ -153,17 +153,17 @@ class Population:
|
||||
|
||||
def __iter__(self):
|
||||
"""Returns an iterable of chromosomes"""
|
||||
return self.chromosome_list
|
||||
return iter(self.chromosome_list)
|
||||
|
||||
|
||||
def __getitem__(self, k):
|
||||
"""Returns the k-th chromosome"""
|
||||
return self.get_chromosome(k)
|
||||
def __getitem__(self, index):
|
||||
"""Returns the indexed chromosome"""
|
||||
return self.chromosome_list[index]
|
||||
|
||||
|
||||
def __setitem__(self, k, chromosome):
|
||||
"""Sets the k-th chromosome"""
|
||||
self.set_chromosome(chromosome, k)
|
||||
def __setitem__(self, index, chromosome):
|
||||
"""Sets the indexed chromosome"""
|
||||
self.chromosome_list[index] = chromosome
|
||||
|
||||
|
||||
def __len__(self):
|
||||
|
||||
Reference in New Issue
Block a user