scc.hh

Go to the documentation of this file.
00001 // Copyright (C) 2008, 2009, 2010, 2011 Laboratoire de Recherche et
00002 // Developpement de 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 
00096     unsigned scc_count() const;
00097 
00101     unsigned initial() const;
00102 
00106     const succ_type& succ(unsigned n) const;
00107 
00113     bool trivial(unsigned n) const;
00114 
00118     bool accepting(unsigned n) const;
00119 
00123     const cond_set& cond_set_of(unsigned n) const;
00124 
00131     bdd ap_set_of(unsigned n) const;
00132 
00139     bdd aprec_set_of(unsigned n) const;
00140 
00144     bdd acc_set_of(unsigned n) const;
00145 
00150     bdd useful_acc_of(unsigned n) const;
00151 
00158     const std::list<const state*>& states_of(unsigned n) const;
00159 
00166     const state* one_state_of(unsigned n) const;
00167 
00171     unsigned scc_of_state(const state* s) const;
00172 
00174     unsigned self_loops() const;
00175 
00176   protected:
00177     bdd update_supp_rec(unsigned state);
00178     int relabel_component();
00179 
00180     struct scc
00181     {
00182     public:
00183       scc(int index) : index(index), acc(bddfalse),
00184                        supp(bddtrue), supp_rec(bddfalse),
00185                        trivial(true), useful_acc(bddfalse) {};
00187       int index;
00190       bdd acc;
00192       std::list<const state*> states;
00194       cond_set conds;
00196       bdd supp;
00198       bdd supp_rec;
00200       succ_type succ;
00202       bool trivial;
00204       bdd useful_acc;
00205     };
00206 
00207     const tgba* aut_;           // Automata to decompose.
00208     typedef std::list<scc> stack_type;
00209     stack_type root_;           // Stack of SCC roots.
00210     std::stack<bdd> arc_acc_;   // A stack of acceptance conditions
00211                                 // between each of these SCC.
00212     std::stack<bdd> arc_cond_;  // A stack of conditions
00213                                 // between each of these SCC.
00214     typedef Sgi::hash_map<const state*, int,
00215                           state_ptr_hash, state_ptr_equal> hash_type;
00216     hash_type h_;               // Map of visited states.  Values >= 0
00217                                 // designate maximal SCC.  Values < 0
00218                                 // number states that are part of
00219                                 // incomplete SCCs being completed.
00220     int num_;                   // Number of visited nodes, negated.
00221     typedef std::pair<const spot::state*, tgba_succ_iterator*> pair_state_iter;
00222     std::stack<pair_state_iter> todo_; // DFS stack.  Holds (STATE,
00223                                        // ITERATOR) pairs where
00224                                        // ITERATOR is an iterator over
00225                                        // the successors of STATE.
00226                                        // ITERATOR should always be
00227                                        // freed when TODO is popped,
00228                                        // but STATE should not because
00229                                        // it is used as a key in H.
00230 
00231     typedef std::vector<scc> scc_map_type;
00232     scc_map_type scc_map_; // Map of constructed maximal SCC.
00233                            // SCC number "n" in H_ corresponds to entry
00234                            // "n" in SCC_MAP_.
00235     unsigned self_loops_; // Self loops count.
00236  };
00237 
00238   scc_stats build_scc_stats(const tgba* a);
00239   scc_stats build_scc_stats(const scc_map& m);
00240 
00241   std::ostream& dump_scc_dot(const tgba* a, std::ostream& out,
00242                              bool verbose = false);
00243   std::ostream& dump_scc_dot(const scc_map& m, std::ostream& out,
00244                              bool verbose = false);
00245 }
00246 
00247 #endif // SPOT_TGBAALGOS_SCC_HH

Please comment this page and report errors about it on the RefDocComments page.
Generated on Tue Feb 1 2011 12:00:52 for spot by doxygen 1.7.1