Skip to content

Commit

Permalink
Merge pull request #140 from lucianolorenti/handling_negative_fitness
Browse files Browse the repository at this point in the history
Roulette: Fix how negatives fitness are handled
  • Loading branch information
thieu1995 authored Feb 20, 2024
2 parents d9918d7 + 565530d commit 2fa4d56
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion mealpy/optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ def get_index_roulette_wheel_selection(self, list_fitness: np.array):
list_fitness = np.array(list_fitness).flatten()
if list_fitness.ptp() == 0:
return int(self.generator.integers(0, len(list_fitness)))
if np.any(list_fitness) < 0:
if np.any(list_fitness < 0):
list_fitness = list_fitness - np.min(list_fitness)
final_fitness = list_fitness
if self.problem.minmax == "min":
Expand Down

0 comments on commit 2fa4d56

Please sign in to comment.