Beispiel #1
0
        /// <summary>
        /// Called when a vertex was reached during a forward search.
        /// </summary>
        /// <returns></returns>
        private bool ReachedForward(EdgePath <T> forwardVisit)
        {
            // check backward search for the same vertex.
            EdgePath <T> backwardVisit;

            if (_targetSearch.TryGetVisit(-forwardVisit.Edge, out backwardVisit))
            { // there is a status for this edge in the target search.
                var localWeight = _weightHandler.Zero;
                if (forwardVisit.From != null)
                {
                    localWeight = _weightHandler.Subtract(forwardVisit.Weight, forwardVisit.From.Weight);
                }
                var totalWeight = _weightHandler.Subtract(_weightHandler.Add(forwardVisit.Weight, backwardVisit.Weight), localWeight);
                if (_weightHandler.IsSmallerThan(totalWeight, _best.Item3))
                { // this is a better match.
                    if (forwardVisit.Vertex == backwardVisit.From.Vertex &&
                        (forwardVisit.From.From != null || backwardVisit.From.From != null))
                    { // paths match and are bigger than one edge.
                        _best             = new Tuple <EdgePath <T>, EdgePath <T>, T>(forwardVisit, backwardVisit, totalWeight);
                        this.HasSucceeded = true;
                    }
                }
            }
            return(false);
        }
Beispiel #2
0
        /// <summary>
        /// Called when a vertex was reached during a backward search.
        /// </summary>
        /// <returns></returns>
        private bool ReachedBackward(uint vertex1, T weight1, float length, EdgePath <T> edge)
        {
            // check forward search for the same vertex.
            EdgePath <T> forwardVisit;

            if (_sourceSearch.TryGetVisit(-edge.Edge, out forwardVisit))
            { // there is a status for this vertex in the source search.
                var localWeight = _weightHandler.Subtract(edge.Weight, weight1);
                var totalWeight = _weightHandler.Subtract(_weightHandler.Add(edge.Weight, forwardVisit.Weight), localWeight);
                if (_weightHandler.IsSmallerThan(totalWeight, _best.Item3))
                { // this vertex is a better match.
                    _best             = new Tuple <EdgePath <T>, EdgePath <T>, T>(forwardVisit, edge, totalWeight);
                    this.HasSucceeded = true;
                }
            }
            return(false);
        }