spot  1.0.1
cycles.hh
Go to the documentation of this file.
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 {
79  {
80  protected:
81  typedef Sgi::hash_set<const state*,
83 
84  // Extra information required for the algorithm for each state.
85  struct state_info
86  {
88  : reach(false), mark(false)
89  {
90  }
91  // Whether the state has already left the stack at least once.
92  bool reach;
93  // set to true when the state current state w is stacked, and
94  // reset either when the state is unstacked after having
95  // contributed to a cycle, or when some state z that (1) w could
96  // reach (even indirectly) without discovering a cycle, and (2)
97  // that a contributed to a contributed to a cycle.
98  bool mark;
99  // Deleted successors (in the paper, states deleted from A(x))
101  // Predecessors of the current states, that could not yet
102  // contribute to a cycle.
104  };
105 
106  // Store the state_info for all visited states.
107  typedef Sgi::hash_map<const state*, state_info,
110 
111  // A tagged_state s is a state* (s->first) associated to its
112  // state_info (s->second). We usually handle tagged_state in the
113  // algorithm to avoid repeated lookup of the state_info data.
114  typedef hash_type::iterator tagged_state;
115 
116  // The automaton we are working on.
117  const tgba* aut_;
118  // The SCC map built for aut_.
119  const scc_map& sm_;
120 
121  // The DFS stack. Each entry contains a tagged state, an iterator
122  // on the transitions leaving that state, and a Boolean f
123  // indicating whether this state as already contributed to a cycle
124  // (f is updated when backtracking, so it should not be used by
125  // cycle_found()).
126  struct dfs_entry
127  {
130  bool f;
131  };
132  typedef std::deque<dfs_entry> dfs_stack;
134 
135  public:
136  enumerate_cycles(const scc_map& map);
137  virtual ~enumerate_cycles() {}
138 
144  void run(unsigned scc);
145 
146 
162  virtual bool cycle_found(const state* start);
163 
164  private:
165  // introduce a new state to the tags map.
166  tagged_state tag_state(const state* s);
167  // add a new state to the dfs_ stack
168  void push_state(tagged_state ts);
169  // block the edge (x,y) because it cannot contribute to a new
170  // cycle currently (sub-procedure from the paper)
171  void nocycle(tagged_state x, tagged_state y);
172  // unmark the state y (sub-procedure from the paper)
173  void unmark(tagged_state y);
174  };
175 
176 }
177 
178 #endif // SPOT_TGBAALGOS_CYCLES_HH

Please comment this page and report errors about it on the RefDocComments page.
Generated on Wed Jan 23 2013 15:00:01 for spot by doxygen 1.8.1.2