1

I am working on a graph database on ArangoDB and I'm trying to have paths through a random walk. My purpose is from a start vertex V, I get for instance 4 random paths with a specified depth.

As far as from now, I've found the following code that works :

FOR vertex, edge, path IN 4..4 ANY 'Vertex/417438' edge_collection OPTIONS {bfs: TRUE, uniqueVertices : True, uniqueEdges : True}
    SORT RAND()
    LIMIT 3
    FILTER  IS_SAME_COLLECTION('Vertex', vertex)
    RETURN path

This indeed gives me 3 paths with a depth of 4, but it takes quite a long time because of the SORT RAND() at the beginning. I guess it first sorts randomly all the possible solution and then returns the solution.

Do you think, there's a way to have random solutions that costs less time?

Thanks for your time and for your futures answers

Syndo rik
  • 755
  • 1
  • 7
  • 15

1 Answers1

1

I've just discussed with someone from the dev Team of Arango. Getting a random node in AQL is not possible for the moment. It's in there roadmap however.

I found a way to do a random Walk on ArangoDB though.

Let's take v, the starting vertex.

  1. Query the number of neighbors N of v with this command :

    FOR clip, edge, path IN ANY '${vertex}' hasClipped OPTIONS {bfs: TRUE, uniqueVertices : True, uniqueEdges : True}
                            COLLECT WITH COUNT INTO len
                            RETURN len
    
  2. Then choose a random number rd between 0 and N and execute the following request :

    FOR obj IN ANY '${vertex}' hasClipped OPTIONS {bfs : true, uniqueVertices : 'path'}
                            LIMIT ${rd}, 1
                            RETURN obj
    

    This request will return a random neighbor among the existing ones.

  3. Iterate to get a random walk with the depth you want.

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
Syndo rik
  • 755
  • 1
  • 7
  • 15