Example #1
0
        /// <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);
                }
            }
        }
Example #2
0
        /// <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);
                }
            }
        }