Population.next_population and better comments
This commit is contained in:
@ -10,6 +10,43 @@ class Population:
|
||||
|
||||
self.fitness = None
|
||||
self.mating_pool = []
|
||||
self.next_population = []
|
||||
|
||||
|
||||
def update(self):
|
||||
self.set_chromosome_list(self.next_population)
|
||||
self.reset_mating_pool()
|
||||
self.reset_next_population()
|
||||
|
||||
|
||||
def remove_chromosome(self, index):
|
||||
"""Removes a chromosome from the indicated index from the population"""
|
||||
del self.chromosome_list[index]
|
||||
|
||||
|
||||
def remove_parent(self, index):
|
||||
"""Removes a parent from the indicated index from the mating pool"""
|
||||
del self.mating_pool[index]
|
||||
|
||||
|
||||
def remove_child(self, index):
|
||||
"""Removes a child from the indicated index from the next population"""
|
||||
del self.next_population[index]
|
||||
|
||||
|
||||
def reset_mating_pool(self):
|
||||
"""Clears the mating pool"""
|
||||
self.mating_pool = []
|
||||
|
||||
|
||||
def reset_next_population(self):
|
||||
"""Clears the next population"""
|
||||
self.next_population = []
|
||||
|
||||
|
||||
def append_children(self, chromosome_list):
|
||||
"""Appends a list of chromosomes to the next population"""
|
||||
self.next_population += chromosome_list
|
||||
|
||||
|
||||
def sort_by_best_fitness(self, ga):
|
||||
@ -22,6 +59,11 @@ class Population:
|
||||
return len(self.chromosome_list)
|
||||
|
||||
|
||||
def total_children(self):
|
||||
"""Returns the size of the next population"""
|
||||
return len(self.next_population)
|
||||
|
||||
|
||||
def get_closet_fitness(self,value):
|
||||
"""Get the chomosome that has the closets fitness to the value defined"""
|
||||
pass
|
||||
@ -39,19 +81,9 @@ class Population:
|
||||
self.mating_pool.append(chromosome)
|
||||
|
||||
|
||||
def remove_chromosome(self, index):
|
||||
"""Removes a chromosome from the indicated index from the population"""
|
||||
del self.chromosome_list[index]
|
||||
|
||||
|
||||
def remove_parent(self, index):
|
||||
"""Removes a parent from the indicated index from the mating pool"""
|
||||
del self.mating_pool[index]
|
||||
|
||||
|
||||
def reset_mating_pool(self):
|
||||
"""Clears the mating pool"""
|
||||
self.mating_pool = []
|
||||
def add_child(self, chromosome):
|
||||
"""Adds a chromosome to the next population"""
|
||||
self.next_population.append(chromosome)
|
||||
|
||||
|
||||
def get_chromosome(self, index):
|
||||
@ -64,6 +96,11 @@ class Population:
|
||||
return self.mating_pool[index]
|
||||
|
||||
|
||||
def get_child(self, index):
|
||||
"""Returns the child at the given index in the next population"""
|
||||
return self.next_population[index]
|
||||
|
||||
|
||||
def get_chromosome_list(self):
|
||||
"""Returns all chromosomes in the population"""
|
||||
return self.chromosome_list
|
||||
@ -74,16 +111,16 @@ class Population:
|
||||
return self.mating_pool
|
||||
|
||||
|
||||
def get_next_population(self):
|
||||
"""Returns chromosomes in the next population"""
|
||||
return self.next_population
|
||||
|
||||
|
||||
def get_fitness(self):
|
||||
"""Returns the population's fitness"""
|
||||
return self.fitness
|
||||
|
||||
|
||||
def set_parent(self, index):
|
||||
"""Sets the indexed chromosome from the population as a parent"""
|
||||
self.add_parent(self.get_chromosome(index))
|
||||
|
||||
|
||||
def set_chromosome_list(self, chromosome_list):
|
||||
"""Sets the chromosome list"""
|
||||
self.chromosome_list = chromosome_list
|
||||
@ -99,6 +136,11 @@ class Population:
|
||||
self.chromosome_list[index] = chromosome
|
||||
|
||||
|
||||
def set_parent(self, index):
|
||||
"""Sets the indexed chromosome from the population as a parent"""
|
||||
self.add_parent(self.get_chromosome(index))
|
||||
|
||||
|
||||
def set_fitness(self, fitness):
|
||||
"""Sets the fitness value of the population"""
|
||||
self.fitness = fitness
|
||||
|
||||
Reference in New Issue
Block a user