コード例 #1
0
        /// <summary>
        /// Calculates and updates the shortcuts by searching for witness paths.
        /// </summary>
        public virtual void Calculate(uint vertex, Shortcuts <T> shortcuts)
        {
            var sources      = new HashSet <OriginalEdge>();
            var waitHandlers = new List <ManualResetEvent>();

            while (true)
            {
                var source  = Constants.NO_VERTEX;
                var targets = new Dictionary <uint, Shortcut <T> >();

                foreach (var shortcut in shortcuts)
                {
                    if (source == Constants.NO_VERTEX &&
                        !sources.Contains(shortcut.Key))
                    {
                        source = shortcut.Key.Vertex1;
                        sources.Add(shortcut.Key);
                    }
                    if (shortcut.Key.Vertex1 == source)
                    {
                        targets[shortcut.Key.Vertex2] = shortcut.Value;
                        sources.Add(shortcut.Key);
                    }
                    if (shortcut.Key.Vertex2 == source)
                    {
                        targets[shortcut.Key.Vertex1] = new Shortcut <T>()
                        {
                            Backward = shortcut.Value.Forward,
                            Forward  = shortcut.Value.Backward
                        };
                        sources.Add(shortcut.Key);
                    }
                }

                if (targets.Count == 0)
                { // no more searches needed.
                    break;
                }

                Calculate(_graph, _weightHandler, vertex, source, targets, _maxSettles,
                          _hopLimit);

                foreach (var targetPair in targets)
                {
                    var          e = new OriginalEdge(source, targetPair.Key);
                    Shortcut <T> s;
                    if (shortcuts.TryGetValue(e, out s))
                    {
                        shortcuts[e] = targetPair.Value;
                    }
                    else
                    {
                        e            = e.Reverse();
                        shortcuts[e] = new Shortcut <T>()
                        {
                            Backward = targetPair.Value.Forward,
                            Forward  = targetPair.Value.Backward
                        };
                    }
                }
            }
        }