Search in sources :

Example 1 with DijkstraSelectorFactory

use of org.neo4j.graphalgo.impl.util.DijkstraSelectorFactory 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)

Example 2 with DijkstraSelectorFactory

use of org.neo4j.graphalgo.impl.util.DijkstraSelectorFactory in project neo4j by neo4j.

the class DijkstraBidirectional method traverser.

private Traverser traverser(Node start, final Node end, PathInterest<Double> interest) {
    final MutableDouble shortestSoFar = new MutableDouble(Double.MAX_VALUE);
    final MutableDouble startSideShortest = new MutableDouble(0);
    final MutableDouble endSideShortest = new MutableDouble(0);
    PathExpander<Double> dijkstraExpander = new DijkstraBidirectionalPathExpander(expander, shortestSoFar, true, startSideShortest, endSideShortest, epsilon);
    var transaction = context.transaction();
    TraversalDescription side = transaction.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 = transaction.bidirectionalTraversalDescription().startSide(startSide).endSide(endSide).collisionEvaluator(Evaluators.all()).collisionPolicy((evaluator, pathPredicate) -> new DijkstraBranchCollisionDetector(evaluator, costEvaluator, shortestSoFar, epsilon, pathPredicate));
    lastTraverser = traversal.traverse(start, end);
    return lastTraverser;
}
Also used : MutableDouble(org.apache.commons.lang3.mutable.MutableDouble) BidirectionalTraversalDescription(org.neo4j.graphdb.traversal.BidirectionalTraversalDescription) TraversalDescription(org.neo4j.graphdb.traversal.TraversalDescription) DijkstraBranchCollisionDetector(org.neo4j.graphalgo.impl.util.DijkstraBranchCollisionDetector) DijkstraSelectorFactory(org.neo4j.graphalgo.impl.util.DijkstraSelectorFactory) MutableDouble(org.apache.commons.lang3.mutable.MutableDouble) BidirectionalTraversalDescription(org.neo4j.graphdb.traversal.BidirectionalTraversalDescription)

Example 3 with DijkstraSelectorFactory

use of org.neo4j.graphalgo.impl.util.DijkstraSelectorFactory in project neo4j by neo4j.

the class Dijkstra method traverser.

private Traverser traverser(Node start, final Node end, PathInterest<Double> interest) {
    MutableDouble shortestSoFar = new MutableDouble(Double.MAX_VALUE);
    PathExpander<Double> dijkstraExpander = new DijkstraPathExpander(expander, shortestSoFar, epsilon, interest.stopAfterLowestCost());
    PathEvaluator<Double> dijkstraEvaluator = new DijkstraEvaluator(shortestSoFar, end, costEvaluator);
    lastTraverser = new MonoDirectionalTraversalDescription().uniqueness(Uniqueness.NODE_PATH).expand(dijkstraExpander, stateFactory).order(new DijkstraSelectorFactory(interest, costEvaluator)).evaluator(dijkstraEvaluator).traverse(start);
    return lastTraverser;
}
Also used : MutableDouble(org.apache.commons.lang3.mutable.MutableDouble) MonoDirectionalTraversalDescription(org.neo4j.kernel.impl.traversal.MonoDirectionalTraversalDescription) DijkstraSelectorFactory(org.neo4j.graphalgo.impl.util.DijkstraSelectorFactory) MutableDouble(org.apache.commons.lang3.mutable.MutableDouble)

Aggregations

MutableDouble (org.apache.commons.lang3.mutable.MutableDouble)3 DijkstraSelectorFactory (org.neo4j.graphalgo.impl.util.DijkstraSelectorFactory)3 DijkstraBranchCollisionDetector (org.neo4j.graphalgo.impl.util.DijkstraBranchCollisionDetector)2 BidirectionalTraversalDescription (org.neo4j.graphdb.traversal.BidirectionalTraversalDescription)2 TraversalDescription (org.neo4j.graphdb.traversal.TraversalDescription)2 CostEvaluator (org.neo4j.graphalgo.CostEvaluator)1 WeightedPath (org.neo4j.graphalgo.WeightedPath)1 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)1 Path (org.neo4j.graphdb.Path)1 PathExpander (org.neo4j.graphdb.PathExpander)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 MonoDirectionalTraversalDescription (org.neo4j.kernel.impl.traversal.MonoDirectionalTraversalDescription)1