Some cleaning up
Added Population.size() and cleaned up the survivor selection.
This commit is contained in:
@ -8,6 +8,10 @@ class Population:
|
|||||||
self.fitness = None
|
self.fitness = None
|
||||||
self.mating_pool = []
|
self.mating_pool = []
|
||||||
|
|
||||||
|
def size(self):
|
||||||
|
"""Returns the size of the population"""
|
||||||
|
return len(self.chromosome_list)
|
||||||
|
|
||||||
def get_closet_fitness(self,value):
|
def get_closet_fitness(self,value):
|
||||||
"""Get the chomosome that has the closets fitness to the value defined"""
|
"""Get the chomosome that has the closets fitness to the value defined"""
|
||||||
pass
|
pass
|
||||||
|
|||||||
@ -44,5 +44,3 @@ class Mutation_Methods:
|
|||||||
gene_mutate_count = int(gene_mutate_count_static)
|
gene_mutate_count = int(gene_mutate_count_static)
|
||||||
|
|
||||||
return chromosome_set
|
return chromosome_set
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -7,15 +7,6 @@ from initialization.chromosome_structure.chromosome import Chromosome
|
|||||||
class Survivor_Selection:
|
class Survivor_Selection:
|
||||||
"""Survivor selection determines which individuals should be brought to the next generation"""
|
"""Survivor selection determines which individuals should be brought to the next generation"""
|
||||||
|
|
||||||
def remove_worst(ga, next_population):
|
def fill_in_best(ga, next_population):
|
||||||
"""
|
"""Fills in the next population with the best chromosomes from the last population until the population size is met."""
|
||||||
Will bring all but the worst-performing chromosomes from the current generation.
|
return ga.population[:ga.population_size-next_population.size()] + next_population
|
||||||
The exact number of chromosomes removed depends on how many offspring were generated by parent selection.
|
|
||||||
"""
|
|
||||||
iterator = 0
|
|
||||||
# While the size of the next population is less than it should be (as determined by the user)
|
|
||||||
while len(next_population.get_all_chromosomes()) < ga.population_size:
|
|
||||||
# Add the best chromosome from the current population that hasn't already been brought over
|
|
||||||
next_population.add_chromosome(ga.population.get_all_chromosomes()[iterator])
|
|
||||||
iterator += 1
|
|
||||||
return next_population
|
|
||||||
|
|||||||
Reference in New Issue
Block a user