spot  1.99.3
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
taatgba.hh
1 // -*- coding: utf-8 -*-
2 // Copyright (C) 2009, 2011, 2012, 2013, 2014, 2015 Laboratoire de
3 // Recherche et Développement 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 <set>
23 #include <iosfwd>
24 #include <vector>
25 #include <string>
26 #include "misc/hash.hh"
27 #include "ltlast/formula.hh"
28 #include "bdddict.hh"
29 #include "twa.hh"
30 
31 namespace spot
32 {
35  class SPOT_API taa_tgba: public twa
36  {
37  public:
38  taa_tgba(const bdd_dict_ptr& dict);
39 
40  struct transition;
41  typedef std::list<transition*> state;
42  typedef std::set<state*> state_set;
43 
45  struct transition
46  {
47  bdd condition;
48  acc_cond::mark_t acceptance_conditions;
49  const state_set* dst;
50  };
51 
52  void add_condition(transition* t, const ltl::formula* f);
53 
55  virtual ~taa_tgba();
56  virtual spot::state* get_init_state() const final;
57  virtual twa_succ_iterator* succ_iter(const spot::state* state) const final;
58  virtual std::string format_state(const spot::state* state) const = 0;
59 
60  protected:
61  virtual bdd compute_support_conditions(const spot::state* state)
62  const final;
63 
64  typedef std::vector<taa_tgba::state_set*> ss_vec;
65 
66  taa_tgba::state_set* init_;
67  ss_vec state_set_vec_;
68 
69  std::map<const ltl::formula*, acc_cond::mark_t,
70  ltl::formula_ptr_less_than> acc_map_;
71 
72  private:
73  // Disallow copy.
74  taa_tgba(const taa_tgba& other) SPOT_DELETED;
75  taa_tgba& operator=(const taa_tgba& other) SPOT_DELETED;
76  };
77 
79  class SPOT_API set_state final: public spot::state
80  {
81  public:
82  set_state(const taa_tgba::state_set* s, bool delete_me = false)
83  : s_(s), delete_me_(delete_me)
84  {
85  }
86 
87  virtual int compare(const spot::state*) const;
88  virtual size_t hash() const;
89  virtual set_state* clone() const;
90 
91  virtual ~set_state()
92  {
93  if (delete_me_)
94  delete s_;
95  }
96 
97  const taa_tgba::state_set* get_state() const;
98  private:
99  const taa_tgba::state_set* s_;
100  bool delete_me_;
101  };
102 
103  class SPOT_API taa_succ_iterator final: public twa_succ_iterator
104  {
105  public:
106  taa_succ_iterator(const taa_tgba::state_set* s, const acc_cond& acc);
107  virtual ~taa_succ_iterator();
108 
109  virtual bool first();
110  virtual bool next();
111  virtual bool done() const;
112 
113  virtual set_state* current_state() const;
114  virtual bdd current_condition() const;
115  virtual acc_cond::mark_t current_acceptance_conditions() const;
116 
117  private:
120  typedef taa_tgba::state::const_iterator iterator;
121  typedef std::pair<iterator, iterator> iterator_pair;
122  typedef std::vector<iterator_pair> bounds_t;
123  typedef std::unordered_map<const spot::set_state*,
124  std::vector<taa_tgba::transition*>,
125  state_ptr_hash, state_ptr_equal> seen_map;
126 
127  struct distance_sort :
128  public std::binary_function<const iterator_pair&,
129  const iterator_pair&, bool>
130  {
131  bool
132  operator()(const iterator_pair& lhs, const iterator_pair& rhs) const
133  {
134  return std::distance(lhs.first, lhs.second) <
135  std::distance(rhs.first, rhs.second);
136  }
137  };
138 
139  std::vector<taa_tgba::transition*>::const_iterator i_;
140  std::vector<taa_tgba::transition*> succ_;
141  seen_map seen_;
142  const acc_cond& acc_;
143  };
144 
147  template<typename label>
148  class SPOT_API taa_tgba_labelled: public taa_tgba
149  {
150  public:
151  taa_tgba_labelled(const bdd_dict_ptr& dict) : taa_tgba(dict) {};
152 
154  {
155  auto i = acc_map_.begin();
156  while (i != acc_map_.end())
157  (i++)->first->destroy();
158  }
159 
160  void set_init_state(const label& s)
161  {
162  std::vector<label> v(1);
163  v[0] = s;
164  set_init_state(v);
165  }
166  void set_init_state(const std::vector<label>& s)
167  {
168  init_ = add_state_set(s);
169  }
170 
171  transition*
172  create_transition(const label& s,
173  const std::vector<label>& d)
174  {
175  state* src = add_state(s);
176  state_set* dst = add_state_set(d);
177  transition* t = new transition;
178  t->dst = dst;
179  t->condition = bddtrue;
180  t->acceptance_conditions = 0U;
181  src->push_back(t);
182  return t;
183  }
184 
185  transition*
186  create_transition(const label& s, const label& d)
187  {
188  std::vector<std::string> vec;
189  vec.push_back(d);
190  return create_transition(s, vec);
191  }
192 
193  void add_acceptance_condition(transition* t, const ltl::formula* f)
194  {
195  auto p = acc_map_.emplace(f, 0);
196  if (p.second)
197  p.first->second = acc_.marks({acc_.add_set()});
198  else
199  f->destroy();
200  t->acceptance_conditions |= p.first->second;
201  }
202 
211  virtual std::string format_state(const spot::state* s) const
212  {
213  const spot::set_state* se = down_cast<const spot::set_state*>(s);
214  assert(se);
215  const state_set* ss = se->get_state();
216  return format_state_set(ss);
217  }
218 
220  void output(std::ostream& os) const
221  {
222  typename ns_map::const_iterator i;
223  for (i = name_state_map_.begin(); i != name_state_map_.end(); ++i)
224  {
225  taa_tgba::state::const_iterator i2;
226  os << "State: " << label_to_string(i->first) << std::endl;
227  for (i2 = i->second->begin(); i2 != i->second->end(); ++i2)
228  {
229  os << ' ' << format_state_set((*i2)->dst)
230  << ", C:" << (*i2)->condition
231  << ", A:" << (*i2)->acceptance_conditions << std::endl;
232  }
233  }
234  }
235 
236  protected:
237  typedef label label_t;
238 
239  typedef std::unordered_map<label, taa_tgba::state*> ns_map;
240  typedef std::unordered_map<const taa_tgba::state*, label,
241  ptr_hash<taa_tgba::state> > sn_map;
242 
243  ns_map name_state_map_;
244  sn_map state_name_map_;
245 
247  virtual std::string label_to_string(const label_t& lbl) const = 0;
248 
251  virtual label_t clone_if(const label_t& lbl) const = 0;
252 
253  private:
256  taa_tgba::state* add_state(const label& name)
257  {
258  typename ns_map::iterator i = name_state_map_.find(name);
259  if (i == name_state_map_.end())
260  {
261  const label& name_ = clone_if(name);
262  taa_tgba::state* s = new taa_tgba::state;
263  name_state_map_[name_] = s;
264  state_name_map_[s] = name_;
265  return s;
266  }
267  return i->second;
268  }
269 
271  taa_tgba::state_set* add_state_set(const std::vector<label>& names)
272  {
273  state_set* ss = new state_set;
274  for (unsigned i = 0; i < names.size(); ++i)
275  ss->insert(add_state(names[i]));
276  state_set_vec_.push_back(ss);
277  return ss;
278  }
279 
280  std::string format_state_set(const taa_tgba::state_set* ss) const
281  {
282  state_set::const_iterator i1 = ss->begin();
283  typename sn_map::const_iterator i2;
284  if (ss->empty())
285  return std::string("{}");
286  if (ss->size() == 1)
287  {
288  i2 = state_name_map_.find(*i1);
289  assert(i2 != state_name_map_.end());
290  return "{" + label_to_string(i2->second) + "}";
291  }
292  else
293  {
294  std::string res("{");
295  while (i1 != ss->end())
296  {
297  i2 = state_name_map_.find(*i1++);
298  assert(i2 != state_name_map_.end());
299  res += label_to_string(i2->second);
300  res += ",";
301  }
302  res[res.size() - 1] = '}';
303  return res;
304  }
305  }
306  };
307 
308  class SPOT_API taa_tgba_string final:
309 #ifndef SWIG
310  public taa_tgba_labelled<std::string>
311 #else
312  public taa_tgba
313 #endif
314  {
315  public:
316  taa_tgba_string(const bdd_dict_ptr& dict) :
318  ~taa_tgba_string();
319  protected:
320  virtual std::string label_to_string(const std::string& label) const;
321  virtual std::string clone_if(const std::string& label) const;
322  };
323 
324  typedef std::shared_ptr<taa_tgba_string> taa_tgba_string_ptr;
325  typedef std::shared_ptr<const taa_tgba_string> const_taa_tgba_string_ptr;
326 
327  inline taa_tgba_string_ptr make_taa_tgba_string(const bdd_dict_ptr& dict)
328  {
329  return std::make_shared<taa_tgba_string>(dict);
330  }
331 
332  class SPOT_API taa_tgba_formula final:
333 #ifndef SWIG
334  public taa_tgba_labelled<const ltl::formula*>
335 #else
336  public taa_tgba
337 #endif
338  {
339  public:
340  taa_tgba_formula(const bdd_dict_ptr& dict) :
342  ~taa_tgba_formula();
343  protected:
344  virtual std::string label_to_string(const label_t& label) const;
345  virtual const ltl::formula* clone_if(const label_t& label) const;
346  };
347 
348  typedef std::shared_ptr<taa_tgba_formula> taa_tgba_formula_ptr;
349  typedef std::shared_ptr<const taa_tgba_formula> const_taa_tgba_formula_ptr;
350 
351  inline taa_tgba_formula_ptr make_taa_tgba_formula(const bdd_dict_ptr& dict)
352  {
353  return std::make_shared<taa_tgba_formula>(dict);
354  }
355 }
Definition: public.hh:31
void destroy() const
Release this node.
Definition: formula.hh:107
An Equivalence Relation for state*.
Definition: twa.hh:138
A Transition-based ω-Automaton.
Definition: twa.hh:480
LTL formula interface.
A self-loop Transition-based Alternating Automaton (TAA) which is seen as a TGBA (abstract class...
Definition: taatgba.hh:35
Definition: taatgba.hh:103
Definition: formula.hh:515
Abstract class for states.
Definition: twa.hh:40
A hash function for pointers.
Definition: hash.hh:39
Explicit transitions.
Definition: taatgba.hh:45
Definition: taatgba.hh:332
Iterate over the successors of a state.
Definition: twa.hh:329
Definition: acc.hh:31
virtual std::string format_state(const spot::state *s) const
Format the state as a string for printing.
Definition: taatgba.hh:211
Hash Function for state*.
Definition: twa.hh:162
Definition: taatgba.hh:308
Set of states deriving from spot::state.
Definition: taatgba.hh:79
Definition: taatgba.hh:148
void output(std::ostream &os) const
Output a TAA in a stream.
Definition: taatgba.hh:220
An LTL formula.
Definition: formula.hh:71
Definition: acc.hh:34

Please direct any question, comment, or bug report to the Spot mailing list at spot@lrde.epita.fr.
Generated on Wed Aug 26 2015 08:42:37 for spot by doxygen 1.8.8