Ejemplo n.º 1
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);
            }
Ejemplo n.º 2
0
 protected internal override Node fetchNextOrNull()
 {
     try
     {
         return(branch.length() >= 0 ? branch.endNode() : null);
     }
     finally
     {
         branch = branch.parent();
     }
 }