// private void minimize() { // // if (isMinimized) // return; // // if (cycles.size()==0) // return; // else // minimize(0); // // isMinimized = true; // } private void minimize(int startIndex) { if (isMinimized) return; // Implementation of "Algorithm 1" from [BGdV04] bool[][] a = getCycleEdgeIncidenceMatrix(); for (int i = startIndex; i < cycles_Renamed_Field.Count; i++) { // "Subroutine 2" // Construct kernel vector u bool[] u = constructKernelVector(edgeList.Count, a, i); // Construct auxiliary graph gu AuxiliaryGraph gu = new AuxiliaryGraph(this, graph, u); SimpleCycle shortestCycle = (SimpleCycle)cycles_Renamed_Field[i]; System.Collections.IEnumerator vertexIterator = graph.vertexSet().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 (vertexIterator.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 = vertexIterator.Current; // check if the vertex is incident to an edge with u[edge] == 1 bool shouldSearchCycle = false; System.Collections.ICollection incidentEdges = graph.edgesOf(vertex); System.Collections.IEnumerator edgeIterator = incidentEdges.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 (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; int index = getEdgeIndex(edge); if (u[index]) { shouldSearchCycle = true; break; } } if (shouldSearchCycle) { System.Object auxVertex0 = gu.auxVertex0(vertex); System.Object auxVertex1 = gu.auxVertex1(vertex); // Search for shortest path System.Collections.IList auxPath = BFSShortestPath.findPathBetween(gu, auxVertex0, auxVertex1); System.Collections.IList edgesOfNewCycle = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10)); System.Object v = vertex; edgeIterator = auxPath.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 (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 auxEdge = (Edge)edgeIterator.Current; // Get the edge corresponding to the aux. edge Edge e = (Edge)gu.edge(auxEdge); edgesOfNewCycle.Add(e); // Get next vertex on path v = e.oppositeVertex(v); } SimpleCycle newCycle = new SimpleCycle(graph, edgesOfNewCycle); if (newCycle.weight() < shortestCycle.weight()) { shortestCycle = newCycle; } } } cycles_Renamed_Field[i] = shortestCycle; // insert the new cycle into the matrix for (int j = 1; j < edgeList.Count; j++) { a[i][j] = shortestCycle.containsEdge((Edge)edgeList[j]); } // perform gaussian elimination on the inserted row for (int j = 0; j < i; j++) { if (a[i][j]) { for (int k = 0; k < edgeList.Count; k++) { a[i][k] = (a[i][k] != a[j][k]); } } } } isMinimized = true; }
public virtual System.Collections.IDictionary relevantCycles() { //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 result = new System.Collections.Hashtable(); bool[][] a = getCycleEdgeIncidenceMatrix(); bool[][] ai = inverseBinaryMatrix(a, cycles_Renamed_Field.Count); for (int i = 0; i < cycles_Renamed_Field.Count; i++) { // Construct kernel vector u from a column of the inverse of a bool[] u = new bool[edgeList.Count]; for (int j = 0; j < cycles_Renamed_Field.Count; j++) { u[j] = ai[j][i]; } // Construct auxiliary graph gu AuxiliaryGraph gu = new AuxiliaryGraph(this, graph, u); System.Collections.IEnumerator vertexIterator = graph.vertexSet().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 (vertexIterator.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 = vertexIterator.Current; System.Collections.ICollection incidentEdges = graph.edgesOf(vertex); // check if the vertex is incident to an edge with u[edge] == 1 bool shouldSearchCycle = false; //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 = incidentEdges.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)it.Current; int index = getEdgeIndex(edge); if (u[index]) { shouldSearchCycle = true; break; } } if (shouldSearchCycle) { System.Object auxVertex0 = gu.auxVertex0(vertex); System.Object auxVertex1 = gu.auxVertex1(vertex); // Search for shortest paths //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 minPaths = new MinimalPathIterator(gu, auxVertex0, auxVertex1); minPaths.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.Collections.IList auxPath = (System.Collections.IList)minPaths.Current; System.Collections.IList edgesOfNewCycle = new System.Collections.ArrayList(auxPath.Count); System.Collections.IEnumerator edgeIterator = auxPath.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 (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 auxEdge = (Edge)edgeIterator.Current; // Get the edge corresponding to the aux. edge Edge e = (Edge)gu.edge(auxEdge); edgesOfNewCycle.Add(e); } SimpleCycle cycle = new SimpleCycle(graph, edgesOfNewCycle); if (cycle.weight() > ((SimpleCycle)cycles_Renamed_Field[i]).weight()) { break; } result[cycle] = (SimpleCycle)cycles_Renamed_Field[i]; } } } } return result; }
private void createMinimumCycleBasis() { org._3pq.jgrapht.Graph subgraph = new Subgraph(graph, null, null); CSGraphT.SupportClass.SetSupport remainingEdges = new CSGraphT.SupportClass.HashSetSupport(graph.edgeSet()); //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 selectedEdges = new CSGraphT.SupportClass.HashSetSupport(); while (!(remainingEdges.Count == 0)) { //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)remainingEdges.GetEnumerator().Current; subgraph.removeEdge(edge); // Compute a shortest cycle through edge System.Collections.IList path = BFSShortestPath.findPathBetween(subgraph, edge.Source, edge.Target); path.Add(edge); SimpleCycle cycle = new SimpleCycle(graph, path); subgraph.addEdge(edge); selectedEdges.Add(edge); cycles_Renamed_Field.Insert(0, cycle); edgeList.Insert(0, edge); SupportClass.ICollectionSupport.RemoveAll(remainingEdges, path); } subgraph.removeAllEdges(selectedEdges); // The cycles just created are already minimal, so we can start minimizing at startIndex int startIndex = cycles_Renamed_Field.Count; // Now we perform a breadth first traversal and build a fundamental tree base // ("Kirchhoff base") of the remaining subgraph System.Object currentVertex = graph.vertexSet()[0]; // We build a spanning tree as a directed graph to easily find the parent of a // vertex in the tree. This means however that we have to create new Edge objects // for the tree and can't just use the Edge objects of the graph, since the // the edge in the graph might have a wrong or no direction. DirectedGraph spanningTree = new SimpleDirectedGraph(); //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 visitedEdges = new CSGraphT.SupportClass.HashSetSupport(); // FIFO for the BFS //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'" System.Collections.ArrayList vertexQueue = new System.Collections.ArrayList(); // currentVertex is the root of the spanning tree spanningTree.addVertex(currentVertex); vertexQueue.Insert(vertexQueue.Count, currentVertex); // We need to remember the tree edges so we can add them at once to the // index list for the incidence matrix System.Collections.IList treeEdges = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10)); while (!(vertexQueue.Count == 0)) { System.Object tempObject; tempObject = vertexQueue[0]; vertexQueue.RemoveAt(0); currentVertex = tempObject; System.Collections.IEnumerator edges = subgraph.edgesOf(currentVertex).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 (edges.MoveNext()) { // find a neighbour vertex of the current vertex //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; if (!visitedEdges.Contains(edge)) { // mark edge as visited visitedEdges.Add(edge); System.Object nextVertex = edge.oppositeVertex(currentVertex); if (!spanningTree.containsVertex(nextVertex)) { // tree edge treeEdges.Add(edge); spanningTree.addVertex(nextVertex); // create a new (directed) Edge object (as explained above) spanningTree.addEdge(currentVertex, nextVertex); // add the next vertex to the BFS-FIFO vertexQueue.Insert(vertexQueue.Count, nextVertex); } else { // non-tree edge // This edge defines a cycle together with the edges of the spanning tree // along the path to the root of the tree. We create a new cycle containing // these edges (not the tree edges, but the corresponding edges in the graph) System.Collections.IList edgesOfCycle = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10)); // follow the path to the root of the tree System.Object vertex = currentVertex; // get parent of vertex System.Collections.IList incomingEdgesOfVertex = spanningTree.incomingEdgesOf(vertex); System.Object parent = (incomingEdgesOfVertex.Count == 0) ? null : ((Edge)incomingEdgesOfVertex[0]).oppositeVertex(vertex); while (parent != null) { // add the corresponding edge to the cycle edgesOfCycle.Add(subgraph.getEdge(vertex, parent)); // go up the tree vertex = parent; // get parent of vertex incomingEdgesOfVertex = spanningTree.incomingEdgesOf(vertex); parent = (incomingEdgesOfVertex.Count == 0) ? null : ((Edge)incomingEdgesOfVertex[0]).oppositeVertex(vertex); } // do the same thing for nextVertex vertex = nextVertex; // get parent of vertex incomingEdgesOfVertex = spanningTree.incomingEdgesOf(vertex); parent = (incomingEdgesOfVertex.Count == 0) ? null : ((Edge)incomingEdgesOfVertex[0]).oppositeVertex(vertex); while (parent != null) { edgesOfCycle.Add(subgraph.getEdge(vertex, parent)); vertex = parent; // get parent of vertex incomingEdgesOfVertex = spanningTree.incomingEdgesOf(vertex); parent = (incomingEdgesOfVertex.Count == 0) ? null : ((Edge)incomingEdgesOfVertex[0]).oppositeVertex(vertex); } // finally, add the non-tree edge to the cycle edgesOfCycle.Add(edge); // add the edge to the index list for the incidence matrix edgeList.Add(edge); SimpleCycle newCycle = new SimpleCycle(graph, edgesOfCycle); cycles_Renamed_Field.Add(newCycle); } } } } // Add all the tree edges to the index list for the incidence matrix SupportClass.ICollectionSupport.AddAll(edgeList, treeEdges); edgeIndexMap = createEdgeIndexMap(edgeList); // Now the index list is ordered: first the non-tree edges, then the tree edge. // Moreover, since the cycles and the corresponding non-tree edge have been added // to their lists in the same order, the incidence matrix is in upper triangular form. // Now we can minimize the cycles created from the tree base minimize(startIndex); }