spot  2.3.3.dev
sccinfo.hh
1 // -*- coding: utf-8 -*-
2 // Copyright (C) 2014-2017 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 #pragma once
21 
22 #include <vector>
23 #include <spot/twa/twagraph.hh>
24 
25 namespace spot
26 {
27 
29  class SPOT_API scc_info_node
30  {
31  public:
32  typedef std::vector<unsigned> scc_succs;
33  friend class scc_info;
34  protected:
35  scc_succs succ_;
36  acc_cond::mark_t acc_;
37  std::vector<unsigned> states_; // States of the component
38  bool trivial_:1;
39  bool accepting_:1; // Necessarily accepting
40  bool rejecting_:1; // Necessarily rejecting
41  bool useful_:1;
42  public:
43  scc_info_node():
44  acc_(0U), trivial_(true), accepting_(false),
45  rejecting_(false), useful_(false)
46  {
47  }
48 
49  scc_info_node(acc_cond::mark_t acc, bool trivial):
50  acc_(acc), trivial_(trivial), accepting_(false),
51  rejecting_(false), useful_(false)
52  {
53  }
54 
55  bool is_trivial() const
56  {
57  return trivial_;
58  }
59 
64  bool is_accepting() const
65  {
66  return accepting_;
67  }
68 
69  // True if we are sure that the SCC is rejecting
73  bool is_rejecting() const
74  {
75  return rejecting_;
76  }
77 
78  bool is_useful() const
79  {
80  return useful_;
81  }
82 
83  acc_cond::mark_t acc_marks() const
84  {
85  return acc_;
86  }
87 
88  const std::vector<unsigned>& states() const
89  {
90  return states_;
91  }
92 
93  const scc_succs& succ() const
94  {
95  return succ_;
96  }
97  };
98 
99 
112  class SPOT_API scc_info
113  {
114  public:
115  // scc_node used to be an inner class, but Swig 3.0.10 does not
116  // support that yet.
117  typedef scc_info_node scc_node;
118  typedef scc_info_node::scc_succs scc_succs;
119 
120  protected:
121 
122  std::vector<unsigned> sccof_;
123  std::vector<scc_node> node_;
124  const_twa_graph_ptr aut_;
125 
126  // Update the useful_ bits. Called automatically.
127  void determine_usefulness();
128 
129  const scc_node& node(unsigned scc) const
130  {
131  return node_[scc];
132  }
133 
134  public:
135  scc_info(const_twa_graph_ptr aut);
136 
137  const_twa_graph_ptr get_aut() const
138  {
139  return aut_;
140  }
141 
142  unsigned scc_count() const
143  {
144  return node_.size();
145  }
146 
147  bool reachable_state(unsigned st) const
148  {
149  return scc_of(st) != -1U;
150  }
151 
152  unsigned scc_of(unsigned st) const
153  {
154  return sccof_[st];
155  }
156 
157  std::vector<scc_node>::const_iterator begin() const
158  {
159  return node_.begin();
160  }
161 
162  std::vector<scc_node>::const_iterator end() const
163  {
164  return node_.end();
165  }
166 
167  std::vector<scc_node>::const_iterator cbegin() const
168  {
169  return node_.cbegin();
170  }
171 
172  std::vector<scc_node>::const_iterator cend() const
173  {
174  return node_.cend();
175  }
176 
177  std::vector<scc_node>::const_reverse_iterator rbegin() const
178  {
179  return node_.rbegin();
180  }
181 
182  std::vector<scc_node>::const_reverse_iterator rend() const
183  {
184  return node_.rend();
185  }
186 
187  const std::vector<unsigned>& states_of(unsigned scc) const
188  {
189  return node(scc).states();
190  }
191 
192  unsigned one_state_of(unsigned scc) const
193  {
194  return states_of(scc).front();
195  }
196 
198  unsigned initial() const
199  {
200  SPOT_ASSERT(scc_count() - 1 == scc_of(aut_->get_init_state_number()));
201  return scc_count() - 1;
202  }
203 
204  const scc_succs& succ(unsigned scc) const
205  {
206  return node(scc).succ();
207  }
208 
209  bool is_trivial(unsigned scc) const
210  {
211  return node(scc).is_trivial();
212  }
213 
214  acc_cond::mark_t acc(unsigned scc) const
215  {
216  return node(scc).acc_marks();
217  }
218 
219  bool is_accepting_scc(unsigned scc) const
220  {
221  return node(scc).is_accepting();
222  }
223 
224  bool is_rejecting_scc(unsigned scc) const
225  {
226  return node(scc).is_rejecting();
227  }
228 
229  // Study the SCC that are currently reported neither as accepting
230  // nor rejecting because of the presence of Fin sets
231  void determine_unknown_acceptance();
232 
233  bool is_useful_scc(unsigned scc) const
234  {
235  return node(scc).is_useful();
236  }
237 
238  bool is_useful_state(unsigned st) const
239  {
240  return reachable_state(st) && node(scc_of(st)).is_useful();
241  }
242 
245  std::vector<std::set<acc_cond::mark_t>> used_acc() const;
246 
247  std::set<acc_cond::mark_t> used_acc_of(unsigned scc) const;
248 
249  acc_cond::mark_t acc_sets_of(unsigned scc) const;
250 
251  std::vector<bool> weak_sccs() const;
252 
253  bdd scc_ap_support(unsigned scc) const;
254  };
255 
256 
260  SPOT_API std::ostream&
261  dump_scc_info_dot(std::ostream& out,
262  const_twa_graph_ptr aut, scc_info* sccinfo = nullptr);
263 
264 }
Definition: graph.hh:33
Compute an SCC map and gather assorted information.
Definition: sccinfo.hh:112
Storage for SCC related information.
Definition: sccinfo.hh:29
bool is_accepting() const
True if we are sure that the SCC is accepting.
Definition: sccinfo.hh:64
std::ostream & dump_scc_info_dot(std::ostream &out, const_twa_graph_ptr aut, scc_info *sccinfo=nullptr)
Dump the SCC graph of aut on out.
unsigned initial() const
Get number of the SCC containing the initial state.
Definition: sccinfo.hh:198
bool is_rejecting() const
Definition: sccinfo.hh:73
Definition: acc.hh:34

Please direct any question, comment, or bug report to the Spot mailing list at spot@lrde.epita.fr.
Generated on Tue Apr 18 2017 14:42:56 for spot by doxygen 1.8.13