Happy-Algorithms-League / hal-cgp

Cartesian genetic programming (CGP) in pure Python.
GNU General Public License v3.0
28 stars 10 forks source link

Default `Population` and `MuPlusLambda` objects in `evolve` are persistent #353

Closed jakobj closed 1 year ago

jakobj commented 2 years ago

The current evolve signature

def evolve(
    ...
    pop: Population = Population(),
    ea: MuPlusLambda = MuPlusLambda(),
    ...
) -> Population:

creates default Population and MuPlusLambda objects if none are passed to the function. Unfortunately, these will be persistent, i.e., subsequent calls to evolve seem to reuse the same objects.

To fix this the default argument should be None and they should initialized to the defaults in the body of the function if None is detected.