@@ -2779,7 +2779,7 @@ def treewidth(self, k=None, certificate=False, algorithm=None):
27792779 if k is not None and k >= g .order () - 1 :
27802780 if certificate :
27812781 from sage .sets .set import Set
2782- return Graph ({Set (g . vertices ()): []}, name = "Tree decomposition" )
2782+ return Graph ({Set (g ): []}, name = "Tree decomposition" )
27832783 return True
27842784
27852785 # TDLIB
@@ -2807,8 +2807,9 @@ def treewidth(self, k=None, certificate=False, algorithm=None):
28072807 return all (cc .treewidth (k ) for cc in g .connected_components_subgraphs ())
28082808 else :
28092809 T = [cc .treewidth (certificate = True ) for cc in g .connected_components_subgraphs ()]
2810- tree = Graph ([sum ([t .vertices () for t in T ],[]), sum ([t .edges (labels = False ) for t in T ],[])],
2811- format = 'vertices_and_edges' , name = "Tree decomposition" )
2810+ tree = Graph ([sum ([list (t ) for t in T ], []),
2811+ sum ([t .edges (labels = False , sort = False ) for t in T ], [])],
2812+ format = 'vertices_and_edges' , name = "Tree decomposition" )
28122813 v = next (T [0 ].vertex_iterator ())
28132814 for t in T [1 :]:
28142815 tree .add_edge (next (t .vertex_iterator ()),v )
@@ -2850,7 +2851,7 @@ def rec(cut, cc):
28502851
28512852 # Removing v may have disconnected cc. We iterate on its
28522853 # connected components
2853- for cci in g .subgraph (ccv ).connected_components ():
2854+ for cci in g .subgraph (ccv ).connected_components (sort = False ):
28542855
28552856 # The recursive subcalls. We remove on-the-fly the vertices
28562857 # from the cut which play no role in separating the
@@ -2873,7 +2874,7 @@ def rec(cut, cc):
28732874 return False
28742875
28752876 # Main call to rec function, i.e. rec({v}, V-{v})
2876- V = g . vertices ( )
2877+ V = list ( g )
28772878 v = frozenset ([V .pop ()])
28782879 TD = rec (v , frozenset (V ))
28792880
@@ -2896,7 +2897,7 @@ def rec(cut, cc):
28962897 changed = True
28972898 while changed :
28982899 changed = False
2899- for v in G .vertices ():
2900+ for v in G .vertices (sort = False ):
29002901 for u in G .neighbor_iterator (v ):
29012902 if u .issuperset (v ):
29022903 G .merge_vertices ([u , v ]) # the new vertex is named 'u'
0 commit comments