public static TryFunc <TVertex, IEnumerable <TEdge> > ShortestPathsDag <TVertex, TEdge>( #if !NET20 this #endif IVertexAndEdgeListGraph <TVertex, TEdge> visitedGraph, Func <TEdge, double> edgeWeights, TVertex source ) where TEdge : IEdge <TVertex> { Contract.Requires(visitedGraph != null); Contract.Requires(edgeWeights != null); Contract.Requires(source != null); var algorithm = new DagShortestPathAlgorithm <TVertex, TEdge>(visitedGraph, edgeWeights); var predecessorRecorder = new VertexPredecessorRecorderObserver <TVertex, TEdge>(); using (predecessorRecorder.Attach(algorithm)) algorithm.Compute(source); var predecessors = predecessorRecorder.VertexPredecessors; return(delegate(TVertex v, out IEnumerable <TEdge> edges) { return EdgeExtensions.TryGetPath(predecessors, v, out edges); }); }
public static TryFunc <TVertex, IEnumerable <TEdge> > TreeCyclePoppingRandom <TVertex, TEdge>( #if !NET20 this #endif IVertexListGraph <TVertex, TEdge> visitedGraph, TVertex root, IMarkovEdgeChain <TVertex, TEdge> edgeChain) where TEdge : IEdge <TVertex> { Contract.Requires(visitedGraph != null); Contract.Requires(root != null); Contract.Requires(visitedGraph.ContainsVertex(root)); Contract.Ensures(Contract.Result <TryFunc <TVertex, IEnumerable <TEdge> > >() != null); var algo = new CyclePoppingRandomTreeAlgorithm <TVertex, TEdge>(visitedGraph, edgeChain); var predecessorRecorder = new VertexPredecessorRecorderObserver <TVertex, TEdge>(); using (predecessorRecorder.Attach(algo)) algo.Compute(root); var predecessors = predecessorRecorder.VertexPredecessors; return(delegate(TVertex v, out IEnumerable <TEdge> edges) { return EdgeExtensions.TryGetPath(predecessors, v, out edges); }); }
public static TryFunc <TVertex, IEnumerable <TEdge> > TreeBreadthFirstSearch <TVertex, TEdge>( #if !NET20 this #endif IVertexListGraph <TVertex, TEdge> visitedGraph, TVertex root) where TEdge : IEdge <TVertex> { //Contract.Requires(visitedGraph != null); //Contract.Requires(root != null); //Contract.Requires(visitedGraph.ContainsVertex(root)); //Contract.Ensures(//Contract.Result<TryFunc<TVertex, IEnumerable<TEdge>>>() != null); var algo = new BreadthFirstSearchAlgorithm <TVertex, TEdge>(visitedGraph); var predecessorRecorder = new VertexPredecessorRecorderObserver <TVertex, TEdge>(); using (predecessorRecorder.Attach(algo)) algo.Compute(root); var predecessors = predecessorRecorder.VertexPredecessors; return(delegate(TVertex v, out IEnumerable <TEdge> edges) { return EdgeExtensions.TryGetPath(predecessors, v, out edges); }); }
public IEnumerable <IEnumerable <TEdge> > AllPaths() { List <IEnumerable <TEdge> > es = new List <IEnumerable <TEdge> >(); foreach (var v in this.EndPathVertices) { IEnumerable <TEdge> path; if (EdgeExtensions.TryGetPath(this.vertexPredecessors, v, out path)) { es.Add(path); } } return(es); }
public bool TryGetPath(TVertex vertex, out IEnumerable <TEdge> path) { return(EdgeExtensions.TryGetPath(this.VertexPredecessors, vertex, out path)); }