Hi again Saikat,

> a WeightedPath in the neo4j world is a path that contains weights between 
> nodes, in the realm of calculating the shortest path using for example the 
> Dijkstra Algorithm the path weights (in this case the distances) are all 
> summed up and the path with the minimum total weight is the one returned.  
> Here's an example using the weightedpath in the neo4j world  
> (http://components.neo4j.org/neo4j-graph-algo/).   In my graph all paths have 
> weights corresponding to length, that being said how do I then convert the 
> data returned by Gremlin to a datastructure that represents a list of 
> WeightedPath objects.  I need this datastructure to be returned through json 
> back to the client.

In the world of Gremlin there is no such thing as "calling a shortest path 
algorithm," "calling an eigenvector algorithm," etc. See the rational behind 
this idea here:
        http://markorodriguez.com/2011/02/08/property-graph-algorithms/

With that said, in Gremlin you have to write your own shortest path from the 
atomic traversal primitives provided (i.e. the steps). Here is a Wiki document 
on doing depth-first, breadth-first, and hybrid models of graph traversal in 
Gremlin:
        https://github.com/tinkerpop/gremlin/wiki/Depth-First-vs.-Breadth-First

Using the constructs there, you can write a shortest path that is tailored to 
your particular domain model. For example, given the domain model articulated 
here:
        
https://github.com/tinkerpop/gremlin/wiki/Defining-a-More-Complex-Property-Graph
 (edges have weights in this graph)
I demonstrate how to get the sum of the weights of each path here: 
        http://paste.pocoo.org/show/340560/

In terms of creating a WeightedPath object for Neo4j Server reasons, you can 
just do plain old Java in Gremlin. Again, Gremlin is a DSL in Groovy and thus, 
Java. I don't know the specifics of how to create a WeightedPath object or even 
if Neo4j allows you too (?protected constructor?).

Anywho, I think what I have provided gives you enough details for how to sum 
weights along paths in a graph...

I can help you more if you need something specific to your domain model --- or 
again, if you give me a specific problem aimed at this domain model:
        
https://github.com/tinkerpop/gremlin/wiki/Defining-a-More-Complex-Property-Graph
I will make it a Gremlin recipe in the Gremlin Cookbook and you can adapt it as 
need be for your domain model.

Also, feel free to ping me personally so we don't flood the Neo4j list if you 
want more specific help. Or, you can always post to:
        http://groups.google.com/group/gremlin-users

Thanks,
Marko.

http://markorodriguez.com

----------------------
SIDE NOTE:
Another thing TinkerPop could provide is something like this:
        ShortestPath.evaluate(g.v(1), g.v(2), 
outE('followed_by').inV[[type:'A']]).paths
In other words, while not providing full control, generic path descriptions 
could be provided to such "high level" graph algorithms.
----------------------


_______________________________________________
Neo4j mailing list
[email protected]
https://lists.neo4j.org/mailman/listinfo/user

Reply via email to