本文整理汇总了Python中networkx.classes.digraph.DiGraph.nodes_iter方法的典型用法代码示例。如果您正苦于以下问题:Python DiGraph.nodes_iter方法的具体用法?Python DiGraph.nodes_iter怎么用?Python DiGraph.nodes_iter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类networkx.classes.digraph.DiGraph
的用法示例。
在下文中一共展示了DiGraph.nodes_iter方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DuoBA_from_ltls
# 需要导入模块: from networkx.classes.digraph import DiGraph [as 别名]
# 或者: from networkx.classes.digraph.DiGraph import nodes_iter [as 别名]
def DuoBA_from_ltls(hard_spec, soft_spec):
hard_buchi = buchi_from_ltl(hard_spec, 'hard_buchi')
soft_buchi = buchi_from_ltl(soft_spec, 'soft_buchi')
hard_symbols = hard_buchi.graph['symbols']
soft_symbols = soft_buchi.graph['symbols']
symbols = set(hard_symbols).union(set(soft_symbols))
DuoBA = DiGraph(type='safe_buchi', hard=hard_buchi, soft=soft_buchi, symols=symbols)
initial = set()
accept = set()
for (h_node, s_node, l) in cartesian_product(hard_buchi.nodes(), soft_buchi.nodes(), [1, 2]):
DuoNode = (h_node, s_node, l)
DuoBA.add_node(DuoNode,hard=h_node, soft=s_node, level=l)
if (h_node in hard_buchi.graph['initial'] and
s_node in soft_buchi.graph['initial'] and l == 1):
initial.add(DuoNode)
if (h_node in hard_buchi.graph['accept'] and l == 1):
accept.add(DuoNode)
DuoBA.graph['accept'] = accept
DuoBA.graph['initial'] = initial
for f_duonode in DuoBA.nodes_iter():
for t_duonode in DuoBA.nodes_iter():
f_h_node, f_s_node, f_level = check_duo_attr(DuoBA, f_duonode)
t_h_node, t_s_node, t_level = check_duo_attr(DuoBA, t_duonode)
if (t_h_node not in DuoBA.graph['hard'].neighbors(f_h_node) or
t_s_node not in DuoBA.graph['soft'].neighbors(f_s_node)):
continue
# relaxed because no common input alphabets are enabled
hardguard = DuoBA.graph['hard'].edge[f_h_node][t_h_node]['guard']
softguard = DuoBA.graph['soft'].edge[f_s_node][t_s_node]['guard']
if ((f_h_node not in DuoBA.graph['hard'].graph['accept'] and
f_level == 1 and t_level == 1) or
(f_h_node in DuoBA.graph['hard'].graph['accept'] and
f_level == 1 and t_level == 2) or
(f_s_node not in DuoBA.graph['soft'].graph['accept'] and
f_level == 2 and t_level == 2) or
(f_s_node in DuoBA.graph['soft'].graph['accept'] and
f_level == 2 and t_level == 1)):
DuoBA.add_edge(f_duonode, t_duonode, hardguard=hardguard, softguard=softguard)
return DuoBA
示例2: get_variance_example_1
# 需要导入模块: from networkx.classes.digraph import DiGraph [as 别名]
# 或者: from networkx.classes.digraph.DiGraph import nodes_iter [as 别名]
def get_variance_example_1():
g = DiGraph()
g.add_edges_from([
(0, 1), (0, 2),
(2, 3), (3, 4),
(2, 'dummy'),
('dummy', 5)
])
g.node['dummy']['dummy'] = True
for n in (0, 1, 2, 5): # topic 1
g.node[n]['repr'] = np.array([0, 0])
for n in (3, 4): # topic 2
g.node[n]['repr'] = np.array([1, 1])
for n in g.nodes_iter():
g.node[n]['r'] = 1
# correct is (0, 1, 2, 5) for cost 0
U = [0, 42]
expected_edge_set = [
set(g.edges()) - {(2, 3), (3, 4)},
set(g.edges())
]
return (g, U, expected_edge_set)