Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed wrong fitness length bug #59

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/p2lab/genetic/genetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion src/p2lab/genetic/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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

Expand Down