SevgiAkten / pycellga

Cellular Genetic Algorithms in Python.
https://sevgiakten.github.io/pycellga/
MIT License
2 stars 1 forks source link

Design problem of using genetic operators #42

Closed jbytecode closed 1 month ago

jbytecode commented 1 month ago

Suppose the code is

selection(pop_list, c).get_parents()

where selection is an instance of one of the selection operators. In each call, a new instance is created (like new in C#) and then the object method is called. This is a performance overhead. The operator objects should be created ones, or, pre-created operator should be passed to the optimizer, e.g.

cga(selection = TournamentSelection(3), cross = OnePointCrossOver(), ...)
jbytecode commented 1 month ago

The issue if current for the other operators, e.g. recombinations:

recombination(
                    parents, problem).get_recombinations()

in the code above, in each single iteration, a new instance of the crossover class is created and the object method is called. I think the use of operators mostly triggers the garbage collector of Python and a performance improvement can be achieved if this stage is optimized.

jbytecode commented 1 month ago

same for the mutations:

if rnd < p_mutation:
                    mutated = mutation(mutation_cand, problem).mutate()
                    offsprings[p] = mutated
                else:
                    pass
jbytecode commented 1 month ago

I think this can be done later, I am setting this a lower priority (seems difficult by now)