public void TarjanArticulation_Smoke_Test() { var graph = new Graph <char>(); graph.AddVertex('A'); graph.AddVertex('B'); graph.AddVertex('C'); graph.AddVertex('D'); graph.AddVertex('E'); graph.AddVertex('F'); graph.AddVertex('G'); graph.AddVertex('H'); graph.AddEdge('A', 'B'); graph.AddEdge('A', 'C'); graph.AddEdge('B', 'C'); graph.AddEdge('C', 'D'); graph.AddEdge('D', 'E'); graph.AddEdge('E', 'F'); graph.AddEdge('F', 'G'); graph.AddEdge('G', 'E'); graph.AddEdge('F', 'H'); var algo = new TarjansArticulationFinder <char>(); var result = algo.FindArticulationPoints(graph); Assert.AreEqual(4, result.Count); var expectedResult = new char[] { 'C', 'D', 'E', 'F' }; foreach (var v in result) { Assert.IsTrue(expectedResult.Contains(v)); } }
public void TarjanArticulation_AdjacencyMatrixGraph_Smoke_Test() { var graph = new Advanced.Algorithms.DataStructures.Graph.AdjacencyMatrix.Graph <char>(); graph.AddVertex('A'); graph.AddVertex('B'); graph.AddVertex('C'); graph.AddVertex('D'); graph.AddVertex('E'); graph.AddVertex('F'); graph.AddVertex('G'); graph.AddVertex('H'); graph.AddEdge('A', 'B'); graph.AddEdge('A', 'C'); graph.AddEdge('B', 'C'); graph.AddEdge('C', 'D'); graph.AddEdge('D', 'E'); graph.AddEdge('E', 'F'); graph.AddEdge('F', 'G'); graph.AddEdge('G', 'E'); graph.AddEdge('F', 'H'); var algorithm = new TarjansArticulationFinder <char>(); var result = algorithm.FindArticulationPoints(graph); Assert.AreEqual(4, result.Count); var expectedResult = new char[] { 'C', 'D', 'E', 'F' }; foreach (var v in result) { Assert.IsTrue(expectedResult.Contains(v)); } }
/// <summary> /// This is using ariticulation alogrithm based on the observation that /// a graph is BiConnected if and only if there is no articulation Points /// </summary> /// <param name="graph"></param> /// <returns></returns> public bool IsBiConnected(Graph <T> graph) { var articulationAlgo = new TarjansArticulationFinder <T>(); return(articulationAlgo.FindArticulationPoints(graph).Count == 0); }