use of org.neo4j.graphdb.traversal.BranchCollisionPolicy 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.BranchCollisionPolicy in project neo4j by neo4j.
the class TestBidirectionalTraversal method mirroredTraversalReversesInitialState.
@Test
void mirroredTraversalReversesInitialState() {
/*
* (a)-->(b)-->(c)-->(d)
*/
createGraph("a TO b", "b TO c", "c TO d");
try (Transaction transaction = getGraphDb().beginTx()) {
BranchCollisionPolicy collisionPolicy = (evaluator, pathPredicate) -> new StandardBranchCollisionDetector(null, null) {
@Override
protected boolean includePath(Path path, TraversalBranch startPath, TraversalBranch endPath) {
assertEquals(0, startPath.state());
assertEquals(10, endPath.state());
return true;
}
};
Iterables.count(transaction.bidirectionalTraversalDescription().mirroredSides(transaction.traversalDescription().uniqueness(NODE_PATH).expand(PathExpanders.forType(to), new InitialBranchState.State<>(0, 10))).collisionPolicy(collisionPolicy).traverse(getNodeWithName(transaction, "a"), getNodeWithName(transaction, "d")));
}
}
Aggregations