Add crossover probability
This commit is contained in:
parent
35ca73ba74
commit
f4dd4700c7
|
@ -146,13 +146,18 @@ def group_parents(parents):
|
|||
return parent_pairs
|
||||
|
||||
|
||||
def crossover(mode, parents, m):
|
||||
def crossover(mode, parents, m, probability=0.7):
|
||||
parent_groups = group_parents(parents)
|
||||
offspring = []
|
||||
if mode == "uniform":
|
||||
for element in parent_groups:
|
||||
expected_crossovers = int(len(parents) * probability)
|
||||
cutoff = expected_crossovers // 2
|
||||
for element in parent_groups[:cutoff]:
|
||||
offspring.append(uniform_crossover(element, m))
|
||||
offspring.append(uniform_crossover(element, m))
|
||||
for element in parent_groups[cutoff:]:
|
||||
offspring.append(element[0])
|
||||
offspring.append(element[1])
|
||||
else:
|
||||
for element in parent_groups:
|
||||
first_offspring, second_offspring = position_crossover(element)
|
||||
|
|
Loading…
Reference in New Issue