Simplify worst element replacement
This commit is contained in:
parent
5812d470a9
commit
3e08b67371
|
@ -1,4 +1,4 @@
|
||||||
from numpy.random import choice, randint, seed
|
from numpy.random import choice, seed
|
||||||
|
|
||||||
|
|
||||||
def get_first_random_solution(m, data):
|
def get_first_random_solution(m, data):
|
||||||
|
@ -9,10 +9,9 @@ def get_first_random_solution(m, data):
|
||||||
|
|
||||||
def replace_worst_element(previous, data):
|
def replace_worst_element(previous, data):
|
||||||
solution = previous.copy()
|
solution = previous.copy()
|
||||||
worst_index = previous["distance"].astype(float).idxmin()
|
worst_index = solution["distance"].astype(float).idxmin()
|
||||||
random_candidate = data.loc[randint(low=0, high=len(data.index))]
|
solution.loc[worst_index] = data.sample(random_state=42).squeeze()
|
||||||
solution.loc[worst_index] = random_candidate
|
return solution, worst_index
|
||||||
return solution
|
|
||||||
|
|
||||||
|
|
||||||
def get_random_solution(previous, data):
|
def get_random_solution(previous, data):
|
||||||
|
|
Loading…
Reference in New Issue