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):
 | 
			
		||||
@ -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):
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user