MCPcopy Create free account
hub / github.com/PKU-ASAL/Simulated-Data / MergeGraph

Method MergeGraph

src/ETW/real-time/ProvGraph.py:574–641  ·  view source on GitHub ↗
(self,graph_cache,graph_list)

Source from the content-addressed store, hash-verified

572 return result
573
574 def MergeGraph(self,graph_cache,graph_list):
575 connection_map = np.zeros((len(graph_cache), len(graph_list)), dtype=int)
576 for i,g1 in enumerate(graph_cache):
577 g1 = g1.graph
578 for k,g2 in enumerate(graph_list):
579 node_l1 = set(g1.nodes())
580 node_l2 = set(g2.nodes())
581 common_node = node_l1 & node_l2
582 if len(common_node) > 0:
583 connection_map[i][k] = 1
584
585 merged_graph_list = []
586 for x in range(connection_map.shape[0]):
587 row = connection_map[x]
588 if np.all(row == 0):
589 merged_graph_list.append(graph_cache[x])
590 graph_cache[x].timestamp += 1
591
592 for y in range(connection_map.shape[1]):
593 col = connection_map[:,y]
594 if np.all(col == 0):
595 cache_graph = CacheGraph(graph_list[y])
596 merged_graph_list.append(cache_graph)
597
598 Merged_graph = []
599 while not np.all(connection_map == 0):
600 start_x, start_y = 0, 0
601 find = False
602 for i in range(connection_map.shape[0]):
603 for j in range(connection_map.shape[1]):
604 if connection_map[i][j] == 1:
605 start_x = i
606 start_y = j
607 find = True
608 break
609 if find:
610 break
611
612 r = self.GetSubset(connection_map,start_x,start_y)
613 r.append(start_x)
614 r.append(start_y + connection_map.shape[0])
615 Merged_graph.append(r)
616
617 for l in Merged_graph:
618 tmp_graph_list = []
619 for idx in l:
620 if idx >= connection_map.shape[0]:
621 tmp_graph_list.append(graph_list[idx - connection_map.shape[0]])
622 else:
623 tmp_graph_list.append(graph_cache[idx].graph)
624 G = nx.compose_all(tmp_graph_list)
625 # for k in G.nodes():
626 # # print(k)
627 # G.nodes[k]['label'] = self.GetNodeNewName(k) + ' ' + str(self.GetNodeState(k) == False)
628
629 # nx.drawing.nx_pydot.write_dot(G, 'debug1.dot')
630
631 # G = self.graph_taylor(G)

Callers 1

update_cacheMethod · 0.95

Calls 2

GetSubsetMethod · 0.95
CacheGraphClass · 0.90

Tested by

no test coverage detected