From b0c4bd79c6b067616ef70ec97ac2add98f35c109 Mon Sep 17 00:00:00 2001 From: SimpleArt <71458112+SimpleArt@users.noreply.github.com> Date: Thu, 12 Nov 2020 16:24:57 -0500 Subject: [PATCH 1/2] Override label variables with attributes --- src/database/matplotlib_graph.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/database/matplotlib_graph.py b/src/database/matplotlib_graph.py index 5100858..74637da 100644 --- a/src/database/matplotlib_graph.py +++ b/src/database/matplotlib_graph.py @@ -23,6 +23,10 @@ class Matplotlib_Graph: def plt_setup(self, X, Y, yscale, xlabel, ylabel, title, type_of_plot, size): """Setup for plt""" + if self.xlabel is not None: xlabel = self.xlabel + if self.ylabel is not None: xlabel = self.ylabel + if self.title is not None: xlabel = self.title + if yscale == "log": # If using log then the values have to be positive numbers Y = [abs(ele) for ele in Y] @@ -85,10 +89,6 @@ class Matplotlib_Graph: # Query for Y data Y = self.database.get_lowest_chromosome() - if(self.yscale == "log"): - # If using log then the values have to be positive numbers - Y = [abs(ele) for ele in Y] - self.plt_setup(X, Y, self.yscale, 'Generation', 'Lowest Fitness', 'Relationship Between Generations and Lowest Fitness', self.type_of_plot, self.size) From 22bd0527e5003f7091c21f86ec0876904c18d536 Mon Sep 17 00:00:00 2001 From: SimpleArt <71458112+SimpleArt@users.noreply.github.com> Date: Thu, 12 Nov 2020 16:40:00 -0500 Subject: [PATCH 2/2] Deepcopy'd data --- src/structure/chromosome.py | 11 ++++++----- src/structure/gene.py | 8 ++------ src/structure/population.py | 14 ++++++-------- 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/src/structure/chromosome.py b/src/structure/chromosome.py index d25080f..e9106ae 100644 --- a/src/structure/chromosome.py +++ b/src/structure/chromosome.py @@ -1,11 +1,12 @@ +from copy import deepcopy + class Chromosome: - def __init__(self, gene_list = None): - if gene_list is None: - self.gene_list = [] - else: - self.gene_list = gene_list + def __init__(self, gene_list = []): + """Initialize the chromosome with fitness value of None, and a + set of genes dependent on user-passed parameter.""" + self.gene_list = deepcopy(gene_list) self.fitness = None diff --git a/src/structure/gene.py b/src/structure/gene.py index 3729d50..bc8f054 100644 --- a/src/structure/gene.py +++ b/src/structure/gene.py @@ -1,15 +1,11 @@ -def check_gene(value): - #Check to make sure the gene is not empty - assert value != "" , "Gene can not be empty" - return value - +from copy import deepcopy class Gene: def __init__(self, value): """Initialize a gene with fitness of value None and the input value""" + self.value = deepcopy(value) self.fitness = None - self.value = check_gene(value) def get_fitness(self): diff --git a/src/structure/population.py b/src/structure/population.py index b532bef..6445d05 100644 --- a/src/structure/population.py +++ b/src/structure/population.py @@ -1,14 +1,12 @@ +from copy import deepcopy + class Population: - def __init__(self, chromosome_list = None): - """Intiialize the population with fitness of value None, and a - set of chromosomes dependant on user-passed parameter""" - - if chromosome_list is None: - self.chromosome_list = [] - else: - self.chromosome_list = chromosome_list + def __init__(self, chromosome_list = []): + """Initialize the population with fitness of value None, and a + set of chromosomes dependant on user-passed parameter.""" + self.chromosome_list = deepcopy(chromosome_list) self.fitness = None self.mating_pool = [] self.next_population = []