예제 #1
0
        /// <summary>
        /// Gets the paths.
        /// </summary>
        public EdgePath <T> GetPath(int source, int target)
        {
            this.CheckHasRunAndHasSucceeded();

            var solution = _paths[source][target];

            if (solution.Path != null)
            {
                return(solution.Path);
            }
            if (solution.Path1 == null ||
                solution.Path2 == null)
            {
                return(null);
            }

            var vertices   = new List <uint>();
            var fromSource = solution.Path1.Expand(_graph, _weightHandler, true);
            var toTarget   = solution.Path2.Expand(_graph, _weightHandler, false);

            // add vertices from source.
            vertices.Add(fromSource.Vertex);
            while (fromSource.From != null)
            {
                if (fromSource.From.Vertex != Constants.NO_VERTEX)
                {     // this should be the end of the path.
                    if (fromSource.Edge == Constants.NO_EDGE)
                    { // only expand when there is no edge id.
                        _graph.ExpandEdge(fromSource.From.Vertex, fromSource.Vertex, vertices, false, true);
                    }
                }
                vertices.Add(fromSource.From.Vertex);
                fromSource = fromSource.From;
            }
            vertices.Reverse();

            // and add vertices to target.
            while (toTarget.From != null)
            {
                if (toTarget.From.Vertex != Constants.NO_VERTEX)
                {     // this should be the end of the path.
                    if (toTarget.Edge == Constants.NO_EDGE)
                    { // only expand when there is no edge id.
                        _graph.ExpandEdge(toTarget.From.Vertex, toTarget.Vertex, vertices, false, false);
                    }
                }
                vertices.Add(toTarget.From.Vertex);
                toTarget = toTarget.From;
            }

            return(_routerDb.BuildEdgePath(_weightHandler, _sources[source], _targets[target], vertices));
        }