Example #1
0
        /// <summary>
        /// Returns a list of the vertices contained in this cycle.
        /// The vertices are in the order of a traversal of the cycle.
        /// </summary>
        /// <returns>a list of the vertices contained in this cycle</returns>
        public IList vertexList()
        {
            IList vertices = new ArrayList(edgeSet().Count);

            Object startVertex = vertexSet()[0];

            Object vertex         = startVertex;
            Object previousVertex = null;
            Object nextVertex     = null;

            while (nextVertex != startVertex)
            {
                vertices.Add(vertex);

                Edge edge = (Edge)edgesOf(vertex)[0];
                nextVertex = edge.oppositeVertex(vertex);

                if (nextVertex == previousVertex)
                {
                    edge       = (Edge)edgesOf(vertex)[1];
                    nextVertex = edge.oppositeVertex(vertex);
                }

                previousVertex = vertex;
                vertex         = nextVertex;
            }

            return(vertices);
        }
        /// <summary> Determine path length to a vertex via an edge, using the path length for
        /// the opposite vertex.
        ///
        /// </summary>
        /// <param name="vertex">the vertex for which to calculate the path length.
        /// </param>
        /// <param name="edge">the edge via which the path is being extended.
        ///
        /// </param>
        /// <returns> calculated path length.
        /// </returns>
        private double calculatePathLength(System.Object vertex, Edge edge)
        {
            assertNonNegativeEdge(edge);

            System.Object otherVertex = edge.oppositeVertex(vertex);
            QueueEntry    otherEntry  = (QueueEntry)getSeenData(otherVertex);

            return(otherEntry.ShortestPathLength + edge.Weight);
        }
Example #3
0
        /// <summary> Returns a list of vertices that are the neighbors of a specified vertex.
        /// If the graph is a multigraph vertices may appear more than once in the
        /// returned list.
        ///
        /// </summary>
        /// <param name="g">the graph to look for neighbors in.
        /// </param>
        /// <param name="vertex">the vertex to get the neighbors of.
        ///
        /// </param>
        /// <returns> a list of the vertices that are the neighbors of the specified
        /// vertex.
        /// </returns>
        public static System.Collections.IList neighborListOf(Graph g, System.Object vertex)
        {
            System.Collections.IList neighbors = new System.Collections.ArrayList();

            //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 = g.edgesOf(vertex).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'"
                Edge e = (Edge)i.Current;
                neighbors.Add(e.oppositeVertex(vertex));
            }

            return(neighbors);
        }
Example #4
0
        private static IList createPath(MyBreadthFirstIterator iter, Object endVertex)
        {
            ArrayList path = new ArrayList();

            while (true)
            {
                Edge edge = iter.getSpanningTreeEdge(endVertex);
                if (edge == null)
                {
                    break;
                }

                path.Add(edge);
                endVertex = edge.oppositeVertex(endVertex);
            }

            path.Reverse();
            return(path);
        }
        private void  createEdgeList(ClosestFirstIterator iter, System.Object endVertex)
        {
            m_edgeList = new System.Collections.ArrayList();

            while (true)
            {
                Edge edge = iter.getSpanningTreeEdge(endVertex);

                if (edge == null)
                {
                    break;
                }

                m_edgeList.Add(edge);
                endVertex = edge.oppositeVertex(endVertex);
            }

            ((ArrayList)m_edgeList).Reverse();
        }
Example #6
0
        private void  addUnseenChildrenOf(System.Object vertex)
        {
            System.Collections.IList edges = m_specifics.edgesOf(vertex);

            //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 = edges.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'"
                Edge e = (Edge)i.Current;
                fireEdgeTraversed(createEdgeTraversalEvent(e));

                System.Object v = e.oppositeVertex(vertex);

                if (isSeenVertex(v))
                {
                    encounterVertexAgain(v, e);
                }
                else
                {
                    encounterVertex(v, e);
                }
            }
        }
        //	private void createShortestPathWeightedGraph() {
        //		shortestPathGraph = new DefaultDirectedGraph();
        //		//shortestPathGraph.addAllVertices(g.vertexSet());
        //		shortestPathGraph.addVertex(targetVertex);
        //
        //		// This map gives the distance of a vertex to the target vertex
        //		Map distanceMap = new HashMap();
        //		distanceMap.put(targetVertex, new Integer(0));
        //
        //		for (ClosestFirstIterator iter = new ClosestFirstIterator(g, targetVertex); iter.hasNext(); ) {
        //			Object vertex = iter.next();
        //			shortestPathGraph.addVertex(vertex);
        //
        //			Edge treeEdge = iter.getSpanningTreeEdge(vertex);
        //
        //			// in the first iteration, vertex is the target vertex; therefore no tree edge exists
        //			if (treeEdge != null) {
        //				Object parent = treeEdge.oppositeVertex(vertex);
        //				int distance = ((Integer)distanceMap.get(parent)).intValue() + 1;
        //				distanceMap.put(vertex, new Integer(distance));
        //
        //				for (Iterator edges = g.edgesOf(vertex).iterator(); edges.hasNext();) {
        //					Edge edge = (Edge) edges.next();
        //					Object opposite = edge.oppositeVertex(vertex);
        //					if (distanceMap.get(opposite) != null) {
        //						if (((Integer) distanceMap.get(opposite)).intValue() + 1 == distance) {
        //							shortestPathGraph.addVertex(opposite);
        //							shortestPathGraph.addEdge(vertex, opposite);
        //						}
        //					}
        //				}
        //			}
        //			if (vertex == sourceVertex) {
        //				break;
        //			}
        //		}
        //
        //		Iterator edgeIterator = shortestPathGraph.outgoingEdgesOf(sourceVertex).iterator();
        //
        //		edgeIteratorStack = new Stack();
        //		edgeIteratorStack.push(edgeIterator);
        //
        //		vertexStack = new Stack();
        //		vertexStack.push(sourceVertex);
        //
        //	}

        public virtual bool MoveNext()
        {
            if (next_Renamed_Field == null)
            {
                while (next_Renamed_Field == null && !(edgeIteratorStack.Count == 0))
                {
                    System.Collections.IEnumerator edgeIterator = (System.Collections.IEnumerator)edgeIteratorStack[edgeIteratorStack.Count - 1];
                    System.Object currentVertex = vertexStack[vertexStack.Count - 1];

                    //System.out.println(currentVertex);

                    //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'"
                    if (edgeIterator.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'"
                        Edge edge = (Edge)edgeIterator.Current;
                        currentVertex = edge.oppositeVertex(currentVertex);
                        edgeIterator  = shortestPathGraph.outgoingEdgesOf(currentVertex).GetEnumerator();

                        edgeIteratorStack.Add(edgeIterator);
                        vertexStack.Add(currentVertex);
                    }
                    else
                    {
                        if (currentVertex == targetVertex)
                        {
                            next_Renamed_Field = edgeList(g, vertexStack);
                        }
                        SupportClass.StackSupport.Pop(edgeIteratorStack);
                        SupportClass.StackSupport.Pop(vertexStack);
                    }
                }
            }

            return(next_Renamed_Field != null);
        }
		/// <summary> Determine path length to a vertex via an edge, using the path length for
		/// the opposite vertex.
		/// 
		/// </summary>
		/// <param name="vertex">the vertex for which to calculate the path length.
		/// </param>
		/// <param name="edge">the edge via which the path is being extended.
		/// 
		/// </param>
		/// <returns> calculated path length.
		/// </returns>
		private double calculatePathLength(System.Object vertex, Edge edge)
		{
			assertNonNegativeEdge(edge);
			
			System.Object otherVertex = edge.oppositeVertex(vertex);
			QueueEntry otherEntry = (QueueEntry) getSeenData(otherVertex);
			
			return otherEntry.ShortestPathLength + edge.Weight;
		}
        private System.Collections.IList lazyFindBiconnectedSets()
        {
            if (biconnectedSets_Renamed_Field == null)
            {
                biconnectedSets_Renamed_Field = new System.Collections.ArrayList();

                IList inspector = new ConnectivityInspector(graph).connectedSets();
                System.Collections.IEnumerator connectedSets = inspector.GetEnumerator();

                while (connectedSets.MoveNext())
                {
                    object obj = ((DictionaryEntry)connectedSets.Current).Value;
                    if (!(obj is CSGraphT.SupportClass.HashSetSupport))
                    {
                        continue;
                    }
                    CSGraphT.SupportClass.SetSupport connectedSet = (CSGraphT.SupportClass.SetSupport)obj;
                    if (connectedSet.Count == 1)
                    {
                        continue;
                    }

                    org._3pq.jgrapht.Graph subgraph = new Subgraph(graph, connectedSet, null);

                    // do DFS

                    // Stack for the DFS
                    System.Collections.ArrayList vertexStack = new System.Collections.ArrayList();

                    CSGraphT.SupportClass.SetSupport visitedVertices = new CSGraphT.SupportClass.HashSetSupport();
                    IDictionary parent      = new System.Collections.Hashtable();
                    IList       dfsVertices = new System.Collections.ArrayList();

                    CSGraphT.SupportClass.SetSupport treeEdges = new CSGraphT.SupportClass.HashSetSupport();

                    System.Object currentVertex = subgraph.vertexSet()[0];//.ToArray()[0];

                    vertexStack.Add(currentVertex);
                    visitedVertices.Add(currentVertex);

                    while (!(vertexStack.Count == 0))
                    {
                        currentVertex = SupportClass.StackSupport.Pop(vertexStack);

                        System.Object parentVertex = parent[currentVertex];

                        if (parentVertex != null)
                        {
                            Edge edge = subgraph.getEdge(parentVertex, currentVertex);

                            // tree edge
                            treeEdges.Add(edge);
                        }

                        visitedVertices.Add(currentVertex);

                        dfsVertices.Add(currentVertex);

                        System.Collections.IEnumerator edges = subgraph.edgesOf(currentVertex).GetEnumerator();
                        while (edges.MoveNext())
                        {
                            // find a neighbour vertex of the current vertex
                            Edge edge = (Edge)edges.Current;

                            if (!treeEdges.Contains(edge))
                            {
                                System.Object nextVertex = edge.oppositeVertex(currentVertex);

                                if (!visitedVertices.Contains(nextVertex))
                                {
                                    vertexStack.Add(nextVertex);

                                    parent[nextVertex] = currentVertex;
                                }
                                else
                                {
                                    // non-tree edge
                                }
                            }
                        }
                    }

                    // DFS is finished. Now create the auxiliary graph h
                    // Add all the tree edges as vertices in h
                    SimpleGraph h = new SimpleGraph();

                    h.addAllVertices(treeEdges);

                    visitedVertices.Clear();

                    CSGraphT.SupportClass.SetSupport connected = new CSGraphT.SupportClass.HashSetSupport();

                    for (System.Collections.IEnumerator it = dfsVertices.GetEnumerator(); it.MoveNext();)
                    {
                        System.Object v = it.Current;

                        visitedVertices.Add(v);

                        // find all adjacent non-tree edges
                        for (System.Collections.IEnumerator adjacentEdges = subgraph.edgesOf(v).GetEnumerator(); adjacentEdges.MoveNext();)
                        {
                            Edge l = (Edge)adjacentEdges.Current;
                            if (!treeEdges.Contains(l))
                            {
                                h.addVertex(l);
                                System.Object u = l.oppositeVertex(v);

                                // we need to check if (u,v) is a back-edge
                                if (!visitedVertices.Contains(u))
                                {
                                    while (u != v)
                                    {
                                        System.Object pu = parent[u];
                                        Edge          f  = subgraph.getEdge(u, pu);

                                        h.addEdge(f, l);

                                        if (!connected.Contains(f))
                                        {
                                            connected.Add(f);
                                            u = pu;
                                        }
                                        else
                                        {
                                            u = v;
                                        }
                                    }
                                }
                            }
                        }
                    }

                    ConnectivityInspector connectivityInspector = new ConnectivityInspector(h);

                    biconnectedSets_Renamed_Field.Add(connectivityInspector.connectedSets());
                }
            }

            return(biconnectedSets_Renamed_Field);
        }
        private void  createShortestPathGraph()
        {
            /*		shortestPathGraph = new DefaultDirectedGraph();
             * //shortestPathGraph.addAllVertices(g.vertexSet());
             *
             * LinkedList queue = new LinkedList();
             *
             * //encounter target vertex
             * queue.addLast(targetVertex);
             * shortestPathGraph.addVertex(targetVertex);
             *
             * int distance = 0;
             *
             * Object firstVertexOfNextLevel = targetVertex;
             * Collection verticesOfNextLevel = new ArrayList();
             *
             * while (!queue.isEmpty()) {
             * //provide next vertex
             * Object vertex = queue.removeFirst();
             *
             * if (vertex == firstVertexOfNextLevel) {
             * distance++;
             * firstVertexOfNextLevel = null;
             * verticesOfNextLevel.clear();
             * }
             *
             * //add unseen children of next vertex
             * List edges = g.edgesOf(vertex);
             *
             * for(Iterator i = edges.iterator(); i.hasNext();) {
             * Edge e = (Edge) i.next(  );
             * Object opposite = e.oppositeVertex(vertex);
             *
             * if (!shortestPathGraph.containsVertex(opposite)) {
             * //encounter vertex
             * queue.addLast(opposite);
             * shortestPathGraph.addVertex(opposite);
             *
             * verticesOfNextLevel.add(opposite);
             *
             * if (firstVertexOfNextLevel == null) {
             * firstVertexOfNextLevel = opposite;
             * }
             * }
             *
             *
             * if (verticesOfNextLevel.contains(opposite)) {
             * shortestPathGraph.addEdge(opposite, vertex);
             * }
             * }
             * }*/


            shortestPathGraph = new DefaultDirectedGraph();
            shortestPathGraph.addVertex(targetVertex);

            // This map gives the distance of a vertex to the target vertex
            //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'"
            System.Collections.IDictionary distanceMap = new System.Collections.Hashtable();

            for (MyBreadthFirstIterator iter = new MyBreadthFirstIterator(g, targetVertex); iter.MoveNext();)
            {
                System.Object vertex = iter.Current;
                shortestPathGraph.addVertex(vertex);

                int distance = iter.level;
                distanceMap[vertex] = (System.Int32)distance;

                //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 edges = g.edgesOf(vertex).GetEnumerator(); edges.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'"
                    Edge          edge     = (Edge)edges.Current;
                    System.Object opposite = edge.oppositeVertex(vertex);
                    if (distanceMap[opposite] != null)
                    {
                        if (((System.Int32)distanceMap[opposite]) + 1 == distance)
                        {
                            shortestPathGraph.addVertex(opposite);
                            shortestPathGraph.addEdge(vertex, opposite);
                        }
                    }
                }

                if (vertex == sourceVertex)
                {
                    break;
                }
            }

            System.Collections.IEnumerator edgeIterator = shortestPathGraph.outgoingEdgesOf(sourceVertex).GetEnumerator();

            edgeIteratorStack = new System.Collections.ArrayList();
            edgeIteratorStack.Add(edgeIterator);

            vertexStack = new System.Collections.ArrayList();
            vertexStack.Add(sourceVertex);
        }