Skip to content

Commit 425d8d9

Browse files
committed
fix NoCrossover missing offsprings #744
1 parent a799e5d commit 425d8d9

File tree

1 file changed

+5
-2
lines changed
  • pymoo/operators/crossover

1 file changed

+5
-2
lines changed

pymoo/operators/crossover/nox.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33

44

55
class NoCrossover(Crossover):
6-
def __init__(self, *, n_parents=1, n_offsprings=1, prob=0.0, **kwargs):
6+
def __init__(self, *, n_parents=1, n_offsprings=None, prob=0.0, **kwargs):
7+
if n_offsprings is None:
8+
n_offsprings = n_parents
79
super().__init__(n_parents, n_offsprings, prob, **kwargs)
810

911
def do(self, problem, pop, *args, random_state, **kwargs):
10-
return Population.create(*[random_state.choice(parents) for parents in pop])
12+
replace = self.n_offsprings > self.n_parents
13+
return Population.create(*[random_state.choice(parents, replace=replace) for parents in pop])

0 commit comments

Comments
 (0)