Search in sources :

Example 1 with CostEvaluator

use of org.neo4j.graphalgo.CostEvaluator 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;
}
Also used : WeightedPath(org.neo4j.graphalgo.WeightedPath) Path(org.neo4j.graphdb.Path) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) BranchCollisionPolicy(org.neo4j.graphdb.traversal.BranchCollisionPolicy) MutableDouble(org.apache.commons.lang3.mutable.MutableDouble) PathExpander(org.neo4j.graphdb.PathExpander) DijkstraSelectorFactory(org.neo4j.graphalgo.impl.util.DijkstraSelectorFactory) PathEvaluator(org.neo4j.graphdb.traversal.PathEvaluator) Evaluator(org.neo4j.graphdb.traversal.Evaluator) CostEvaluator(org.neo4j.graphalgo.CostEvaluator) BidirectionalTraversalDescription(org.neo4j.graphdb.traversal.BidirectionalTraversalDescription) BranchCollisionDetector(org.neo4j.graphdb.traversal.BranchCollisionDetector) DijkstraBranchCollisionDetector(org.neo4j.graphalgo.impl.util.DijkstraBranchCollisionDetector) BidirectionalTraversalDescription(org.neo4j.graphdb.traversal.BidirectionalTraversalDescription) TraversalDescription(org.neo4j.graphdb.traversal.TraversalDescription) DijkstraBranchCollisionDetector(org.neo4j.graphalgo.impl.util.DijkstraBranchCollisionDetector)

Aggregations

MutableDouble (org.apache.commons.lang3.mutable.MutableDouble)1 CostEvaluator (org.neo4j.graphalgo.CostEvaluator)1 WeightedPath (org.neo4j.graphalgo.WeightedPath)1 DijkstraBranchCollisionDetector (org.neo4j.graphalgo.impl.util.DijkstraBranchCollisionDetector)1 DijkstraSelectorFactory (org.neo4j.graphalgo.impl.util.DijkstraSelectorFactory)1 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)1 Path (org.neo4j.graphdb.Path)1 PathExpander (org.neo4j.graphdb.PathExpander)1 BidirectionalTraversalDescription (org.neo4j.graphdb.traversal.BidirectionalTraversalDescription)1 BranchCollisionDetector (org.neo4j.graphdb.traversal.BranchCollisionDetector)1 BranchCollisionPolicy (org.neo4j.graphdb.traversal.BranchCollisionPolicy)1 Evaluator (org.neo4j.graphdb.traversal.Evaluator)1 PathEvaluator (org.neo4j.graphdb.traversal.PathEvaluator)1 TraversalDescription (org.neo4j.graphdb.traversal.TraversalDescription)1