scc.hh

Go to the documentation of this file.
00001 // Copyright (C) 2008, 2009  Laboratoire de Recherche et Developpement de
00002 // l'Epita.
00003 //
00004 // This file is part of Spot, a model checking library.
00005 //
00006 // Spot is free software; you can redistribute it and/or modify it
00007 // under the terms of the GNU General Public License as published by
00008 // the Free Software Foundation; either version 2 of the License, or
00009 // (at your option) any later version.
00010 //
00011 // Spot is distributed in the hope that it will be useful, but WITHOUT
00012 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
00013 // or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
00014 // License for more details.
00015 //
00016 // You should have received a copy of the GNU General Public License
00017 // along with Spot; see the file COPYING.  If not, write to the Free
00018 // Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
00019 // 02111-1307, USA.
00020 
00021 #ifndef SPOT_TGBAALGOS_SCC_HH
00022 # define SPOT_TGBAALGOS_SCC_HH
00023 
00024 #include <map>
00025 #include <stack>
00026 #include <vector>
00027 #include "tgba/tgba.hh"
00028 #include <iosfwd>
00029 #include "misc/hash.hh"
00030 #include "misc/bddlt.hh"
00031 
00032 namespace spot
00033 {
00034 
00035   struct scc_stats
00036   {
00038     unsigned scc_total;
00040     unsigned acc_scc;
00045     unsigned dead_scc;
00046 
00052     unsigned acc_paths;
00056     unsigned dead_paths;
00057     unsigned self_loops;
00058 
00060     std::vector<bool> useless_scc_map;
00061 
00065     bdd useful_acc;
00066 
00067     std::ostream& dump(std::ostream& out) const;
00068   };
00069 
00071   class scc_map
00072   {
00073   public:
00074     typedef std::map<unsigned, bdd> succ_type;
00075     typedef std::set<bdd, bdd_less_than> cond_set;
00076 
00081     scc_map(const tgba* aut);
00082 
00083     ~scc_map();
00084 
00086     void build_map();
00087 
00089     const tgba* get_aut() const;
00090 
00094     unsigned scc_count() const;
00095 
00099     unsigned initial() const;
00100 
00104     const succ_type& succ(unsigned n) const;
00105 
00109     bool accepting(unsigned n) const;
00110 
00114     const cond_set& cond_set_of(unsigned n) const;
00115 
00122     bdd ap_set_of(unsigned n) const;
00123 
00130     bdd aprec_set_of(unsigned n) const;
00131 
00135     bdd acc_set_of(unsigned n) const;
00136 
00141     bdd useful_acc_of(unsigned n) const;
00142 
00149     const std::list<const state*>& states_of(unsigned n) const;
00150 
00154     unsigned scc_of_state(const state* s) const;
00155 
00157     unsigned self_loops() const;
00158 
00159   protected:
00160     bdd update_supp_rec(unsigned state);
00161     int relabel_component();
00162 
00163     struct scc
00164     {
00165     public:
00166       scc(int index) : index(index), acc(bddfalse),
00167                        supp(bddtrue), supp_rec(bddfalse),
00168                        trivial(true), useful_acc(bddfalse) {};
00170       int index;
00173       bdd acc;
00175       std::list<const state*> states;
00177       cond_set conds;
00179       bdd supp;
00181       bdd supp_rec;
00183       succ_type succ;
00185       bool trivial;
00187       bdd useful_acc;
00188     };
00189 
00190     const tgba* aut_;           // Automata to decompose.
00191     typedef std::list<scc> stack_type;
00192     stack_type root_;           // Stack of SCC roots.
00193     std::stack<bdd> arc_acc_;   // A stack of acceptance conditions
00194                                 // between each of these SCC.
00195     std::stack<bdd> arc_cond_;  // A stack of conditions
00196                                 // between each of these SCC.
00197     typedef Sgi::hash_map<const state*, int,
00198                           state_ptr_hash, state_ptr_equal> hash_type;
00199     hash_type h_;               // Map of visited states.  Values >= 0
00200                                 // designate maximal SCC.  Values < 0
00201                                 // number states that are part of
00202                                 // incomplete SCCs being completed.
00203     int num_;                   // Number of visited nodes, negated.
00204     typedef std::pair<const spot::state*, tgba_succ_iterator*> pair_state_iter;
00205     std::stack<pair_state_iter> todo_; // DFS stack.  Holds (STATE,
00206                                        // ITERATOR) pairs where
00207                                        // ITERATOR is an iterator over
00208                                        // the successors of STATE.
00209                                        // ITERATOR should always be
00210                                        // freed when TODO is popped,
00211                                        // but STATE should not because
00212                                        // it is used as a key in H.
00213 
00214     typedef std::vector<scc> scc_map_type;
00215     scc_map_type scc_map_; // Map of constructed maximal SCC.
00216                            // SCC number "n" in H_ corresponds to entry
00217                            // "n" in SCC_MAP_.
00218     unsigned self_loops_; // Self loops count.
00219  };
00220 
00221   scc_stats build_scc_stats(const tgba* a);
00222   scc_stats build_scc_stats(const scc_map& m);
00223 
00224   std::ostream& dump_scc_dot(const tgba* a, std::ostream& out,
00225                              bool verbose = false);
00226   std::ostream& dump_scc_dot(const scc_map& m, std::ostream& out,
00227                              bool verbose = false);
00228 }
00229 
00230 #endif // SPOT_TGBAALGOS_SCC_HH

Please comment this page and report errors about it on the RefDocComments page.
Generated on Fri Apr 16 09:40:33 2010 for spot by doxygen 1.6.3