Skip to content

Commit

Permalink
fix bug in acyclic_orientations
Browse files Browse the repository at this point in the history
  • Loading branch information
dcoudert committed Oct 3, 2024
1 parent b0f09d9 commit 62bff5e
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/sage/graphs/orientations.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,29 @@ def acyclic_orientations(G):
sage: len(list(it))
42
Check the orientation of edges::
sage: g = Graph([(0, 1), (1, 2), (2, 3), (3, 0), (0, 2)])
sage: sorted(sorted(h.edges(labels=False)) for h in g.acyclic_orientations())
[[(0, 1), (0, 2), (0, 3), (1, 2), (2, 3)],
[(0, 1), (0, 2), (0, 3), (1, 2), (3, 2)],
[(0, 1), (0, 2), (0, 3), (2, 1), (2, 3)],
[(0, 1), (0, 2), (0, 3), (2, 1), (3, 2)],
[(0, 1), (0, 2), (1, 2), (3, 0), (3, 2)],
[(0, 1), (0, 2), (2, 1), (3, 0), (3, 2)],
[(0, 1), (0, 3), (2, 0), (2, 1), (2, 3)],
[(0, 1), (2, 0), (2, 1), (2, 3), (3, 0)],
[(0, 1), (2, 0), (2, 1), (3, 0), (3, 2)],
[(0, 2), (0, 3), (1, 0), (1, 2), (2, 3)],
[(0, 2), (0, 3), (1, 0), (1, 2), (3, 2)],
[(0, 2), (1, 0), (1, 2), (3, 0), (3, 2)],
[(0, 3), (1, 0), (1, 2), (2, 0), (2, 3)],
[(0, 3), (1, 0), (2, 0), (2, 1), (2, 3)],
[(1, 0), (1, 2), (2, 0), (2, 3), (3, 0)],
[(1, 0), (1, 2), (2, 0), (3, 0), (3, 2)],
[(1, 0), (2, 0), (2, 1), (2, 3), (3, 0)],
[(1, 0), (2, 0), (2, 1), (3, 0), (3, 2)]]
TESTS:
To count the number of acyclic orientations for a graph with 0 vertices::
Expand Down Expand Up @@ -291,8 +314,9 @@ def helper(G, globO, m, k):

# Iterate over acyclic orientations and create relabeled graphs
for orientation in orientations:
relabeled_graph = DiGraph([(reverse_vertex_labels[u], reverse_vertex_labels[v], label) for (u, v), label in orientation.items()])
yield relabeled_graph
D = DiGraph([(u, v) if label else (v, u) for (u, v), label in orientation.items()])
D.relabel(perm=reverse_vertex_labels, inplace=True)
yield D


def strong_orientations_iterator(G):
Expand Down

0 comments on commit 62bff5e

Please sign in to comment.