ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 16 Mar 2021 21:23:41 +0100iterate over all directed acyclic graphs (DAGs) on n verticeshttps://ask.sagemath.org/question/56190/iterate-over-all-directed-acyclic-graphs-dags-on-n-vertices/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?
**UPDATE.** The code is corrected, thanks to *tmonteil*.
from sage.combinat.gray_codes import product as gc_product
def Dags0(n):
for P in Posets(n):
H = P.hasse_diagram()
E = list( set(H.transitive_closure().edges(labels=False)) - set(H.edges(labels=False)) )
G = H.copy()
C = G.canonical_label()
CC = set(C.dig6_string())
yield C
for e,d in gc_product([2]*len(E)):
if d>0:
G.add_edge(E[e])
else:
G.delete_edge(E[e])
C = G.canonical_label()
dig6 = C.dig6_string()
if dig6 not in CC:
CC.add(dig6)
yield CMax AlekseyevTue, 16 Mar 2021 21:23:41 +0100https://ask.sagemath.org/question/56190/digraphs.nauty_directg() missing in SageMath 8.6?https://ask.sagemath.org/question/46220/digraphsnauty_directg-missing-in-sagemath-86/Hello, I recently picked up SageMath to perform digraph computations regarding
a research interest. I'm running into a strange issue regarding a function that
should exist, judging by the documentation (link at the bottom of this post),
but apparently does not. If I attempt to run a small test copied directly from
said documentation:
gen = graphs.nauty_geng("-c 3")
dgs = list(digraphs.nauty_directg(gen))
the program fails to compile and yields
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-29-ae6a73f0fd49> in <module>()
1 gen = graphs.nauty_geng("-c 3")
----> 2 dgs = list(digraphs.nauty_directg(gen))
/opt/sagemath-8.6/local/lib/python2.7/site-packages/sage/misc/lazy_import.pyx in sage.misc.lazy_import.LazyImport.__getattr__ (build/cythonized/sage/misc/lazy_import.c:3536)()
320 True
321 """
--> 322 return getattr(self.get_object(), attr)
323
324 # We need to wrap all the slot methods, as they are not forwarded
AttributeError: DiGraphGenerators instance has no attribute 'nauty_directg'
Could anyone tell me whether I'm I making a horrible rookie mistake, or is this functionality is simply missing from SageMath 8.6? Or is there something else at play?
Thanks,
Pepijn
Documentation at: [http://doc.sagemath.org/html/en/reference/graphs/sage/graphs/digraph_generators.html#sage.graphs.digraph_generators.DiGraphGenerators.nauty_directg](http://doc.sagemath.org/html/en/reference/graphs/sage/graphs/digraph_generators.html#sage.graphs.digraph_generators.DiGraphGenerators.nauty_directg)PepijnWissingTue, 16 Apr 2019 12:09:34 +0200https://ask.sagemath.org/question/46220/