diff --git a/src/EasyGA.py b/src/EasyGA.py index c33c408..8e5cfc1 100644 --- a/src/EasyGA.py +++ b/src/EasyGA.py @@ -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): diff --git a/src/structure/population.py b/src/structure/population.py index 6d409e6..a6bddce 100644 --- a/src/structure/population.py +++ b/src/structure/population.py @@ -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()) + )