本文整理汇总了Python中networkx.is_frozen方法的典型用法代码示例。如果您正苦于以下问题:Python networkx.is_frozen方法的具体用法?Python networkx.is_frozen怎么用?Python networkx.is_frozen使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类networkx
的用法示例。
在下文中一共展示了networkx.is_frozen方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _common_format
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import is_frozen [as 别名]
def _common_format(g, edge_notation):
lines = []
lines.append("Name: %s" % g.name)
lines.append("Type: %s" % type(g).__name__)
lines.append("Frozen: %s" % nx.is_frozen(g))
lines.append("Density: %0.3f" % nx.density(g))
lines.append("Nodes: %s" % g.number_of_nodes())
for n, n_data in g.nodes(data=True):
if n_data:
lines.append(" - %s (%s)" % (n, n_data))
else:
lines.append(" - %s" % n)
lines.append("Edges: %s" % g.number_of_edges())
for (u, v, e_data) in g.edges(data=True):
if e_data:
lines.append(" %s %s %s (%s)" % (u, edge_notation, v, e_data))
else:
lines.append(" %s %s %s" % (u, edge_notation, v))
return lines
示例2: is_frozen
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import is_frozen [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
示例3: is_frozen
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import is_frozen [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: _remove_alarms_of_other_projects
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import is_frozen [as 别名]
def _remove_alarms_of_other_projects(self,
graph,
current_project_id,
is_admin_project):
"""Removes wrong alarms from the graph
Removes alarms of other tenants from the graph, In case the tenant is
admin then project_id can also be None.
:type graph: NXGraph
:type current_project_id: string
:type is_admin_project: boolean
"""
alarms_to_remove = []
for alarm in graph.get_vertices(query_dict=base.ALARMS_ALL_QUERY):
if not alarm.get(VProps.PROJECT_ID, None):
cat_filter = {VProps.VITRAGE_CATEGORY: EntityCategory.RESOURCE}
resource_neighbors = \
self.entity_graph.neighbors(alarm.vertex_id,
vertex_attr_filter=cat_filter)
if len(resource_neighbors) > 0:
resource_proj_id = \
resource_neighbors[0].get(VProps.PROJECT_ID, None)
cond1 = is_admin_project and resource_proj_id and \
resource_proj_id != current_project_id
cond2 = not is_admin_project and \
(not resource_proj_id or
resource_proj_id != current_project_id)
if cond1 or cond2:
alarms_to_remove.append(alarm)
if alarms_to_remove and is_frozen(graph._g):
graph._g = graph._g.copy()
for alarm in alarms_to_remove:
graph.remove_vertex(alarm)
示例5: apply_edge_attr_filter
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import is_frozen [as 别名]
def apply_edge_attr_filter(graph, edge_attr_filter):
edges = graph._g.edges(data=True, keys=True)
edges_to_remove = [(u, v, k) for (u, v, k, d) in edges
if not check_filter(d, edge_attr_filter)]
if edges_to_remove and is_frozen(graph._g):
graph._g = graph._g.copy()
for source, target, key in edges_to_remove:
graph._g.remove_edge(u=source, v=target, key=key)
示例6: test_is_frozen
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import is_frozen [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)
示例7: test_is_frozen
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import is_frozen [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 is_frozen [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
示例9: freeze
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import is_frozen [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
示例10: freeze
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import is_frozen [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