/// <summary> Constructs a minimum cycle basis of a graph. /// /// </summary> /// <param name="g">the graph for the cycle basis /// </param> public CycleBasis(UndirectedGraph g) { baseGraph = g; // We construct a simple graph out of the input (multi-)graph // as a subgraph with no multiedges. // The removed edges are collected in multiEdgeList // Moreover, shortest cycles through these edges are constructed and // collected in mulitEdgeCycles UndirectedGraph simpleGraph = new UndirectedSubgraph(g, null, null); // Iterate over the edges and discard all edges with the same source and target //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 it = g.edgeSet().GetEnumerator(); it.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)((DictionaryEntry)it.Current).Value; System.Object u = edge.Source; System.Object v = edge.Target; System.Collections.IList edges = simpleGraph.getAllEdges(u, v); if (edges.Count > 1) { // Multiple edges between u and v. // Keep the edge with the least weight Edge minEdge = edge; //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 jt = edges.GetEnumerator(); jt.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 nextEdge = (Edge)jt.Current; minEdge = nextEdge.Weight < minEdge.Weight ? nextEdge : minEdge; } // ...and remove the others. //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 jt = edges.GetEnumerator(); jt.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 nextEdge = (Edge)jt.Current; if (nextEdge != minEdge) { // Remove edge from the graph simpleGraph.removeEdge(nextEdge); // Create a new cycle through this edge by finding // a shortest path between the vertices of the edge //UPGRADE_TODO: Class 'java.util.HashSet' was converted to 'CSGraphT.SupportClass.HashSetSupport' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilHashSet'" CSGraphT.SupportClass.SetSupport edgesOfCycle = new CSGraphT.SupportClass.HashSetSupport(); edgesOfCycle.Add(nextEdge); edgesOfCycle.AddAll(DijkstraShortestPath.findPathBetween(simpleGraph, u, v)); multiEdgeList.Add(nextEdge); mulitEdgeCycles.Add(new SimpleCycle(baseGraph, edgesOfCycle)); } } } } System.Collections.IList biconnectedComponents = new BiconnectivityInspector(simpleGraph).biconnectedSets(); for (IEnumerator it = biconnectedComponents.GetEnumerator(); it.MoveNext();) { CSGraphT.SupportClass.SetSupport edges = (CSGraphT.SupportClass.SetSupport)it.Current; //IList edges = (IList)it.Current; if (edges.Count > 1) { CSGraphT.SupportClass.SetSupport vertices = new CSGraphT.SupportClass.HashSetSupport(); for (System.Collections.IEnumerator edgeIt = edges.GetEnumerator(); edgeIt.MoveNext();) { Edge edge = (Edge)((DictionaryEntry)edgeIt.Current).Value; vertices.Add(edge.Source); vertices.Add(edge.Target); } UndirectedGraph subgraph = new UndirectedSubgraph(simpleGraph, vertices, edges); SimpleCycleBasis cycleBasis = new SimpleCycleBasis(subgraph); subgraphBases.Add(cycleBasis); } else { Edge edge = (Edge)((DictionaryEntry)edges.GetEnumerator().Current).Value; multiEdgeList.Add(edge); } } }
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); }