本文整理匯總了Python中networkx.line_graph方法的典型用法代碼示例。如果您正苦於以下問題:Python networkx.line_graph方法的具體用法?Python networkx.line_graph怎麽用?Python networkx.line_graph使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類networkx
的用法示例。
在下文中一共展示了networkx.line_graph方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _create_line_graph
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import line_graph [as 別名]
def _create_line_graph(self, graph):
r"""Getting the embedding of graphs.
Arg types:
* **graph** *(NetworkX graph)* - The graph transformed to be a line graph.
Return types:
* **line_graph** *(NetworkX graph)* - The line graph of the source graph.
"""
graph = nx.line_graph(graph)
node_mapper = {node: i for i, node in enumerate(graph.nodes())}
edges = [[node_mapper[edge[0]], node_mapper[edge[1]]] for edge in graph.edges()]
line_graph = nx.from_edgelist(edges)
return line_graph
示例2: test_star
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import line_graph [as 別名]
def test_star(self):
G = nx.star_graph(5)
L = nx.line_graph(G)
assert_true(nx.is_isomorphic(L, nx.complete_graph(5)))
示例3: test_path
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import line_graph [as 別名]
def test_path(self):
G = nx.path_graph(5)
L = nx.line_graph(G)
assert_true(nx.is_isomorphic(L, nx.path_graph(4)))
示例4: test_cycle
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import line_graph [as 別名]
def test_cycle(self):
G = nx.cycle_graph(5)
L = nx.line_graph(G)
assert_true(nx.is_isomorphic(L, G))
示例5: test_digraph1
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import line_graph [as 別名]
def test_digraph1(self):
G = nx.DiGraph()
G.add_edges_from([(0,1),(0,2),(0,3)])
L = nx.line_graph(G)
# no edge graph, but with nodes
assert_equal(L.adj, {(0,1):{}, (0,2):{}, (0,3):{}})
示例6: test_digraph2
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import line_graph [as 別名]
def test_digraph2(self):
G = nx.DiGraph()
G.add_edges_from([(0,1),(1,2),(2,3)])
L = nx.line_graph(G)
assert_equal(sorted(L.edges()), [((0, 1), (1, 2)), ((1, 2), (2, 3))])
示例7: test_create2
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import line_graph [as 別名]
def test_create2(self):
G = nx.Graph()
G.add_edges_from([(0,1),(1,2),(2,3)])
L = nx.line_graph(G, create_using=nx.DiGraph())
assert_equal(sorted(L.edges()), [((0, 1), (1, 2)), ((1, 2), (2, 3))])
示例8: test_digraph1
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import line_graph [as 別名]
def test_digraph1(self):
G = nx.DiGraph()
G.add_edges_from([(0, 1), (0, 2), (0, 3)])
L = nx.line_graph(G)
# no edge graph, but with nodes
assert_equal(L.adj, {(0, 1): {}, (0, 2): {}, (0, 3): {}})
示例9: test_digraph2
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import line_graph [as 別名]
def test_digraph2(self):
G = nx.DiGraph()
G.add_edges_from([(0, 1), (1, 2), (2, 3)])
L = nx.line_graph(G)
assert_edges_equal(L.edges(), [((0, 1), (1, 2)), ((1, 2), (2, 3))])
示例10: test_create2
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import line_graph [as 別名]
def test_create2(self):
G = nx.Graph()
G.add_edges_from([(0, 1), (1, 2), (2, 3)])
L = nx.line_graph(G, create_using=nx.DiGraph())
assert_edges_equal(L.edges(), [((0, 1), (1, 2)), ((1, 2), (2, 3))])
示例11: test_line_inverse_line_complete
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import line_graph [as 別名]
def test_line_inverse_line_complete(self):
G = nx.complete_graph(10)
H = nx.line_graph(G)
J = nx.inverse_line_graph(H)
assert_true(nx.is_isomorphic(G, J))
示例12: test_line_inverse_line_path
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import line_graph [as 別名]
def test_line_inverse_line_path(self):
G = nx.path_graph(10)
H = nx.line_graph(G)
J = nx.inverse_line_graph(H)
assert_true(nx.is_isomorphic(G, J))
示例13: test_line_inverse_line_hypercube
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import line_graph [as 別名]
def test_line_inverse_line_hypercube(self):
G = nx.hypercube_graph(5)
H = nx.line_graph(G)
J = nx.inverse_line_graph(H)
assert_true(nx.is_isomorphic(G, J))
示例14: test_line_inverse_line_cycle
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import line_graph [as 別名]
def test_line_inverse_line_cycle(self):
G = nx.cycle_graph(10)
H = nx.line_graph(G)
J = nx.inverse_line_graph(H)
assert_true(nx.is_isomorphic(G, J))
示例15: test_line_inverse_line_multipartite
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import line_graph [as 別名]
def test_line_inverse_line_multipartite(self):
G = nx.complete_multipartite_graph(3, 4, 5)
H = nx.line_graph(G)
J = nx.inverse_line_graph(H)
assert_true(nx.is_isomorphic(G, J))