Skip to content

Commit

Permalink
Forcing single operators into list in the GeneticAlgorithm construc…
Browse files Browse the repository at this point in the history
…tor to avoid `TypeError: object of type 'function' has no len()` on `for i in range(len(selection_operators)):`
  • Loading branch information
gnypit committed Jan 24, 2025
1 parent ca300f6 commit 7d2b9ad
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions genal/genetic_algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@ def __init__(self, initial_pop_size: int, number_of_generations: int, elite_size
"""Based on lists of (callable) function selected by the User from selection_operators.py
and crossover_operators.py, a more general dict is created with all the possible combinations of the operators.
"""
if type(selection) is not list:
selection = [selection]
if type(crossover) is not list:
crossover = [crossover]

self.operators = self.__zip_crossover_selection(selection_operators=selection, crossover_operators=crossover)
# self.operators = [(sel_op, cross_op) for sel_op in selection for cross_op in crossover]
self.pool_size = pool_size # will be redundant after the selection args are properly handled
Expand Down

0 comments on commit 7d2b9ad

Please sign in to comment.