graph.py 文件源码

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

项目:PyGraphArt 作者: dnlcrl 项目源码 文件源码
def topological_sort(self):
        '''
        Returns a list topological sorted nodes
        '''
        if self.is_cyclic(self.FSs):
            print 'cannot apply labels, graph contains cycles'
            return
        big_l = []  # Empty list that will contain the sorted elements
        # Set of all nodes with no incoming edges
        big_s = set([0])
        bs_copy = self.BSs.copy()
        while len(big_s) > 0:
            n = big_s.pop()
            big_l.append(n)
            for m in self.FSs[n]:
                bs_copy[m] = np.delete(bs_copy[m], np.where(bs_copy[m] == n))
                # bs_copy[m].remove(n)
                if len(bs_copy[m]) == 0:
                    big_s.add(int(m))
        return big_l
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号