private void Compute <TVertex, TEdge>(AdjacencyGraph <TVertex, TEdge> g) where TEdge : IEdge <TVertex> { var strong = new StronglyConnectedComponentsAlgorithm <TVertex, TEdge>(g); strong.Compute(); checkStrong(strong); }
public void Compute <TVertex, TEdge>([PexAssumeNotNull] AdjacencyGraph <TVertex, TEdge> g) where TEdge : IEdge <TVertex> { var strong = new StronglyConnectedComponentsAlgorithm <TVertex, TEdge>(g); strong.Compute(); checkStrong(strong); }
public void Simple() { IVertexListGraph <string, Edge <string> > g = new AdjacencyGraphFactory().Simple(); StronglyConnectedComponentsAlgorithm <string, Edge <String> > strong = new StronglyConnectedComponentsAlgorithm <string, Edge <String> >(g); strong.Compute(); checkStrong(strong); }
public void EmptyGraph() { var g = new AdjacencyGraph <string, Edge <string> >(true); var strong = new StronglyConnectedComponentsAlgorithm <string, Edge <String> >(g); strong.Compute(); Assert.AreEqual(0, strong.ComponentCount); checkStrong(strong); }
public void Loop() { IVertexListGraph <string, Edge <string> > g = new AdjacencyGraphFactory().Loop(); StronglyConnectedComponentsAlgorithm <string, Edge <String> > strong = new StronglyConnectedComponentsAlgorithm <string, Edge <String> >(g); strong.Compute(); Assert.AreEqual(1, strong.ComponentCount); checkStrong(strong); }
public void OneVertex() { AdjacencyGraph <string, Edge <string> > g = new AdjacencyGraph <string, Edge <string> >(true); g.AddVertex("test"); var strong = new StronglyConnectedComponentsAlgorithm <string, Edge <String> >(g); strong.Compute(); Assert.AreEqual(1, strong.ComponentCount); checkStrong(strong); }
public static int StronglyConnectedComponents <TVertex, TEdge>( IVertexListGraph <TVertex, TEdge> g, IDictionary <TVertex, int> components) where TEdge : IEdge <TVertex> { GraphContracts.AssumeNotNull(g, "g"); GraphContracts.AssumeNotNull(components, "components"); var conn = new StronglyConnectedComponentsAlgorithm <TVertex, TEdge>(g, components); conn.Compute(); return(conn.ComponentCount); }
/// <summary> /// Computes the strongly connected components of a graph /// </summary> /// <typeparam name="TVertex">type of the vertices</typeparam> /// <typeparam name="TEdge">type of the edges</typeparam> /// <param name="g"></param> /// <param name="components"></param> /// <returns>number of components</returns> public static int StronglyConnectedComponents <TVertex, TEdge> (this IVertexListGraph <TVertex, TEdge> g, out IDictionary <TVertex, int> components) where TEdge : IEdge <TVertex> { Contract.Requires(g != null); Contract.Ensures(Contract.ValueAtReturn(out components) != null); components = new Dictionary <TVertex, int>(); var conn = new StronglyConnectedComponentsAlgorithm <TVertex, TEdge>(g, components); conn.Compute(); return(conn.ComponentCount); }
public void TwoVertexOnEdge() { AdjacencyGraph <string, Edge <string> > g = new AdjacencyGraph <string, Edge <string> >(true); g.AddVertex("v1"); g.AddVertex("v2"); g.AddEdge(new Edge <string>("v1", "v2")); var strong = new StronglyConnectedComponentsAlgorithm <string, Edge <String> >(g); strong.Compute(); Assert.AreEqual(2, strong.ComponentCount); checkStrong(strong); }