From 423c9884a89fa889d313eb3ba3bdb2a867c003ca Mon Sep 17 00:00:00 2001 From: SimpleArt <71458112+SimpleArt@users.noreply.github.com> Date: Fri, 1 Jan 2021 11:23:20 -0500 Subject: [PATCH] Update Crossover.py --- src/crossover/Crossover.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/crossover/Crossover.py b/src/crossover/Crossover.py index d146b96..a3e16e3 100644 --- a/src/crossover/Crossover.py +++ b/src/crossover/Crossover.py @@ -61,7 +61,7 @@ class Population: ) - def random(ga): + def random_mate(ga): """Select random pairs from the mating pool. Every parent is paired with a random parent. """ @@ -100,9 +100,9 @@ class Individual: @_check_weight @_gene_by_gene - def uniform(ga, value_1, value_2, *, weight = 0.5): + def uniform(ga, *gene_values, *, weight = 0.5): """Cross two parents by swapping all genes randomly.""" - return random.choices(gene_pair, cum_weights = [weight, 1])[0] + return random.choices(gene_values, cum_weights = [weight, 1])[0] class Arithmetic: @@ -136,7 +136,7 @@ class Individual: @_check_weight @_gene_by_gene - def random(ga, value_1, value_2, *, weight = 0.5): + def random_value(ga, value_1, value_2, *, weight = 0.5): """Cross two parents by taking a random integer or float value between each of the genes.""" value = value_1 + ga.weighted_random(weight) * (value_2-value_1) @@ -158,7 +158,7 @@ class Individual: # Too small to cross if len(parent_1) < 2: - return parent_1.gene_list + raise ValueError("Parent lengths must be at least 2.") # Unequal parent lengths if len(parent_1) != len(parent_2):