Beispiel #1
0
        /// <summary> Initializes the internal traversal object structure. Sets up the
        /// internal queue with the directed graph vertices and creates the control
        /// structure for the in-degrees.
        ///
        /// </summary>
        /// <param name="dg">the directed graph to be iterated.
        /// </param>
        /// <param name="queue">initializer for m_queue
        /// </param>
        /// <param name="inDegreeMap">initializer for m_inDegreeMap
        ///
        /// </param>
        /// <returns> start vertex
        /// </returns>
        //UPGRADE_TODO: Class 'java.util.LinkedList' was converted to 'System.Collections.ArrayList' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilLinkedList'"
        private static System.Object initialize(DirectedGraph dg, System.Collections.ArrayList queue, System.Collections.IDictionary inDegreeMap)
        {
            //UPGRADE_TODO: Method 'java.util.Iterator.hasNext' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratorhasNext'"
            for (System.Collections.IEnumerator i = dg.vertexSet().GetEnumerator(); i.MoveNext();)
            {
                //UPGRADE_TODO: Method 'java.util.Iterator.next' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratornext'"
                System.Object vertex = i.Current;

                int inDegree = dg.inDegreeOf(vertex);
                inDegreeMap[vertex] = new ModifiableInteger(inDegree);

                if (inDegree == 0)
                {
                    queue.Add(vertex);
                }
            }

            if ((queue.Count == 0))
            {
                return(null);
            }
            else
            {
                return(queue[0]);
            }
        }
Beispiel #2
0
        /// <summary> The constructor of the StrongConnectivityInspector class.
        ///
        /// </summary>
        /// <param name="directedGraph">the graph to inspect
        ///
        /// </param>
        /// <throws>  IllegalArgumentException </throws>
        public StrongConnectivityInspector(DirectedGraph directedGraph)
        {
            if (directedGraph == null)
            {
                throw new System.ArgumentException("null not allowed for graph!");
            }

            m_graph = directedGraph;
            m_vertexToVertexData         = null;
            m_orderedVertices            = null;
            m_stronglyConnectedSets      = null;
            m_stronglyConnectedSubgraphs = null;
        }
Beispiel #3
0
        /*
         * The subroutine of DFS. NOTE: the set is used to distinguish between 1st
         * and 2nd round of DFS. set == null: finished vertices are stored (1st
         * round). set != null: all vertices found will be saved in the set (2nd
         * round)
         */
        private void  dfsVisit(DirectedGraph graph, VertexData vertexData, SupportClass.SetSupport vertices)
        {
            System.Collections.ArrayList stack = new System.Collections.ArrayList();
            stack.Add(vertexData);

            while (!(stack.Count == 0))
            {
                VertexData data = (VertexData)SupportClass.StackSupport.Pop(stack);

                if (!data.m_discovered)
                {
                    data.m_discovered = true;

                    if (vertices != null)
                    {
                        vertices.Add(data.m_vertex);
                    }

                    // TODO: other way to identify when this vertex is finished!?
                    stack.Add(new VertexData(this, data, true, true));

                    // follow all edges
                    System.Collections.IEnumerator iter = graph.outgoingEdgesOf(data.m_vertex).GetEnumerator();

                    //UPGRADE_TODO: Method 'java.util.Iterator.hasNext' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratorhasNext'"
                    while (iter.MoveNext())
                    {
                        //UPGRADE_TODO: Method 'java.util.Iterator.next' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratornext'"
                        DirectedEdge edge       = (DirectedEdge)iter.Current;
                        VertexData   targetData = (VertexData)m_vertexToVertexData[edge.Target];

                        if (!targetData.m_discovered)
                        {
                            // the "recursion"
                            stack.Add(targetData);
                        }
                    }
                }
                else if (data.m_finished)
                {
                    if (vertices == null)
                    {
                        // see TODO above
                        m_orderedVertices.Insert(0, data.m_vertex);
                    }
                }
            }
        }
		/// <summary> Creates a new listenable directed graph.
		/// 
		/// </summary>
		/// <param name="base">the backing graph.
		/// </param>
		public ListenableDirectedGraph(DirectedGraph base_Renamed):base(base_Renamed)
		{
		}
Beispiel #5
0
 /// <summary> Creates a cycle detector for the specified graph.  Currently only
 /// directed graphs are supported.
 ///
 /// </summary>
 /// <param name="graph">the DirectedGraph in which to detect cycles
 /// </param>
 public CycleDetector(DirectedGraph graph)
 {
     m_graph = graph;
 }
		/// <summary> Creates a new directed subgraph.
		/// 
		/// </summary>
		/// <param name="base">the base (backing) graph on which the subgraph will be
		/// based.
		/// </param>
		/// <param name="vertexSubset">vertices to include in the subgraph. If
		/// <code>null</code> then all vertices are included.
		/// </param>
		/// <param name="edgeSubset">edges to in include in the subgraph. If
		/// <code>null</code> then all the edges whose vertices found in the
		/// graph are included.
		/// </param>
		public DirectedSubgraph(DirectedGraph base_Renamed, SupportClass.SetSupport vertexSubset, SupportClass.SetSupport edgeSubset):base(base_Renamed, vertexSubset, edgeSubset)
		{
		}
 /// <summary> Constructor for AsUndirectedGraph.
 ///
 /// </summary>
 /// <param name="g">the backing directed graph over which an undirected view is to
 /// be created.
 /// </param>
 public AsUndirectedGraph(DirectedGraph g) : base(g)
 {
 }
 /// <summary> Creates a new unmodifiable directed graph based on the specified backing
 /// graph.
 ///
 /// </summary>
 /// <param name="g">the backing graph on which an unmodifiable graph is to be
 /// created.
 /// </param>
 public UnmodifiableDirectedGraph(DirectedGraph g) : base(g)
 {
 }
		// NOTE: This is a hack to deal with the fact that CrossComponentIterator
		// needs to know the start vertex in its constructor
		//UPGRADE_TODO: Class 'java.util.LinkedList' was converted to 'System.Collections.ArrayList' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilLinkedList'"
		private TopologicalOrderIterator(DirectedGraph dg, System.Collections.ArrayList queue, System.Collections.IDictionary inDegreeMap):this(dg, initialize(dg, queue, inDegreeMap))
		{
			m_queue = queue;
			m_inDegreeMap = inDegreeMap;
		}
Beispiel #10
0
 // NOTE: This is a hack to deal with the fact that CrossComponentIterator
 // needs to know the start vertex in its constructor
 //UPGRADE_TODO: Class 'java.util.LinkedList' was converted to 'System.Collections.ArrayList' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilLinkedList'"
 private TopologicalOrderIterator(DirectedGraph dg, System.Collections.ArrayList queue, System.Collections.IDictionary inDegreeMap) : this(dg, initialize(dg, queue, inDegreeMap))
 {
     m_queue       = queue;
     m_inDegreeMap = inDegreeMap;
 }
Beispiel #11
0
 /// <summary> Creates a new topological order iterator over the directed graph
 /// specified. Traversal will start at one of the graphs <i>sources</i>.
 /// See the definition of source at <a
 /// href="http://mathworld.wolfram.com/Source.html">
 /// http://mathworld.wolfram.com/Source.html</a>.
 ///
 /// </summary>
 /// <param name="dg">the directed graph to be iterated.
 /// </param>
 //UPGRADE_TODO: Class 'java.util.LinkedList' was converted to 'System.Collections.ArrayList' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilLinkedList'"
 //UPGRADE_TODO: Class 'java.util.HashMap' was converted to 'System.Collections.Hashtable' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilHashMap'"
 public TopologicalOrderIterator(DirectedGraph dg) : this(dg, new System.Collections.ArrayList(), new System.Collections.Hashtable())
 {
 }
		/// <summary> Initializes the internal traversal object structure. Sets up the
		/// internal queue with the directed graph vertices and creates the control
		/// structure for the in-degrees.
		/// 
		/// </summary>
		/// <param name="dg">the directed graph to be iterated.
		/// </param>
		/// <param name="queue">initializer for m_queue
		/// </param>
		/// <param name="inDegreeMap">initializer for m_inDegreeMap
		/// 
		/// </param>
		/// <returns> start vertex
		/// </returns>
		//UPGRADE_TODO: Class 'java.util.LinkedList' was converted to 'System.Collections.ArrayList' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilLinkedList'"
		private static System.Object initialize(DirectedGraph dg, System.Collections.ArrayList queue, System.Collections.IDictionary inDegreeMap)
		{
			//UPGRADE_TODO: Method 'java.util.Iterator.hasNext' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratorhasNext'"
			for (System.Collections.IEnumerator i = dg.vertexSet().GetEnumerator(); i.MoveNext(); )
			{
				//UPGRADE_TODO: Method 'java.util.Iterator.next' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratornext'"
				System.Object vertex = i.Current;
				
				int inDegree = dg.inDegreeOf(vertex);
				inDegreeMap[vertex] = new ModifiableInteger(inDegree);
				
				if (inDegree == 0)
				{
					queue.Add(vertex);
				}
			}
			
			if ((queue.Count == 0))
			{
				return null;
			}
			else
			{
				return queue[0];
			}
		}
		// NOTE: This is intentionally private, because starting the sort "in the
		// middle" doesn't make sense.
		private TopologicalOrderIterator(DirectedGraph dg, System.Object start):base(dg, start)
		{
		}
Beispiel #14
0
 /// <summary> Creates a new directed subgraph.
 ///
 /// </summary>
 /// <param name="base">the base (backing) graph on which the subgraph will be
 /// based.
 /// </param>
 /// <param name="vertexSubset">vertices to include in the subgraph. If
 /// <code>null</code> then all vertices are included.
 /// </param>
 /// <param name="edgeSubset">edges to in include in the subgraph. If
 /// <code>null</code> then all the edges whose vertices found in the
 /// graph are included.
 /// </param>
 public DirectedSubgraph(DirectedGraph base_Renamed, SupportClass.SetSupport vertexSubset, SupportClass.SetSupport edgeSubset) : base(base_Renamed, vertexSubset, edgeSubset)
 {
 }
Beispiel #15
0
 // NOTE: This is intentionally private, because starting the sort "in the
 // middle" doesn't make sense.
 private TopologicalOrderIterator(DirectedGraph dg, System.Object start) : base(dg, start)
 {
 }
Beispiel #16
0
 /// <summary> Creates a new listenable directed graph.
 ///
 /// </summary>
 /// <param name="base">the backing graph.
 /// </param>
 public ListenableDirectedGraph(DirectedGraph base_Renamed) : base(base_Renamed)
 {
 }
		/// <summary> Creates a new topological order iterator over the directed graph
		/// specified. Traversal will start at one of the graphs <i>sources</i>.
		/// See the definition of source at <a
		/// href="http://mathworld.wolfram.com/Source.html">
		/// http://mathworld.wolfram.com/Source.html</a>.
		/// 
		/// </summary>
		/// <param name="dg">the directed graph to be iterated.
		/// </param>
		//UPGRADE_TODO: Class 'java.util.LinkedList' was converted to 'System.Collections.ArrayList' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilLinkedList'"
		//UPGRADE_TODO: Class 'java.util.HashMap' was converted to 'System.Collections.Hashtable' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilHashMap'"
		public TopologicalOrderIterator(DirectedGraph dg):this(dg, new System.Collections.ArrayList(), new System.Collections.Hashtable())
		{
		}