java - Random Postorder traversal in neo4j -


i'm trying create algorithm in neo4j using java api. algorithm called grail (http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.169.1656&rep=rep1&type=pdf) , assigns labels graph later answering reachability queries.

this algorithm uses postorder depth first search random traversal each time (each child of node visited randomly in each traversal). in neo4j java api there algorithm doing (https://github.com/neo4j/neo4j/blob/7f47df8b5d61b0437e39298cd15e840aa1bcfed8/community/kernel/src/main/java/org/neo4j/graphdb/traversal/postorderdepthfirstselector.java) without randomness , can't seem find way this.

my code has traversal description in want add custom order (branchorderingpolicy) in order achieve before mentioned algorithm. this:

 .order(**postorderdepthfirst()**) 

the answer question came rather easy after lot of thinking. had alter path expander (i created own) returns relationhipss traversal takes next , there simple line of code randomize relationships. code :

public class customexpander implements pathexpander {

private final relationshiptype relationshiptype; private final direction direction; private final integer times;  public customexpander (relationshiptype relationshiptype, direction direction ,integer times) {     this.relationshiptype = relationshiptype;     this.direction = direction;     this.times=times; }    @override public iterable<relationship> expand(path path, branchstate state) {         list<relationship> results = new arraylist<relationship>();         ( relationship r : path.endnode().getrelationships( relationshiptype, direction ) )         {              results.add( r );          }         collections.shuffle(results);         }            return results;              }   @override public pathexpander<string> reverse() {     return null; } 

}


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -