graph.py 文件源码

python
阅读 34 收藏 0 点赞 0 评论 0

项目:cppdep 作者: rakhimov 项目源码 文件源码
def __condensation(self):
        """Produces condensation of cyclic graphs."""
        subgraphs = nx.strongly_connected_component_subgraphs(self.digraph)
        for subgraph in list(subgraphs):
            if subgraph.number_of_nodes() == 1:
                continue  # not a cycle
            pre_edges = []
            suc_edges = []
            for node in subgraph:
                assert node not in self.node2cycle
                assert node in self.digraph  # no accidental copying
                self.node2cycle[node] = subgraph
                for pre_node in self.digraph.predecessors(node):
                    if not subgraph.has_node(pre_node):
                        pre_edges.append((pre_node, node))
                        self.digraph.add_edge(pre_node, subgraph)
                for suc_node in self.digraph.successors(node):
                    if not subgraph.has_node(suc_node):
                        suc_edges.append((node, suc_node))
                        self.digraph.add_edge(subgraph, suc_node)
                self.digraph.remove_node(node)
            assert subgraph not in self.cycles
            self.cycles[subgraph] = (pre_edges, suc_edges)

        cycle_order = lambda x: min(str(u) for u in x)
        for index, cycle in enumerate(sorted(self.cycles, key=cycle_order)):
            self.cycle2index[cycle] = index

    # pylint: disable=invalid-name
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号