示例#1
0
        private IEnumerable <PrecomputedDijkstraTableRow <TVertex, TEdge> > ComputeRowsSingleSource(
            IVertexAndEdgeListGraph <TVertex, TEdge> graph,
            TVertex sourceVertex,
            Func <TEdge, double> cost, Func <TEdge, double> bound, double maxRadius)
        {
            var dijkstra = new BoundedDijkstraShortestPathAlgorithm <TVertex, TEdge>(graph, cost, bound, maxRadius);

            try
            {
                dijkstra.Compute(sourceVertex);
            }
            catch (OutOfRadiusException)
            {
            }

            var pred = dijkstra.Predecessors;

            foreach (var u in dijkstra.VisitedVertices)
            {
                if (u.Equals(sourceVertex))
                {
                    continue;
                }

                var v = u;
                while (!pred[v].Source.Equals(sourceVertex))
                {
                    v = pred[v].Source;
                }
                graph.TryGetEdge(sourceVertex, v, out var sourceEdge);
                var targetEdge = pred[u];
                var row        = new PrecomputedDijkstraTableRow <TVertex, TEdge>(sourceEdge, targetEdge, dijkstra.GetDistance(u));
                yield return(row);
            }
        }
 /// <inheritdoc />
 public bool TryGetEdge(TVertex source, TVertex target, out TEdge edge)
 {
     return(_baseGraph.TryGetEdge(source, target, out edge));
 }