public void CondensateAndCheckDAG(
     [PexAssumeNotNull]IVertexAndEdgeListGraph<string, Edge<string>> g)
 {
     this.algo = new CondensationGraphAlgorithm<string, Edge<string>, AdjacencyGraph<string, Edge<string>>>(g);
     algo.Compute();
     CheckDAG(g);
 }
 public void CondensateAndCheckComponentCount(IVertexAndEdgeListGraph<string, Edge<string>> g)
 {
     this.algo = new CondensationGraphAlgorithm<string, Edge<string>, AdjacencyGraph<string, Edge<string>>>(g);
     this.algo.StronglyConnected = false;
     algo.Compute();
     CheckComponentCount(g);
 }
        public CondensedTypeGraph CondenseGraph()
        {
            CondensationGraphAlgorithm cgalgo = new CondensationGraphAlgorithm(this);

            cgalgo.InitCondensationGraphVertex += new CondensationGraphVertexEventHandler(CGVertexHandler);
            CondensedTypeGraph cg = new CondensedTypeGraph();

            cgalgo.Create(cg);
            return(cg);
        }
Exemplo n.º 4
0
        private static void CheckComponentCount <TVertex, TEdge>(
            [NotNull] IVertexAndEdgeListGraph <TVertex, TEdge> graph,
            [NotNull] CondensationGraphAlgorithm <TVertex, TEdge, AdjacencyGraph <TVertex, TEdge> > algorithm)
            where TEdge : IEdge <TVertex>
        {
            // Check number of vertices = number of strongly connected components
            int components = graph.WeaklyConnectedComponents(new Dictionary <TVertex, int>());

            Assert.AreEqual(components, algorithm.CondensedGraph.VertexCount, "Component count does not match.");
        }
Exemplo n.º 5
0
        private static void CheckVertexCount <TVertex, TEdge>(
            [NotNull] IVertexAndEdgeListGraph <TVertex, TEdge> graph,
            [NotNull] CondensationGraphAlgorithm <TVertex, TEdge, AdjacencyGraph <TVertex, TEdge> > algorithm)
            where TEdge : IEdge <TVertex>
        {
            int count = 0;

            foreach (AdjacencyGraph <TVertex, TEdge> vertices in algorithm.CondensedGraph.Vertices)
            {
                count += vertices.VertexCount;
            }
            Assert.AreEqual(graph.VertexCount, count, "VertexCount does not match.");
        }
Exemplo n.º 6
0
        private static void RunWeaklyConnectedCondensateAndCheck <TVertex, TEdge>(
            [NotNull] IVertexAndEdgeListGraph <TVertex, TEdge> graph)
            where TEdge : IEdge <TVertex>
        {
            var algorithm = new CondensationGraphAlgorithm <TVertex, TEdge, AdjacencyGraph <TVertex, TEdge> >(graph)
            {
                StronglyConnected = false
            };

            algorithm.Compute();
            CheckVertexCount(graph, algorithm);
            CheckEdgeCount(graph, algorithm);
            CheckComponentCount(graph, algorithm);
        }
Exemplo n.º 7
0
        public static IMutableBidirectionalGraph <TGraph, CondensatedEdge <TVertex, TEdge, TGraph> > Condensate <TVertex, TEdge, TGraph>(
            IVertexAndEdgeListGraph <TVertex, TEdge> g)
            where TEdge : IEdge <TVertex>
            where TGraph : IMutableVertexAndEdgeListGraph <TVertex, TEdge>, new()
        {
            if (g == null)
            {
                throw new ArgumentNullException("g");
            }

            CondensationGraphAlgorithm <TVertex, TEdge, TGraph> condensator = new CondensationGraphAlgorithm <TVertex, TEdge, TGraph>(g);

            condensator.Compute();
            return(condensator.CondensatedGraph);
        }
Exemplo n.º 8
0
        /// <summary>
        /// entry point for the application.
        /// </summary>
        public void Test(string outputImageFolder)
        {
            AdjacencyGraph g = new AdjacencyGraph(new MyVertexProvider(), new EdgeProvider(), true);

            MyVertex[] v = new MyVertex[12];
            for (int i = 0; i < 12; i++)
            {
                v[i]       = (MyVertex)g.AddVertex();
                v[i].Name  = "Vertex " + i;
                v[i].Value = i;
            }
            g.AddEdge(v[0], v[1]);
            g.AddEdge(v[1], v[2]);
            g.AddEdge(v[2], v[3]);
            g.AddEdge(v[3], v[0]);
            g.AddEdge(v[2], v[0]);
            g.AddEdge(v[4], v[5]);
            g.AddEdge(v[5], v[6]);
            g.AddEdge(v[6], v[7]);
            g.AddEdge(v[7], v[4]);
            g.AddEdge(v[2], v[5]);
            g.AddEdge(v[8], v[9]);
            g.AddEdge(v[9], v[8]);
            g.AddEdge(v[10], v[11]);
            g.AddEdge(v[11], v[10]);
            g.AddEdge(v[2], v[9]);
            g.AddEdge(v[9], v[10]);

            GraphvizAlgorithm renderer = new GraphvizAlgorithm(g, outputImageFolder, NGraphviz.Helpers.GraphvizImageType.Jpeg);

            renderer.FormatVertex += new FormatVertexEventHandler(FormatGraph);
            renderer.Write("Original_Graph.jpeg");

            CondensationGraphAlgorithm cgalgo = new CondensationGraphAlgorithm(g);

            cgalgo.InitCondensationGraphVertex += new CondensationGraphVertexEventHandler(CGVertexHandler);

            AdjacencyGraph cg = new AdjacencyGraph(new MyVertexProvider(), new EdgeProvider(), true);

            cgalgo.Create(cg);

            //	Render the Condensation Graph
            renderer = new GraphvizAlgorithm(cg, outputImageFolder, NGraphviz.Helpers.GraphvizImageType.Jpeg);
            renderer.FormatVertex += new FormatVertexEventHandler(FormatGraph);
            renderer.Write("CG.jpeg");
        }
        public void Constructor()
        {
            var graph      = new AdjacencyGraph <int, Edge <int> >();
            var algorithm1 = new CondensationGraphAlgorithm <int, Edge <int>, AdjacencyGraph <int, Edge <int> > >(graph);

            AssertAlgorithmProperties(algorithm1, graph);

            algorithm1 = new CondensationGraphAlgorithm <int, Edge <int>, AdjacencyGraph <int, Edge <int> > >(graph)
            {
                StronglyConnected = false
            };
            AssertAlgorithmProperties(algorithm1, graph, false);

            var algorithm2 = new CondensationGraphAlgorithm <int, Edge <int>, BidirectionalGraph <int, Edge <int> > >(graph);

            AssertAlgorithmProperties(algorithm2, graph);

            algorithm2 = new CondensationGraphAlgorithm <int, Edge <int>, BidirectionalGraph <int, Edge <int> > >(graph)
            {
                StronglyConnected = false
            };
            AssertAlgorithmProperties(algorithm2, graph, false);

            #region Local function

            void AssertAlgorithmProperties <TVertex, TEdge, TGraph>(
                CondensationGraphAlgorithm <TVertex, TEdge, TGraph> algo,
                IVertexAndEdgeListGraph <TVertex, TEdge> g,
                bool stronglyConnected = true)
                where TEdge : IEdge <TVertex>
                where TGraph : IMutableVertexAndEdgeSet <TVertex, TEdge>, new()
            {
                AssertAlgorithmState(algo, g);
                Assert.AreEqual(stronglyConnected, algo.StronglyConnected);
                Assert.IsNull(algo.CondensedGraph);
            }

            #endregion
        }