Updated genes,chromosme,population prints

This commit is contained in:
Daniel Wilczak
2020-09-24 15:02:58 -04:00
parent 9c5092525a
commit c4ead43d6d
4 changed files with 17 additions and 7 deletions

View File

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

View File

@ -21,4 +21,4 @@ class gene:
self.value = value
def __repr__(self):
return f"Gene({self.value} - Fitness{self.fitness})"
return f'[{self.value}]'

View File

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

View File

@ -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__())