本文整理汇总了Python中networkx.DiGraph.__len__方法的典型用法代码示例。如果您正苦于以下问题:Python DiGraph.__len__方法的具体用法?Python DiGraph.__len__怎么用?Python DiGraph.__len__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类networkx.DiGraph
的用法示例。
在下文中一共展示了DiGraph.__len__方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PipelineFramework
# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import __len__ [as 别名]
class PipelineFramework(object):
"""A PipelineFramework is a set Tasks that may have data dependencies."""
def __init__(self, tasks_reqs):
"""Construct a PipelineFramework based on the given Tasks and their requirements.
A PipelineFramework is the structure of the pipeline, it contains no patient data.
:param tasks_reqs: the Tasks and their requirements
:type tasks_reqs: iterable of tuples, each with a Task and its list of required UIDs
:raises: ValueError
"""
self.dag = DiGraph()
task_dict = {}
for task, _ in tasks_reqs:
if task_dict.get(task._uid) is not None:
raise ValueError("Pipeline contains duplicate Task {}".format(task._uid))
self.dag.add_node(task, done=False)
task_dict[task._uid] = task
for task, reqs in tasks_reqs:
for req_uid in reqs:
uid = task_dict.get(req_uid)
if uid is None:
raise KeyError("Unknown UID {} set as requirement for {}".format(req_uid, task._uid))
self.dag.add_edge(uid, task)
if not is_directed_acyclic_graph(self.dag):
raise ValueError("Pipeline contains a cycle.")
def __len__(self):
"""Determine the length of the Pipeline.
:returns: the number of Tasks in this Pipeline
:rtype: {int}
"""
return self.dag.__len__()