From c4ead43d6d185e457a4e14a2ea5ba57b44c53788 Mon Sep 17 00:00:00 2001 From: Daniel Wilczak Date: Thu, 24 Sep 2020 15:02:58 -0400 Subject: [PATCH] Updated genes,chromosme,population prints --- src/initialization/chromosome_structure/chromosome.py | 5 ++++- src/initialization/gene_structure/gene.py | 2 +- src/initialization/population_structure/population.py | 10 +++++++++- src/run_testing.py | 7 +++---- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/initialization/chromosome_structure/chromosome.py b/src/initialization/chromosome_structure/chromosome.py index 02fe0b4..1880f54 100644 --- a/src/initialization/chromosome_structure/chromosome.py +++ b/src/initialization/chromosome_structure/chromosome.py @@ -28,4 +28,7 @@ class chromosome: self.fitness = fitness def __repr__(self): - return f"chromosome({self.genes.__repr__()})" + output_str = '' + for gene in self.genes: + output_str += gene.__repr__() + return output_str diff --git a/src/initialization/gene_structure/gene.py b/src/initialization/gene_structure/gene.py index e309237..ea3b547 100644 --- a/src/initialization/gene_structure/gene.py +++ b/src/initialization/gene_structure/gene.py @@ -21,4 +21,4 @@ class gene: self.value = value def __repr__(self): - return f"Gene({self.value} - Fitness{self.fitness})" + return f'[{self.value}]' diff --git a/src/initialization/population_structure/population.py b/src/initialization/population_structure/population.py index 643a6a2..fd80c28 100644 --- a/src/initialization/population_structure/population.py +++ b/src/initialization/population_structure/population.py @@ -32,7 +32,15 @@ class population: self.fitness = fitness def __repr__(self): - return f"population({self.chromosomes.__repr__()})" + pass + + def print_all(self): + # Ex .Current population + # Chromosome 1 - [gene][gene][gene][.etc] / Chromosome fitness - # + print("Current population:") + for index in range(len(self.chromosomes)): + print(f'Chromosome - {index} {self.chromosomes[index]}', end = "") + print(f' / Fitness = {self.chromosomes[index].fitness}') def generate_first_chromosomes(self, chromosome_count, chromosome_length, gene_lower_bound, gene_upper_bound): #Creating the chromosomes with Genes of random size diff --git a/src/run_testing.py b/src/run_testing.py index 63107b6..1d5b785 100644 --- a/src/run_testing.py +++ b/src/run_testing.py @@ -14,7 +14,6 @@ new_population = ga.make_population() # Creating population ga.initialize() -print(ga.population) - -for chromosome in ga.population.chromosomes: - print(chromosome.genes[0].__dict__) +ga.population.print_all() +print("") +print(ga.population.chromosomes[0].__repr__())