use of org.neo4j.graphdb.traversal.TraversalDescription in project neo4j by neo4j.
the class TraversalAStar method findPaths.
private Iterable<WeightedPath> findPaths(Node start, Node end, boolean multiplePaths) {
PathInterest interest;
if (multiplePaths) {
interest = stopAfterLowestWeight ? PathInterestFactory.allShortest() : PathInterestFactory.all();
} else {
interest = PathInterestFactory.single();
}
GraphDatabaseService db = start.getGraphDatabase();
TraversalDescription traversalDescription = db.traversalDescription().uniqueness(Uniqueness.NONE).expand(expander, initialState);
lastTraverser = traversalDescription.order(new SelectorFactory(end, interest)).evaluator(includeWhereEndNodeIs(end)).traverse(start);
return new Iterable<WeightedPath>() {
@Override
public Iterator<WeightedPath> iterator() {
return new WeightedPathIterator(lastTraverser.iterator(), costEvaluator, stopAfterLowestWeight);
}
};
}
use of org.neo4j.graphdb.traversal.TraversalDescription in project neo4j by neo4j.
the class TraversalShortestPath method instantiateTraverser.
@Override
protected Traverser instantiateTraverser(Node start, Node end) {
GraphDatabaseService db = start.getGraphDatabase();
TraversalDescription sideBase = db.traversalDescription().breadthFirst().uniqueness(NODE_PATH);
return db.bidirectionalTraversalDescription().mirroredSides(sideBase.expand(expander)).sideSelector(LEVEL_STOP_DESCENT_ON_RESULT, maxDepth).collisionEvaluator(toDepth(maxDepth)).traverse(start, end);
}
use of org.neo4j.graphdb.traversal.TraversalDescription in project neo4j by neo4j.
the class AllPaths method instantiateTraverser.
@Override
protected Traverser instantiateTraverser(Node start, Node end) {
// // Legacy single-directional traversal (for reference or something)
// return traversal().expand( expander ).depthFirst().uniqueness( uniqueness() )
// .evaluator( toDepth( maxDepth ) ).evaluator( Evaluators.includeWhereEndNodeIs( end ) )
// .traverse( start );
// Bidirectional traversal
GraphDatabaseService db = start.getGraphDatabase();
TraversalDescription base = db.traversalDescription().depthFirst().uniqueness(uniqueness());
return db.bidirectionalTraversalDescription().startSide(base.expand(expander).evaluator(toDepth(maxDepth / 2))).endSide(base.expand(expander.reverse()).evaluator(toDepth(maxDepth - maxDepth / 2))).traverse(start, end);
}
use of org.neo4j.graphdb.traversal.TraversalDescription in project neo4j by neo4j.
the class DijkstraBidirectional method traverser.
private Traverser traverser(Node start, final Node end, PathInterest interest) {
final MutableDouble shortestSoFar = new MutableDouble(Double.MAX_VALUE);
final MutableDouble startSideShortest = new MutableDouble(0);
final MutableDouble endSideShortest = new MutableDouble(0);
PathExpander dijkstraExpander = new DijkstraBidirectionalPathExpander(expander, shortestSoFar, true, startSideShortest, endSideShortest, epsilon);
GraphDatabaseService db = start.getGraphDatabase();
TraversalDescription side = db.traversalDescription().expand(dijkstraExpander, stateFactory).order(new DijkstraSelectorFactory(interest, costEvaluator)).evaluator(new DijkstraBidirectionalEvaluator(costEvaluator)).uniqueness(Uniqueness.NODE_PATH);
TraversalDescription startSide = side;
TraversalDescription endSide = side.reverse();
BidirectionalTraversalDescription traversal = db.bidirectionalTraversalDescription().startSide(startSide).endSide(endSide).collisionEvaluator(Evaluators.all()).collisionPolicy(new BranchCollisionPolicy() {
@Override
public BranchCollisionDetector create(Evaluator evaluator, Predicate<Path> pathPredicate) {
return new DijkstraBranchCollisionDetector(evaluator, costEvaluator, shortestSoFar, epsilon, pathPredicate);
}
});
lastTraverser = traversal.traverse(start, end);
return lastTraverser;
}
use of org.neo4j.graphdb.traversal.TraversalDescription in project neo4j by neo4j.
the class ExactDepthPathFinder method instantiateTraverser.
@Override
protected Traverser instantiateTraverser(Node start, Node end) {
GraphDatabaseService db = start.getGraphDatabase();
TraversalDescription side = db.traversalDescription().breadthFirst().uniqueness(uniqueness).order(new BranchOrderingPolicy() {
@Override
public BranchSelector create(TraversalBranch startSource, PathExpander expander) {
return new LiteDepthFirstSelector(startSource, startThreshold, expander);
}
});
return db.bidirectionalTraversalDescription().startSide(side.expand(expander).evaluator(toDepth(onDepth / 2))).endSide(side.expand(expander.reverse()).evaluator(toDepth(onDepth - onDepth / 2))).collisionEvaluator(atDepth(onDepth)).traverse(start, end);
}
Aggregations