Return best solution or the same if there's none
This commit is contained in:
		
							parent
							
								
									3e08b67371
								
							
						
					
					
						commit
						028db4ba91
					
				@ -15,11 +15,16 @@ def replace_worst_element(previous, data):
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def get_random_solution(previous, data):
 | 
			
		||||
    solution = replace_worst_element(previous, data)
 | 
			
		||||
    while solution["distance"].sum() <= previous["distance"].sum():
 | 
			
		||||
        if solution.equals(previous):
 | 
			
		||||
            break
 | 
			
		||||
        solution = replace_worst_element(previous=solution, data=data)
 | 
			
		||||
    candidates = []
 | 
			
		||||
    candidates.append(previous)
 | 
			
		||||
    solution, worst_index = replace_worst_element(previous, data)
 | 
			
		||||
    previous_worst_distance = previous["distance"].loc[worst_index]
 | 
			
		||||
    while candidates[-1].distance.loc[worst_index] <= previous_worst_distance:
 | 
			
		||||
        last_solution = candidates[-1]
 | 
			
		||||
        solution, _ = replace_worst_element(previous=solution, data=data)
 | 
			
		||||
        if solution.equals(last_solution):
 | 
			
		||||
            return last_solution
 | 
			
		||||
        candidates.append(solution)
 | 
			
		||||
    return solution
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user