public void TestGraph() { Console.Write("\n Testing CsGraph class"); Console.Write("\n ======================="); CsNode <string, string> node1 = new CsNode <string, string>("node1"); CsNode <string, string> node2 = new CsNode <string, string>("node2"); CsNode <string, string> node3 = new CsNode <string, string>("node3"); CsNode <string, string> node4 = new CsNode <string, string>("node4"); CsNode <string, string> node5 = new CsNode <string, string>("node5"); node1.addChild(node2, "edge12"); node1.addChild(node3, "edge13"); node2.addChild(node3, "edge23"); node2.addChild(node4, "edge24"); node3.addChild(node1, "edge31"); node5.addChild(node1, "edge51"); node5.addChild(node4, "edge54"); CsGraph <string, string> graph = new CsGraph <string, string>("Fred"); graph.addNode(node1); graph.addNode(node2); graph.addNode(node3); graph.addNode(node4); graph.addNode(node5); graph.startNode = node1; Console.Write("\n\n starting walk at {0}", graph.startNode.name); Console.Write("\n not showing backtracks"); graph.walk(); graph.startNode = node2; Console.Write("\n\n starting walk at {0}", graph.startNode.name); graph.showBackTrack = true; Console.Write("\n show backtracks"); //graph.setOperation(new demoOperation()); graph.walk(); Console.Write("\n\n"); }
public static void Main(string[] args) { CsGraph <FileNode, string> graph = new CsGraph <FileNode, string>("DepGraph"); FileNode fileNode1 = new FileNode(); fileNode1.fileName = "F1"; FileNode fileNode2 = new FileNode(); fileNode2.fileName = "F2"; FileNode fileNode3 = new FileNode(); fileNode3.fileName = "F3"; FileNode fileNode4 = new FileNode(); fileNode4.fileName = "F4"; FileNode fileNode5 = new FileNode(); fileNode5.fileName = "F5"; FileNode fileNode6 = new FileNode(); fileNode6.fileName = "F6"; FileNode fileNode7 = new FileNode(); fileNode7.fileName = "F7"; FileNode fileNode8 = new FileNode(); fileNode8.fileName = "F8"; Vertex v1 = new Vertex("F1") { nodeValue = fileNode1 }; Vertex v2 = new Vertex("F2") { nodeValue = fileNode2 }; Vertex v3 = new Vertex("F3") { nodeValue = fileNode3 }; Vertex v4 = new Vertex("F4") { nodeValue = fileNode4 }; Vertex v5 = new Vertex("F5") { nodeValue = fileNode5 }; Vertex v6 = new Vertex("F6") { nodeValue = fileNode6 }; Vertex v7 = new Vertex("F7") { nodeValue = fileNode7 }; Vertex v8 = new Vertex("F8") { nodeValue = fileNode8 }; v1.addChild(v2, "edge12"); v1.addChild(v5, "edge15"); v2.addChild(v6, "edge26"); v3.addChild(v4, "edge34"); v3.addChild(v2, "edge32"); v3.addChild(v7, "edge37"); v4.addChild(v7, "edge47"); v5.addChild(v1, "edge51"); v5.addChild(v6, "edge56"); v6.addChild(v3, "edge63"); v6.addChild(v7, "edge67"); v7.addChild(v8, "edge78"); v8.addChild(v4, "edge84"); graph.addNode(v1); graph.addNode(v2); graph.addNode(v3); graph.addNode(v4); graph.addNode(v5); graph.addNode(v6); graph.addNode(v7); graph.addNode(v8); var cycle_list = TarjanSccSolver.DetectCycle(graph); showStrongComponent(cycle_list); }