From 8ed9420f9446bb5f3c1e2dd6406839c06c1622f3 Mon Sep 17 00:00:00 2001 From: UmbertoJr Date: Sun, 10 Nov 2019 10:44:35 +0100 Subject: [PATCH] utils --- src/utils.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/utils.py b/src/utils.py index 8d57da3..b7f7331 100644 --- a/src/utils.py +++ b/src/utils.py @@ -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