From b8f1de9b52cc16748fc58c40ee2a56d2f3b9a3cf Mon Sep 17 00:00:00 2001 From: SimpleArt <71458112+SimpleArt@users.noreply.github.com> Date: Mon, 12 Oct 2020 22:58:26 -0400 Subject: [PATCH] Fixed crossover methods --- src/crossover/crossover_methods.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/crossover/crossover_methods.py b/src/crossover/crossover_methods.py index d7f4175..c45ca1a 100644 --- a/src/crossover/crossover_methods.py +++ b/src/crossover/crossover_methods.py @@ -1,6 +1,4 @@ import random -from initialization.chromosome_structure.chromosome import Chromosome -from initialization.population_structure.population import Population class Crossover_Methods: @@ -11,26 +9,26 @@ class Crossover_Methods: """Select sequential pairs from the mating pool""" mating_pool = ga.population.mating_pool - return Population([ga.crossover_individual_impl(mating_pool[index], mating_pool[index+1]) for index in range(len(mating_pool)-1)]) + return ga.make_population([ga.crossover_individual_impl(ga, mating_pool[index], mating_pool[index+1]) for index in range(len(mating_pool)-1)]) def random_selection(ga): """Select random pairs from the mating pool""" mating_pool = ga.population.mating_pool - return Population([ga.crossover_individual_impl(random.choice(mating_pool), random.choice(mating_pool)) for n in mating_pool]) + return ga.make_population([ga.crossover_individual_impl(ga, random.choice(mating_pool), random.choice(mating_pool)) for n in mating_pool]) class Individual: """Methods for crossing parents""" - def single_point_crossover(parent_one, parent_two): + def single_point_crossover(ga, parent_one, parent_two): """Cross two parents by swapping genes at one random point""" index = random.randint(0, parent_one.size()-1) - return Chromosome(parent_one.get_gene_list()[:index] + parent_two.get_gene_list()[index:]) + return ga.make_chromosome(parent_one.get_gene_list()[:index] + parent_two.get_gene_list()[index:]) - def multi_point_crossover(parent_one, parent_two): + def multi_point_crossover(ga, parent_one, parent_two): """Cross two parents by swapping genes at multiple points""" pass