コード例 #1
0
        private IEnumerable <Cell> ShortestPathCells(Cell source, Cell destination)
        {
            IEnumerable <DirectedEdge> path = DijkstraShortestPath
                                              .FindPath(_graph, IndexFor(source.Point), IndexFor(destination.Point));

            if (path == null)
            {
                yield break;
            }

            yield return(source);

            foreach (DirectedEdge edge in path)
            {
                yield return(CellFor(edge.To));
            }
        }
コード例 #2
0
        public List <Point> ShortestPathList(Point source, Point destination)
        {
            var list = new List <Point>();
            IEnumerable <DirectedEdge> path = DijkstraShortestPath
                                              .FindPath(_graph, IndexFor(source), IndexFor(destination));

            if (path == null)
            {
                return(list);
            }

            foreach (DirectedEdge edge in path)
            {
                list.Add(CoordFor(edge.To));
            }

            return(list);
        }
コード例 #3
0
        public static IEnumerable <DirectedEdge> FindPath(EdgeWeightedDigraph graph, int sourceVertex, int destinationVertex)
        {
            var dijkstraShortestPath = new DijkstraShortestPath(graph, sourceVertex, destinationVertex);

            return(dijkstraShortestPath.PathTo(destinationVertex));
        }