Exemplo n.º 1
0
        /** Visit a state (perform DFS) */
        public void visit(int v)
        {
            SCC_DFS_Data sdd = new SCC_DFS_Data();
            sdd.dfs_nr = current_dfs_nr++;
            sdd.root_index = v;
            sdd.inComponent = false;

            _stack.Push(v);

            //todo: be careful of the following swap
            //_dfs_data[v].reset(sdd);
            //Ultility.swap(_dfs_data[v], sdd);
            _dfs_data[v] = sdd;

            //for (typename SuccessorAccess::successor_iterator  succ_it=_successor_access.begin(_graph, v);succ_it!=_successor_access.end(_graph, v); ++succ_it)
            if(_labelMark == null)
            {
                for (KeyValuePair<APElement, BitSet> it_set = _graph[v].edges_begin(); !_graph[v].edges_end(); it_set = _graph[v].increment())
                {
                    for (int succ_it = BitSetIterator.start(it_set.Value); succ_it != BitSetIterator.end(it_set.Value); succ_it = BitSetIterator.increment(it_set.Value, succ_it))
                    {
                        int w = succ_it;

                        if (_dfs_data[w] == null) //.get()
                        {
                            // not yet visited
                            visit(w);
                        }

                        SCC_DFS_Data sdd_w = _dfs_data[w]; //.get();
                        if (sdd_w.inComponent == false)
                        {
                            int dfs_nr_root_v = _dfs_data[sdd.root_index].dfs_nr;
                            int dfs_nr_root_w = _dfs_data[sdd_w.root_index].dfs_nr;

                            if (dfs_nr_root_v > dfs_nr_root_w)
                            {
                                sdd.root_index = sdd_w.root_index;
                            }
                        }
                    }
                }
            }
            else
            {
                BitSet it_set = _graph[v].getEdge(_labelMark);
                for (int succ_it = BitSetIterator.start(it_set); succ_it != BitSetIterator.end(it_set); succ_it = BitSetIterator.increment(it_set, succ_it))
                {
                    int w = succ_it;

                    if (_dfs_data[w] == null) //.get()
                    {
                        // not yet visited
                        visit(w);
                    }

                    SCC_DFS_Data sdd_w = _dfs_data[w]; //.get();
                    if (sdd_w.inComponent == false)
                    {
                        int dfs_nr_root_v = _dfs_data[sdd.root_index].dfs_nr;
                        int dfs_nr_root_w = _dfs_data[sdd_w.root_index].dfs_nr;

                        if (dfs_nr_root_v > dfs_nr_root_w)
                        {
                            sdd.root_index = sdd_w.root_index;
                        }
                    }
                }
            }

            if (sdd.root_index == v)
            {
                BitSet set = new BitSet();

                int w;
                do
                {
                    //w=_stack.Peek(); //.top();
                    w = _stack.Pop();

                    set.set(w);
                    _result.setState2SCC(w, scc_nr);

                    SCC_DFS_Data sdd_w = _dfs_data[w];//.get();
                    sdd_w.inComponent = true;
                } while (w != v);

                scc_nr = _result.addSCC(set) + 1;
            }
        }
Exemplo n.º 2
0
        /** Visit a state (perform DFS) */
        public void visit(int v)
        {
            SCC_DFS_Data sdd = new SCC_DFS_Data();

            sdd.dfs_nr      = current_dfs_nr++;
            sdd.root_index  = v;
            sdd.inComponent = false;

            _stack.Push(v);

            //todo: be careful of the following swap
            //_dfs_data[v].reset(sdd);
            //Ultility.swap(_dfs_data[v], sdd);
            _dfs_data[v] = sdd;

            //for (typename SuccessorAccess::successor_iterator  succ_it=_successor_access.begin(_graph, v);succ_it!=_successor_access.end(_graph, v); ++succ_it)
            if (_labelMark == null)
            {
                for (KeyValuePair <APElement, BitSet> it_set = _graph[v].edges_begin(); !_graph[v].edges_end(); it_set = _graph[v].increment())
                {
                    for (int succ_it = BitSetIterator.start(it_set.Value); succ_it != BitSetIterator.end(it_set.Value); succ_it = BitSetIterator.increment(it_set.Value, succ_it))
                    {
                        int w = succ_it;

                        if (_dfs_data[w] == null) //.get()
                        {
                            // not yet visited
                            visit(w);
                        }

                        SCC_DFS_Data sdd_w = _dfs_data[w]; //.get();
                        if (sdd_w.inComponent == false)
                        {
                            int dfs_nr_root_v = _dfs_data[sdd.root_index].dfs_nr;
                            int dfs_nr_root_w = _dfs_data[sdd_w.root_index].dfs_nr;

                            if (dfs_nr_root_v > dfs_nr_root_w)
                            {
                                sdd.root_index = sdd_w.root_index;
                            }
                        }
                    }
                }
            }
            else
            {
                BitSet it_set = _graph[v].getEdge(_labelMark);
                for (int succ_it = BitSetIterator.start(it_set); succ_it != BitSetIterator.end(it_set); succ_it = BitSetIterator.increment(it_set, succ_it))
                {
                    int w = succ_it;

                    if (_dfs_data[w] == null) //.get()
                    {
                        // not yet visited
                        visit(w);
                    }

                    SCC_DFS_Data sdd_w = _dfs_data[w]; //.get();
                    if (sdd_w.inComponent == false)
                    {
                        int dfs_nr_root_v = _dfs_data[sdd.root_index].dfs_nr;
                        int dfs_nr_root_w = _dfs_data[sdd_w.root_index].dfs_nr;

                        if (dfs_nr_root_v > dfs_nr_root_w)
                        {
                            sdd.root_index = sdd_w.root_index;
                        }
                    }
                }
            }



            if (sdd.root_index == v)
            {
                BitSet set = new BitSet();

                int w;
                do
                {
                    //w=_stack.Peek(); //.top();
                    w = _stack.Pop();

                    set.set(w);
                    _result.setState2SCC(w, scc_nr);

                    SCC_DFS_Data sdd_w = _dfs_data[w];//.get();
                    sdd_w.inComponent = true;
                } while (w != v);

                scc_nr = _result.addSCC(set) + 1;
            }
        }