spot
0.8.3
|
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; 00213 bdd useful_acc; 00214 }; 00215 00216 const tgba* aut_; // Automata to decompose. 00217 typedef std::list<scc> stack_type; 00218 stack_type root_; // Stack of SCC roots. 00219 std::stack<bdd> arc_acc_; // A stack of acceptance conditions 00220 // between each of these SCC. 00221 std::stack<bdd> arc_cond_; // A stack of conditions 00222 // between each of these SCC. 00223 typedef Sgi::hash_map<const state*, int, 00224 state_ptr_hash, state_ptr_equal> hash_type; 00225 hash_type h_; // Map of visited states. Values >= 0 00226 // designate maximal SCC. Values < 0 00227 // number states that are part of 00228 // incomplete SCCs being completed. 00229 int num_; // Number of visited nodes, negated. 00230 typedef std::pair<const spot::state*, tgba_succ_iterator*> pair_state_iter; 00231 std::stack<pair_state_iter> todo_; // DFS stack. Holds (STATE, 00232 // ITERATOR) pairs where 00233 // ITERATOR is an iterator over 00234 // the successors of STATE. 00235 // ITERATOR should always be 00236 // freed when TODO is popped, 00237 // but STATE should not because 00238 // it is used as a key in H. 00239 00240 typedef std::vector<scc> scc_map_type; 00241 scc_map_type scc_map_; // Map of constructed maximal SCC. 00242 // SCC number "n" in H_ corresponds to entry 00243 // "n" in SCC_MAP_. 00244 unsigned self_loops_; // Self loops count. 00245 }; 00246 00247 scc_stats build_scc_stats(const tgba* a); 00248 scc_stats build_scc_stats(const scc_map& m); 00249 00250 std::ostream& dump_scc_dot(const tgba* a, std::ostream& out, 00251 bool verbose = false); 00252 std::ostream& dump_scc_dot(const scc_map& m, std::ostream& out, 00253 bool verbose = false); 00254 } 00255 00256 #endif // SPOT_TGBAALGOS_SCC_HH