spot  1.2.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
cycles.hh
1 // -*- coding: utf-8 -*-
2 // Copyright (C) 2012, 2013 Laboratoire de Recherche et Développement
3 // de l'Epita (LRDE).
4 //
5 // This file is part of Spot, a model checking library.
6 //
7 // Spot is free software; you can redistribute it and/or modify it
8 // under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // Spot is distributed in the hope that it will be useful, but WITHOUT
13 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
15 // License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 
20 #ifndef SPOT_TGBAALGOS_CYCLES_HH
21 # define SPOT_TGBAALGOS_CYCLES_HH
22 
23 #include "scc.hh"
24 #include "misc/hash.hh"
25 #include <deque>
26 
27 namespace spot
28 {
33 
46  class SPOT_API enumerate_cycles
80  {
81  protected:
82  typedef Sgi::hash_set<const state*,
83  state_ptr_hash, state_ptr_equal> set_type;
84 
85  // Extra information required for the algorithm for each state.
86  struct state_info
87  {
88  state_info()
89  : reach(false), mark(false)
90  {
91  }
92  // Whether the state has already left the stack at least once.
93  bool reach;
94  // set to true when the state current state w is stacked, and
95  // reset either when the state is unstacked after having
96  // contributed to a cycle, or when some state z that (1) w could
97  // reach (even indirectly) without discovering a cycle, and (2)
98  // that a contributed to a contributed to a cycle.
99  bool mark;
100  // Deleted successors (in the paper, states deleted from A(x))
101  set_type del;
102  // Predecessors of the current states, that could not yet
103  // contribute to a cycle.
104  set_type b;
105  };
106 
107  // Store the state_info for all visited states.
108  typedef Sgi::hash_map<const state*, state_info,
109  state_ptr_hash, state_ptr_equal> hash_type;
110  hash_type tags_;
111 
112  // A tagged_state s is a state* (s->first) associated to its
113  // state_info (s->second). We usually handle tagged_state in the
114  // algorithm to avoid repeated lookup of the state_info data.
115  typedef hash_type::iterator tagged_state;
116 
117  // The automaton we are working on.
118  const tgba* aut_;
119  // The SCC map built for aut_.
120  const scc_map& sm_;
121 
122  // The DFS stack. Each entry contains a tagged state, an iterator
123  // on the transitions leaving that state, and a Boolean f
124  // indicating whether this state as already contributed to a cycle
125  // (f is updated when backtracking, so it should not be used by
126  // cycle_found()).
127  struct dfs_entry
128  {
129  tagged_state ts;
130  tgba_succ_iterator* succ;
131  bool f;
132  };
133  typedef std::deque<dfs_entry> dfs_stack;
134  dfs_stack dfs_;
135 
136  public:
137  enumerate_cycles(const scc_map& map);
138  virtual ~enumerate_cycles() {}
139 
145  void run(unsigned scc);
146 
147 
163  virtual bool cycle_found(const state* start);
164 
165  private:
166  // introduce a new state to the tags map.
167  tagged_state tag_state(const state* s);
168  // add a new state to the dfs_ stack
169  void push_state(tagged_state ts);
170  // block the edge (x,y) because it cannot contribute to a new
171  // cycle currently (sub-procedure from the paper)
172  void nocycle(tagged_state x, tagged_state y);
173  // unmark the state y (sub-procedure from the paper)
174  void unmark(tagged_state y);
175  };
176 
177 }
178 
179 #endif // SPOT_TGBAALGOS_CYCLES_HH

Please direct any question, comment, or bug report to the Spot mailing list at spot@lrde.epita.fr.
Generated on Thu May 15 2014 11:04:11 for spot by doxygen 1.8.4