public override void Reset()
        {
            base.Reset();
            Distances = new Dictionary <Node, CostType>();
            Dictionary <Node, CostType> seen1  = new Dictionary <Node, CostType>();
            Dictionary <Node, CostType> seen2  = new Dictionary <Node, CostType>();
            Dictionary <Node, CostType> dists2 = new Dictionary <Node, CostType>();

            DijkstraIterator = new DijkstraIterator(this, StartNodeConflict, Predecessors1, seen1, seen2, Distances, dists2, false);
        }
Exemple #2
0
        /// <summary>
        /// Makes the main calculation If some limit is set, the shortest path(s)
        /// that could be found within those limits will be calculated.
        /// </summary>
        /// <returns> True if a path was found. </returns>
        public virtual bool Calculate()
        {
            // Do this first as a general error check since this is supposed to be
            // called whenever a result is asked for.
            if (StartNodeConflict == null || EndNodeConflict == null)
            {
                throw new Exception("Start or end node undefined.");
            }
            // Don't do it more than once
            if (DoneCalculation)
            {
                return(true);
            }
            DoneCalculation = true;
            // Special case when path length is zero
            if (StartNodeConflict.Equals(EndNodeConflict))
            {
                FoundPathsMiddleNodes = new HashSet <Node>();
                FoundPathsMiddleNodes.Add(StartNodeConflict);
                FoundPathsCost = CostAccumulator.addCosts(StartCost, StartCost);
                return(true);
            }
            Dictionary <Node, CostType> seen1  = new Dictionary <Node, CostType>();
            Dictionary <Node, CostType> seen2  = new Dictionary <Node, CostType>();
            Dictionary <Node, CostType> dists1 = new Dictionary <Node, CostType>();
            Dictionary <Node, CostType> dists2 = new Dictionary <Node, CostType>();
            DijkstraIterator            iter1  = new DijkstraIterator(this, StartNodeConflict, Predecessors1, seen1, seen2, dists1, dists2, false);
            DijkstraIterator            iter2  = new DijkstraIterator(this, EndNodeConflict, Predecessors2, seen2, seen1, dists2, dists1, true);
            Node node1 = null;
            Node node2 = null;

            while (iter1.MoveNext() && iter2.MoveNext())
            {
                if (LimitReached())
                {
                    break;
                }
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                if (iter1.HasNext())
                {
                    node1 = iter1.Current;
                    if (node1 == null)
                    {
                        break;
                    }
                }
                if (LimitReached())
                {
                    break;
                }
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                if (!iter1.Done && iter2.HasNext())
                {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                    node2 = iter2.Next();
                    if (node2 == null)
                    {
                        break;
                    }
                }
                if (LimitReached(seen1[node1], seen2[node2]))
                {
                    break;
                }
                if (iter1.Done || iter2.Done)                           // A path was found
                {
                    return(true);
                }
            }

            return(false);
        }