From 7c55bf431b34ae48e7ecb00c110d2e44627812e7 Mon Sep 17 00:00:00 2001 From: SimpleArt <71458112+SimpleArt@users.noreply.github.com> Date: Wed, 30 Dec 2020 16:21:47 -0500 Subject: [PATCH] Renamed files --- src/crossover/{Crossover_Methods.py => Crossover.py} | 10 +++++++--- .../Fitness_Examples.py | 0 src/{fitness_function => fitness_examples}/README.md | 0 src/{fitness_function => fitness_examples}/__init__.py | 0 .../test_methods.py | 0 src/mutation/{Mutation_Methods.py => Mutation.py} | 0 .../Parent_Selection.py => parent/Parent.py} | 6 +----- src/{parent_selection => parent}/README.md | 0 src/{parent_selection => parent}/__init__.py | 0 .../test_parent_selection_methods.py | 0 src/structure/gene.py | 2 +- src/{survivor_selection => survivor}/README.md | 0 .../Survivor_Selection.py => survivor/Survivor.py} | 0 src/{survivor_selection => survivor}/__init__.py | 0 .../test_survivor_methods.py | 0 src/{termination_point => termination}/README.md | 0 .../Termination.py} | 0 src/{termination_point => termination}/__init__.py | 0 .../test_termination_methods.py | 0 19 files changed, 9 insertions(+), 9 deletions(-) rename src/crossover/{Crossover_Methods.py => Crossover.py} (98%) rename src/{fitness_function => fitness_examples}/Fitness_Examples.py (100%) rename src/{fitness_function => fitness_examples}/README.md (100%) rename src/{fitness_function => fitness_examples}/__init__.py (100%) rename src/{fitness_function => fitness_examples}/test_methods.py (100%) rename src/mutation/{Mutation_Methods.py => Mutation.py} (100%) rename src/{parent_selection/Parent_Selection.py => parent/Parent.py} (97%) rename src/{parent_selection => parent}/README.md (100%) rename src/{parent_selection => parent}/__init__.py (100%) rename src/{parent_selection => parent}/test_parent_selection_methods.py (100%) rename src/{survivor_selection => survivor}/README.md (100%) rename src/{survivor_selection/Survivor_Selection.py => survivor/Survivor.py} (100%) rename src/{survivor_selection => survivor}/__init__.py (100%) rename src/{survivor_selection => survivor}/test_survivor_methods.py (100%) rename src/{termination_point => termination}/README.md (100%) rename src/{termination_point/Termination_Methods.py => termination/Termination.py} (100%) rename src/{termination_point => termination}/__init__.py (100%) rename src/{termination_point => termination}/test_termination_methods.py (100%) diff --git a/src/crossover/Crossover_Methods.py b/src/crossover/Crossover.py similarity index 98% rename from src/crossover/Crossover_Methods.py rename to src/crossover/Crossover.py index 6cf5dd3..d146b96 100644 --- a/src/crossover/Crossover_Methods.py +++ b/src/crossover/Crossover.py @@ -46,12 +46,14 @@ class Population: """Methods for selecting chromosomes to crossover.""" - def sequential(ga, mating_pool): + def sequential(ga): """Select sequential pairs from the mating pool. Every parent is paired with the previous parent. The first parent is paired with the last parent. """ - + + mating_pool = ga.population.mating_pool + for index in range(len(mating_pool)): # for each parent in the mating pool ga.crossover_individual_impl( # apply crossover to mating_pool[index], # the parent and @@ -59,11 +61,13 @@ class Population: ) - def random(ga, mating_pool): + def random(ga): """Select random pairs from the mating pool. Every parent is paired with a random parent. """ + mating_pool = ga.population.mating_pool + for parent in mating_pool: # for each parent in the mating pool ga.crossover_individual_impl( # apply crossover to parent, # the parent and diff --git a/src/fitness_function/Fitness_Examples.py b/src/fitness_examples/Fitness_Examples.py similarity index 100% rename from src/fitness_function/Fitness_Examples.py rename to src/fitness_examples/Fitness_Examples.py diff --git a/src/fitness_function/README.md b/src/fitness_examples/README.md similarity index 100% rename from src/fitness_function/README.md rename to src/fitness_examples/README.md diff --git a/src/fitness_function/__init__.py b/src/fitness_examples/__init__.py similarity index 100% rename from src/fitness_function/__init__.py rename to src/fitness_examples/__init__.py diff --git a/src/fitness_function/test_methods.py b/src/fitness_examples/test_methods.py similarity index 100% rename from src/fitness_function/test_methods.py rename to src/fitness_examples/test_methods.py diff --git a/src/mutation/Mutation_Methods.py b/src/mutation/Mutation.py similarity index 100% rename from src/mutation/Mutation_Methods.py rename to src/mutation/Mutation.py diff --git a/src/parent_selection/Parent_Selection.py b/src/parent/Parent.py similarity index 97% rename from src/parent_selection/Parent_Selection.py rename to src/parent/Parent.py index d5c7d4d..d01c92e 100644 --- a/src/parent_selection/Parent_Selection.py +++ b/src/parent/Parent.py @@ -15,7 +15,6 @@ def _check_selection_probability(selection_method): else: raise Exception("Selection probability must be between 0 and 1 to select parents.") - new_method.__name__ = selection_method.__name__ return new_method @@ -32,7 +31,6 @@ def _check_positive_fitness(selection_method): else: raise Exception("Converted fitness values can't have negative values or be all 0. Consider using rank selection or stochastic selection instead.") - new_method.__name__ = selection_method.__name__ return new_method @@ -43,10 +41,9 @@ def _ensure_sorted(selection_method): """ def new_method(ga): - ga.population.sort_by_best_fitness(ga) + ga.sort_by_best_fitness() selection_method(ga) - new_method.__name__ = selection_method.__name__ return new_method @@ -61,7 +58,6 @@ def _compute_parent_amount(selection_method): parent_amount = max(2, round(len(ga.population)*ga.parent_ratio)) selection_method(ga, parent_amount) - new_method.__name__ = selection_method.__name__ return new_method diff --git a/src/parent_selection/README.md b/src/parent/README.md similarity index 100% rename from src/parent_selection/README.md rename to src/parent/README.md diff --git a/src/parent_selection/__init__.py b/src/parent/__init__.py similarity index 100% rename from src/parent_selection/__init__.py rename to src/parent/__init__.py diff --git a/src/parent_selection/test_parent_selection_methods.py b/src/parent/test_parent_selection_methods.py similarity index 100% rename from src/parent_selection/test_parent_selection_methods.py rename to src/parent/test_parent_selection_methods.py diff --git a/src/structure/gene.py b/src/structure/gene.py index 9b24efd..cf67e70 100644 --- a/src/structure/gene.py +++ b/src/structure/gene.py @@ -16,7 +16,7 @@ class Gene: def __eq__(self, other_gene): """Comparing two genes by their value.""" - return self.value == Gene(other_value).value + return self.value == Gene(other_gene).value def __repr__(self): diff --git a/src/survivor_selection/README.md b/src/survivor/README.md similarity index 100% rename from src/survivor_selection/README.md rename to src/survivor/README.md diff --git a/src/survivor_selection/Survivor_Selection.py b/src/survivor/Survivor.py similarity index 100% rename from src/survivor_selection/Survivor_Selection.py rename to src/survivor/Survivor.py diff --git a/src/survivor_selection/__init__.py b/src/survivor/__init__.py similarity index 100% rename from src/survivor_selection/__init__.py rename to src/survivor/__init__.py diff --git a/src/survivor_selection/test_survivor_methods.py b/src/survivor/test_survivor_methods.py similarity index 100% rename from src/survivor_selection/test_survivor_methods.py rename to src/survivor/test_survivor_methods.py diff --git a/src/termination_point/README.md b/src/termination/README.md similarity index 100% rename from src/termination_point/README.md rename to src/termination/README.md diff --git a/src/termination_point/Termination_Methods.py b/src/termination/Termination.py similarity index 100% rename from src/termination_point/Termination_Methods.py rename to src/termination/Termination.py diff --git a/src/termination_point/__init__.py b/src/termination/__init__.py similarity index 100% rename from src/termination_point/__init__.py rename to src/termination/__init__.py diff --git a/src/termination_point/test_termination_methods.py b/src/termination/test_termination_methods.py similarity index 100% rename from src/termination_point/test_termination_methods.py rename to src/termination/test_termination_methods.py