本文整理汇总了Python中networkx.OrderedDiGraph方法的典型用法代码示例。如果您正苦于以下问题:Python networkx.OrderedDiGraph方法的具体用法?Python networkx.OrderedDiGraph怎么用?Python networkx.OrderedDiGraph使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类networkx
的用法示例。
在下文中一共展示了networkx.OrderedDiGraph方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_write_p2g
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import OrderedDiGraph [as 别名]
def test_write_p2g(self):
s = b"""foo
3 2
1
1
2
2
3
"""
fh = io.BytesIO()
G = nx.OrderedDiGraph()
G.name = 'foo'
G.add_edges_from([(1, 2), (2, 3)])
write_p2g(G, fh)
fh.seek(0)
r = fh.read()
assert_equal(r, s)
示例2: test_write_p2g
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import OrderedDiGraph [as 别名]
def test_write_p2g(self):
s=b"""foo
3 2
1
1
2
2
3
"""
fh=io.BytesIO()
G=nx.OrderedDiGraph()
G.name='foo'
G.add_edges_from([(1,2),(2,3)])
write_p2g(G,fh)
fh.seek(0)
r=fh.read()
assert_equal(r,s)
示例3: test_differential_operator
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import OrderedDiGraph [as 别名]
def test_differential_operator(self, n_vertices=98):
r"""The Laplacian must always be the divergence of the gradient,
whether the Laplacian is combinatorial or normalized, and whether the
graph is directed or weighted."""
def test_incidence_nx(graph):
r"""Test that the incidence matrix corresponds to NetworkX."""
incidence_pg = np.sign(graph.D.toarray())
G = nx.OrderedDiGraph if graph.is_directed() else nx.OrderedGraph
graph_nx = nx.from_scipy_sparse_matrix(graph.W, create_using=G)
incidence_nx = nx.incidence_matrix(graph_nx, oriented=True)
np.testing.assert_equal(incidence_pg, incidence_nx.toarray())
for graph in [graphs.Graph(np.zeros((n_vertices, n_vertices))),
graphs.Graph(np.identity(n_vertices)),
graphs.Graph([[0, 0.8], [0.8, 0]]),
graphs.Graph([[1.3, 0], [0.4, 0.5]]),
graphs.ErdosRenyi(n_vertices, directed=False, seed=42),
graphs.ErdosRenyi(n_vertices, directed=True, seed=42)]:
for lap_type in ['combinatorial', 'normalized']:
graph.compute_laplacian(lap_type)
graph.compute_differential_operator()
L = graph.D.dot(graph.D.T)
np.testing.assert_allclose(L.toarray(), graph.L.toarray())
test_incidence_nx(graph)
示例4: graph
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import OrderedDiGraph [as 别名]
def graph(self):
if self._graph:
return self._graph
g = networkx.OrderedDiGraph()
for task in self.tasks.values():
g.add_node(task)
for dep in task.depends_on():
g.add_edge(task, dep)
self._graph = g
return self.graph
示例5: test_digraph
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import OrderedDiGraph [as 别名]
def test_digraph():
G = nx.OrderedDiGraph()
示例6: test_attribute_dict_integrity
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import OrderedDiGraph [as 别名]
def test_attribute_dict_integrity(self):
# we must not replace dict-like graph data structures with dicts
G = nx.OrderedGraph()
G.add_nodes_from("abc")
H = to_networkx_graph(G, create_using=nx.OrderedGraph)
assert_equal(list(H.nodes), list(G.nodes))
H = nx.OrderedDiGraph(G)
assert_equal(list(H.nodes), list(G.nodes))
示例7: test_digraph
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import OrderedDiGraph [as 别名]
def test_digraph(self):
G = nx.OrderedDiGraph()
示例8: setUp
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import OrderedDiGraph [as 别名]
def setUp(self):
self.G = nx.OrderedDiGraph()
self.G.add_nodes_from([1, 2, 3])
self.G.add_edges_from([(2, 3), (1, 3)])
示例9: test_attribute_dict_integrity
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import OrderedDiGraph [as 别名]
def test_attribute_dict_integrity(self):
# we must not replace dict-like graph data structures with dicts
G = nx.OrderedGraph()
G.add_nodes_from("abc")
H = to_networkx_graph(G, create_using=nx.OrderedGraph())
assert_equal(list(H.nodes), list(G.nodes))
H = nx.OrderedDiGraph(G)
assert_equal(list(H.nodes), list(G.nodes))