@@ -22,7 +22,10 @@ Here is what the module can do:
22
22
:meth:`connected_components_sizes` | Return the sizes of the connected components as a list.
23
23
:meth:`blocks_and_cut_vertices` | Return the blocks and cut vertices of the graph.
24
24
:meth:`blocks_and_cuts_tree` | Return the blocks-and-cuts tree of the graph.
25
+ :meth:`is_biconnected` | Check whether the graph is biconnected.
26
+ :meth:`biconnected_components` | Return the list of biconnected components.
25
27
:meth:`biconnected_components_subgraphs` | Return a list of biconnected components as graph objects.
28
+ :meth:`number_of_biconnected_components` | Return the number of biconnected components.
26
29
:meth:`is_cut_edge` | Check whether the input edge is a cut-edge or a bridge.
27
30
:meth:`is_edge_cut` | Check whether the input edges form an edge cut.
28
31
:meth:`is_cut_vertex` | Check whether the input vertex is a cut-vertex.
@@ -90,7 +93,7 @@ def is_connected(G, forbidden_vertices=None):
90
93
91
94
.. SEEALSO::
92
95
93
- - :meth:`~Graph .is_biconnected`
96
+ - :meth:`~sage.graphs.generic_graph.GenericGraph .is_biconnected`
94
97
95
98
EXAMPLES::
96
99
@@ -507,7 +510,7 @@ def blocks_and_cut_vertices(G, algorithm='Tarjan_Boost', sort=False, key=None):
507
510
508
511
- :meth:`blocks_and_cuts_tree`
509
512
- :func:`sage.graphs.base.boost_graph.blocks_and_cut_vertices`
510
- - :meth:`~Graph .is_biconnected`
513
+ - :meth:`~sage.graphs.generic_graph.GenericGraph .is_biconnected`
511
514
- :meth:`~Graph.bridges`
512
515
513
516
EXAMPLES:
@@ -718,7 +721,7 @@ def blocks_and_cuts_tree(G):
718
721
.. SEEALSO::
719
722
720
723
- :meth:`~sage.graphs.generic_graph.GenericGraph.blocks_and_cut_vertices`
721
- - :meth:`~Graph .is_biconnected`
724
+ - :meth:`~sage.graphs.generic_graph.GenericGraph .is_biconnected`
722
725
723
726
EXAMPLES::
724
727
@@ -780,12 +783,89 @@ def blocks_and_cuts_tree(G):
780
783
return g
781
784
782
785
786
+ def is_biconnected (G ):
787
+ r """
788
+ Check whether the graph is biconnected.
789
+
790
+ A biconnected graph is a connected graph on two or more vertices that is not
791
+ broken into disconnected pieces by deleting any single vertex.
792
+
793
+ .. SEEALSO::
794
+
795
+ - :meth:`~sage. graphs. generic_graph. GenericGraph. is_connected`
796
+ - :meth:`~sage. graphs. generic_graph. GenericGraph. blocks_and_cut_vertices`
797
+ - :meth:`~sage. graphs. generic_graph. GenericGraph. blocks_and_cuts_tree`
798
+ - :wikipedia:`Biconnected_graph`
799
+
800
+ EXAMPLES::
801
+
802
+ sage: G = graphs. PetersenGraph( )
803
+ sage: G. is_biconnected( )
804
+ True
805
+ sage: G. add_path( [0,'a','b' ])
806
+ sage: G. is_biconnected( )
807
+ False
808
+ sage: G. add_edge( 'b', 1)
809
+ sage: G. is_biconnected( )
810
+ True
811
+
812
+ TESTS::
813
+
814
+ sage: Graph( ) . is_biconnected( )
815
+ False
816
+ sage: Graph( 1) . is_biconnected( )
817
+ False
818
+ sage: graphs. CompleteGraph( 2) . is_biconnected( )
819
+ True
820
+ """
821
+ if G.order() < 2 or not G.is_connected():
822
+ return False
823
+ return not G.blocks_and_cut_vertices()[1 ]
824
+
825
+
826
+ def biconnected_components (G ):
827
+ r """
828
+ Return the list of biconnected components.
829
+
830
+ A biconnected component is a maximal subgraph on two or more vertices that
831
+ is biconnected, i. e. , removing any vertex does not disconnect it.
832
+
833
+ INPUT:
834
+
835
+ - ``G`` -- the input graph
836
+
837
+ EXAMPLES::
838
+
839
+ sage: from sage. graphs. connectivity import biconnected_components
840
+ sage: G = Graph( {0: [1, 2 ], 1: [0, 2 ], 2: [0, 1, 3 ], 3: [2 ]})
841
+ sage: sorted( len( b) for b in biconnected_components( G))
842
+ [2, 3 ]
843
+ sage: sorted( len( b) for b in biconnected_components( 2 * G))
844
+ [2, 2, 3, 3 ]
845
+
846
+ TESTS:
847
+
848
+ If ``G`` is not a Sage graph, an error is raised::
849
+
850
+ sage: from sage. graphs. connectivity import biconnected_components
851
+ sage: biconnected_components( 'I am not a graph')
852
+ Traceback ( most recent call last) :
853
+ ...
854
+ TypeError: the input must be a Sage graph
855
+ """
856
+ from sage.graphs.generic_graph import GenericGraph
857
+ if not isinstance (G, GenericGraph):
858
+ raise TypeError (" the input must be a Sage graph" )
859
+
860
+ return [b for b in blocks_and_cut_vertices(G)[0 ] if len (b) > 1 ]
861
+
862
+
783
863
def biconnected_components_subgraphs (G ):
784
864
r """
785
865
Return a list of biconnected components as graph objects.
786
866
787
- A biconnected component is a maximal subgraph that is biconnected, i . e . ,
788
- removing any vertex does not disconnect it.
867
+ A biconnected component is a maximal subgraph on two or more vertices that
868
+ is biconnected, i . e . , removing any vertex does not disconnect it.
789
869
790
870
INPUT:
791
871
@@ -817,7 +897,71 @@ def biconnected_components_subgraphs(G):
817
897
if not isinstance (G, GenericGraph):
818
898
raise TypeError (" the input must be a Sage graph" )
819
899
820
- return [G.subgraph(c) for c in blocks_and_cut_vertices(G)[0 ]]
900
+ return [G.subgraph(c) for c in G.biconnected_components()]
901
+
902
+
903
+ def number_of_biconnected_components (G ):
904
+ r """
905
+ Return the number of biconnected components.
906
+
907
+ A biconnected component is a maximal subgraph on two or more vertices that
908
+ is biconnected, i. e. , removing any vertex does not disconnect it.
909
+
910
+ .. SEEALSO::
911
+
912
+ - :meth:`~sage. graphs. generic_graph. GenericGraph. blocks_and_cut_vertices`
913
+ - :meth:`~sage. graphs. generic_graph. GenericGraph. is_biconnected`
914
+
915
+ EXAMPLES:
916
+
917
+ The disjoint union of cycles has as many biconnected components as the
918
+ number of cycles::
919
+
920
+ sage: G = graphs. CycleGraph( 5)
921
+ sage: G. number_of_biconnected_components( )
922
+ 1
923
+ sage: ( 3 * G) . number_of_biconnected_components( )
924
+ 3
925
+
926
+ A block graph is a connected graph in which every biconnected component
927
+ ( block) is a clique. Hence its number of biconnected components is its
928
+ number of blocks::
929
+
930
+ sage: number_of_blocks = randint( 4, 10)
931
+ sage: G = graphs. RandomBlockGraph( number_of_blocks, 5)
932
+ sage: G. number_of_biconnected_components( ) == number_of_blocks
933
+ True
934
+
935
+ By definition, an edge is a biconnected component. Hence, the number of
936
+ biconnected components of a tree is its number of edges::
937
+
938
+ sage: T = graphs. RandomTree( randint( 0, 10))
939
+ sage: T. number_of_biconnected_components( ) == T. size( )
940
+ True
941
+
942
+ An isolated vertex is a block but not a biconnected component::
943
+
944
+ sage: G = Graph( 3)
945
+ sage: len( G. blocks_and_cut_vertices( ) [0 ])
946
+ 3
947
+ sage: G. number_of_biconnected_components( )
948
+ 0
949
+
950
+ TESTS:
951
+
952
+ An error is raised if the input is not a Sage graph::
953
+
954
+ sage: from sage. graphs. connectivity import number_of_biconnected_components
955
+ sage: number_of_biconnected_components( 'I am not a graph')
956
+ Traceback ( most recent call last) :
957
+ ...
958
+ TypeError: the input must be a Sage graph
959
+ """
960
+ from sage.graphs.generic_graph import GenericGraph
961
+ if not isinstance (G, GenericGraph):
962
+ raise TypeError (" the input must be a Sage graph" )
963
+
964
+ return len (G.biconnected_components())
821
965
822
966
823
967
def is_edge_cut (G , edges ):
@@ -3365,7 +3509,7 @@ cdef class TriconnectivitySPQR:
3365
3509
.. SEEALSO::
3366
3510
3367
3511
- :meth:`sage. graphs. connectivity. spqr_tree`
3368
- - :meth:`~Graph . is_biconnected`
3512
+ - :meth:`~sage . graphs . generic_graph . GenericGraph . is_biconnected`
3369
3513
- :wikipedia:`SPQR_tree`
3370
3514
3371
3515
EXAMPLES:
@@ -4791,7 +4935,7 @@ def is_triconnected(G):
4791
4935
.. SEEALSO::
4792
4936
4793
4937
- :meth:`~sage. graphs. generic_graph. GenericGraph. is_connected`
4794
- - :meth:`~Graph . is_biconnected`
4938
+ - :meth:`~sage . graphs . generic_graph . GenericGraph . is_biconnected`
4795
4939
- :meth:`~sage. graphs. connectivity. spqr_tree`
4796
4940
- :wikipedia:`SPQR_tree`
4797
4941
0 commit comments