Skip to content

NoCrossOver does random selection #743

@oxinabox

Description

@oxinabox

I expected NoCrossOver to basically mean the cross-over step wasn't done.
Either because it generated exactly the same as it was input,
or because it just was hard coded to skip that step.
but instead it randomly selects.
This only matters if it has n_parents > 1, and that only became possible after #742

But it does actually randomly select from the parents.
If your population is large relative to its diversity that is fine as there are probably redundant copies of those elements.
But if not it can result in some thing being dropped.

My own implementation of this is:

import itertools
class NoCrossover2(Crossover):
    def __init__(self, n_parents=1):
        # note: n_parents == n_offspring
        super().__init__(n_parents, n_parents, 0.0)

    def do(self, problem, pop, *args, **kwargs):
        # Keep all parents by just flattening out the matings
        return Population.create(*itertools.chain.from_iterable(pop))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions