spot  1.99.4a
dfs_stats.hh
1 // -*- coding: utf-8 -*-
2 // Copyright (C) 2015 Laboratoire de Recherche et
3 // Developpement 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 #pragma once
21 
22 #include "twaalgos/reachiter.hh"
23 #include "twaalgos/stats.hh"
24 #include "proviso.hh"
25 
26 namespace spot
27 {
28  // \brief DFS Exploration easily extendable for POR purpose.
30  {
31  public:
32  stats_dfs(const const_twa_ptr& a, tgba_statistics& s,
33  proviso& proviso, bool dotty = false)
35  proviso_(proviso), dotty_(dotty)
36  {
37  last = -1;
38  expanded_ = 0;
39  already_expanded_ = 0;
40  }
41 
42  void
43  process_state(const state* s, int n, twa_succ_iterator* it)
44  {
45  ++s_.states;
46  last = n;
47  if (it->all_enabled())
48  ++already_expanded_;
49 
50  if (proviso_.expand_new_state(n, it->all_enabled(), it, seen, s, aut_))
51  {
52  it->fire_all();
53  ++expanded_;
54  }
55  }
56 
57  bool
59  {
60  assert(it->done());
61  if (proviso_.expand_before_pop(n, it, seen))
62  {
63  it->fire_all();
64  it->next();
65  ++expanded_;
66  assert(!it->done());
67  return false;
68  }
69 
70  return true;
71  }
72 
73  void
74  process_link(const state*, int src, const state*, int dst,
75  const twa_succ_iterator* it)
76  {
77  if (dotty_)
78  std::cout << ' ' << src << " -> " << dst << std::endl;
79  ++s_.transitions;
80 
81  // Since all edges are processed we do not consider edges
82  // leading to new states (not used for proviso)
83  if (dst > last)
84  return;
85 
86  if (proviso_.expand_src_closingedge(src, dst))
87  {
88  it->fire_all();
89  ++expanded_;
90  }
91  }
92 
93  void start()
94  {
95  if (dotty_)
96  std::cout << "digraph G {\n";
97  }
98 
99  void end()
100  {
101  if (dotty_)
102  std::cout << '}' << std::endl;
103  }
104 
105 
106  void dump()
107  {
108  std::cout << "expanded: " << expanded_ << std::endl;
109  std::cout << "already_expanded: " << already_expanded_ << std::endl;
110  }
111  private:
112  int last; // FIXME ??? last state encountered
113  int expanded_;
114  int already_expanded_;
115  tgba_statistics& s_;
116  proviso& proviso_;
117  bool dotty_;
118  };
119 }
Definition: graph.hh:32
void end()
Called by run() once all states have been explored.
Definition: dfs_stats.hh:99
bool will_pop_state(const state *, int n, twa_succ_iterator *it)
Definition: dfs_stats.hh:58
Abstract class for states.
Definition: twa.hh:42
virtual bool done() const =0
Check whether the iteration is finished.
virtual bool all_enabled() const
this method is only usefull if partial order reductions are enabled to check wether all states have b...
Definition: twa.hh:404
virtual bool next()=0
Jump to the next successor (if any).
Definition: dfs_stats.hh:29
void process_link(const state *, int src, const state *, int dst, const twa_succ_iterator *it)
Definition: dfs_stats.hh:74
Iterate over the successors of a state.
Definition: twa.hh:331
Definition: stats.hh:35
void start()
Called by run() before starting its iteration.
Definition: dfs_stats.hh:93
virtual void fire_all() const
this method is only usefull if partial order reductions are enabled
Definition: twa.hh:399
Iterate over all states of an automaton using a DFS.
Definition: reachiter.hh:116
Definition: proviso.hh:31
void process_state(const state *s, int n, twa_succ_iterator *it)
Definition: dfs_stats.hh:43

Please direct any question, comment, or bug report to the Spot mailing list at spot@lrde.epita.fr.
Generated on Sun Oct 11 2015 10:50:08 for spot by doxygen 1.8.9.1