Minor changes
This commit is contained in:
@ -110,7 +110,7 @@ class GA(Attributes):
|
||||
for chromosome in self.population.get_chromosome_list():
|
||||
|
||||
# Update fitness if needed or asked by the user
|
||||
if chromosome.get_fitness() is None or self.update_fitness:
|
||||
if chromosome.fitness is None or self.update_fitness:
|
||||
chromosome.set_fitness(self.fitness_function_impl(chromosome))
|
||||
|
||||
|
||||
@ -122,10 +122,10 @@ class GA(Attributes):
|
||||
"""
|
||||
|
||||
return sorted(
|
||||
chromosome_list, # list to be sorted
|
||||
key = lambda chromosome: chromosome.get_fitness(), # by fitness
|
||||
reverse = (self.target_fitness_type == 'max') # ordered by fitness type
|
||||
)
|
||||
chromosome_list, # list to be sorted
|
||||
key = lambda chromosome: chromosome.fitness, # by fitness
|
||||
reverse = (self.target_fitness_type == 'max') # ordered by fitness type
|
||||
)
|
||||
|
||||
|
||||
def get_chromosome_fitness(self, index):
|
||||
@ -169,13 +169,13 @@ class GA(Attributes):
|
||||
print(self.population)
|
||||
|
||||
|
||||
def print_best(self):
|
||||
def print_best_chromosome(self):
|
||||
"""Prints the best chromosome and its fitness"""
|
||||
print(f"Best Chromosome \t: {self.population[0]}")
|
||||
print(f"Best Fitness \t: {self.population[0].get_fitness()}")
|
||||
|
||||
|
||||
def print_worst(self):
|
||||
def print_worst_chromosome(self):
|
||||
"""Prints the worst chromosome and its fitness"""
|
||||
print(f"Worst Chromosome \t: {self.population[-1]}")
|
||||
print(f"Worst Fitness \t: {self.population[-1].get_fitness()}")
|
||||
|
||||
Reference in New Issue
Block a user