コード例 #1
0
		/// <summary>
		/// Compute the condensation graph and store it in the supplied graph 'cg'
		/// </summary>
		/// <param name="cg">
		/// Instance of mutable graph in which the condensation graph 
		/// transformation is stored
		/// </param>
		public void Create( IMutableVertexAndEdgeListGraph cg )	
        {
			if (cg==null)
				throw new ArgumentNullException("cg");			

			if (components==null)
				ComputeComponents();			
					
			//  components list contains collection of 
            // input graph Vertex for each SCC Vertex_ID 
            // (i.e Vector< Vector<Vertex> > )
			//	Key = SCC Vertex ID 
			sccVertexMap = BuildSCCVertexMap(components);
			
			//	Lsit of SCC vertices
			VertexCollection toCgVertices = new VertexCollection();
			IDictionaryEnumerator it = sccVertexMap.GetEnumerator();
			while( it.MoveNext() )	
				//	as scc_vertex_map is a sorted list, order of SCC IDs will match CG vertices
			{
				IVertex curr = cg.AddVertex();
				OnInitCondensationGraphVertex(new CondensationGraphVertexEventArgs(curr, (IVertexCollection)it.Value));
				toCgVertices.Add(curr);
			}
			
			for( int srcSccId=0; srcSccId<sccVertexMap.Keys.Count; srcSccId++ )	
            {   
				VertexCollection adj = new VertexCollection();
				foreach( IVertex u in (IVertexCollection)sccVertexMap[srcSccId] )	
                {					
					foreach(IEdge e in VisitedGraph.OutEdges(u))	{
						IVertex v = e.Target;        			
						int targetSccId = components[v];
						if (srcSccId != targetSccId)	
                        {
							// Avoid loops in the condensation graph
							IVertex sccV = toCgVertices[targetSccId];
							if( !adj.Contains(sccV) )		// Avoid parallel edges
								adj.Add(sccV);
						}
					}
				}
				IVertex s = toCgVertices[srcSccId];
				foreach( IVertex t in adj )
					cg.AddEdge(s, t);
			}
		}
コード例 #2
0
 public void Create(IMutableVertexAndEdgeListGraph cg)
 {
     if (cg == null)
     {
         throw new ArgumentNullException("cg");
     }
     if (this.components == null)
     {
         this.ComputeComponents();
     }
     this.sccVertexMap = this.BuildSCCVertexMap(this.components);
     VertexCollection vertexs = new VertexCollection();
     IDictionaryEnumerator enumerator = this.sccVertexMap.GetEnumerator();
     while (enumerator.MoveNext())
     {
         IVertex cgVertex = cg.AddVertex();
         this.OnInitCondensationGraphVertex(new CondensationGraphVertexEventArgs(cgVertex, (IVertexCollection) enumerator.Value));
         vertexs.Add(cgVertex);
     }
     for (int i = 0; i < this.sccVertexMap.Keys.Count; i++)
     {
         VertexCollection vertexs2 = new VertexCollection();
         IVertexEnumerator enumerator2 = ((IVertexCollection) this.sccVertexMap[i]).GetEnumerator();
         while (enumerator2.MoveNext())
         {
             IVertex vertex2 = enumerator2.get_Current();
             IEdgeEnumerator enumerator3 = this.VisitedGraph.OutEdges(vertex2).GetEnumerator();
             while (enumerator3.MoveNext())
             {
                 IVertex vertex3 = enumerator3.get_Current().get_Target();
                 int num2 = this.components.get_Item(vertex3);
                 if (i != num2)
                 {
                     IVertex vertex4 = vertexs.get_Item(num2);
                     if (!vertexs2.Contains(vertex4))
                     {
                         vertexs2.Add(vertex4);
                     }
                 }
             }
         }
         IVertex vertex5 = vertexs.get_Item(i);
         VertexCollection.Enumerator enumerator4 = vertexs2.GetEnumerator();
         while (enumerator4.MoveNext())
         {
             IVertex vertex6 = enumerator4.get_Current();
             cg.AddEdge(vertex5, vertex6);
         }
     }
 }