Пример #1
0
        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");
        }
Пример #2
0
        internal static void UnitTest(Graph G, String description)
        {
            Console.WriteLine(description);
            Console.WriteLine("-------------------------------------");
            Console.Write(G);

            EulerianPath euler = new EulerianPath(G);

            Console.Write("Eulerian path:  ");
            if (euler.HasEulerianPath)
            {
                foreach (int v in euler.Path())
                {
                    Console.Write(v + " ");
                }
                Console.WriteLine();
            }
            else
            {
                Console.WriteLine("none");
            }
            Console.WriteLine();
        }