static void TestDiGraph() { Graph graph = new DiGraph(); var random = new Random(); Stopwatch watch = new Stopwatch(); watch.Restart(); graph.AddEdge(0, 1); int toAdd; int from; for (int i = 2; i < 10000; i++) { toAdd = i; from = random.Next(0, i); graph.AddEdge(from, toAdd); } Console.WriteLine("DiGraph: " + watch.ElapsedMilliseconds); Console.WriteLine("DFP in DiGraph"); watch.Restart(); DepthFirstSearch dfp = new DepthFirstSearch(graph); dfp.DFS(0); Console.WriteLine("DFP in: " + watch.ElapsedTicks); //dfp.OutputOrder(); dfp.OutputPath(5000); Console.WriteLine("BFP in DiGraph"); watch.Restart(); BreadthFirstSearch bfp = new BreadthFirstSearch(graph); bfp.Execute(0); Console.WriteLine("BFP in: " + watch.ElapsedTicks); //bfp.OutputOrder(); bfp.OutputPath(5000); Console.WriteLine("Cycle in DiGraph"); watch.Restart(); GraphCycle cycle = new GraphCycle(graph); cycle.CS(); Console.WriteLine("CS in: " + watch.ElapsedTicks); cycle.OutputCycle(); Console.WriteLine("Topo sort in DiGraph"); watch.Restart(); DepthFirstOrder order = new DepthFirstOrder(graph); order.DFO(); Console.WriteLine("Topo sort in: " + watch.ElapsedTicks); //order.OutputReversePost(); }
static void TestGraph() { Graph graph = new Graph(); var random = new Random(); Stopwatch watch = new Stopwatch(); watch.Restart(); graph.AddEdge(0, 1); int toAdd; int from; for (int i = 2; i < 10000; i++) { toAdd = i; from = random.Next(0, i); graph.AddEdge(from, toAdd); } Console.WriteLine("Graph: " + watch.ElapsedMilliseconds); Console.WriteLine("DFP in Graph"); watch.Restart(); DepthFirstSearch dfp = new DepthFirstSearch(graph); dfp.DFS(0); Console.WriteLine("DFP in: " + watch.ElapsedTicks); //dfp.OutputOrder(); dfp.OutputPath(5000); Console.WriteLine("BFP in Graph"); watch.Restart(); BreadthFirstSearch bfp = new BreadthFirstSearch(graph); bfp.Execute(0); Console.WriteLine("BFP in: " + watch.ElapsedTicks); //bfp.OutputOrder(); bfp.OutputPath(5000); }