Skip to content

Commit 30c483a

Browse files
author
Release Manager
committed
sagemathgh-40217: Enum cycle in an undirected graph (and fix bug in yen_k_shortest_simple_path algorithm) <!-- ^ Please provide a concise and informative title. --> <!-- ^ Don't put issue numbers in the title, do this in the PR description below. --> <!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method to calculate 1 + 2". --> <!-- v Describe your changes below in detail. --> <!-- v Why is this change required? What problem does it solve? --> <!-- v If this PR resolves an open issue, please link to it here. For example, "Fixes sagemath#12345". --> Add implementation of enumeration of cycles in an undirected graph. Specifically, I make ```sage/graphs/cycle_enumeration.py``` and modify + ```~sage.graphs.cycle_enumeration._all_simple_cycles_iterator_edge``` + ```~sage.graphs.cycle_enumeration.all_cycles_iterator``` + ```~sage.graphs.cycle_enumeration.all_simple_cycles``` In implementing these funcionts, I fix bug in ```~sage.graphs.path_enumeration.yen_k_shortest_simple_paths```. This bug occurs when there is no path between source and target. Also, I add ```~sage.graphs.connectivity.biconnected_components_subgraphs```. ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [ ] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies sagemath#40248 <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - sagemath#12345: short description why this is a dependency --> <!-- - sagemath#34567: ... --> URL: sagemath#40217 Reported by: Yuta Inoue Reviewer(s): David Coudert
2 parents 0b52cb0 + 0418243 commit 30c483a

File tree

7 files changed

+934
-782
lines changed

7 files changed

+934
-782
lines changed

src/doc/en/reference/graphs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,5 +122,6 @@ Libraries of algorithms
122122
sage/graphs/connectivity
123123
sage/graphs/edge_connectivity
124124
sage/graphs/domination
125+
sage/graphs/cycle_enumeration
125126

126127
.. include:: ../footer.txt

src/sage/graphs/connectivity.pyx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Here is what the module can do:
2323
:meth:`connected_components_sizes` | Return the sizes of the connected components as a list.
2424
:meth:`blocks_and_cut_vertices` | Return the blocks and cut vertices of the graph.
2525
:meth:`blocks_and_cuts_tree` | Return the blocks-and-cuts tree of the graph.
26+
:meth:`biconnected_components_subgraphs` | Return a list of biconnected components as graph objects.
2627
:meth:`is_cut_edge` | Check whether the input edge is a cut-edge or a bridge.
2728
:meth:`is_edge_cut` | Check whether the input edges form an edge cut.
2829
:meth:`is_cut_vertex` | Check whether the input vertex is a cut-vertex.
@@ -812,6 +813,44 @@ def blocks_and_cuts_tree(G):
812813
g.add_edge(('B', bloc), ('C', c))
813814
return g
814815

816+
def biconnected_components_subgraphs(G):
817+
r"""
818+
Return a list of biconnected components as graph objects.
819+
820+
A biconnected component is a maximal subgraph that is biconnected, i.e.,
821+
removing any vertex does not disconnect it.
822+
823+
INPUT:
824+
825+
- ``G`` -- the input graph
826+
827+
EXAMPLES::
828+
829+
sage: from sage.graphs.connectivity import biconnected_components_subgraphs
830+
sage: G = Graph({0: [1, 2], 1: [0, 2], 2: [0, 1, 3], 3: [2]})
831+
sage: L = biconnected_components_subgraphs(G)
832+
sage: L
833+
[Subgraph of (): Graph on 2 vertices, Subgraph of (): Graph on 3 vertices]
834+
sage: L[0].edges()
835+
[(2, 3, None)]
836+
sage: L[1].edges()
837+
[(0, 1, None), (0, 2, None), (1, 2, None)]
838+
839+
TESTS:
840+
841+
If ``G`` is not a Sage graph, an error is raised::
842+
843+
sage: from sage.graphs.connectivity import biconnected_components_subgraphs
844+
sage: biconnected_components_subgraphs('I am not a graph')
845+
Traceback (most recent call last):
846+
...
847+
TypeError: the input must be a Sage graph
848+
"""
849+
from sage.graphs.generic_graph import GenericGraph
850+
if not isinstance(G, GenericGraph):
851+
raise TypeError("the input must be a Sage graph")
852+
853+
return [G.subgraph(c) for c in blocks_and_cut_vertices(G)[0]]
815854

816855
def is_edge_cut(G, edges):
817856
"""

0 commit comments

Comments
 (0)