This commit is contained in:
UmbertoJr 2019-11-10 10:44:35 +01:00
parent da5d4ca8ef
commit 8ed9420f94

View file

@ -113,3 +113,30 @@ class multi_fragment:
sol_list.append(n1)
return sol_list
@staticmethod
def mf(instance):
mat = np.copy(instance.dist_matrix)
mat = np.triu(mat)
mat[mat == 0] = 100000
solution = {str(i): [] for i in range(instance.nPoints)}
start_list = [i for i in range(instance.nPoints)]
inside = 0
for el in np.argsort(mat.flatten()):
node1, node2 = el // instance.nPoints, el % instance.nPoints
possible_edge = [node1, node2]
if multi_fragment.check_if_available(node1, node2, solution):
if multi_fragment.check_if_not_close(possible_edge, solution):
# print("entrato", inside)
solution[str(node1)].append(node2)
solution[str(node2)].append(node1)
if len(solution[str(node1)]) == 2:
start_list.remove(node1)
if len(solution[str(node2)]) == 2:
start_list.remove(node2)
inside += 1
# print(node1, node2, inside)
if inside == instance.nPoints - 1:
# print(f"ricostruire la solutione da {start_list}",
# f"vicini di questi due nodi {[solution[str(i)] for i in start_list]}")
solution = multi_fragment.create_solution(start_list, solution)
return solution