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

selection-only function #24

Closed
wants to merge 1 commit into from
Closed
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
32 changes: 18 additions & 14 deletions src/p2lab/genetic/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ def build_crossover_fn(

Arguments:
crossover_method: Function that defines the method of crossover
used. See below
used. If None, the crossover function will simply
be a selection function. See below for various methods
**kwargs: Arguments passed to the crossover method
"""

Expand Down Expand Up @@ -61,22 +62,25 @@ def crossover_fn(
# Extract list of pokemon to crossover
team1_pokemon = team1_old.pokemon
team2_pokemon = team2_old.pokemon

# If a crossover method has been specified
if not crossover_method is None:

# Crossover occurs with parameterised probability
crossover = np.random.choice(
a=[True, False], p=[crossover_prob, 1 - crossover_prob]
)

# Perform crossover
if crossover:
team1_pokemon, team2_pokemon = crossover_method(
team1=team1_pokemon,
team2=team2_pokemon,
num_pokemon=num_pokemon,
allow_all=allow_all,
**kwargs,
# Crossover occurs with parameterised probability
crossover = np.random.choice(
a=[True, False], p=[crossover_prob, 1 - crossover_prob]
)

# Perform crossover
if crossover:
team1_pokemon, team2_pokemon = crossover_method(
team1=team1_pokemon,
team2=team2_pokemon,
num_pokemon=num_pokemon,
allow_all=allow_all,
**kwargs,
)

# Build new teams
team1_new = Team(pokemon=team1_pokemon)
team2_new = Team(pokemon=team2_pokemon)
Expand Down