HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Generating all directed acyclic graphs with constraints

Submitted by: @import:stackexchange-cs··
0
Viewed 0 times
constraintsacyclicallwithgraphsdirectedgenerating

Problem

I am interested in listing all the unlabeled1 acyclic digraphs with n vertices which satisfy some additional constraints, such as (a) the resulting graph is connected and (b) except for R identified root vertices, all vertices have two incoming edges and zero or one outgoing edges.

There may also be additional domain-specific constraints, but they are probably easy enough to implement by simply generating and rejecting graphs that do not meet the constraints. In principle, conditions (a) and (b) above could be satisfied in this way above, but at least in the case of (b) it seems very advantageous to consider them directly in generating process since the output is likely to be quite sparse (i.e., a large majority of graphs will fail to satisfy (b) and this ration increases with increasing n).

My problem is twofold:

-
Even ignoring the constraints part, I have not be able to determine how to efficiently generate DAGs. I know there are a lot of them so I'll mostly be dealing with smallish n, let's say `n

-
I want to apply the at least enough of the constraint part during the generation to avoid the case where nearly all generated graphs are simply rejected. That is, I hope the generation of the constrained graphs is considerably faster than the generation of the much larger number without constraints.

You can find lots of information on random generation of such graphs, but not much on exhaustive generation (which seems like the easier of the two problems).

1 That is, I want to exclude generation of isomorphic graphs.

Solution

For small $n$, the easiest solution might be to download a list of all non-isomorphic graphs and then filter them according to your condition.

You might take a look at Brendan McKay's collection, constructed using geng as part of the Nauty graph isomorphism package.

See Enumerate all non-isomorphic graphs of a certain size for more details and citations.

Context

StackExchange Computer Science Q#60460, answer score: 4

Revisions (0)

No revisions yet.