public override IEnumerator <PropertyContainer> Iterator()
        {
            // TODO Don't loop through them all up front
            LinkedList <PropertyContainer> entities = new LinkedList <PropertyContainer>();
            TraversalBranch branch = _start;

            while (branch.Length() > 0)
            {
                entities.AddFirst(branch.EndNode());
                entities.AddFirst(branch.LastRelationship());
                branch = branch.Parent();
            }
            entities.AddFirst(branch.EndNode());
            if (_cachedStartNode == null)
            {
                _cachedStartNode = branch.EndNode();
            }
            if (_end.length() > 0)
            {
                entities.AddLast(_end.lastRelationship());
                branch = _end.parent();
                while (branch.Length() > 0)
                {
                    entities.AddLast(branch.EndNode());
                    entities.AddLast(branch.LastRelationship());
                    branch = branch.Parent();
                }
                entities.AddLast(branch.EndNode());
            }
            return(entities.GetEnumerator());
        }
Exemple #2
0
        public override IEnumerable <Node> Nodes()
        {
            LinkedList <Node> nodes  = new LinkedList <Node>();
            TraversalBranch   branch = this;

            while (branch.Length() > 0)
            {
                nodes.AddFirst(branch.EndNode());
                branch = branch.Parent();
            }
            nodes.AddFirst(branch.EndNode());
            return(nodes);
        }
Exemple #3
0
        public override IEnumerator <PropertyContainer> Iterator()
        {
            LinkedList <PropertyContainer> entities = new LinkedList <PropertyContainer>();
            TraversalBranch branch = this;

            while (branch.Length() > 0)
            {
                entities.AddFirst(branch.EndNode());
                entities.AddFirst(branch.LastRelationship());
                branch = branch.Parent();
            }
            entities.AddFirst(branch.EndNode());
            return(entities.GetEnumerator());
        }
        private LinkedList <Relationship> GatherRelationships(TraversalBranch first, TraversalBranch then)
        {
            // TODO Don't loop through them all up front
            LinkedList <Relationship> relationships = new LinkedList <Relationship>();
            TraversalBranch           branch        = first;

            while (branch.Length() > 0)
            {
                relationships.AddFirst(branch.LastRelationship());
                branch = branch.Parent();
            }
            // We can might as well cache start node since we're right now there anyway
            if (_cachedStartNode == null && first == _start && branch.Length() >= 0)
            {
                _cachedStartNode = branch.EndNode();
            }
            branch = then;
            while (branch.Length() > 0)
            {
                relationships.AddLast(branch.LastRelationship());
                branch = branch.Parent();
            }
            if (_cachedStartNode == null && then == _start && branch.Length() >= 0)
            {
                _cachedStartNode = branch.EndNode();
            }
            return(relationships);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Override @SuppressWarnings("unchecked") public java.util.Collection<org.neo4j.graphdb.Path> evaluate(org.neo4j.graphdb.traversal.TraversalBranch branch, org.neo4j.graphdb.Direction direction)
        public override ICollection <Path> Evaluate(TraversalBranch branch, Direction direction)
        {
            // [0] for paths from start, [1] for paths from end
            ICollection <TraversalBranch>[] pathsHere = _paths[branch.EndNode()];
            int index = direction.ordinal();

            if (pathsHere == null)
            {
                pathsHere = new System.Collections.ICollection[]
                {
                    new List <TraversalBranch>(),
                    new List <TraversalBranch>()
                };
                _paths[branch.EndNode()] = pathsHere;
            }
            pathsHere[index].Add(branch);

            // If there are paths from the other side then include all the
            // combined paths
            ICollection <TraversalBranch> otherCollections = pathsHere[index == 0 ? 1 : 0];

            if (otherCollections.Count > 0)
            {
                ICollection <Path> foundPaths = new List <Path>();
                foreach (TraversalBranch otherBranch in otherCollections)
                {
                    TraversalBranch startPath             = index == 0 ? branch : otherBranch;
                    TraversalBranch endPath               = index == 0 ? otherBranch : branch;
                    BidirectionalTraversalBranchPath path = new BidirectionalTraversalBranchPath(startPath, endPath);
                    if (IsAcceptablePath(path))
                    {
                        if (_returnedPaths.Add(path) && IncludePath(path, startPath, endPath))
                        {
                            foundPaths.Add(path);
                        }
                    }
                }

                if (foundPaths.Count > 0)
                {
                    return(foundPaths);
                }
            }
            return(null);
        }
Exemple #6
0
            public override TraversalBranch Next(TraversalContext metadata)
            {
                // Exhaust current if not already exhausted
                while (true)
                {
                    TraversalBranch next = Current.next(Expander, metadata);
                    if (next == null)
                    {
                        break;
                    }

                    long      endNodeId = next.EndNode().Id;
                    Visit <P> stay      = Visits[endNodeId];

                    D cost        = outerInstance.CalculateValue(next);
                    P newPriority = outerInstance.AddPriority(next, CurrentAggregatedValue, cost);

                    bool newStay = stay == null;
                    if (newStay)
                    {
                        stay = new Visit <P>(newPriority);
                        Visits[endNodeId] = stay;
                    }
                    if (newStay || !outerInstance.interest.CanBeRuledOut(stay.VisitCount, newPriority, stay.Cost))
                    {
                        if (outerInstance.interest.Comparator().Compare(newPriority, stay.Cost) < 0)
                        {
                            stay.Cost = newPriority;
                        }
                        Queue.put(next, newPriority);
                    }
                }

                do
                {
                    // Pop the top from priorityMap
                    Entry <TraversalBranch, P> entry = Queue.pop();
                    if (entry != null)
                    {
                        Current = entry.Entity;
                        Visit <P> stay = Visits[Current.endNode().Id];
                        stay.VisitCount++;
                        if (outerInstance.interest.StillInteresting(stay.VisitCount))
                        {
                            CurrentAggregatedValue = entry.Priority;
                            return(Current);
                        }
                    }
                    else
                    {
                        return(null);
                    }
                } while (true);
            }
        private IEnumerable <Node> GatherNodes(TraversalBranch first, TraversalBranch then)
        {
            // TODO Don't loop through them all up front
            LinkedList <Node> nodes  = new LinkedList <Node>();
            TraversalBranch   branch = first;

            while (branch.Length() > 0)
            {
                nodes.AddFirst(branch.EndNode());
                branch = branch.Parent();
            }
            if (_cachedStartNode == null && first == _start && branch.Length() >= 0)
            {
                _cachedStartNode = branch.EndNode();
            }
            nodes.AddFirst(branch.EndNode());
            branch = then.Parent();
            if (branch != null)
            {
                while (branch.Length() > 0)
                {
                    nodes.AddLast(branch.EndNode());
                    branch = branch.Parent();
                }
                if (branch.Length() >= 0)
                {
                    nodes.AddLast(branch.EndNode());
                }
            }
            if (_cachedStartNode == null && then == _start && branch != null && branch.Length() >= 0)
            {
                _cachedStartNode = branch.EndNode();
            }
            return(nodes);
        }
Exemple #8
0
 protected internal override PositionData AddPriority(TraversalBranch source, PositionData currentAggregatedValue, double?value)
 {
     return(new PositionData(currentAggregatedValue.WayLengthG + value, outerInstance.estimateEvaluator.GetCost(source.EndNode(), End)));
 }