Ejemplo n.º 1
0
            public override Node Next()
            {
                if (!HasNext())
                {
                    throw new NoSuchElementException();
                }

                Node     currentNode = Queue.extractMin();
                CostType currentCost = MySeen[currentNode];

                // Already done with this node?
                if (MyDistances.ContainsKey(currentNode))
                {
                    return(null);
                }
                if (outerInstance.LimitReached())
                {
                    return(null);
                }
                ++outerInstance.NumberOfNodesTraversed;
                MyDistances[currentNode] = currentCost;
                // TODO: remove from seen or not? probably not... because of path
                // detection
                // Check if we have found a better path
                CheckForPath(currentNode, currentCost, OtherSeen);
                // Found a path? (abort traversing from this node)
                if (OtherDistances.ContainsKey(currentNode))
                {
                    OneShortestPathHasBeenFound = true;
                }
                else
                {
                    // Otherwise, follow all edges from this node
                    foreach (RelationshipType costRelationType in outerInstance.CostRelationTypes)
                    {
                        ResourceIterable <Relationship> relationships = Iterables.asResourceIterable(currentNode.GetRelationships(costRelationType, Direction));
                        using (ResourceIterator <Relationship> iterator = relationships.GetEnumerator())
                        {
                            while (iterator.MoveNext())
                            {
                                Relationship relationship = iterator.Current;
                                if (outerInstance.LimitReached())
                                {
                                    break;
                                }
                                ++outerInstance.NumberOfTraversedRelationShips;
                                // Target node
                                Node target = relationship.GetOtherNode(currentNode);
                                if (OtherDistances.ContainsKey(target))
                                {
                                    continue;
                                }
                                // Find out if an eventual path would go in the opposite
                                // direction of the edge
                                bool     backwardsEdge = relationship.EndNode.Equals(currentNode) ^ Backwards;
                                CostType newCost       = outerInstance.CostAccumulator.addCosts(currentCost, outerInstance.CostEvaluator.getCost(relationship, backwardsEdge ? Direction.INCOMING : Direction.OUTGOING));
                                // Already done with target node?
                                if (MyDistances.ContainsKey(target))
                                {
                                    // Have we found a better cost for a node which is
                                    // already
                                    // calculated?
                                    if (outerInstance.CostComparator.Compare(MyDistances[target], newCost) > 0)
                                    {
                                        throw new Exception("Cycle with negative costs found.");
                                    }
                                    // Equally good path found?
                                    else if (outerInstance.CalculateAllShortestPaths && outerInstance.CostComparator.Compare(MyDistances[target], newCost) == 0)
                                    {
                                        // Put it in predecessors
                                        IList <Relationship> myPredecessors = Predecessors[currentNode];
                                        // Dont do it if this relation is already in
                                        // predecessors (other direction)
                                        if (myPredecessors == null || !myPredecessors.Contains(relationship))
                                        {
                                            IList <Relationship> predList = Predecessors[target];
                                            if (predList == null)
                                            {
                                                // This only happens if we get back to
                                                // the
                                                // start node, which is just bogus
                                            }
                                            else
                                            {
                                                predList.Add(relationship);
                                            }
                                        }
                                    }
                                    continue;
                                }
                                // Have we found a better cost for this node?
                                if (!MySeen.ContainsKey(target) || outerInstance.CostComparator.Compare(MySeen[target], newCost) > 0)
                                {
                                    // Put it in the queue
                                    if (!MySeen.ContainsKey(target))
                                    {
                                        Queue.insertValue(target, newCost);
                                    }
                                    // or update the entry. (It is important to keep
                                    // these
                                    // cases apart to limit the size of the queue)
                                    else
                                    {
                                        Queue.decreaseValue(target, newCost);
                                    }
                                    // Update it
                                    MySeen[target] = newCost;
                                    // Put it in predecessors
                                    IList <Relationship> predList = new LinkedList <Relationship>();
                                    predList.Add(relationship);
                                    Predecessors[target] = predList;
                                }
                                // Have we found an equal cost for (additional path to)
                                // this
                                // node?
                                else if (outerInstance.CalculateAllShortestPaths && outerInstance.CostComparator.Compare(MySeen[target], newCost) == 0)
                                {
                                    // Put it in predecessors
                                    IList <Relationship> predList = Predecessors[target];
                                    predList.Add(relationship);
                                }
                            }
                        }
                    }
                }
                // Check how far we need to continue when searching for all shortest
                // paths
                if (outerInstance.CalculateAllShortestPaths && OneShortestPathHasBeenFound)
                {
                    // If we cannot continue or continuation would only find more
                    // expensive paths: conclude that all shortest paths have been
                    // found.
                    AllShortestPathsHasBeenFound = Queue.Empty || outerInstance.CostComparator.Compare(MySeen[Queue.peek()], currentCost) > 0;
                }
                return(currentNode);
            }
Ejemplo n.º 2
0
 internal virtual IList <object> GetObjectsAsList(ResourceIterator <IDictionary <string, object> > r, string key)
 {
     return(r.Select(s => s.get(key)).ToList());
 }
Ejemplo n.º 3
0
 internal virtual void AssertKeyIs(ResourceIterator <IDictionary <string, object> > r, string key, params object[] items)
 {
     AssertKeyIsArray(r, key, items);
 }
Ejemplo n.º 4
0
        private ISet <string> GetFileNames(ResourceIterator <File> files)
        {
//JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter:
            return(Files.Select(File.getAbsolutePath).Where(this.segmentsFilePredicate).collect(Collectors.toSet()));
        }
Ejemplo n.º 5
0
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
//ORIGINAL LINE: public static <T> org.neo4j.graphdb.ResourceIterable<T> asResourceIterable(final org.neo4j.graphdb.ResourceIterator<T> it)
        public static ResourceIterable <T> AsResourceIterable <T>(ResourceIterator <T> it)
        {
            return(() => it);
        }
Ejemplo n.º 6
0
 private void AssertKeyIs(ResourceIterator <IDictionary <string, object> > r, string key, params string[] items)
 {
     AssertKeyIsArray(r, key, items);
 }
Ejemplo n.º 7
0
 public MappingResourceIteratorAnonymousInnerClass(ResourceIterableWrapper <T, U> outerInstance, ResourceIterator <U> iterator) : base(iterator)
 {
     this.outerInstance = outerInstance;
 }
Ejemplo n.º 8
0
 public MappingResourceIteratorAnonymousInnerClass(NodeExpansion outerInstance, ResourceIterator <Relationship> doExpand, Node node) : base(doExpand)
 {
     this.outerInstance = outerInstance;
     this._node         = node;
 }
Ejemplo n.º 9
0
 public MappingResourceIterator(ResourceIterator <S> sourceResourceIterator)
 {
     this._sourceIterator = sourceResourceIterator;
 }
        internal virtual void AssertEmpty(ResourceIterator <R> iterator)
        {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertFalse("no more", iterator.hasNext());
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Instantiates a new limiting iterator which iterates over {@code source}
 /// and if {@code limit} items have been returned the next <seealso cref="hasNext()"/>
 /// will return {@code false}.
 /// </summary>
 /// <param name="source"> the source of items. </param>
 /// <param name="limit"> the limit, i.e. the max number of items to return. </param>
 public LimitingResourceIterator(ResourceIterator <T> source, int limit)
 {
     this._source = source;
     this._limit  = limit;
 }
Ejemplo n.º 12
0
 public PrefetchingResourceIteratorAnonymousInnerClass(ResourcePathIterableWrapperAnonymousInnerClass2 outerInstance, ResourceIterator <Path> pathIterator)
 {
     this.outerInstance = outerInstance;
     this._pathIterator = pathIterator;
 }
Ejemplo n.º 13
0
 private void GetSnapshotFilesMetadata(ResourceIterator <File> snapshot, ICollection <StoreFileMetadata> targetFiles)
 {
     snapshot.Select(_toStoreFileMetatadata).ForEach(targetFiles.add);
 }
Ejemplo n.º 14
0
 internal ExceptionConversion(ResourceIterator <T> inner)
 {
     this.Inner = inner;
 }