How to find paths between 2 vertices

402 views
Skip to first unread message

Andrey Yesyev

unread,
Mar 24, 2014, 3:15:58 PM3/24/14
to orient-...@googlegroups.com
Hi there,

I've come to the most interesting part of my project - traversing graph.

Now I'm investigating how I can find

1. All paths between 2 vertices
2. Shortest path between 2 vertices. If I can solve the first problem, this won't be an issue.
3. Get related vertices to vertex V with given depth D of relationship.

I've come across with SELECT .. TRAVERSE query. But it's still unclear for me, how it works in general.
And how I can find all paths using this query in particular.

Also, I'm looking in using Gremlin for these problems.
I came up with this piece of code

        OrientGraph graph = DatabaseManager.getInstance().getDatabase("remote:192.168.200.1/ePersona").getConnection();
        final Vertex v = graph.getVertex("#21:14");
        GremlinPipeline pipe = new GremlinPipeline(graph.getVertex("#21:7")).as("person");
        List path = pipe.both("RELATED").loop("person", new PipeFunction<LoopPipe.LoopBundle, Boolean>() {
            @Override
            public Boolean compute(LoopPipe.LoopBundle loopBundle) {
                return loopBundle.getLoops() <5 && !((Vertex)loopBundle.getObject()).getId().toString().equals("#21:14") ;
            }
        }).path().toList();

Trying to find all paths between vertices #21:14 and #21:7. I've got 3634 of vertices and 12572 edges in my DB, this query has been working for 15 minutes for now and I don't think it'll be done any time soon.

This means I'm stuck again.

Any comments, suggestions are very welcome!

-Andrey

Andrey Lomakin

unread,
Mar 25, 2014, 1:45:30 AM3/25/14
to orient-database
HI Andrey.
So you have following options:
1. we have shortestPath function to find short path.
2. You can use traverse, it start from link which you provided and go through all links are present in doucuments.
3. You can use Gremlin,  better you Groovy fur such task, like this one : a.out('KNOWS').loop(1){it.loops<100}{true}.has('name', 'B').path{it.name

Your mistake is that you work with gremlin query on client side. 
I mean you should create select with gremlin query pass it on server side and then see the result, otherwise you will always need to retrieve data from remote connect to the client to process request.


--

---
You received this message because you are subscribed to the Google Groups "OrientDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to orient-databa...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Best regards,
Andrey Lomakin.

Orient Technologies
the Company behind OrientDB

Andrey Yesyev

unread,
Mar 25, 2014, 8:45:24 AM3/25/14
to orient-...@googlegroups.com
Thanks for your comments, Andrey.


--

---
You received this message because you are subscribed to a topic in the Google Groups "OrientDB" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/orient-database/O7KasChmY-Q/unsubscribe.
To unsubscribe from this group and all its topics, send an email to orient-databa...@googlegroups.com.

Andrey Yesyev

unread,
Mar 25, 2014, 9:09:11 AM3/25/14
to orient-...@googlegroups.com
I've got one questions.

There is an approach described how to do that more efficiently, using store/except pattern

gremlin> s = [root] as Set
==>v[0]
gremlin
> target = '99'; c = 0; root.both().except(s).store(s).sideEffect{c++}.loop(4){it.object.id != target && it.loops
<= 10}.has('id',target).path().iterate(); c

Works way faster. Have no idea how to run it in my app, though!

Andrey Yesyev

unread,
Mar 25, 2014, 3:10:24 PM3/25/14
to orient-...@googlegroups.com
In case someone's interested, found an answer for my question here https://groups.google.com/forum/#!msg/aureliusgraphs/d3jvgJeArOU/lMoObkk-If0J
Reply all
Reply to author
Forward
0 new messages