public void Constructor()
        {
            VertexPredicate <int> vertexPredicate = vertex => true;
            var graph          = new BidirectionalGraph <int, Edge <int> >();
            var condensedGraph = new BidirectionalGraph <int, MergedEdge <int, Edge <int> > >();
            var algorithm      = new EdgeMergeCondensationGraphAlgorithm <int, Edge <int> >(graph, condensedGraph, vertexPredicate);

            AssertAlgorithmProperties(algorithm, graph, condensedGraph, vertexPredicate);

            #region Local function

            void AssertAlgorithmProperties <TVertex, TEdge>(
                EdgeMergeCondensationGraphAlgorithm <TVertex, TEdge> algo,
                IBidirectionalGraph <TVertex, TEdge> g,
                IMutableBidirectionalGraph <TVertex, MergedEdge <TVertex, TEdge> > cg,
                VertexPredicate <TVertex> predicate)
                where TEdge : IEdge <TVertex>
            {
                AssertAlgorithmState(algo, g);
                Assert.AreSame(predicate, algo.VertexPredicate);
                Assert.AreSame(cg, algo.CondensedGraph);
            }

            #endregion
        }
Example #2
0
        public GcTypeHeap Merge(int minimumSize)
        {
            var merged = new BidirectionalGraph <GcType, MergedEdge <GcType, GcTypeEdge> >(false, this.graph.VertexCount);
            var merger = new EdgeMergeCondensationGraphAlgorithm <GcType, GcTypeEdge>(
                this.graph,
                merged,
                delegate(GcType type)
            {
                return(type.Size >= minimumSize);
            });

            merger.Compute();
            var clone = new BidirectionalGraph <GcType, GcTypeEdge>(
                false,
                merged.VertexCount);

            foreach (var type in merged.Vertices)
            {
                clone.AddVertex(type);
            }
            foreach (var medge in merged.Edges)
            {
                GcTypeEdge edge = new GcTypeEdge(medge.Source, medge.Target);
                foreach (GcTypeEdge e in medge.Edges)
                {
                    edge.Count += e.Count;
                }
                clone.AddEdge(edge);
            }

            Console.WriteLine("resulting {0} types, {1} edges", clone.VertexCount, clone.EdgeCount);
            return(new GcTypeHeap(clone));
        }
        CondensateEdges <TVertex, TEdge>(this IBidirectionalGraph <TVertex, TEdge> visitedGraph,
                                         VertexPredicate <TVertex> vertexPredicate
                                         ) where TEdge : IEdge <TVertex>
        {
            Contract.Requires(visitedGraph != null);
            Contract.Requires(vertexPredicate != null);

            var condensated = new BidirectionalGraph <TVertex, MergedEdge <TVertex, TEdge> >();
            var condensator = new EdgeMergeCondensationGraphAlgorithm <TVertex, TEdge>(
                visitedGraph,
                condensated,
                vertexPredicate);

            condensator.Compute();

            return(condensated);
        }
Example #4
0
        public GcTypeHeap Merge(int minimumSize)
        {
            var merged = new BidirectionalGraph<GcType,MergedEdge<GcType,GcTypeEdge>>(false, this.graph.VertexCount);
            var merger = new EdgeMergeCondensationGraphAlgorithm<GcType, GcTypeEdge>(
                this.graph,
                merged,
                delegate(GcType type)
                {
                    return type.Size >= minimumSize;
                });
            merger.Compute();
            var clone = new BidirectionalGraph<GcType, GcTypeEdge>(
                false,
                merged.VertexCount);
            foreach (var type in merged.Vertices)
                clone.AddVertex(type);
            foreach (var medge in merged.Edges)
            {
                GcTypeEdge edge = new GcTypeEdge(medge.Source, medge.Target);
                foreach (GcTypeEdge e in medge.Edges)
                    edge.Count += e.Count;
                clone.AddEdge(edge);
            }

            Console.WriteLine("resulting {0} types, {1} edges", clone.VertexCount, clone.EdgeCount);
            return new GcTypeHeap(clone);
        }