Skip to content

Enum cycle in an undirected graph (and fix bug in yen_k_shortest_simple_path algorithm) #40217

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/doc/en/reference/graphs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,6 @@ Libraries of algorithms
sage/graphs/connectivity
sage/graphs/edge_connectivity
sage/graphs/domination
sage/graphs/cycle_enumeration

.. include:: ../footer.txt
39 changes: 39 additions & 0 deletions src/sage/graphs/connectivity.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Here is what the module can do:
:meth:`connected_components_sizes` | Return the sizes of the connected components as a list.
:meth:`blocks_and_cut_vertices` | Return the blocks and cut vertices of the graph.
:meth:`blocks_and_cuts_tree` | Return the blocks-and-cuts tree of the graph.
:meth:`biconnected_components_subgraphs` | Return a list of biconnected components as graph objects.
:meth:`is_cut_edge` | Check whether the input edge is a cut-edge or a bridge.
:meth:`is_edge_cut` | Check whether the input edges form an edge cut.
:meth:`is_cut_vertex` | Check whether the input vertex is a cut-vertex.
Expand Down Expand Up @@ -812,6 +813,44 @@ def blocks_and_cuts_tree(G):
g.add_edge(('B', bloc), ('C', c))
return g

def biconnected_components_subgraphs(G):
r"""
Return a list of biconnected components as graph objects.

A biconnected component is a maximal subgraph that is biconnected, i.e.,
removing any vertex does not disconnect it.

INPUT:

- ``G`` -- the input graph

EXAMPLES::

sage: from sage.graphs.connectivity import biconnected_components_subgraphs
sage: G = Graph({0: [1, 2], 1: [0, 2], 2: [0, 1, 3], 3: [2]})
sage: L = biconnected_components_subgraphs(G)
sage: L
[Subgraph of (): Graph on 2 vertices, Subgraph of (): Graph on 3 vertices]
sage: L[0].edges()
[(2, 3, None)]
sage: L[1].edges()
[(0, 1, None), (0, 2, None), (1, 2, None)]

TESTS:

If ``G`` is not a Sage graph, an error is raised::

sage: from sage.graphs.connectivity import biconnected_components_subgraphs
sage: biconnected_components_subgraphs('I am not a graph')
Traceback (most recent call last):
...
TypeError: the input must be a Sage graph
"""
from sage.graphs.generic_graph import GenericGraph
if not isinstance(G, GenericGraph):
raise TypeError("the input must be a Sage graph")

return [G.subgraph(c) for c in blocks_and_cut_vertices(G)[0]]

def is_edge_cut(G, edges):
"""
Expand Down
Loading
Loading