Deepcopy'd data

This commit is contained in:
SimpleArt
2020-11-12 16:40:00 -05:00
parent b0c4bd79c6
commit 22bd0527e5
3 changed files with 14 additions and 19 deletions

View File

@ -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

View File

@ -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):

View File

@ -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 = []