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"); }
public static void MainTest(string[] args) { int V1 = int.Parse(args[0]); int V2 = int.Parse(args[1]); int E = int.Parse(args[2]); int F = int.Parse(args[3]); Bipartite b; // create random bipartite graph with V1 vertices on left side, // V2 vertices on right side, and E edges; then add F random edges Graph G = GraphGenerator.Bipartite(V1, V2, E); Console.WriteLine("Graph is {0}\n", G); b = new Bipartite(G); BipartiteReport(b); for (int i = 0; i < F; i++) { int v = StdRandom.Uniform(V1 + V2); int w = StdRandom.Uniform(V1 + V2); G.AddEdge(v, w); } Console.WriteLine("After adding {0} random edges", F); Console.WriteLine("Graph is {0}\n", G); b = new Bipartite(G); BipartiteReport(b); }
public static void MainTest(string[] args) { int V1 = int.Parse(args[0]); int V2 = int.Parse(args[1]); int E = int.Parse(args[2]); Graph G = GraphGenerator.Bipartite(V1, V2, E); if (G.V < 1000) { Console.WriteLine(G); } HopcroftKarp matching = new HopcroftKarp(G); // print maximum matching Console.Write("Number of edges in max matching = {0}\n", matching.Count); Console.Write("Number of vertices in min vertex cover = {0}\n", matching.Count); Console.Write("Graph has a perfect matching = {0}\n", matching.IsPerfect); Console.WriteLine(); if (G.V >= 1000) { return; } Console.Write("Max matching: "); for (int v = 0; v < G.V; v++) { int w = matching.Mate(v); if (matching.IsMatched(v) && v < w) // print each edge only once { Console.Write(v + "-" + w + " "); } } Console.WriteLine(); // print minimum vertex cover Console.Write("Min vertex cover: "); for (int v = 0; v < G.V; v++) { if (matching.InMinVertexCover(v)) { Console.Write(v + " "); } } Console.WriteLine(); }
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); EulerianPath.UnitTest(G1, "Eulerian cycle"); // Eulerian path Graph G2 = GraphGenerator.EulerianPath(V, E); EulerianPath.UnitTest(G2, "Eulerian path"); // add one random edge Graph G3 = new Graph(G2); G3.AddEdge(StdRandom.Uniform(V), StdRandom.Uniform(V)); EulerianPath.UnitTest(G3, "one random edge added to Eulerian path"); // self loop Graph G4 = new Graph(V); int v4 = StdRandom.Uniform(V); G4.AddEdge(v4, v4); EulerianPath.UnitTest(G4, "single self loop"); // single edge Graph G5 = new Graph(V); G5.AddEdge(StdRandom.Uniform(V), StdRandom.Uniform(V)); EulerianPath.UnitTest(G5, "single edge"); // empty graph Graph G6 = new Graph(V); EulerianPath.UnitTest(G6, "empty graph"); // random graph Graph G7 = GraphGenerator.Simple(V, E); EulerianPath.UnitTest(G7, "simple graph"); }
public static void MainTest(string[] args) { int V = int.Parse(args[0]); int E = int.Parse(args[1]); int V1 = V / 2; int V2 = V - V1; Console.WriteLine("complete graph"); Console.WriteLine(GraphGenerator.Complete(V)); Console.WriteLine(); Console.WriteLine("simple"); Console.WriteLine(GraphGenerator.Simple(V, E)); Console.WriteLine(); Console.WriteLine("Erdos-Renyi"); double p = E / (V * (V - 1) / 2.0); Console.WriteLine(GraphGenerator.Simple(V, p)); Console.WriteLine(); Console.WriteLine("complete bipartite"); Console.WriteLine(GraphGenerator.CompleteBipartite(V1, V2)); Console.WriteLine(); Console.WriteLine("bipartite"); Console.WriteLine(GraphGenerator.Bipartite(V1, V2, E)); Console.WriteLine(); Console.WriteLine("Erdos Renyi bipartite"); double q = (double)E / (V1 * V2); Console.WriteLine(GraphGenerator.Bipartite(V1, V2, q)); Console.WriteLine(); Console.WriteLine("path"); Console.WriteLine(GraphGenerator.Path(V)); Console.WriteLine(); Console.WriteLine("cycle"); Console.WriteLine(GraphGenerator.Cycle(V)); Console.WriteLine(); Console.WriteLine("binary tree"); Console.WriteLine(GraphGenerator.BinaryTree(V)); Console.WriteLine(); Console.WriteLine("tree"); Console.WriteLine(GraphGenerator.Tree(V)); Console.WriteLine(); Console.WriteLine("4-regular"); Console.WriteLine(GraphGenerator.Regular(V, 4)); Console.WriteLine(); Console.WriteLine("star"); Console.WriteLine(GraphGenerator.Star(V)); Console.WriteLine(); Console.WriteLine("wheel"); Console.WriteLine(GraphGenerator.Wheel(V)); Console.WriteLine(); }