@@ -817,6 +817,7 @@ def make_nice_tree_decomposition(graph, tree_decomp):
817
817
INPUT:
818
818
819
819
- ``graph`` -- a Sage graph
820
+
820
821
- ``tree_decomp`` -- a tree decomposition
821
822
822
823
OUTPUT:
@@ -853,7 +854,7 @@ def make_nice_tree_decomposition(graph, tree_decomp):
853
854
sage: make_nice_tree_decomposition( bip_one_four, bip_one_four_TD)
854
855
Nice tree decomposition of Tree decomposition: Graph on 15 vertices
855
856
856
- The following two examples are for testing GitHub Issue 36843 ::
857
+ Check that :issue:`36843` is fixed ::
857
858
858
859
sage: from sage. graphs. graph_decompositions. tree_decomposition import make_nice_tree_decomposition
859
860
sage: triangle = graphs. CompleteGraph( 3)
@@ -868,6 +869,30 @@ def make_nice_tree_decomposition(graph, tree_decomp):
868
869
sage: graph_TD = graph. treewidth( certificate=True)
869
870
sage: make_nice_tree_decomposition( graph, graph_TD)
870
871
Nice tree decomposition of Tree decomposition: Graph on 25 vertices
872
+
873
+ ::
874
+
875
+ sage: from sage. graphs. graph_decompositions. tree_decomposition import make_nice_tree_decomposition
876
+ sage: empty_graph = graphs. EmptyGraph( )
877
+ sage: tree_decomp = empty_graph. treewidth( certificate=True)
878
+ sage: len( make_nice_tree_decomposition( empty_graph, tree_decomp))
879
+ 0
880
+
881
+ ::
882
+
883
+ sage: from sage. graphs. graph_decompositions. tree_decomposition import make_nice_tree_decomposition
884
+ sage: singleton = graphs. CompleteGraph( 1)
885
+ sage: tree_decomp = singleton. treewidth( certificate=True)
886
+ sage: make_nice_tree_decomposition( singleton, tree_decomp)
887
+ Nice tree decomposition of Tree decomposition: Graph on 3 vertices
888
+
889
+ ::
890
+
891
+ sage: from sage. graphs. graph_decompositions. tree_decomposition import make_nice_tree_decomposition
892
+ sage: an_edge = graphs. CompleteGraph( 2)
893
+ sage: tree_decomp = an_edge. treewidth( certificate=True)
894
+ sage: make_nice_tree_decomposition( an_edge, tree_decomp)
895
+ Nice tree decomposition of Tree decomposition: Graph on 5 vertices
871
896
"""
872
897
if not is_valid_tree_decomposition(graph, tree_decomp):
873
898
raise ValueError (" input must be a valid tree decomposition for this graph" )
@@ -1035,6 +1060,7 @@ def make_nice_tree_decomposition(graph, tree_decomp):
1035
1060
1036
1061
return nice_tree_decomp
1037
1062
1063
+
1038
1064
def label_nice_tree_decomposition (nice_TD , root , directed = False ):
1039
1065
r """
1040
1066
Return a nice tree decomposition with nodes labelled accordingly.
@@ -1045,7 +1071,9 @@ def label_nice_tree_decomposition(nice_TD, root, directed=False):
1045
1071
1046
1072
- ``root`` -- the root of the nice tree decomposition
1047
1073
1048
- - ``directed`` -- boolean ( default: ``False``) ; whether to return the directed graph
1074
+ - ``directed`` -- boolean ( default: ``False``) ; whether to return the nice
1075
+ tree decomposition as a directed graph rooted at vertex ``root`` or as an
1076
+ undirected graph
1049
1077
1050
1078
OUTPUT:
1051
1079
@@ -1058,7 +1086,9 @@ def label_nice_tree_decomposition(nice_TD, root, directed=False):
1058
1086
sage: bip_one_four_TD = bip_one_four. treewidth( certificate=True)
1059
1087
sage: nice_TD = make_nice_tree_decomposition( bip_one_four, bip_one_four_TD)
1060
1088
sage: root = sorted( nice_TD. vertices( )) [0 ]
1061
- sage: label_TD = label_nice_tree_decomposition( nice_TD, root)
1089
+ sage: label_TD = label_nice_tree_decomposition( nice_TD, root, directed=True)
1090
+ sage: print( label_TD. name( ))
1091
+ Labelled Nice tree decomposition of Tree decomposition
1062
1092
sage: for node in sorted( label_TD) :
1063
1093
.... : print( node, label_TD. get_vertex( node))
1064
1094
( 0, {}) forget
@@ -1081,13 +1111,13 @@ def label_nice_tree_decomposition(nice_TD, root, directed=False):
1081
1111
from sage.graphs.graph import Graph
1082
1112
1083
1113
directed_TD = DiGraph(nice_TD.breadth_first_search(start = root, edges = True ),
1084
- format = ' list_of_edges' )
1114
+ format = ' list_of_edges' ,
1115
+ name = ' Labelled {}' .format(nice_TD))
1085
1116
1086
1117
# The loop starts from the root node
1087
1118
# We assume the tree decomposition is valid and nice,
1088
1119
# hence saving time on checking.
1089
1120
for node in directed_TD:
1090
- in_deg = directed_TD.in_degree(node)
1091
1121
out_deg = directed_TD.out_degree(node)
1092
1122
1093
1123
if out_deg == 2 :
0 commit comments