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)
|
||||
|
||||
|
||||
def element_in_dataframe(solution, element):
|
||||
duplicates = solution.query(f"point == {element}")
|
||||
return not duplicates.empty
|
||||
|
||||
|
||||
def mutate(solution, n, probability=0.001):
|
||||
if random() > probability:
|
||||
return solution
|
||||
|
@ -127,9 +132,10 @@ def mutate(solution, n, probability=0.001):
|
|||
return solution
|
||||
|
||||
|
||||
def element_in_dataframe(solution, element):
|
||||
duplicates = solution.query(f"point == {element}")
|
||||
return not duplicates.empty
|
||||
def tournament_selection(solution):
|
||||
individuals = solution.sample(n=2)
|
||||
best_index = solution["distance"].astype(float).idxmax()
|
||||
return individuals.iloc[best_index]
|
||||
|
||||
|
||||
def replace_worst_element(previous, n, data):
|
||||
|
|
Loading…
Reference in New Issue