@@ -55,7 +55,7 @@ def corneil_habib_paul_tedder_algorithm(G):
5555 OUTPUT: an object of type Node representing the modular decomposition tree
5656 of the graph G
5757
58- This function compute the modular decomposition of the given graph by the
58+ This function computes the modular decomposition of the given graph by the
5959 algorithm of Corneil, Habib, Paul and Tedder [TCHP2008 ]_. It is a recursive,
6060 linear-time algorithm that first computes the slice decomposition of the
6161 graph ( via the extended lexBFS algorithm) and then computes the modular
@@ -112,17 +112,16 @@ cdef object _md_tree_node_to_md_tree_inner_rec(const md_tree_node *n,
112112 cdef md_tree_node * c
113113 if deref(n).is_leaf():
114114 return Node.create_leaf(Gb.vertex_label(deref(n).vertex))
115- else :
116- if deref(n).is_series():
117- node = Node(NodeType.SERIES)
118- elif deref(n).is_parallel():
119- node = Node(NodeType.PARALLEL)
120- else : # is_prime
121- node = Node(NodeType.PRIME)
122- node.children.extend(
123- _md_tree_node_to_md_tree_inner_rec(c, Gb)
124- for c in deref(n).children)
125- return node
115+
116+ if deref(n).is_series():
117+ node = Node(NodeType.SERIES)
118+ elif deref(n).is_parallel():
119+ node = Node(NodeType.PARALLEL)
120+ else : # is_prime
121+ node = Node(NodeType.PRIME)
122+ node.children.extend(_md_tree_node_to_md_tree_inner_rec(c, Gb)
123+ for c in deref(n).children)
124+ return node
126125
127126
128127cdef object md_tree_node_to_md_tree(const md_tree_node * n, CGraphBackend Gb):
@@ -151,8 +150,7 @@ cdef object md_tree_node_to_md_tree(const md_tree_node *n, CGraphBackend Gb):
151150 """
152151 if n == NULL :
153152 return Node(NodeType.EMPTY)
154- else :
155- return _md_tree_node_to_md_tree_inner_rec(n, Gb)
153+ return _md_tree_node_to_md_tree_inner_rec(n, Gb)
156154
157155
158156# ###############################################################################
@@ -321,7 +319,7 @@ class Node:
321319 @classmethod
322320 def create_leaf (cls , v ):
323321 """
324- Return Node object that is a leaf corresponding to the vertex ``v``
322+ Return Node object that is a leaf corresponding to the vertex ``v``.
325323
326324 INPUT:
327325
@@ -621,6 +619,21 @@ def modular_decomposition(G, algorithm=None):
621619 This function should not be used directly, it should be called via the
622620 ``modular_decomposition`` method of ``Graph``.
623621
622+ INPUT:
623+
624+ - ``G`` -- graph whose modular decomposition tree is to be computed
625+
626+ - ``algorithm`` -- string ( default: ``None``) ; the algorithm to use among:
627+
628+ - ``None`` or ``'corneil_habib_paul_tedder'`` -- will use the
629+ Corneil-Habib-Paul-Tedder algorithm from [TCHP2008 ]_, its complexity
630+ is linear in the number of vertices and edges.
631+
632+ - ``'habib_maurer'`` -- will use the Habib-Maurer algorithm from
633+ [HM1979 ]_, its complexity is cubic in the number of vertices.
634+
635+ OUTPUT: The modular decomposition tree, as an object of type ``Node``.
636+
624637 TESTS::
625638
626639 sage: from sage. graphs. graph_decompositions. modular_decomposition import *
@@ -1472,10 +1485,24 @@ def check_algos_are_equivalent(trials, graph_gen, verbose=False):
14721485 Verify that both algorithms compute the same tree ( up to equivalence) for
14731486 random graphs.
14741487
1488+ INPUT:
1489+
1490+ - ``trials`` -- integer; the number of tests the function will run.
1491+
1492+ - ``graph_gen`` -- function; a function that can be called without argument
1493+ and returns a random graph.
1494+
1495+ - ``verbose`` -- boolean ( defaul: ``False``) ; enable printing debug
1496+ information.
1497+
1498+ OUTPUT: ``None``. Raises an ``AssertionError`` on failure.
1499+
14751500 EXAMPLES::
14761501
14771502 sage: from sage. graphs. graph_decompositions. modular_decomposition import *
1503+ sage: check_algos_are_equivalent( 3, lambda : graphs. RandomGNP( 10, 0. 1))
14781504 sage: check_algos_are_equivalent( 3, lambda : graphs. RandomGNP( 10, 0. 5))
1505+ sage: check_algos_are_equivalent( 3, lambda : graphs. RandomGNP( 10, 0. 9))
14791506 """
14801507 for _ in range (trials):
14811508 graph = graph_gen()
0 commit comments