public void OutputAllMergedActions( EdgePredecessorRecorderVisitor erec, GraphvizAlgorithm gw, string path) { int i = 1000; Console.WriteLine("All paths (merged):"); foreach (EdgeCollection ec in erec.AllMergedPaths()) { CurrentEdgePath = ec; gw.Write(String.Format("path-merged{1}", path, i)); foreach (IEdge edge in ec) { Console.WriteLine("{0}->{1}, {2}", ((NamedVertex)edge.Source).Name, ((NamedVertex)edge.Target).Name, ((NamedEdge)edge).Name ); } ++i; Console.WriteLine(); } CurrentEdgePath = null; }
/// <summary> /// Add a predecessor recorder to the edge dfs algorithm. /// </summary> /// <param name="edfs"></param> /// <returns>predecessor recorder</returns> public EdgePredecessorRecorderVisitor AddPredecessorRecorder(EdgeDepthFirstSearchAlgorithm edfs) { // The visitor that will record actions path for us EdgePredecessorRecorderVisitor erec = new EdgePredecessorRecorderVisitor(); edfs.DiscoverTreeEdge += new EdgeEdgeEventHandler(erec.DiscoverTreeEdge); edfs.FinishEdge += new EdgeEventHandler(erec.FinishEdge); return(erec); }
/// <summary> /// Output end of path edges /// </summary> /// <param name="erec"></param> public void OutputEndPathEdges(EdgePredecessorRecorderVisitor erec) { // these are the edges that are terminal. Console.WriteLine("End path edges:"); foreach (IEdge se in erec.EndPathEdges) { Console.WriteLine("\t{0}->{1}, {2}", ((NamedVertex)se.Source).Name, ((NamedVertex)se.Target).Name, ((NamedEdge)se).Name ); } }
/// <summary> /// Executes edge dfs /// </summary> /// <param name="g"></param> public void TestAllActions(IVertexAndEdgeListGraph g, string path) { // Testing dfs all apth DepthFirstSearchAlgorithm dfs = new DepthFirstSearchAlgorithm(g); PredecessorRecorderVisitor visv = new PredecessorRecorderVisitor(); dfs.RegisterPredecessorRecorderHandlers(visv); IVertex s0 = Traversal.FirstVertexIf(g.Vertices, new NameEqualPredicate("S0")); dfs.Compute(s0); Console.WriteLine("vertex paths"); foreach (EdgeCollection ec in visv.AllPaths()) { foreach (IEdge edge in ec) { Console.WriteLine("{0}->{1}, {2}", ((NamedVertex)edge.Source).Name, ((NamedVertex)edge.Target).Name, ((NamedEdge)edge).Name ); } Console.WriteLine(); } // end of dfs test GraphvizAlgorithm gw = RenderActions(g, path); // The all action algorithms EdgeDepthFirstSearchAlgorithm edfs = CreateEdgeDfs(g); // add tracer AlgorithmTracerVisitor vis = AddTracer(edfs, path); // add predecessor recorder EdgePredecessorRecorderVisitor erec = AddPredecessorRecorder(edfs); // computing all actions edfs.Compute(s0); // display end path edges OutputEndPathEdges(erec); // display all actions path OutputAllActions(erec, gw, path); }