public Graph.Graph StrongComponent() { Graph.Graph g = new Graph.DirectedGraph(13); g.AddEdge(4, 2); g.AddEdge(2,3); g.AddEdge(3,2); g.AddEdge(6,0); g.AddEdge(0,1); g.AddEdge(2,0); g.AddEdge(11,12); g.AddEdge(12,9); g.AddEdge(9,10); g.AddEdge(9,11); g.AddEdge(7,9); g.AddEdge(10,12); g.AddEdge(11,4); g.AddEdge(4,3); g.AddEdge(3,5); g.AddEdge(6,8); g.AddEdge(8,6); g.AddEdge(5, 4); g.AddEdge(0, 5); g.AddEdge(6, 4); g.AddEdge(6, 9); g.AddEdge(7, 6); return g; }
public void DepthFirstOrder() { Graph.Graph g = new Graph.DirectedGraph(7); g.AddEdge(0, 5); g.AddEdge(0, 2); g.AddEdge(0, 1); g.AddEdge(3, 6); g.AddEdge(3, 5); g.AddEdge(3, 4); g.AddEdge(5, 2); g.AddEdge(6, 4); g.AddEdge(6, 0); g.AddEdge(3, 2); g.AddEdge(1, 4); Graph.DepthFirstOrder dfs = new Graph.DepthFirstOrder(g); //4,1,2,5,0,6,3 //this doesn't come out in the order of the lecture but it doesn't matter //it just has to be in in any order from bottom to top //this result actually makes more sense because 2 goes no where and it is at the top var postOrder = dfs.ReverseOrder().ToArray(); Assert.AreEqual(postOrder[0], 3); Assert.AreEqual(postOrder[1], 6); Assert.AreEqual(postOrder[2], 0); Assert.AreEqual(postOrder[3], 1); Assert.AreEqual(postOrder[4], 4); Assert.AreEqual(postOrder[5], 5); Assert.AreEqual(postOrder[6], 2); }
public void DirectedBredthFirstSearchWorks() { Graph.Graph g = new Graph.DirectedGraph(9); g.AddEdge(0, 2); g.AddEdge(0, 1); g.AddEdge(2, 4); g.AddEdge(5, 0); g.AddEdge(1, 2); g.AddEdge(3, 2); g.AddEdge(4, 3); g.AddEdge(3, 5); g.AddEdge(3, 5); Graph.BreadthFirstSearch dfs = new Graph.BreadthFirstSearch(g, 0); Assert.AreEqual(dfs.edgeTo[1], 0); Assert.AreEqual(dfs.edgeTo[2], 0); Assert.AreEqual(dfs.edgeTo[3], 4); Assert.AreEqual(dfs.edgeTo[4], 2); Assert.AreEqual(dfs.edgeTo[5], 3); Assert.AreEqual(dfs.disTo[1], 1); Assert.AreEqual(dfs.disTo[2], 1); Assert.AreEqual(dfs.disTo[3], 3); Assert.AreEqual(dfs.disTo[4], 2); Assert.AreEqual(dfs.disTo[5], 4); }