private static void DiGraph() { IDiGraph G = new DiGraph.DiGraph(new Scanner(new StreamReader(File.OpenRead("tinyDG.txt")))); Bag <int> sources = new Bag <int>(); StdOut.Println("搜索几个结点:"); int i = StdIn.ReadInt(); while (i-- > 0) { sources.Add(StdIn.ReadInt()); } DirectedDFS reachable = new DirectedDFS(G, sources); for (int v = 0; v < G.V; v++) { if (reachable.Marked(v)) { StdOut.Print(v + " "); } } //string filename = "jobs.txt"; //文件有问题 //string seperator = "/"; //SymbolDiGraph sg = new SymbolDiGraph(filename, seperator); //Topological topological = new Topological(sg.G); //foreach (int v in topological.Order) // StdOut.Println(sg.Name(v)); StdOut.Println(); StdOut.Println("强连通分量的数量"); ISCC scc = new KosarajuSCC(G); StdOut.Println(scc.Count); }
public IDiGraph Reverse() { IDiGraph R = new DiGraph(V); for (int v = 0; v < V; v++) { foreach (int w in Adj(v)) { R.AddEdge(w, v); } } return(R); }
public Topological(IEdgeWeightedDIgraph G) { IDiGraph g = new DiGraph(G.V); for (int i = 0; i < G.V; i++) { foreach (var e in G.Adj(i)) { g.AddEdge(e.From, e.To); } } Order = Init(g); }