Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

acyclic subdigraph

I have a graph D, and would like to iterate over its (maximal) acyclic subdigraphs (not necessarily induced).

My current best bet is to iterate over all permutations of the vertex set of D and, for each one, create an acyclic digraph A by going through each edge of D in turn and adding to A only those edges ij where i is less than j in the current permutation.

But this seems awfully inefficient.

More precisely:

D = DiGraph()
D.add_edges([[0,1],[0,2],[1,2],[1,3],[2,3],[3,4],[4,5],[4,6],[5,6],[5,0],[6,0]])
n = D.num_verts()

for p in Permutations(n):
    A = DiGraph()
    for e in D.edges():
        if p[e[0]] < p[e[1]]:
            A.add_edge(p[e[0]] -1,p[e[1]] -1

    # Here A is a maximal acyclic subdigraph of D
    do_stuff(A)

Any ideas would be greatly appreciated.

acyclic subdigraphIterate over acyclic subdigraphs

I have a graph D, and would like to iterate over its (maximal) acyclic subdigraphs (not necessarily induced).

My current best bet is to iterate over all permutations of the vertex set of D and, for each one, create an acyclic digraph A by going through each edge of D in turn and adding to A only those edges ij where i is less than j in the current permutation.

But this seems awfully inefficient.

More precisely:

D = DiGraph()
D.add_edges([[0,1],[0,2],[1,2],[1,3],[2,3],[3,4],[4,5],[4,6],[5,6],[5,0],[6,0]])
n = D.num_verts()

for p in Permutations(n):
    A = DiGraph()
    for e in D.edges():
        if p[e[0]] < p[e[1]]:
            A.add_edge(p[e[0]] -1,p[e[1]] -1
-1)

    # Here A is a maximal acyclic subdigraph of D
    do_stuff(A)

Any ideas would be greatly appreciated.

click to hide/show revision 3
retagged

Iterate over acyclic subdigraphs

I have a graph D, and would like to iterate over its (maximal) acyclic subdigraphs (not necessarily induced).

My current best bet is to iterate over all permutations of the vertex set of D and, for each one, create an acyclic digraph A by going through each edge of D in turn and adding to A only those edges ij where i is less than j in the current permutation.

But this seems awfully inefficient.

More precisely:

D = DiGraph()
D.add_edges([[0,1],[0,2],[1,2],[1,3],[2,3],[3,4],[4,5],[4,6],[5,6],[5,0],[6,0]])
n = D.num_verts()

for p in Permutations(n):
    A = DiGraph()
    for e in D.edges():
        if p[e[0]] < p[e[1]]:
            A.add_edge(p[e[0]] -1,p[e[1]] -1)

    # Here A is a maximal acyclic subdigraph of D
    do_stuff(A)

Any ideas would be greatly appreciated.

click to hide/show revision 4
retagged

Iterate over acyclic subdigraphs

I have a graph D, and would like to iterate over its (maximal) acyclic subdigraphs (not necessarily induced).

My current best bet is to iterate over all permutations of the vertex set of D and, for each one, create an acyclic digraph A by going through each edge of D in turn and adding to A only those edges ij where i is less than j in the current permutation.

But this seems awfully inefficient.

More precisely:

D = DiGraph()
D.add_edges([[0,1],[0,2],[1,2],[1,3],[2,3],[3,4],[4,5],[4,6],[5,6],[5,0],[6,0]])
n = D.num_verts()

for p in Permutations(n):
    A = DiGraph()
    for e in D.edges():
        if p[e[0]] < p[e[1]]:
            A.add_edge(p[e[0]] -1,p[e[1]] -1)

    # Here A is a maximal acyclic subdigraph of D
    do_stuff(A)

Any ideas would be greatly appreciated.