Fix pseudorandom solution generation
This commit is contained in:
		
							parent
							
								
									d04d0becfe
								
							
						
					
					
						commit
						b63b5b08b6
					
				@ -1,5 +1,5 @@
 | 
				
			|||||||
from preprocessing import parse_file
 | 
					from preprocessing import parse_file
 | 
				
			||||||
from pandas import DataFrame
 | 
					from pandas import DataFrame, Series
 | 
				
			||||||
from sys import argv
 | 
					from sys import argv
 | 
				
			||||||
from random import seed, randint
 | 
					from random import seed, randint
 | 
				
			||||||
from time import time
 | 
					from time import time
 | 
				
			||||||
@ -30,7 +30,7 @@ def get_furthest_element(element, data):
 | 
				
			|||||||
    furthest_index = element_df["distance"].astype(float).idxmax()
 | 
					    furthest_index = element_df["distance"].astype(float).idxmax()
 | 
				
			||||||
    furthest_row = data.iloc[furthest_index]
 | 
					    furthest_row = data.iloc[furthest_index]
 | 
				
			||||||
    furthest_point = get_different_element(original=element, row=furthest_row)
 | 
					    furthest_point = get_different_element(original=element, row=furthest_row)
 | 
				
			||||||
    return {"point": furthest_point, "distance": furthest_row["distance"]}
 | 
					    return Series(data={"point": furthest_point, "distance": furthest_row["distance"]})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def remove_solution_dataset(data, solution):
 | 
					def remove_solution_dataset(data, solution):
 | 
				
			||||||
@ -44,14 +44,15 @@ def greedy_algorithm(n, m, data):
 | 
				
			|||||||
    for _ in range(m):
 | 
					    for _ in range(m):
 | 
				
			||||||
        last_solution = int(solutions["point"].tail(n=1))
 | 
					        last_solution = int(solutions["point"].tail(n=1))
 | 
				
			||||||
        centroid = get_furthest_element(element=last_solution, data=data)
 | 
					        centroid = get_furthest_element(element=last_solution, data=data)
 | 
				
			||||||
        solutions = solutions.append(dict(centroid), ignore_index=True)
 | 
					        solutions = solutions.append(centroid, ignore_index=True)
 | 
				
			||||||
        data = remove_solution_dataset(data=data, solution=last_solution)
 | 
					        data = remove_solution_dataset(data=data, solution=last_solution)
 | 
				
			||||||
    return solutions
 | 
					    return solutions
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def get_pseudorandom_solution(n, data):
 | 
					def get_pseudorandom_solution(n, data):
 | 
				
			||||||
    seed(42)
 | 
					    seed(42)
 | 
				
			||||||
    return data.iloc[randint(a=0, b=n)]
 | 
					    solution = data.iloc[randint(a=0, b=n)]
 | 
				
			||||||
 | 
					    return Series(data={"point": solution["destination"], "distance": 0})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def local_search(n, m, data):
 | 
					def local_search(n, m, data):
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user