本文整理匯總了Python中networkx.petersen_graph方法的典型用法代碼示例。如果您正苦於以下問題:Python networkx.petersen_graph方法的具體用法?Python networkx.petersen_graph怎麽用?Python networkx.petersen_graph使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類networkx
的用法示例。
在下文中一共展示了networkx.petersen_graph方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_petersen_cutset
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import petersen_graph [as 別名]
def test_petersen_cutset():
G = nx.petersen_graph()
for flow_func in flow_funcs:
kwargs = dict(flow_func=flow_func)
# edge cuts
edge_cut = nx.minimum_edge_cut(G, **kwargs)
assert_equal(3, len(edge_cut), msg=msg.format(flow_func.__name__))
H = G.copy()
H.remove_edges_from(edge_cut)
assert_false(nx.is_connected(H), msg=msg.format(flow_func.__name__))
# node cuts
node_cut = nx.minimum_node_cut(G, **kwargs)
assert_equal(3, len(node_cut), msg=msg.format(flow_func.__name__))
H = G.copy()
H.remove_nodes_from(node_cut)
assert_false(nx.is_connected(H), msg=msg.format(flow_func.__name__))
示例2: test_petersen
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import petersen_graph [as 別名]
def test_petersen(self):
"""Check boundaries in the petersen graph
cheeger(G,k)=min(|bdy(S)|/|S| for |S|=k, 0<k<=|V(G)|/2)
"""
from itertools import combinations
P=nx.petersen_graph()
def cheeger(G,k):
return min( float(len(nx.node_boundary(G,nn)))/k
for nn in combinations(G,k) )
assert_almost_equals(cheeger(P,1),3.00,places=2)
assert_almost_equals(cheeger(P,2),2.00,places=2)
assert_almost_equals(cheeger(P,3),1.67,places=2)
assert_almost_equals(cheeger(P,4),1.00,places=2)
assert_almost_equals(cheeger(P,5),0.80,places=2)
示例3: test_petersen
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import petersen_graph [as 別名]
def test_petersen(self):
"""Check boundaries in the petersen graph
cheeger(G,k)=min(|bdy(S)|/|S| for |S|=k, 0<k<=|V(G)|/2)
"""
def cheeger(G, k):
return min(len(nx.node_boundary(G, nn)) / k
for nn in combinations(G, k))
P = nx.petersen_graph()
assert_almost_equals(cheeger(P, 1), 3.00, places=2)
assert_almost_equals(cheeger(P, 2), 2.00, places=2)
assert_almost_equals(cheeger(P, 3), 1.67, places=2)
assert_almost_equals(cheeger(P, 4), 1.00, places=2)
assert_almost_equals(cheeger(P, 5), 0.80, places=2)
示例4: test_is_eulerian
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import petersen_graph [as 別名]
def test_is_eulerian(self):
assert_true(is_eulerian(nx.complete_graph(5)))
assert_true(is_eulerian(nx.complete_graph(7)))
assert_true(is_eulerian(nx.hypercube_graph(4)))
assert_true(is_eulerian(nx.hypercube_graph(6)))
assert_false(is_eulerian(nx.complete_graph(4)))
assert_false(is_eulerian(nx.complete_graph(6)))
assert_false(is_eulerian(nx.hypercube_graph(3)))
assert_false(is_eulerian(nx.hypercube_graph(5)))
assert_false(is_eulerian(nx.petersen_graph()))
assert_false(is_eulerian(nx.path_graph(4)))
示例5: main
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import petersen_graph [as 別名]
def main():
# create a problem instance with petersen graph:
gcp = GraphColoringProblem(nx.petersen_graph(), 10)
# generate a random solution with up to 5 different colors:
solution = np.random.randint(5, size=len(gcp))
print("solution = ", solution)
print("number of colors = ", gcp.getNumberOfColors(solution))
print("Number of violations = ", gcp.getViolationsCount(solution))
print("Cost = ", gcp.getCost(solution))
plot = gcp.plotGraph(solution)
plot.show()
示例6: graphviz_layout
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import petersen_graph [as 別名]
def graphviz_layout(G,prog='neato',root=None, args=''):
"""Create node positions for G using Graphviz.
Parameters
----------
G : NetworkX graph
A graph created with NetworkX
prog : string
Name of Graphviz layout program
root : string, optional
Root node for twopi layout
args : string, optional
Extra arguments to Graphviz layout program
Returns : dictionary
Dictionary of x,y, positions keyed by node.
Examples
--------
>>> G = nx.petersen_graph()
>>> pos = nx.nx_agraph.graphviz_layout(G)
>>> pos = nx.nx_agraph.graphviz_layout(G, prog='dot')
Notes
-----
This is a wrapper for pygraphviz_layout.
"""
return pygraphviz_layout(G,prog=prog,root=root,args=args)
示例7: test_tensor_product_classic_result
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import petersen_graph [as 別名]
def test_tensor_product_classic_result():
K2 = nx.complete_graph(2)
G = nx.petersen_graph()
G = tensor_product(G, K2)
assert_true(nx.is_isomorphic(G, nx.desargues_graph()))
G = nx.cycle_graph(5)
G = tensor_product(G, K2)
assert_true(nx.is_isomorphic(G, nx.cycle_graph(10)))
G = nx.tetrahedral_graph()
G = tensor_product(G, K2)
assert_true(nx.is_isomorphic(G, nx.cubical_graph()))
示例8: graph_example_1
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import petersen_graph [as 別名]
def graph_example_1():
G = nx.convert_node_labels_to_integers(nx.grid_graph([5,5]),
label_attribute='labels')
rlabels = nx.get_node_attributes(G, 'labels')
labels = dict((v, k) for k, v in rlabels.items())
for nodes in [(labels[(0,0)], labels[(1,0)]),
(labels[(0,4)], labels[(1,4)]),
(labels[(3,0)], labels[(4,0)]),
(labels[(3,4)], labels[(4,4)]) ]:
new_node = G.order()+1
# Petersen graph is triconnected
P = nx.petersen_graph()
G = nx.disjoint_union(G,P)
# Add two edges between the grid and P
G.add_edge(new_node+1, nodes[0])
G.add_edge(new_node, nodes[1])
# K5 is 4-connected
K = nx.complete_graph(5)
G = nx.disjoint_union(G,K)
# Add three edges between P and K5
G.add_edge(new_node+2,new_node+11)
G.add_edge(new_node+3,new_node+12)
G.add_edge(new_node+4,new_node+13)
# Add another K5 sharing a node
G = nx.disjoint_union(G,K)
nbrs = G[new_node+10]
G.remove_node(new_node+10)
for nbr in nbrs:
G.add_edge(new_node+17, nbr)
G.add_edge(new_node+16, new_node+5)
G.name = 'Example graph for connectivity'
return G
示例9: test_petersen
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import petersen_graph [as 別名]
def test_petersen():
G = nx.petersen_graph()
assert_equal(3, approx.node_connectivity(G))
assert_equal(3, approx.node_connectivity(G, 0, 5))
# Approximation fails with tutte graph
#def test_tutte():
# G = nx.tutte_graph()
# assert_equal(3, approx.node_connectivity(G))
示例10: test_petersen
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import petersen_graph [as 別名]
def test_petersen():
# Actual coefficient is 0
G = nx.petersen_graph()
assert_equal(average_clustering(G, trials=int(len(G)/2)),
nx.average_clustering(G))
示例11: graphviz_layout
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import petersen_graph [as 別名]
def graphviz_layout(G, prog='neato', root=None, args=''):
"""Create node positions for G using Graphviz.
Parameters
----------
G : NetworkX graph
A graph created with NetworkX
prog : string
Name of Graphviz layout program
root : string, optional
Root node for twopi layout
args : string, optional
Extra arguments to Graphviz layout program
Returns
-------
Dictionary of x, y, positions keyed by node.
Examples
--------
>>> G = nx.petersen_graph()
>>> pos = nx.nx_agraph.graphviz_layout(G)
>>> pos = nx.nx_agraph.graphviz_layout(G, prog='dot')
Notes
-----
This is a wrapper for pygraphviz_layout.
"""
return pygraphviz_layout(G, prog=prog, root=root, args=args)
示例12: test_tensor_product_classic_result
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import petersen_graph [as 別名]
def test_tensor_product_classic_result():
K2 = nx.complete_graph(2)
G = nx.petersen_graph()
G = nx.tensor_product(G, K2)
assert_true(nx.is_isomorphic(G, nx.desargues_graph()))
G = nx.cycle_graph(5)
G = nx.tensor_product(G, K2)
assert_true(nx.is_isomorphic(G, nx.cycle_graph(10)))
G = nx.tetrahedral_graph()
G = nx.tensor_product(G, K2)
assert_true(nx.is_isomorphic(G, nx.cubical_graph()))
示例13: graph_example_1
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import petersen_graph [as 別名]
def graph_example_1():
G = nx.convert_node_labels_to_integers(nx.grid_graph([5, 5]),
label_attribute='labels')
rlabels = nx.get_node_attributes(G, 'labels')
labels = {v: k for k, v in rlabels.items()}
for nodes in [(labels[(0, 0)], labels[(1, 0)]),
(labels[(0, 4)], labels[(1, 4)]),
(labels[(3, 0)], labels[(4, 0)]),
(labels[(3, 4)], labels[(4, 4)])]:
new_node = G.order() + 1
# Petersen graph is triconnected
P = nx.petersen_graph()
G = nx.disjoint_union(G, P)
# Add two edges between the grid and P
G.add_edge(new_node + 1, nodes[0])
G.add_edge(new_node, nodes[1])
# K5 is 4-connected
K = nx.complete_graph(5)
G = nx.disjoint_union(G, K)
# Add three edges between P and K5
G.add_edge(new_node + 2, new_node + 11)
G.add_edge(new_node + 3, new_node + 12)
G.add_edge(new_node + 4, new_node + 13)
# Add another K5 sharing a node
G = nx.disjoint_union(G, K)
nbrs = G[new_node + 10]
G.remove_node(new_node + 10)
for nbr in nbrs:
G.add_edge(new_node + 17, nbr)
G.add_edge(new_node + 16, new_node + 5)
return G
示例14: test_petersen_disjoint_paths
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import petersen_graph [as 別名]
def test_petersen_disjoint_paths():
G = nx.petersen_graph()
for flow_func in flow_funcs:
kwargs = dict(flow_func=flow_func)
# edge disjoint paths
edge_dpaths = list(nx.edge_disjoint_paths(G, 0, 6, **kwargs))
assert_true(are_edge_disjoint_paths(G, edge_dpaths), msg=msg.format(flow_func.__name__))
assert_equal(3, len(edge_dpaths), msg=msg.format(flow_func.__name__))
# node disjoint paths
node_dpaths = list(nx.node_disjoint_paths(G, 0, 6, **kwargs))
assert_true(are_node_disjoint_paths(G, node_dpaths), msg=msg.format(flow_func.__name__))
assert_equal(3, len(node_dpaths), msg=msg.format(flow_func.__name__))
示例15: test_petersen
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import petersen_graph [as 別名]
def test_petersen():
G = nx.petersen_graph()
for flow_func in flow_funcs:
assert_equal(3, nx.node_connectivity(G, flow_func=flow_func),
msg=msg.format(flow_func.__name__))
assert_equal(3, nx.edge_connectivity(G, flow_func=flow_func),
msg=msg.format(flow_func.__name__))