Changed population print

This commit is contained in:
SimpleArt
2020-11-17 08:40:51 -05:00
parent c5d323cb20
commit 1d97a92fb7
2 changed files with 6 additions and 17 deletions

View File

@ -156,7 +156,7 @@ class GA(Attributes):
def print_population(self):
"""Prints the entire population"""
self.population.print_all()
print(self.population)
def print_best(self):

View File

@ -151,19 +151,8 @@ class Population:
def __repr__(self):
"""Returns a backend string representation of the entire population"""
pass
def print_all(self):
"""Prints information about the population in the following format:
Current population
Chromosome 1 - [gene][gene][gene][.etc] / Chromosome fitness -
Chromosome 2 - [gene][gene][gene][.etc] / Chromosome fitness -
etc.
"""
print("Current population:")
for index in range(self.size()):
print(f'Chromosome - {index} {self.get_chromosome(index)}', end = "")
print(f' / Fitness = {self.get_chromosome(index).get_fitness()}')
return ''.join(
'Chromosome - {index} {self.get_chromosome(index)} ' +
'/ Fitness = {self.get_chromosome(index).get_fitness()}\n'
for index in range(self.size())
)