@@ -80,15 +80,6 @@ def acyclic_orientations(G):
8080 sage: len(list(it))
8181 54
8282
83- For C100 graph, we get first 10 orientations pretty quickly::
84-
85- sage: from itertools import islice
86- sage: import timeit
87- sage: G_C100, start_time = graphs.CycleGraph(100), timeit.default_timer()
88- sage: it_C100, first_10_orientations = G_C100.acyclic_orientations(), list(islice(G_C100.acyclic_orientations(), 10))
89- sage: print(timeit.default_timer() - start_time < 0.5)
90- True
91-
9283 TESTS:
9384
9485 Acyclic orientations of a complete graph::
@@ -248,11 +239,8 @@ def helper(G, globO, m, k):
248239 # Reorder vertices based on the logic in reorder_vertices function
249240 vertex_labels = reorder_vertices (G )
250241
251- # Create a new graph with updated vertex labels using SageMath
252- from sage .graphs .graph import Graph
253- new_G = Graph ()
254- for u , v in G .edges (labels = False ): # Assuming the graph edges are unlabelled
255- new_G .add_edge (vertex_labels [u ], vertex_labels [v ])
242+ # Create a new graph with updated vertex labels using SageMath, Assuming the graph edges are unlabelled
243+ new_G = G .relabel (perm = vertex_labels , inplace = False )
256244
257245 G = new_G
258246
@@ -265,6 +253,18 @@ def helper(G, globO, m, k):
265253 m = len (edge_labels )
266254 k = len (vertex_labels )
267255 orientations = helper (G , globO , m , k )
256+
257+ # Create a mapping between original and new vertex labels
258+ reverse_vertex_labels = {label : vertex for vertex , label in vertex_labels .items ()}
259+
260+ # Iterate over acyclic orientations and relabel the vertices
261+ for orientation in orientations :
262+ relabeled_orientation = {}
263+ for (u , v ), label in orientation .items ():
264+ relabeled_orientation [(reverse_vertex_labels [u ], reverse_vertex_labels [v ])] = label
265+
266+ yield relabeled_orientation
267+
268268 return orientations
269269
270270
0 commit comments