"""This module provides functionality related to apex graphs."""fromcopyimportdeepcopyfromitertoolsimportcombinationsimportnetworkxasnximportpyrigi._utils._input_checkas_input_check
[docs]defis_vertex_apex(graph:nx.Graph)->bool:""" Return whether the graph is vertex apex. Alias for :func:`~.is_k_vertex_apex` with ``k=1``. Definitions ----------- :prf:ref:`Vertex apex graph <def-apex-graph>` """returnis_k_vertex_apex(graph,1)
[docs]defis_k_vertex_apex(graph:nx.Graph,k:int)->bool:""" Return whether the graph is ``k``-vertex apex. Definitions ----------- :prf:ref:`k-vertex apex graph <def-apex-graph>` Examples -------- >>> import pyrigi.graphDB as graphs >>> G = graphs.Complete(5) >>> is_k_vertex_apex(G, 1) True """_input_check.integrality_and_range(k,"k",min_val=0,max_val=graph.number_of_nodes())_G=deepcopy(graph)forvertex_listincombinations(graph.nodes,k):incident_edges=list(_G.edges(vertex_list))_G.remove_nodes_from(vertex_list)ifnx.is_planar(_G):returnTrue_G.add_edges_from(incident_edges)returnFalse
[docs]defis_edge_apex(graph:nx.Graph)->bool:""" Return whether the graph is edge apex. Alias for :func:`~.is_k_edge_apex` with ``k=1`` Definitions ----------- :prf:ref:`Edge apex graph <def-apex-graph>` """returnis_k_edge_apex(graph,1)
[docs]defis_k_edge_apex(graph:nx.Graph,k:int)->bool:""" Return whether the graph is ``k``-edge apex. Definitions ----------- :prf:ref:`k-edge apex graph <def-apex-graph>` Examples -------- >>> import pyrigi.graphDB as graphs >>> G = graphs.Complete(5) >>> is_k_edge_apex(G, 1) True """_input_check.integrality_and_range(k,"k",min_val=0,max_val=graph.number_of_edges())_G=deepcopy(graph)foredge_listincombinations(graph.edges,k):_G.remove_edges_from(edge_list)ifnx.is_planar(_G):returnTrue_G.add_edges_from(edge_list)returnFalse
[docs]defis_critically_vertex_apex(graph:nx.Graph)->bool:""" Return whether the graph is critically vertex apex. Alias for :func:`~.is_critically_k_vertex_apex` with ``k=1``. Definitions ----------- :prf:ref:`Critically vertex apex graph <def-apex-graph>` """returnis_critically_k_vertex_apex(graph,1)
[docs]defis_critically_k_vertex_apex(graph:nx.Graph,k:int)->bool:""" Return whether the graph is critically ``k``-vertex apex. Definitions ----------- :prf:ref:`Critically k-vertex apex graph <def-apex-graph>` Examples -------- >>> import pyrigi.graphDB as graphs >>> G = graphs.Complete(5) >>> is_critically_k_vertex_apex(G, 1) True """_input_check.integrality_and_range(k,"k",min_val=0,max_val=graph.number_of_nodes())_G=deepcopy(graph)forvertex_listincombinations(graph.nodes,k):incident_edges=list(_G.edges(vertex_list))_G.remove_nodes_from(vertex_list)ifnotnx.is_planar(_G):returnFalse_G.add_edges_from(incident_edges)returnTrue
[docs]defis_critically_edge_apex(graph:nx.Graph)->bool:""" Return whether the graph is critically edge apex. Alias for :func:`~.is_critically_k_edge_apex` with ``k=1``. Definitions ----------- :prf:ref:`Critically edge apex graph <def-apex-graph>` """returnis_critically_k_edge_apex(graph,1)
[docs]defis_critically_k_edge_apex(graph:nx.Graph,k:int)->bool:""" Return whether the graph is critically ``k``-edge apex. Definitions ----------- :prf:ref:`Critically k-edge apex graph <def-apex-graph>` Examples -------- >>> import pyrigi.graphDB as graphs >>> G = graphs.Complete(5) >>> is_critically_k_edge_apex(G, 1) True """_input_check.integrality_and_range(k,"k",min_val=0,max_val=graph.number_of_edges())_G=deepcopy(graph)foredge_listincombinations(graph.edges,k):_G.remove_edges_from(edge_list)ifnotnx.is_planar(_G):returnFalse_G.add_edges_from(edge_list)returnTrue