本文整理汇总了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')