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));
        }
        public static void TestCourseScheduling()
        {
            // Create a graph
            DirectedGraph dg = GraphProbHelper.CreatedirectedGraphWithoutCycle();

            // Now schedule the order in which courses needed to be taken
            CourseScheduling cs = new CourseScheduling(dg);

            cs.DFSTopologicalSort();
        }
Example #3
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 #4
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());
        }