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

Method MergeGraph

src/Sysdig/real-time/ProvGraph.py:608–668  ·  view source on GitHub ↗
(self,graph_cache,graph_list)

Source from the content-addressed store, hash-verified

606 return result
607
608 def MergeGraph(self,graph_cache,graph_list):
609 connection_map = np.zeros((len(graph_cache), len(graph_list)), dtype=int)
610 for i,g1 in enumerate(graph_cache):
611 g1 = g1.graph
612 for k,g2 in enumerate(graph_list):
613 node_l1 = set(g1.nodes())
614 node_l2 = set(g2.nodes())
615 common_node = node_l1 & node_l2
616 if len(common_node) > 0:
617 connection_map[i][k] = 1
618
619 merged_graph_list = []
620 for x in range(connection_map.shape[0]):
621 row = connection_map[x]
622 if np.all(row == 0):
623 merged_graph_list.append(graph_cache[x])
624 graph_cache[x].timestamp += 1
625
626 for y in range(connection_map.shape[1]):
627 col = connection_map[:,y]
628 if np.all(col == 0):
629 # g = self.graph_taylor(graph_list[y])
630 # g.graph['score'] = np.sum([self.GetNodeScore(node) for node in g.nodes])
631 cache_graph = CacheGraph(graph_list[y])
632 merged_graph_list.append(cache_graph)
633
634 Merged_graph = []
635 while not np.all(connection_map == 0):
636 start_x, start_y = 0, 0
637 find = False
638 for i in range(connection_map.shape[0]):
639 for j in range(connection_map.shape[1]):
640 if connection_map[i][j] == 1:
641 start_x = i
642 start_y = j
643 find = True
644 break
645 if find:
646 break
647
648 r = self.GetSubset(connection_map,start_x,start_y)
649 r.append(start_x)
650 r.append(start_y + connection_map.shape[0])
651 Merged_graph.append(r)
652
653 for l in Merged_graph:
654 tmp_graph_list = []
655 for idx in l:
656 if idx >= connection_map.shape[0]:
657 tmp_graph_list.append(graph_list[idx - connection_map.shape[0]])
658 else:
659 tmp_graph_list.append(graph_cache[idx].graph)
660 G = nx.compose_all(tmp_graph_list)
661
662 G = self.graph_taylor(G)
663
664 # assert(nx.is_weakly_connected(G))
665 G.graph['score'] = np.sum([self.nodes[node]['score'] for node in G.nodes])

Callers 1

update_cacheMethod · 0.95

Calls 3

GetSubsetMethod · 0.95
graph_taylorMethod · 0.95
CacheGraphClass · 0.90

Tested by

no test coverage detected