Fix pseudorandom solution generation
This commit is contained in:
		
							parent
							
								
									d04d0becfe
								
							
						
					
					
						commit
						b63b5b08b6
					
				@ -1,5 +1,5 @@
 | 
			
		||||
from preprocessing import parse_file
 | 
			
		||||
from pandas import DataFrame
 | 
			
		||||
from pandas import DataFrame, Series
 | 
			
		||||
from sys import argv
 | 
			
		||||
from random import seed, randint
 | 
			
		||||
from time import time
 | 
			
		||||
@ -30,7 +30,7 @@ def get_furthest_element(element, data):
 | 
			
		||||
    furthest_index = element_df["distance"].astype(float).idxmax()
 | 
			
		||||
    furthest_row = data.iloc[furthest_index]
 | 
			
		||||
    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):
 | 
			
		||||
@ -44,14 +44,15 @@ def greedy_algorithm(n, m, data):
 | 
			
		||||
    for _ in range(m):
 | 
			
		||||
        last_solution = int(solutions["point"].tail(n=1))
 | 
			
		||||
        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)
 | 
			
		||||
    return solutions
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def get_pseudorandom_solution(n, data):
 | 
			
		||||
    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):
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user