0

I'm working with randomly generated digraphs. I need to verify that the graphs I have have a girth of at least, say 3.

The solution I used is the following:

  1. I generate a random adjacency matrix
  2. I create an igraph.Graph instance from the matrix
  3. I call .girth() method to check the girth is correct.
  4. If correct, I keep my process; otherwise I return to step 1.

However; sometimes I have graphs that definitly should not pass the girth check but they do. For instance: Graph with girth 2. have an girth 2: there are two pairs of vertices (a,b) with a,b, and b,a in the arcs.

My theory is that igraph do not understand these pair of vertices as a proper cycle; if that is the case how do I fix this?

For the record: here how goes my random generation:

M = np.zeros((n,n))
    for i in range(n):
        pick_list = [j for j in range(n) if j!=i]
        x = random.sample(pick_list, outdegree)
        for j in x:
            M[i][j] = 1
Qise
  • 192
  • 6
  • 1
    From the igraph documentation: The current implementation works for undirected graphs only, directed graphs are treated as undirected graphs. Self-loops and multiple edges are ignored. See https://igraph.org/c/doc/igraph-Structural.html#igraph_girth – Vincent Traag Feb 11 '22 at 10:29
  • I see; thanks for pointing that – Qise Feb 11 '22 at 14:44

1 Answers1

0

So apparently the .girth() does not work properly for digraph. I did this to solve my problem:

    D_k = copy.deepcopy(D)

    for k in range(2, girth):
        D_k = D_k.dot(D)
        if sum([D_k[i][i] for i in range(n)]) != 0: # equivalent to: trace of D_k
            return False
    return True

A bad solution but at least it is correct.

Qise
  • 192
  • 6
  • Saying that "it does not work properly" is not fair, and may be misleading to people who read this answer. It works precisely as described in the documentation. There is no bug. You are welcome to open a feature request for directed girth, and provide links to descriptions of the relevant algorithms. – Szabolcs Feb 12 '22 at 10:55