Commit db2ebce9 by Yoann Dufresne

fix bugs induced by the d2g heritage simplification in all the mains

parent ba61e7d2
 ... ... @@ -7,47 +7,49 @@ from d2_path import Path, Unitig """ Remove unnecessary transitions """ def transitive_reduction(d2g): nxg = d2g.nx_graph edges = list(nxg.edges()) edges = list(d2g.edges(data=True)) # Remove self edges for edge in edges: if edge[0] == edge[1]: nxg.remove_edge(*edge) d2g.remove_edge(*edge) edges = list(d2g.edges(data=True)) nb_removed = 0 for edge in edges: while len(edges) > 0: dg1_name, dg2_name, data = edges.pop(0) # Extract dgs dg1 = d2g.nodes[edge[0]] dg2 = d2g.nodes[edge[1]] dg1 = d2g.node_by_name[dg1_name] dg2 = d2g.node_by_name[dg2_name] # Extract common neighbors nei1 = frozenset(nxg.neighbors(d2g.nodes.inverse[dg1])) nei2 = frozenset(nxg.neighbors(d2g.nodes.inverse[dg2])) nei1 = frozenset(d2g.neighbors(dg1_name)) nei2 = frozenset(d2g.neighbors(dg2_name)) common = nei1.intersection(nei2) # Look for all the common neighbors, if edge must be remove or not current_dist = d2g.distances[dg1.idx][dg2.idx] current_dist = d2g[dg1_name][dg2_name]["distance"] for node in common: com_dg = d2g.nodes[node] extern_dist = d2g.distances[dg1.idx][com_dg.idx] + d2g.distances[com_dg.idx][dg2.idx] com_dg = d2g.node_by_name[node] extern_dist = d2g[dg1_name][node]["distance"] + d2g[node][dg2_name]["distance"] # If better path, remove the edge if extern_dist <= current_dist: # Remove from graph nxg.remove_edge(*edge) # Remove in distances del d2g.distances[dg1.idx][dg2.idx] if len(d2g.distances[dg1.idx]) == 0: del d2g.distances[dg1.idx] del d2g.distances[dg2.idx][dg1.idx] if len(d2g.distances[dg2.idx]) == 0: del d2g.distances[dg2.idx] d2g.remove_edge(dg1_name, dg2_name) # Remove from edge list edge = (dg1_name, dg2_name, data) if edge in edges: edges.remove(edge) # Mark as removed nb_removed += 1 break print(f"{nb_removed} edge removed") print(f"{len(nxg.edges())} remaining") print(f"{len(d2g.edges())} remaining") """ For each node of the d2 graph, construct a node in the reduced graph. ... ...