Implement binary tournament selection operator
This commit is contained in:
parent
84a165ea6f
commit
9cafdc0536
|
@ -115,6 +115,11 @@ def crossover(mode, parents, m):
|
||||||
return position_crossover(parents, m)
|
return position_crossover(parents, m)
|
||||||
|
|
||||||
|
|
||||||
|
def element_in_dataframe(solution, element):
|
||||||
|
duplicates = solution.query(f"point == {element}")
|
||||||
|
return not duplicates.empty
|
||||||
|
|
||||||
|
|
||||||
def mutate(solution, n, probability=0.001):
|
def mutate(solution, n, probability=0.001):
|
||||||
if random() > probability:
|
if random() > probability:
|
||||||
return solution
|
return solution
|
||||||
|
@ -127,9 +132,10 @@ def mutate(solution, n, probability=0.001):
|
||||||
return solution
|
return solution
|
||||||
|
|
||||||
|
|
||||||
def element_in_dataframe(solution, element):
|
def tournament_selection(solution):
|
||||||
duplicates = solution.query(f"point == {element}")
|
individuals = solution.sample(n=2)
|
||||||
return not duplicates.empty
|
best_index = solution["distance"].astype(float).idxmax()
|
||||||
|
return individuals.iloc[best_index]
|
||||||
|
|
||||||
|
|
||||||
def replace_worst_element(previous, n, data):
|
def replace_worst_element(previous, n, data):
|
||||||
|
|
Loading…
Reference in New Issue