public void Simple() { IVertexListGraph g = GraphFactory.Simple(); StrongComponentsAlgorithm strong = new StrongComponentsAlgorithm(g); strong.Compute(); checkStrong(strong); }
public void RegularLattice() { IVertexListGraph g = GraphFactory.RegularLattice(10,10); StrongComponentsAlgorithm strong = new StrongComponentsAlgorithm(g); strong.Compute(); checkStrong(strong); }
public void FileDependency() { IVertexListGraph g = GraphFactory.FileDependency(); StrongComponentsAlgorithm strong = new StrongComponentsAlgorithm(g); strong.Compute(); checkStrong(strong); }
public void Loop() { IVertexListGraph g = GraphFactory.Loop(); StrongComponentsAlgorithm strong = new StrongComponentsAlgorithm(g); Assert.AreEqual(1, strong.Compute()); strong.Compute(); checkStrong(strong); }
public void OneVertex() { AdjacencyGraph g =new AdjacencyGraph(true); IVertex v1 = g.AddVertex(); StrongComponentsAlgorithm strong = new StrongComponentsAlgorithm(g); Assert.AreEqual(1, strong.Compute()); checkStrong(strong); }
public void EmptyGraph() { IVertexListGraph g = GraphFactory.EmptyParallelEdgesAllowed(); StrongComponentsAlgorithm strong = new StrongComponentsAlgorithm(g); Assert.AreEqual(0, strong.Compute()); checkStrong(strong); }
/// <summary> /// Computes the strong components. /// </summary> /// <remarks> /// <para> /// Thread safe. /// </para> /// </remarks> /// <param name="g">graph to explore</param> /// <param name="components">component map where results are recorded</param> /// <returns>number of strong components</returns> public static int StrongComponents( IVertexListGraph g, VertexIntDictionary components) { StrongComponentsAlgorithm strong = new StrongComponentsAlgorithm(g, components); return(strong.Compute()); }
public void TwoVertexOnEdge() { AdjacencyGraph g =new AdjacencyGraph(true); IVertex v1 = g.AddVertex(); IVertex v2 = g.AddVertex(); IEdge e = g.AddEdge(v1,v2); StrongComponentsAlgorithm strong = new StrongComponentsAlgorithm(g); Assert.AreEqual(2, strong.Compute()); checkStrong(strong); }
internal void ComputeComponents() { if (components == null) { components = new VertexIntDictionary(); } // components is a MAP containing vertex number as key & component_id as value. It maps every vertex in input graph to SCC vertex ID which contains it StrongComponentsAlgorithm algo = new StrongComponentsAlgorithm( VisitedGraph, this.components ); algo.Compute(); }
internal void ComputeComponents() { if( components == null ) components = new VertexIntDictionary(); // components is a MAP containing vertex number as key & component_id as value. It maps every vertex in input graph to SCC vertex ID which contains it StrongComponentsAlgorithm algo = new StrongComponentsAlgorithm( VisitedGraph, this.components ); algo.Compute(); }
private void checkStrong(StrongComponentsAlgorithm strong) { Assert.AreEqual(strong.VisitedGraph.VerticesCount, strong.Components.Count); Assert.AreEqual(strong.VisitedGraph.VerticesCount, strong.DiscoverTimes.Count); Assert.AreEqual(strong.VisitedGraph.VerticesCount, strong.Roots.Count); foreach(IVertex v in strong.VisitedGraph.Vertices) { Assert.IsTrue(strong.Components.Contains(v)); Assert.IsTrue(strong.DiscoverTimes.Contains(v)); } foreach(DictionaryEntry de in strong.Components) { Assert.IsNotNull(de.Key); Assert.IsNotNull(de.Value); Assert.LowerEqualThan((int)de.Value,strong.Count); } foreach(DictionaryEntry de in strong.DiscoverTimes) { Assert.IsNotNull(de.Key); Assert.IsNotNull(de.Value); } }
/// <summary> /// Computes the strong components. /// </summary> /// <remarks> /// <para> /// Thread safe. /// </para> /// </remarks> /// <param name="g">graph to explore</param> /// <param name="components">component map where results are recorded</param> /// <returns>number of strong components</returns> public static int StrongComponents( IVertexListGraph g, VertexIntDictionary components) { StrongComponentsAlgorithm strong = new StrongComponentsAlgorithm(g,components); return strong.Compute(); }
public CondensedTypeGraph(bool allowParallel) : base(new CondensedVertexProvider(), new EdgeProvider(), allowParallel) { _sccCountalg = new StrongComponentsAlgorithm(this); }
public CondensedTypeGraph() : base(new CondensedVertexProvider(), new EdgeProvider(), false) { _sccCountalg = new StrongComponentsAlgorithm(this); }
public TypeDependencyGraph TypeDepAnalysis(List<TypeReference> typesToExamine) { TypeDependencyGraph tdg = new TypeDependencyGraph(); StrongComponentsAlgorithm scgo = new StrongComponentsAlgorithm(this); scgo.Compute(); Dictionary<int, List<IVertex>> sccMap = new Dictionary<int, List<IVertex>>(); foreach (System.Collections.DictionaryEntry de in scgo.Components) { IVertex v = (IVertex)de.Key; int scc_id = (int)de.Value; if (!sccMap.ContainsKey(scc_id)) { sccMap[scc_id] = new List<IVertex>(); } sccMap[scc_id].Add(v); } Stack<List<TypeVertex>> PendingEdges = new Stack<List<TypeVertex>>(); List<TypeVertex> VertexToRemove = new List<TypeVertex>(); VertexEventHandler discV = delegate(Object s, VertexEventArgs e) { PendingEdges.Push(new List<TypeVertex>()); TypeVertex tv = (TypeVertex)e.Vertex; if (scgo.Components.Contains(tv) && sccMap[scgo.Components[tv]].Count > 1) { tv.SCCNum = scgo.Components[tv]; tdg.AddVertex(tv); } else if (typesToExamine.Contains(tv.TypeRef)) { tdg.AddVertex(tv); } else { VertexToRemove.Add(tv); } }; VertexEventHandler finishV = delegate(Object s, VertexEventArgs e) { TypeVertex tv = (TypeVertex)e.Vertex; List<TypeVertex> pes = PendingEdges.Pop(); if (tdg.ContainsVertex(tv)) { foreach (TypeVertex target in pes) { if (tdg.ContainsVertex(target) && !tdg.ContainsEdge(tv, target)) tdg.AddEdge(tv, target); } } }; EdgeEventHandler treeedge = delegate(Object o, EdgeEventArgs e) { PendingEdges.Peek().Add((TypeVertex)e.Edge.Target); }; DepthFirstSearchAlgorithm dfs = new DepthFirstSearchAlgorithm(this); dfs.DiscoverVertex += discV; dfs.FinishVertex += finishV; dfs.TreeEdge += treeedge; dfs.Compute(); foreach (TypeVertex v in VertexToRemove) { this.RemoveVertex(v); } return tdg; }