public static void TestGetAllPathsInGraphFromStartVertexToEndVertex() { DirectedGraph dg = GraphProbHelper.CreateDirectedGraph(); Console.WriteLine("All the paths from start vertex to the end vertex are:"); GetAllPathsInGraphFromStartVertexToEndVertex(dg.AllVertices[2], dg.AllVertices[3]); }
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 TestIsCycleInUnDirectedGraph() { UndirectedGraph udg = GraphProbHelper.CreateUndirectedGraphWithoutCycle(); Console.WriteLine("Is the cycle present in the undirected graph: {0}", IsCycleInUnDirectedGraph(udg)); udg = GraphProbHelper.CreateUndirectedGraphWithCycle(); Console.WriteLine("Is the cycle present in the undirected graph: {0}", IsCycleInUnDirectedGraph(udg)); }
public static void TestCheckBipartiteGraph() { DirectedGraph dg = GraphProbHelper.CreateDirectedGraph(); Console.WriteLine("Can the graph nodes be colored: {0}", IsBiPartiteGraph(dg.AllVertices[2])); dg.RemoveEdge(0, 1); Console.WriteLine("Can the graph nodes be colored: {0}", IsBiPartiteGraph(dg.AllVertices[2])); }
public static void TestColorVerticesWithDifferentColor() { DirectedGraph dg = GraphProbHelper.CreateDirectedGraph(); Console.WriteLine("Can the graph nodes be colored: {0}", ColorVerticesWithDifferentColor(dg.AllVertices[2])); dg.RemoveEdge(0, 1); Console.WriteLine("Can the graph nodes be colored: {0}", ColorVerticesWithDifferentColor(dg.AllVertices[2])); }
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(); }
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(); }
public static void TestIsGraphATree() { IsGraphATree gt = new IsGraphATree(); UndirectedGraph udg = GraphProbHelper.CreateUndirectedGraphWithoutCycleWithoutUnconnectedNodes(); Console.WriteLine("Is the cycle present in the undirected graph: {0}", gt.IsGraphTree(udg)); udg = GraphProbHelper.CreateUndirectedGraphWithoutCycle(); Console.WriteLine("Is the cycle present in the undirected graph: {0}", gt.IsGraphTree(udg)); udg = GraphProbHelper.CreateUndirectedGraphWithCycle(); Console.WriteLine("Is the cycle present in the undirected graph: {0}", gt.IsGraphTree(udg)); }
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); } }
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()); }
public static void TestStronglyConnectedGraph() { StronglyConnectedGraph scg = new StronglyConnectedGraph(); UndirectedGraph notStronglyConnected = GraphProbHelper.CreateUndirectedGraphNotStronglyConnected(); Console.WriteLine("The graph is strongly connected. Expected: False, Actual: {0}", scg.IsUndirectedGraphStronglyConnected(notStronglyConnected)); UndirectedGraph stronglyConnected = GraphProbHelper.CreateUndirectedGraphStronglyConnected(); Console.WriteLine("The graph is strongly connected. Expected: True, Actual: {0}", scg.IsUndirectedGraphStronglyConnected(stronglyConnected)); DirectedGraphWithVertexDictionary dg = GraphProbHelper.CreateDirectedGraphWithVertexDictStronglyConnected(); Console.WriteLine("The graph is strongly connected. Expected: True, Actual: {0}", scg.IsDirectedGraphStronglyConnected(dg)); dg = GraphProbHelper.CreateDirectedGraphWithVertexDictNotStronglyConnected(); Console.WriteLine("The graph is strongly connected. Expected: False, Actual: {0}", scg.IsDirectedGraphStronglyConnected(dg)); }
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); }