Fixed chromosome so now it adds to the database and added __str__ to chromo
This commit is contained in:
@ -68,10 +68,8 @@ class SQL_Database:
|
|||||||
""" Insert current generations population """
|
""" Insert current generations population """
|
||||||
|
|
||||||
# Structure the insert data
|
# Structure the insert data
|
||||||
db_chromosome_list = [
|
db_chromosome_list = [(ga.current_generation, chromosome.fitness, chromosome.__str__())
|
||||||
(ga.current_generation, chromosome.fitness, '[chromosome]')
|
for chromosome in ga.population.get_chromosome_list() ]
|
||||||
for chromosome in ga.population.get_chromosome_list()
|
|
||||||
]
|
|
||||||
|
|
||||||
# Create sql query structure
|
# Create sql query structure
|
||||||
sql = ''' INSERT INTO data(generation,fitness,chromosome)
|
sql = ''' INSERT INTO data(generation,fitness,chromosome)
|
||||||
|
|||||||
@ -59,4 +59,16 @@ class Chromosome:
|
|||||||
output_str = ''
|
output_str = ''
|
||||||
for gene in self.gene_list:
|
for gene in self.gene_list:
|
||||||
output_str += gene.__repr__()
|
output_str += gene.__repr__()
|
||||||
|
|
||||||
|
return output_str
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
"""Create a string of the chromosome. Ex chromsome = 1,2,3"""
|
||||||
|
output_str = ''
|
||||||
|
for gene in self.gene_list:
|
||||||
|
if gene == self.gene_list[0]:
|
||||||
|
output_str += str(gene.get_value())
|
||||||
|
else:
|
||||||
|
output_str += ',' + str(gene.get_value())
|
||||||
|
|
||||||
return output_str
|
return output_str
|
||||||
|
|||||||
Reference in New Issue
Block a user