Implement element evaluation
This commit is contained in:
parent
74528b8c39
commit
921e094858
|
@ -1,3 +1,4 @@
|
||||||
|
from numpy import put, sum, append, where, zeros
|
||||||
from numpy.random import choice, seed
|
from numpy.random import choice, seed
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,6 +10,17 @@ def get_first_random_solution(n, m):
|
||||||
return solution
|
return solution
|
||||||
|
|
||||||
|
|
||||||
|
def evaluate_element(element, data):
|
||||||
|
fitness = []
|
||||||
|
genotype = where(element == True)
|
||||||
|
indexes = genotype[0]
|
||||||
|
distances = data.query(f"source in @indexes and destination in @indexes")
|
||||||
|
for item in indexes[:-1]:
|
||||||
|
element_df = distances.query(f"source == {item} or destination == {item}")
|
||||||
|
max_distance = element_df["distance"].astype(float).max()
|
||||||
|
fitness = append(arr=fitness, values=max_distance)
|
||||||
|
distances = distances.query(f"source != {item} and destination != {item}")
|
||||||
|
return sum(fitness)
|
||||||
|
|
||||||
|
|
||||||
def element_in_dataframe(solution, element):
|
def element_in_dataframe(solution, element):
|
||||||
|
|
Loading…
Reference in New Issue