public static void MainTest(string[] args) { int V = int.Parse(args[0]); int E = int.Parse(args[1]); // Eulerian cycle Graph G1 = GraphGenerator.EulerianCycle(V, E); EulerianCycle.UnitTest(G1, "Eulerian cycle"); // Eulerian path Graph G2 = GraphGenerator.EulerianPath(V, E); EulerianCycle.UnitTest(G2, "Eulerian path"); // empty graph Graph G3 = new Graph(V); EulerianCycle.UnitTest(G3, "empty graph"); // self loop Graph G4 = new Graph(V); int v4 = StdRandom.Uniform(V); G4.AddEdge(v4, v4); EulerianCycle.UnitTest(G4, "single self loop"); // union of two disjoint cycles Graph H1 = GraphGenerator.EulerianCycle(V / 2, E / 2); Graph H2 = GraphGenerator.EulerianCycle(V - V / 2, E - E / 2); int[] perm = new int[V]; for (int i = 0; i < V; i++) { perm[i] = i; } StdRandom.Shuffle(perm); Graph G5 = new Graph(V); for (int v = 0; v < H1.V; v++) { foreach (int w in H1.Adj(v)) { G5.AddEdge(perm[v], perm[w]); } } for (int v = 0; v < H2.V; v++) { foreach (int w in H2.Adj(v)) { G5.AddEdge(perm[V / 2 + v], perm[V / 2 + w]); } } EulerianCycle.UnitTest(G5, "Union of two disjoint cycles"); // random digraph Graph G6 = GraphGenerator.Simple(V, E); EulerianCycle.UnitTest(G6, "simple graph"); }
internal static void UnitTest(Graph G, string description) { Console.WriteLine(description); Console.WriteLine("-------------------------------------"); Console.Write(G); EulerianCycle euler = new EulerianCycle(G); Console.Write("Eulerian cycle: "); if (euler.HasEulerianCycle) { foreach (int v in euler.Cycle()) { Console.Write(v + " "); } Console.WriteLine(); } else { Console.WriteLine("none"); } Console.WriteLine(); }