示例#1
0
        /// <summary>
        /// Adds the undirected edge <tt>e</tt> to this edge-weighted graph.
        /// </summary>
        /// <param name="e">e the edge</param>
        /// <exception cref="IndexOutOfRangeException">unless both endpoints are between 0 and V-1</exception>
        public void AddEdge(EdgeW e)
        {
            var v = e.Either();
            var w = e.Other(v);

            ValidateVertex(v);
            ValidateVertex(w);
            _adj[v].Add(e);
            _adj[w].Add(e);
            E++;
        }
示例#2
0
        /// <summary>
        /// relax edge e and update pq if changed
        /// </summary>
        /// <param name="e"></param>
        /// <param name="v"></param>
        private void Relax(EdgeW e, int v)
        {
            var w = e.Other(v);

            if (_distTo[w] > _distTo[v] + e.Weight)
            {
                _distTo[w] = _distTo[v] + e.Weight;
                _edgeTo[w] = e;
                if (_pq.Contains(w))
                {
                    _pq.DecreaseKey(w, _distTo[w]);
                }
                else
                {
                    _pq.Insert(w, _distTo[w]);
                }
            }
        }