当前位置: 首页>>代码示例>>Python>>正文


Python Graph.topological_sorting方法代码示例

本文整理汇总了Python中igraph.Graph.topological_sorting方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.topological_sorting方法的具体用法?Python Graph.topological_sorting怎么用?Python Graph.topological_sorting使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在igraph.Graph的用法示例。


在下文中一共展示了Graph.topological_sorting方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: DAGApp

# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import topological_sorting [as 别名]

#.........这里部分代码省略.........
        return self._kernels[kernel_idx]

    def _prep_baseline(self):
        self._depth_sorted = [[v_.index
                               for v_ in self._g.vs.select(depth_eq=d_)]
                              for d_ in range(1, self._max_depth + 1)]
        finish_time = dict.fromkeys(self._g.vs.indices, 0)
        for l, node_list in enumerate(self._depth_sorted):
            if l == 0:
                for node in node_list:
                    finish_time[node] = self._length[node]
            else:
                for node in node_list:
                    start = max([finish_time[n_] for n_ in
                                 self._g.neighbors(node,
                                                   mode=GRAPH_IN)])
                    finish_time[node] = start + self._length[node]
        self._baseline_runtime = max(finish_time.values())

    def get_kernel_depth(self, kernel_idx):
        return self._g.vs[kernel_idx]['depth']

    def get_all_kernel_depth(self):
        return self._g.vs['depth']

    def kernels_topo_sort(self):
        """sort kernels in a topological order.

        Returns
        -------
        list
          kernel indexes in a topological sort order
        """
        return self._g.topological_sorting()

    def get_precedent_kernel(self, kernel_idx):
        """Get the precedent (pre-requisite) kernels.

        Returns
        -------
        list
          A list of kernel indexes that precedent the given kernel. None
          if no precedent kernels exist, e.g. the starting kernel.
        """
        return self._g.neighbors(kernel_idx, mode=GRAPH_IN)

    def kernels_depth_sort(self):
        """sort kernels by their depth.

        Returns
        -------
        list
          kernel indexes grouped by its depth in the DAG. An example output looks
          like::

            [
               [0,1],   # depth == 0
               [2,3,4], # depth == 1
               [5,6],   # depth == 2
            ]
        """
        try:
            return self._depth_sorted
        except AttributeError:
            raise AppError('App not initiliazed properly')
开发者ID:liangwang,项目名称:lumos,代码行数:69,代码来源:application.py


注:本文中的igraph.Graph.topological_sorting方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。