예제 #1
0
        /**
         * Returns List::List::Object with the Lists of nodes of all elementary
         * cycles in the graph.
         *
         * @return List::List::Object with the Lists of the elementary cycles.
         */
        public List <List <int> > getElementaryCycles()
        {
            this.cycles  = new List <List <int> >();
            this.blocked = graphNodes.ToDictionary(n => n, n => false);
            this.B       = graphNodes.ToDictionary(n => n, n => new List <int>());
            this.stack   = new List <int>();
            StronglyConnectedComponents sccs = new StronglyConnectedComponents(adjList);
            int s = 0;

            while (true)
            {
                SCCResult sccResult = sccs.getAdjacencyList(s, graphNodes);
                if (sccResult != null && sccResult.getAdjList() != null)
                {
                    var scc = sccResult.getAdjList();
                    s = sccResult.getLowestNodeId();

                    foreach (var j in scc.Keys)
                    {
                        if ((scc[j] != null) && (scc[j].Count > 0))
                        {
                            blocked[j] = false;
                            B[j]       = new List <int>();
                        }
                    }

                    findCycles(s, s, scc);
                    s = StronglyConnectedComponents.getNextNode(s, graphNodes);
                }
                else
                {
                    break;
                }
            }

            return(cycles);
        }