Fixed method names and added some crossover methods and tests for floats

This commit is contained in:
SimpleArt
2020-10-13 21:07:05 -04:00
parent b966b22b04
commit 0090db9dce
7 changed files with 89 additions and 36 deletions

View File

@ -6,22 +6,22 @@ class Survivor_Selection:
def fill_in_best(ga, next_population):
"""Fills in the next population with the best chromosomes from the last population"""
ga.population.set_all_chromosomes(ga.population.get_all_chromosomes()[:ga.population.size()-next_population.size()] + next_population.get_all_chromosomes())
ga.population.set_chromosome_list(ga.population.get_chromosome_list()[:ga.population.size()-next_population.size()] + next_population.get_chromosome_list())
def fill_in_random(ga, next_population):
"""Fills in the next population with random chromosomes from the last population"""
ga.population.set_all_chromosomes([
random.choice(ga.population.get_all_chromosomes())
ga.population.set_chromosome_list([
random.choice(ga.population.get_chromosome_list())
for n in range(ga.population.size()-next_population.size())]
+ next_population.get_all_chromosomes())
+ next_population.get_chromosome_list())
def fill_in_parents_then_random(ga, next_population):
"""Fills in the next population with all parents followed by random chromosomes from the last population"""
ga.population.set_all_chromosomes([
random.choice(ga.population.get_all_chromosomes())
ga.population.set_chromosome_list([
random.choice(ga.population.get_chromosome_list())
for n in range(ga.population.size()-len(ga.population.get_mating_pool())-next_population.size())]
+ ga.population.get_mating_pool() + next_population.get_all_chromosomes())
+ ga.population.get_mating_pool() + next_population.get_chromosome_list())