Search code examples
graph-algorithmdijkstrashortest-pathtinkerpop3jung2

Using efficiently JUNG with TinkerPop3


I am using TinkerPop3 in Java and I have a weighted multi-graph on which I would like to run Dijkstra algorithm to find Shortest Weighted Path between two vertices. I have found in other questions that the recommended way to do this is by using JUNG with TinkerPop, but they are related to TinkerPop2, which had the JungGraph as part of blueprints.

My questions is whether there is any efficient way to use JUNG on Tinkerpop3 graphs, as the only way I have found for now is to create a new JUNG graph and iteratively add all edges from my TinkerPop3 graph to it. Any alternative suggestions to JUNG are also welcomed.


Solution

  • I am neither familiar with TinkerPop nor with its data model. In general you have two basic ways to provide an instance of B given an instance of A, given that B and A are reasonably compatible:

    1. copy: create an instance of B, iterate over the elements of A and copy them into B (this is your current solution)
    2. view: create a class that redirects calls to the methods of A to the appropriate methods for B. You can do this by implementing the appropriate interface (or extending the appropriate (abstract) class).

    Assuming you're using JUNG 2.x, you could extend the Abstract[Typed]Graph class. You may find it useful to look at the GraphDecorator class to see an example of this sort of delegation (in that case the class being delegated to is an instance of Graph, but it should be straightforward to adapt the model to delegate to TinkerPop if that model has appropriate methods).

    Note: the JUNG data model used in v2.x is being replaced with the Guava common.graph data model in JUNG v3.x. The same basic ideas apply, however.