Exemple #1
0
        private IEnumerable <IBlock> ShortestPathBlocks(IBlock start, IBlock end)
        {
            yield return(null);

            IEnumerable <DirectedEdge> path = DijkstraShortestPath.FindPath(_graph, IndexFor(start), IndexFor(end));

            if (path == null)
            {
                yield return(null);
            }
            else
            {
                yield return(start);

                foreach (DirectedEdge edge in path)
                {
                    yield return(BlockFor(edge.To));
                }
            }
        }
        /// <summary>
        /// Returns an IEnumerable of DirectedEdges representing a shortest path from the specified sourceVertex to the specified destinationVertex
        /// This is more efficent than creating a new DijkstraShorestPath instance and calling PathTo( destinationVertex ) when we only
        /// want a single path from Source to Destination and don't want many paths from the source to multiple different destinations.
        /// </summary>
        /// <param name="graph">The edge-weighted directed graph</param>
        /// <param name="sourceVertex">The source vertext to find a shortest path from</param>
        /// <param name="destinationVertex">The destination vertex to find a shortest path to</param>
        public static IEnumerable <DirectedEdge> FindPath(EdgeWeightedDigraph graph, int sourceVertex, int destinationVertex)
        {
            var dijkstraShortestPath = new DijkstraShortestPath(graph, sourceVertex, destinationVertex);

            return(dijkstraShortestPath.PathTo(destinationVertex));
        }