From 156bcb1b8e32691369bf67bf0f0d0188beca7c55 Mon Sep 17 00:00:00 2001 From: philswatton Date: Wed, 28 Jun 2023 13:55:37 +0100 Subject: [PATCH] fixed wrong fitness length bug --- src/p2lab/genetic/genetic.py | 3 ++- src/p2lab/genetic/operations.py | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/p2lab/genetic/genetic.py b/src/p2lab/genetic/genetic.py index 6368284..f111bea 100644 --- a/src/p2lab/genetic/genetic.py +++ b/src/p2lab/genetic/genetic.py @@ -145,8 +145,9 @@ async def genetic_algorithm( # Only do this step if not mutating with fitness, as fitness scores become # invalid after crossover if doing so if not mutate_with_fitness: - new_teams = crossover_fn( + new_teams, new_fitness = crossover_fn( teams=new_teams, + fitness=new_fitness, num_teams=num_teams, num_pokemon=team_size, crossover_prob=crossover_prob, diff --git a/src/p2lab/genetic/operations.py b/src/p2lab/genetic/operations.py index 10bca47..0205caf 100644 --- a/src/p2lab/genetic/operations.py +++ b/src/p2lab/genetic/operations.py @@ -55,6 +55,7 @@ def build_crossover_fn( def crossover_fn( teams: list[Team], + fitness: np.ndarray, num_teams: int, num_pokemon: int, crossover_prob: float, @@ -117,8 +118,9 @@ def crossover_fn( # best to run an even number of teams lol if num_teams % 2 != 0: new_teams.pop() + fitness = fitness[:-1] - return new_teams + return new_teams, fitness return crossover_fn