コード例 #1
0
        private void MergeVertex(TVertex v)
        {
            // get in edges and outedge
            List <MergedEdge <TVertex, TEdge> > inEdges =
                new List <MergedEdge <TVertex, TEdge> >(this.CondensatedGraph.InEdges(v));
            List <MergedEdge <TVertex, TEdge> > outEdges =
                new List <MergedEdge <TVertex, TEdge> >(this.CondensatedGraph.OutEdges(v));

            // remove vertex
            this.CondensatedGraph.RemoveVertex(v);

            // add condensated edges
            for (int i = 0; i < inEdges.Count; ++i)
            {
                MergedEdge <TVertex, TEdge> inEdge = inEdges[i];
                if (inEdge.Source.Equals(v))
                {
                    continue;
                }

                for (int j = 0; j < outEdges.Count; ++j)
                {
                    MergedEdge <TVertex, TEdge> outEdge = outEdges[j];
                    if (outEdge.Target.Equals(v))
                    {
                        continue;
                    }

                    MergedEdge <TVertex, TEdge> newEdge =
                        MergedEdge <TVertex, TEdge> .Merge(inEdge, outEdge);

                    this.CondensatedGraph.AddEdge(newEdge);
                }
            }
        }
コード例 #2
0
        protected override void InternalCompute()
        {
            // adding vertices to the new graph
            // and pusing filtered vertices in queue
            Queue <TVertex> filteredVertices = new Queue <TVertex>();

            foreach (var v in this.VisitedGraph.Vertices)
            {
                this.CondensatedGraph.AddVertex(v);
                if (!this.VertexPredicate(v))
                {
                    filteredVertices.Enqueue(v);
                }
            }

            // adding all edges
            foreach (var edge in this.VisitedGraph.Edges)
            {
                MergedEdge <TVertex, TEdge> mergedEdge = new MergedEdge <TVertex, TEdge>(edge.Source, edge.Target);
                mergedEdge.Edges.Add(edge);

                this.CondensatedGraph.AddEdge(mergedEdge);
            }

            // remove vertices
            while (filteredVertices.Count > 0)
            {
                TVertex filteredVertex = filteredVertices.Dequeue();

                // do the cross product between inedges and outedges
                MergeVertex(filteredVertex);
            }
        }
コード例 #3
0
ファイル: MergedEdge.cs プロジェクト: barsgroup/QuickGraph
        public static MergedEdge <TVertex, TEdge> Merge(
            MergedEdge <TVertex, TEdge> inEdge,
            MergedEdge <TVertex, TEdge> outEdge
            )
        {
            MergedEdge <TVertex, TEdge> newEdge = new MergedEdge <TVertex, TEdge>(
                inEdge.Source, outEdge.Target);

            newEdge.edges = new List <TEdge>(inEdge.Edges.Count + outEdge.Edges.Count);
            newEdge.edges.AddRange(inEdge.Edges);
            newEdge.edges.AddRange(outEdge.edges);

            return(newEdge);
        }
コード例 #4
0
ファイル: MergedEdge.cs プロジェクト: kigyoteve/QuickGraph
        public static MergedEdge <TVertex, TEdge> Merge(
            MergedEdge <TVertex, TEdge> inEdge,
            MergedEdge <TVertex, TEdge> outEdge
            )
        {
            Contract.Requires(inEdge != null);
            Contract.Requires(outEdge != null);
            MergedEdge <TVertex, TEdge> newEdge = new MergedEdge <TVertex, TEdge>(
                inEdge.Source, outEdge.Target);

            newEdge.edges = new List <TEdge>(inEdge.Edges.Count + outEdge.Edges.Count);
            newEdge.edges.AddRange(inEdge.Edges);
            newEdge.edges.AddRange(outEdge.edges);

            return(newEdge);
        }