Is there a simple way to iterate over all DAGs on n vertices?
So far, I do this via posets and gray code like shown below, but is it an overkill?
from sage.combinat.gray_codes import product as gc_product
def Dags(n):
for P in Posets(n):
H = P.hasse_diagram()
E = [(v,u) for v in P for u in set(P.principal_upper_set(v))-set(H.neighbors_out(v))-{v}]
G = H.copy()
for e,d in gc_product([2]*len(E)):
if d>0:
G.add_edge(E[e])
else:
G.delete_edge(E[e])
yield G