Example #1
0
        public static void TestIsCycleInDirectedGraph()
        {
            DirectedGraph dg = GraphProbHelper.CreatedirectedGraphWithCycle();

            Console.WriteLine("Does this graph has cycle: {0}", IsCycleInDirectedGraph(dg));

            dg = GraphProbHelper.CreatedirectedGraphWithoutCycle();
            Console.WriteLine("Does this graph has cycle: {0}", IsCycleInDirectedGraph(dg));
        }
Example #2
0
        public static void TestSolveAMaze()
        {
            UndirectedGraph udg = GraphProbHelper.CreateUndirectedGraph();

            if (IsMazeSolved(udg.AllVertices[0], udg.AllVertices[5]))
            {
                MazePath.Reverse();
                PrintMazePath(MazePath);
            }

            MazePath = new List <GraphVertex>();
            DirectedGraph dg = GraphProbHelper.CreatedirectedGraphWithoutCycle();

            if (IsMazeSolved(dg.AllVertices[0], dg.AllVertices[5]))
            {
                MazePath.Reverse();
                PrintMazePath(MazePath);
            }

            MazePath = new List <GraphVertex>();
            DirectedGraph dgc = GraphProbHelper.CreatedirectedGraphWithCycle();

            if (IsMazeSolved(dgc.AllVertices[0], dgc.AllVertices[5]))
            {
                MazePath.Reverse();
                PrintMazePath(MazePath);
            }

            // test the iterative method
            List <GraphVertex> path = SolveMazeIter(udg.AllVertices[0], udg.AllVertices[5]);

            if (path != null)
            {
                PrintMazePath(path);
            }

            path = SolveMazeIter(dg.AllVertices[0], dg.AllVertices[5]);
            if (path != null)
            {
                PrintMazePath(path);
            }

            path = SolveMazeIter(dgc.AllVertices[0], dgc.AllVertices[5]);
            if (path != null)
            {
                PrintMazePath(path);
            }
        }
Example #3
0
        public static void TestReverseGraph()
        {
            DirectedGraph dg = GraphProbHelper.CreatedirectedGraphWithCycle();

            Console.WriteLine("Adjacency matrix of a input directed graph is as shown below");
            GraphProbHelper.PrintDirectedGraphInAdjacencyMatrix(dg);

            Console.WriteLine("Adjacency matrix of a reversed directed graph is as shown below");
            GraphProbHelper.PrintDirectedGraphInAdjacencyMatrix(dg.ReverseDirectedGraph());

            dg = GraphProbHelper.CreatedirectedGraphWithoutCycle();
            Console.WriteLine("Adjacency matrix of a input directed graph is as shown below");
            GraphProbHelper.PrintDirectedGraphInAdjacencyMatrix(dg);

            Console.WriteLine("Adjacency matrix of a reversed directed graph is as shown below");
            GraphProbHelper.PrintDirectedGraphInAdjacencyMatrix(dg.ReverseDirectedGraph());
        }
Example #4
0
        public static void TestCloneGraph()
        {
            UndirectedGraph udg = GraphProbHelper.CreateUndirectedGraphWithCycle();

            Console.WriteLine("The actual graph looks like:");
            GraphProbHelper.PrintGraphBFS(udg.AllVertices[0]);

            Console.WriteLine("The clone looks like");
            GraphVertex clone = Clone(udg.AllVertices[0]);

            GraphProbHelper.PrintGraphBFS(clone);

            DirectedGraph dg = GraphProbHelper.CreatedirectedGraphWithCycle();

            Console.WriteLine("The actual graph looks like:");
            GraphProbHelper.PrintGraphBFS(dg.AllVertices[0]);

            Console.WriteLine("The clone looks like");
            clone = Clone(dg.AllVertices[0]);
            GraphProbHelper.PrintGraphBFS(clone);
        }