Getting the paths based on different values of the same attribute

14 views
Skip to first unread message

jorge castrejon

unread,
Nov 12, 2013, 1:23:04 PM11/12/13
to dex...@googlegroups.com

Hi,

I've been struggling with how to find every path that follows a certain patern (i.e Va(property1="a")->Vb(property1="b")->Vc(property1="c")) and store the vertices (Va,Vb and Vc in this example) for every path found.

As for now, i find all vertices which property1 is "a" and then i use the interseccion of "neighbors" and "select(property1,Condition.Equal,v.setString("b")" finally i repeat this step by each hop.

¿Any tips on how do this query?.

Thank for your time.


PD: API Java

c3po.ac

unread,
Nov 13, 2013, 5:05:49 AM11/13/13
to dex...@googlegroups.com
A few ideas to get the maximum performance in this query:

1- Materialize the neighbors for all the edge types involved.

int newEdgeType(java.lang.String name, boolean directed, boolean neighbors) <- TRUE


2- Find all the vertices with "property1" as "a" using a Select, as you currently do.

3- Create a single Value local variable outside the loops, which you will reuse to get attributes later:

Value val = new Value();



4- Iterate the Objects from step 2:

ObjectsIterator it_A = nodes_A.iterator();
 
while (it_A.hasNext()) {
       
long oid_A = it_A.next();
 
       
// STEP 5
       
// For each oid_A get its neigbors that fit the B condition
       
// Assuming there's only one possible edge type. You should repteat this
       
// process for each possible edge type.
       
Objects nodes_B = graph.neighbors(oid_A, the_edge_type, EdgesDirection.Outgoing);
       
ObjectsIterator it_B = nodes_B.iterator();
       
while (it_B.hasNext()) {
           
long oid_B = it_B.next();
 
           
// Get the property for the oid_B node
           graph
.getAtrribute(oid_B, theProperty, val);
 
           
// Check if the value fits the condition
         
if ( /* the val is ok */)
         
{
                 
// STEP 6
                 
// Repeat the same process of the step 5 again for the C objects
               
Objects nodes_C = graph.neighbors(oid_B, the_edge_type, EdgesDirection.Outgoing);
               
ObjectsIterator it_C = nodes_C.iterator();
               
while (it_C.hasNext()) {
                   
long oid_C = it_C.next();
 
                   
// Get the property for the oid_C node
                    graph
.getAtrribute(oid_C, theProperty, val);
 
                   
// Check if the value fits the condition
                   
if ( /* the val is ok */)
                   
{
                         
// PATH FOUND: oid_A -> oid_B -> oid_C
                   
}
               
}
                it_C
.close();
                nodes_C
.close();
         
}
       
}
       it_B
.close();
       nodes_B
.close();
 
 
}
 
// Remember to close the iterators and Objects
 it_A
.close();
 nodes_A
.close();


This is not the most elegant or flexible solution, but it will be the fastest because it will avoid  temporary Objects creation.

In fact, temporary objects are returned from the Neighbors operations, but the neighbors are materialized and these Objects are not modified, so I think that should be the fastest implementation possible with Dex.

Best regards

El dimarts 12 de novembre de 2013 19:23:04 UTC+1, jorge castrejon va escriure:

jorge castrejon

unread,
Nov 13, 2013, 2:16:05 PM11/13/13
to dex...@googlegroups.com

Thanks for the answer.
That’s what I was looking for, it’s very similar to my code so there haven’t been any problems incorporating it.
Reply all
Reply to author
Forward
0 new messages