/// <summary>
        /// Computes the k-shortest path from <paramref name="source"/>
        /// <paramref name="target"/> using Hoffman-Pavley algorithm.
        /// </summary>
        /// <typeparam name="TVertex">type of the vertices</typeparam>
        /// <typeparam name="TEdge">type of the edges</typeparam>
        /// <param name="visitedGraph"></param>
        /// <param name="edgeWeights"></param>
        /// <param name="source"></param>
        /// <param name="target"></param>
        /// <param name="pathCount"></param>
        /// <returns></returns>
        public static IEnumerable <IEnumerable <TEdge> > RankedShortestPathHoffmanPavley <TVertex, TEdge>(
            this IBidirectionalGraph <TVertex, TEdge> visitedGraph,
            Func <TEdge, double> edgeWeights,
            TVertex source,
            TVertex target,
            int pathCount)
            where TEdge : IEdge <TVertex>
        {
            Contract.Requires(visitedGraph != null);
            Contract.Requires(edgeWeights != null);
            Contract.Requires(source != null && visitedGraph.ContainsVertex(source));
            Contract.Requires(target != null && visitedGraph.ContainsVertex(target));
            Contract.Requires(pathCount > 1);

            var algo = new HoffmanPavleyRankedShortestPathAlgorithm <TVertex, TEdge>(visitedGraph, edgeWeights);

            algo.ShortestPathCount = pathCount;
            algo.Compute(source, target);

            return(algo.ComputedShortestPaths);
        }
示例#2
0
        /// <summary>
        /// Recursively collects all vertices that can be reached from a given vertex
        /// by traversing only those edges that are chosen by a given predicate.
        /// </summary>
        public static IEnumerable <TVertex> GetAdjacentVertices <TVertex, TEdge>(this IBidirectionalGraph <TVertex, TEdge> graph,
                                                                                 TVertex vertex, EdgeDirection direction, EdgePredicate <TVertex, TEdge> edgePredicate = null, bool recursive = false)
            where TEdge : IEdge <TVertex>
        {
            if (!graph.ContainsVertex(vertex))
            {
                return(Enumerable.Empty <TVertex>());
            }

            var collectedVertices = new List <TVertex>();

            CollectAdjacentVerticesRecursive(graph, vertex, direction, collectedVertices, edgePredicate, recursive);
            return(collectedVertices.Except(vertex));
        }
 /// <inheritdoc />
 public bool ContainsVertex(TVertex vertex)
 {
     return(OriginalGraph.ContainsVertex(vertex));
 }