From ae74ce1766ffb1c1c09be30326b7315029f7c43b Mon Sep 17 00:00:00 2001 From: SimpleArt <71458112+SimpleArt@users.noreply.github.com> Date: Sun, 25 Oct 2020 22:36:54 -0400 Subject: [PATCH] Minor edits --- src/attributes.py | 5 ++++- src/crossover/crossover_methods.py | 20 +++++++++---------- .../parent_selection_methods.py | 3 ++- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/attributes.py b/src/attributes.py index 417ed17..31e6239 100644 --- a/src/attributes.py +++ b/src/attributes.py @@ -19,6 +19,8 @@ from mutation import Mutation_Methods from crossover import Crossover_Methods class attributes: + """SAMPLE TEXT""" + def __init__(self): """Initialize the GA.""" @@ -55,7 +57,7 @@ class attributes: # Methods for accomplishing Parent-Selection -> Crossover -> Survivor_Selection -> Mutation self.parent_selection_impl = Parent_Selection.Rank.tournament self.crossover_individual_impl = Crossover_Methods.Individual.single_point - self.crossover_population_impl = Crossover_Methods.Population.random_selection + self.crossover_population_impl = Crossover_Methods.Population.sequential_selection self.survivor_selection_impl = Survivor_Selection.fill_in_best self.mutation_individual_impl = Mutation_Methods.Individual.single_gene self.mutation_population_impl = Mutation_Methods.Population.random_selection @@ -67,6 +69,7 @@ class attributes: # Getter and setters for all varibles @property def chromosome_length(self): + """SAMPLE TEXT""" return self._chromosome_length @chromosome_length.setter diff --git a/src/crossover/crossover_methods.py b/src/crossover/crossover_methods.py index de63fea..e15a2e6 100644 --- a/src/crossover/crossover_methods.py +++ b/src/crossover/crossover_methods.py @@ -3,7 +3,7 @@ import random class Crossover_Methods: class Population: - """Methods for selecting chromosomes to crossover""" + """Methods for selecting chromosomes to crossover.""" def sequential_selection(ga): """Select sequential pairs from the mating pool. @@ -41,22 +41,22 @@ class Crossover_Methods: class Individual: - """Methods for crossing parents""" + """Methods for crossing parents.""" def single_point(ga, parent_one, parent_two): - """Cross two parents by swapping genes at one random point""" + """Cross two parents by swapping genes at one random point.""" index = random.randint(0, parent_one.size()-1) return ga.make_chromosome(parent_one.get_gene_list()[:index] + parent_two.get_gene_list()[index:]) def multi_point(ga, parent_one, parent_two): - """Cross two parents by swapping genes at multiple points""" + """Cross two parents by swapping genes at multiple points.""" pass def uniform(ga, parent_one, parent_two): - """Cross two parents by swapping all genes randomly""" + """Cross two parents by swapping all genes randomly.""" return ga.make_chromosome([ # Make a new chromosome random.choice([ # by selecting random genes from @@ -66,10 +66,10 @@ class Crossover_Methods: for i in range(parent_one.size())]) # for each gene class Arithmetic: - """Crossover methods for numerical genes""" + """Crossover methods for numerical genes.""" def int_random(ga, parent_one, parent_two): - """Cross two parents by taking a random integer value between each of the genes""" + """Cross two parents by taking a random integer value between each of the genes.""" return ga.make_chromosome([ # Make a new chromosome ga.make_gene( # filled with new genes @@ -81,7 +81,7 @@ class Crossover_Methods: def int_weighted(ga, parent_one, parent_two): - """Cross two parents by taking a a weighted average of the genes""" + """Cross two parents by taking a a weighted average of the genes.""" # the percentage of genes taken from the first gene weight = 0.25 @@ -95,7 +95,7 @@ class Crossover_Methods: def float_random(ga, parent_one, parent_two): - """Cross two parents by taking a random numeric value between each of the genes""" + """Cross two parents by taking a random numeric value between each of the genes.""" return ga.make_chromosome([ # Make a new chromosome ga.make_gene( # filled with new genes @@ -108,7 +108,7 @@ class Crossover_Methods: def float_weighted(ga, parent_one, parent_two): - """Cross two parents by taking a a weighted average of the genes""" + """Cross two parents by taking a a weighted average of the genes.""" # the percentage of genes taken from the first gene weight = 0.25 diff --git a/src/parent_selection/parent_selection_methods.py b/src/parent_selection/parent_selection_methods.py index 5c14c4c..faf2e82 100644 --- a/src/parent_selection/parent_selection_methods.py +++ b/src/parent_selection/parent_selection_methods.py @@ -55,7 +55,8 @@ class Parent_Selection: that it will be selected. Using the example of a casino roulette wheel. Where the chromosomes are the numbers to be selected and the board size for those numbers are directly proportional to the chromosome's current fitness. Where - the ball falls is a randomly generated number between 0 and 1.""" + the ball falls is a randomly generated number between 0 and 1. + """ # Make sure the population is sorted by fitness ga.population.sort_by_best_fitness(ga)