Remove duplicates in local search
This commit is contained in:
		
							parent
							
								
									028db4ba91
								
							
						
					
					
						commit
						5e6a6d00e9
					
				@ -28,12 +28,20 @@ def get_random_solution(previous, data):
 | 
			
		||||
    return solution
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def remove_duplicates(element, data):
 | 
			
		||||
    duplicate_free_df = data.query(
 | 
			
		||||
        "(source not in @element.source) or (destination not in @element.destination)"
 | 
			
		||||
    )
 | 
			
		||||
    return duplicate_free_df
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def explore_neighbourhood(element, data, max_iterations=100000):
 | 
			
		||||
    neighbourhood = []
 | 
			
		||||
    neighbourhood.append(element)
 | 
			
		||||
    for _ in range(max_iterations):
 | 
			
		||||
        previous_solution = neighbourhood[-1]
 | 
			
		||||
        neighbour = get_random_solution(previous=previous_solution, data=data)
 | 
			
		||||
        data = remove_duplicates(element=neighbour, data=data)
 | 
			
		||||
        if neighbour.equals(previous_solution):
 | 
			
		||||
            break
 | 
			
		||||
        neighbourhood.append(neighbour)
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user