예제 #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);
        }
예제 #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);
        }
예제 #3
0
        /// <summary>
        /// Appends the given path in reverse to the edge path.
        /// </summary>
        public static EdgePath <T> Append <T>(this EdgePath <T> path, EdgePath <T> reversePath, WeightHandler <T> weightHandler)
            where T : struct
        {
            if (path.Vertex != reversePath.Vertex)
            {
                throw new System.Exception("Cannot append path that ends with a different vertex.");
            }

            while (reversePath.From != null)
            {
                var localWeight = weightHandler.Subtract(reversePath.Weight, reversePath.From.Weight);
                path        = new EdgePath <T>(reversePath.From.Vertex, weightHandler.Add(path.Weight, localWeight), -reversePath.Edge, path);
                reversePath = reversePath.From;
            }
            return(path);
        }