Simplify worst element replacement

This commit is contained in:
coolneng 2021-04-16 20:05:45 +02:00
parent 5812d470a9
commit 3e08b67371
Signed by: coolneng
GPG Key ID: 9893DA236405AF57
1 changed files with 4 additions and 5 deletions

View File

@ -1,4 +1,4 @@
from numpy.random import choice, randint, seed
from numpy.random import choice, seed
def get_first_random_solution(m, data):
@ -9,10 +9,9 @@ def get_first_random_solution(m, data):
def replace_worst_element(previous, data):
solution = previous.copy()
worst_index = previous["distance"].astype(float).idxmin()
random_candidate = data.loc[randint(low=0, high=len(data.index))]
solution.loc[worst_index] = random_candidate
return solution
worst_index = solution["distance"].astype(float).idxmin()
solution.loc[worst_index] = data.sample(random_state=42).squeeze()
return solution, worst_index
def get_random_solution(previous, data):