本文整理汇总了Python中networkx.freeze方法的典型用法代码示例。如果您正苦于以下问题:Python networkx.freeze方法的具体用法?Python networkx.freeze怎么用?Python networkx.freeze使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类networkx
的用法示例。
在下文中一共展示了networkx.freeze方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: is_frozen
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import freeze [as 别名]
def is_frozen(G):
"""Return True if graph is frozen.
Parameters
----------
G : graph
A NetworkX graph
See Also
--------
freeze
"""
try:
return G.frozen
except AttributeError:
return False
示例2: subgraph_view
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import freeze [as 别名]
def subgraph_view(G, filter_node=no_filter, filter_edge=no_filter):
newG = nx.freeze(G.__class__())
newG._NODE_OK = filter_node
newG._EDGE_OK = filter_edge
# create view by assigning attributes from G
newG._graph = G
newG.graph = G.graph
newG._node = FilterAtlas(G._node, filter_node)
if G.is_multigraph():
Adj = FilterMultiAdjacency
def reverse_edge(u, v, k): return filter_edge(v, u, k)
else:
Adj = FilterAdjacency
def reverse_edge(u, v): return filter_edge(v, u)
if G.is_directed():
newG._succ = Adj(G._succ, filter_node, filter_edge)
newG._pred = Adj(G._pred, filter_node, reverse_edge)
newG._adj = newG._succ
else:
newG._adj = Adj(G._adj, filter_node, filter_edge)
return newG
示例3: is_frozen
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import freeze [as 别名]
def is_frozen(G):
"""Returns True if graph is frozen.
Parameters
----------
G : graph
A NetworkX graph
See Also
--------
freeze
"""
try:
return G.frozen
except AttributeError:
return False
示例4: freeze
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import freeze [as 别名]
def freeze(self):
"""Freezes the graph so that no more mutations can occur."""
if not self.frozen:
nx.freeze(self)
return self
示例5: setUp
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import freeze [as 别名]
def setUp(self):
G=nx.Graph(name="test")
e=[('a','b'),('b','c'),('c','d'),('d','e'),('e','f'),('a','f')]
G.add_edges_from(e,width=10)
G.add_node('g',color='green')
G.graph['number']=1
DG=nx.DiGraph(G)
MG=nx.MultiGraph(G)
MG.add_edge('a', 'a')
MDG=nx.MultiDiGraph(G)
MDG.add_edge('a', 'a')
fG = G.copy()
fDG = DG.copy()
fMG = MG.copy()
fMDG = MDG.copy()
nx.freeze(fG)
nx.freeze(fDG)
nx.freeze(fMG)
nx.freeze(fMDG)
self.G=G
self.DG=DG
self.MG=MG
self.MDG=MDG
self.fG=fG
self.fDG=fDG
self.fMG=fMG
self.fMDG=fMDG
示例6: test_freeze
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import freeze [as 别名]
def test_freeze(self):
G=nx.freeze(self.G)
assert_equal(G.frozen,True)
assert_raises(nx.NetworkXError, G.add_node, 1)
assert_raises(nx.NetworkXError, G.add_nodes_from, [1])
assert_raises(nx.NetworkXError, G.remove_node, 1)
assert_raises(nx.NetworkXError, G.remove_nodes_from, [1])
assert_raises(nx.NetworkXError, G.add_edge, 1,2)
assert_raises(nx.NetworkXError, G.add_edges_from, [(1,2)])
assert_raises(nx.NetworkXError, G.remove_edge, 1,2)
assert_raises(nx.NetworkXError, G.remove_edges_from, [(1,2)])
assert_raises(nx.NetworkXError, G.clear)
示例7: test_is_frozen
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import freeze [as 别名]
def test_is_frozen(self):
assert_equal(nx.is_frozen(self.G), False)
G=nx.freeze(self.G)
assert_equal(G.frozen, nx.is_frozen(self.G))
assert_equal(G.frozen,True)
示例8: freeze
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import freeze [as 别名]
def freeze(self):
nx.freeze(self)
示例9: setUp
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import freeze [as 别名]
def setUp(self):
G = nx.Graph(name="test")
e = [('a', 'b'), ('b', 'c'), ('c', 'd'), ('d', 'e'), ('e', 'f'), ('a', 'f')]
G.add_edges_from(e, width=10)
G.add_node('g', color='green')
G.graph['number'] = 1
DG = nx.DiGraph(G)
MG = nx.MultiGraph(G)
MG.add_edge('a', 'a')
MDG = nx.MultiDiGraph(G)
MDG.add_edge('a', 'a')
fG = G.copy()
fDG = DG.copy()
fMG = MG.copy()
fMDG = MDG.copy()
nx.freeze(fG)
nx.freeze(fDG)
nx.freeze(fMG)
nx.freeze(fMDG)
self.G = G
self.DG = DG
self.MG = MG
self.MDG = MDG
self.fG = fG
self.fDG = fDG
self.fMG = fMG
self.fMDG = fMDG
示例10: generic_graph_view
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import freeze [as 别名]
def generic_graph_view(G, create_using=None):
if create_using is None:
newG = G.__class__()
else:
newG = nx.empty_graph(0, create_using)
if G.is_multigraph() != newG.is_multigraph():
raise NetworkXError("Multigraph for G must agree with create_using")
newG = nx.freeze(newG)
# create view by assigning attributes from G
newG._graph = G
newG.graph = G.graph
newG._node = G._node
if newG.is_directed():
if G.is_directed():
newG._succ = G._succ
newG._pred = G._pred
newG._adj = G._succ
else:
newG._succ = G._adj
newG._pred = G._adj
newG._adj = G._adj
elif G.is_directed():
if G.is_multigraph():
newG._adj = UnionMultiAdjacency(G._succ, G._pred)
else:
newG._adj = UnionAdjacency(G._succ, G._pred)
else:
newG._adj = G._adj
return newG
示例11: test_is_frozen
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import freeze [as 别名]
def test_is_frozen(self):
assert_equal(nx.is_frozen(self.G), False)
G = nx.freeze(self.G)
assert_equal(G.frozen, nx.is_frozen(self.G))
assert_equal(G.frozen, True)
示例12: test_freeze
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import freeze [as 别名]
def test_freeze(self):
G = nx.freeze(self.G)
assert_equal(G.frozen, True)
assert_raises(nx.NetworkXError, G.add_node, 1)
assert_raises(nx.NetworkXError, G.add_nodes_from, [1])
assert_raises(nx.NetworkXError, G.remove_node, 1)
assert_raises(nx.NetworkXError, G.remove_nodes_from, [1])
assert_raises(nx.NetworkXError, G.add_edge, 1, 2)
assert_raises(nx.NetworkXError, G.add_edges_from, [(1, 2)])
assert_raises(nx.NetworkXError, G.remove_edge, 1, 2)
assert_raises(nx.NetworkXError, G.remove_edges_from, [(1, 2)])
assert_raises(nx.NetworkXError, G.clear)
示例13: freeze
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import freeze [as 别名]
def freeze(G):
"""Modify graph to prevent further change by adding or removing
nodes or edges.
Node and edge data can still be modified.
Parameters
----------
G : graph
A NetworkX graph
Examples
--------
>>> G=nx.Graph()
>>> G.add_path([0,1,2,3])
>>> G=nx.freeze(G)
>>> try:
... G.add_edge(4,5)
... except nx.NetworkXError as e:
... print(str(e))
Frozen graph can't be modified
Notes
-----
To "unfreeze" a graph you must make a copy by creating a new graph object:
>>> graph = nx.path_graph(4)
>>> frozen_graph = nx.freeze(graph)
>>> unfrozen_graph = nx.Graph(frozen_graph)
>>> nx.is_frozen(unfrozen_graph)
False
See Also
--------
is_frozen
"""
G.add_node=frozen
G.add_nodes_from=frozen
G.remove_node=frozen
G.remove_nodes_from=frozen
G.add_edge=frozen
G.add_edges_from=frozen
G.remove_edge=frozen
G.remove_edges_from=frozen
G.clear=frozen
G.frozen=True
return G
示例14: freeze
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import freeze [as 别名]
def freeze(G):
"""Modify graph to prevent further change by adding or removing
nodes or edges.
Node and edge data can still be modified.
Parameters
----------
G : graph
A NetworkX graph
Examples
--------
>>> G = nx.path_graph(4)
>>> G = nx.freeze(G)
>>> try:
... G.add_edge(4, 5)
... except nx.NetworkXError as e:
... print(str(e))
Frozen graph can't be modified
Notes
-----
To "unfreeze" a graph you must make a copy by creating a new graph object:
>>> graph = nx.path_graph(4)
>>> frozen_graph = nx.freeze(graph)
>>> unfrozen_graph = nx.Graph(frozen_graph)
>>> nx.is_frozen(unfrozen_graph)
False
See Also
--------
is_frozen
"""
G.add_node = frozen
G.add_nodes_from = frozen
G.remove_node = frozen
G.remove_nodes_from = frozen
G.add_edge = frozen
G.add_edges_from = frozen
G.add_weighted_edges_from = frozen
G.remove_edge = frozen
G.remove_edges_from = frozen
G.clear = frozen
G.frozen = True
return G
示例15: freeze
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import freeze [as 别名]
def freeze(G):
"""Modify graph to prevent further change by adding or removing
nodes or edges.
Node and edge data can still be modified.
Parameters
----------
G : graph
A NetworkX graph
Examples
--------
>>> G = nx.path_graph(4)
>>> G = nx.freeze(G)
>>> try:
... G.add_edge(4, 5)
... except nx.NetworkXError as e:
... print(str(e))
Frozen graph can't be modified
Notes
-----
To "unfreeze" a graph you must make a copy by creating a new graph object:
>>> graph = nx.path_graph(4)
>>> frozen_graph = nx.freeze(graph)
>>> unfrozen_graph = nx.Graph(frozen_graph)
>>> nx.is_frozen(unfrozen_graph)
False
See Also
--------
is_frozen
"""
G.add_node = frozen
G.add_nodes_from = frozen
G.remove_node = frozen
G.remove_nodes_from = frozen
G.add_edge = frozen
G.add_edges_from = frozen
G.remove_edge = frozen
G.remove_edges_from = frozen
G.clear = frozen
G.frozen = True
return G