Python networkx.is_frozen() Examples
The following are 12
code examples of networkx.is_frozen().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
networkx
, or try the search function
.
Example #1
Source File: graph.py From taskflow with Apache License 2.0 | 6 votes |
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
Example #2
Source File: function.py From qgisSpaceSyntaxToolkit with GNU General Public License v3.0 | 6 votes |
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
Example #3
Source File: function.py From Carnets with BSD 3-Clause "New" or "Revised" License | 6 votes |
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
Example #4
Source File: function.py From aws-kube-codesuite with Apache License 2.0 | 6 votes |
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
Example #5
Source File: topology.py From vitrage with Apache License 2.0 | 5 votes |
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)
Example #6
Source File: networkx_algorithm.py From vitrage with Apache License 2.0 | 5 votes |
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)
Example #7
Source File: test_function.py From qgisSpaceSyntaxToolkit with GNU General Public License v3.0 | 5 votes |
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)
Example #8
Source File: test_function.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #9
Source File: test_function.py From aws-kube-codesuite with Apache License 2.0 | 5 votes |
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)
Example #10
Source File: function.py From qgisSpaceSyntaxToolkit with GNU General Public License v3.0 | 4 votes |
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
Example #11
Source File: function.py From Carnets with BSD 3-Clause "New" or "Revised" License | 4 votes |
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
Example #12
Source File: function.py From aws-kube-codesuite with Apache License 2.0 | 4 votes |
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