Search in sources :

Example 16 with TraversalDescription

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);
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) TraversalDescription(org.neo4j.graphdb.traversal.TraversalDescription)

Example 17 with TraversalDescription

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;
}
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 18 with TraversalDescription

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);
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) BranchOrderingPolicy(org.neo4j.graphdb.traversal.BranchOrderingPolicy) TraversalDescription(org.neo4j.graphdb.traversal.TraversalDescription) LiteDepthFirstSelector(org.neo4j.graphalgo.impl.util.LiteDepthFirstSelector) PathExpander(org.neo4j.graphdb.PathExpander) TraversalBranch(org.neo4j.graphdb.traversal.TraversalBranch) BranchSelector(org.neo4j.graphdb.traversal.BranchSelector)

Example 19 with TraversalDescription

use of org.neo4j.graphdb.traversal.TraversalDescription in project jo-client-platform by jo-source.

the class SyncNeo4JSimpleTraversalReaderServiceImpl method getAllRelatedBeans.

private Set<? extends BEAN_TYPE> getAllRelatedBeans(final List<? extends IBeanKey> parentBeans, final PARAM_TYPE parameter, final IExecutionCallback executionCallback) {
    final Set<BEAN_TYPE> result = new LinkedHashSet<BEAN_TYPE>();
    for (final IBeanKey beanKey : parentBeans) {
        CapServiceToolkit.checkCanceled(executionCallback);
        final Node parentNode = NodeAccess.findNode(parentBeanTypeId, beanKey.getId());
        if (parentNode != null) {
            for (final TraversalDescription traversalDescription : traversalDescriptions) {
                for (final Node resultNode : traversalDescription.traverse(parentNode).nodes()) {
                    CapServiceToolkit.checkCanceled(executionCallback);
                    if (resultNode.hasProperty(beanTypePropertyName) && beanTypeIdString.equals(resultNode.getProperty(beanTypePropertyName))) {
                        result.add(beanFactory.createNodeBean(beanType, beanTypeId, resultNode));
                    }
                }
            }
        }
    }
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) IBeanKey(org.jowidgets.cap.common.api.bean.IBeanKey) Node(org.neo4j.graphdb.Node) TraversalDescription(org.neo4j.graphdb.traversal.TraversalDescription)

Example 20 with TraversalDescription

use of org.neo4j.graphdb.traversal.TraversalDescription in project graphdb by neo4j-attic.

the class OldTraverserWrapper method traversal.

private static TraversalDescription traversal(TraverserImpl traverser, Order order, StopEvaluator stopEvaluator, ReturnableEvaluator returnableEvaluator) {
    TraversalDescription description = BASE_DESCRIPTION;
    switch(order) {
        case BREADTH_FIRST:
            description = description.breadthFirst();
            break;
        case DEPTH_FIRST:
            description = description.depthFirst();
            break;
        default:
            throw new IllegalArgumentException("Onsupported traversal order: " + order);
    }
    description = description.prune(new Pruner(traverser, stopEvaluator));
    description = description.filter(new Filter(traverser, returnableEvaluator));
    return description;
}
Also used : TraversalDescription(org.neo4j.graphdb.traversal.TraversalDescription)

Aggregations

TraversalDescription (org.neo4j.graphdb.traversal.TraversalDescription)37 Test (org.junit.Test)20 Node (org.neo4j.graphdb.Node)12 Path (org.neo4j.graphdb.Path)12 Transaction (org.neo4j.graphdb.Transaction)7 Evaluator (org.neo4j.graphdb.traversal.Evaluator)6 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)5 HashMap (java.util.HashMap)3 WeightedPath (org.neo4j.graphalgo.WeightedPath)3 LiteDepthFirstSelector (org.neo4j.graphalgo.impl.util.LiteDepthFirstSelector)3 BidirectionalTraversalDescription (org.neo4j.graphdb.traversal.BidirectionalTraversalDescription)3 BranchOrderingPolicy (org.neo4j.graphdb.traversal.BranchOrderingPolicy)3 BranchSelector (org.neo4j.graphdb.traversal.BranchSelector)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Direction (org.neo4j.graphdb.Direction)2 PathExpander (org.neo4j.graphdb.PathExpander)2 Relationship (org.neo4j.graphdb.Relationship)2 RelationshipType (org.neo4j.graphdb.RelationshipType)2 TraversalBranch (org.neo4j.graphdb.traversal.TraversalBranch)2