Exemplo n.º 1
0
        public static void TestGetShortestPathBetween2Vertex()
        {
            UndirectedGraph    udg          = GraphProbHelper.CreateUndirectedGraph();
            List <GraphVertex> shortestPath = GetShortestPathBetween2Vertex(udg.AllVertices[0], udg.AllVertices[5]);

            Console.WriteLine("The shortest path is as shown below:");
            foreach (GraphVertex vertex in shortestPath)
            {
                Console.Write(vertex.Data + " -> ");
            }
            Console.WriteLine();
        }
Exemplo n.º 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);
            }
        }