spot  0.9.2
taatgba.hh
Go to the documentation of this file.
1 // -*- coding: utf-8 -*-
2 // Copyright (C) 2009, 2011, 2012 Laboratoire de Recherche et
3 // 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 2 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 Spot; see the file COPYING. If not, write to the Free
19 // Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 // 02111-1307, USA.
21 
22 #ifndef SPOT_TGBA_TAATGBA_HH
23 # define SPOT_TGBA_TAATGBA_HH
24 
25 #include <set>
26 #include <iosfwd>
27 #include <vector>
28 #include "misc/hash.hh"
29 #include "ltlast/formula.hh"
30 #include "bdddict.hh"
31 #include "tgba.hh"
32 
33 namespace spot
34 {
37  class taa_tgba : public tgba
38  {
39  public:
40  taa_tgba(bdd_dict* dict);
41 
42  struct transition;
43  typedef std::list<transition*> state;
44  typedef std::set<state*> state_set;
45 
47  struct transition
48  {
49  bdd condition;
51  const state_set* dst;
52  };
53 
54  void add_condition(transition* t, const ltl::formula* f);
55 
57  virtual ~taa_tgba();
58  virtual spot::state* get_init_state() const;
59  virtual tgba_succ_iterator*
60  succ_iter(const spot::state* local_state,
61  const spot::state* global_state = 0,
62  const tgba* global_automaton = 0) const;
63  virtual bdd_dict* get_dict() const;
64  virtual std::string format_state(const spot::state* state) const = 0;
65  virtual bdd all_acceptance_conditions() const;
66  virtual bdd neg_acceptance_conditions() const;
67 
68  protected:
69  virtual bdd compute_support_conditions(const spot::state* state) const;
70  virtual bdd compute_support_variables(const spot::state* state) const;
71 
72  typedef std::vector<taa_tgba::state_set*> ss_vec;
73 
80 
81  private:
82  // Disallow copy.
83  taa_tgba(const taa_tgba& other);
84  taa_tgba& operator=(const taa_tgba& other);
85  };
86 
88  class state_set : public spot::state
89  {
90  public:
91  state_set(const taa_tgba::state_set* s, bool delete_me = false)
92  : s_(s), delete_me_(delete_me)
93  {
94  }
95 
96  virtual int compare(const spot::state*) const;
97  virtual size_t hash() const;
98  virtual state_set* clone() const;
99 
100  virtual ~state_set()
101  {
102  if (delete_me_)
103  delete s_;
104  }
105 
106  const taa_tgba::state_set* get_state() const;
107  private:
110  };
111 
113  {
114  public:
115  taa_succ_iterator(const taa_tgba::state_set* s, bdd all_acc);
116  virtual ~taa_succ_iterator();
117 
118  virtual void first();
119  virtual void next();
120  virtual bool done() const;
121 
122  virtual state_set* current_state() const;
123  virtual bdd current_condition() const;
124  virtual bdd current_acceptance_conditions() const;
125 
126  private:
129  typedef taa_tgba::state::const_iterator iterator;
130  typedef std::pair<iterator, iterator> iterator_pair;
131  typedef std::vector<iterator_pair> bounds_t;
132  typedef Sgi::hash_map<
133  const spot::state_set*, std::vector<taa_tgba::transition*>,
135 
136  struct distance_sort :
137  public std::binary_function<const iterator_pair&,
138  const iterator_pair&, bool>
139  {
140  bool
141  operator()(const iterator_pair& lhs, const iterator_pair& rhs) const
142  {
143  return std::distance(lhs.first, lhs.second) <
144  std::distance(rhs.first, rhs.second);
145  }
146  };
147 
148  std::vector<taa_tgba::transition*>::const_iterator i_;
149  std::vector<taa_tgba::transition*> succ_;
152  };
153 
156  template<typename label, typename label_hash>
158  {
159  public:
161 
162  void set_init_state(const label& s)
163  {
164  std::vector<label> v(1);
165  v[0] = s;
166  set_init_state(v);
167  }
168  void set_init_state(const std::vector<label>& s)
169  {
170  init_ = add_state_set(s);
171  }
172 
173  transition*
174  create_transition(const label& s,
175  const std::vector<label>& d)
176  {
177  state* src = add_state(s);
178  state_set* dst = add_state_set(d);
179  transition* t = new transition;
180  t->dst = dst;
181  t->condition = bddtrue;
182  t->acceptance_conditions = bddfalse;
183  src->push_back(t);
184  return t;
185  }
186  transition*
187  create_transition(const label& s, const label& d)
188  {
189  std::vector<std::string> vec;
190  vec.push_back(d);
191  return create_transition(s, vec);
192  }
193 
195  {
196  if (dict_->acc_map.find(f) == dict_->acc_map.end())
197  {
198  int v = dict_->register_acceptance_variable(f, this);
199  bdd neg = bdd_nithvar(v);
201 
202  // Append neg to all acceptance conditions.
203  typename ns_map::iterator i;
204  for (i = name_state_map_.begin(); i != name_state_map_.end(); ++i)
205  {
206  taa_tgba::state::iterator i2;
207  for (i2 = i->second->begin(); i2 != i->second->end(); ++i2)
208  (*i2)->acceptance_conditions &= neg;
209  }
210 
212  }
213 
214  bdd_dict::fv_map::iterator i = dict_->acc_map.find(f);
215  assert(i != dict_->acc_map.end());
216  f->destroy();
217  bdd v = bdd_ithvar(i->second);
218  t->acceptance_conditions |= v & bdd_exist(neg_acceptance_conditions_, v);
219  }
220 
229  virtual std::string format_state(const spot::state* s) const
230  {
231  const spot::state_set* se = down_cast<const spot::state_set*>(s);
232  assert(se);
233  const state_set* ss = se->get_state();
234  return format_state_set(ss);
235  }
236 
238  void output(std::ostream& os) const
239  {
240  typename ns_map::const_iterator i;
241  for (i = name_state_map_.begin(); i != name_state_map_.end(); ++i)
242  {
243  taa_tgba::state::const_iterator i2;
244  os << "State: " << label_to_string(i->first) << std::endl;
245  for (i2 = i->second->begin(); i2 != i->second->end(); ++i2)
246  {
247  os << " " << format_state_set((*i2)->dst)
248  << ", C:" << (*i2)->condition
249  << ", A:" << (*i2)->acceptance_conditions << std::endl;
250  }
251  }
252  }
253 
254  protected:
255  typedef label label_t;
256 
257  typedef Sgi::hash_map<
258  const label, taa_tgba::state*, label_hash
260  typedef Sgi::hash_map<
263 
266 
268  virtual std::string label_to_string(const label_t& lbl) const = 0;
269 
272  virtual label_t clone_if(const label_t& lbl) const = 0;
273 
274  private:
277  taa_tgba::state* add_state(const label& name)
278  {
279  typename ns_map::iterator i = name_state_map_.find(name);
280  if (i == name_state_map_.end())
281  {
282  const label& name_ = clone_if(name);
284  name_state_map_[name_] = s;
285  state_name_map_[s] = name_;
286  return s;
287  }
288  return i->second;
289  }
290 
292  taa_tgba::state_set* add_state_set(const std::vector<label>& names)
293  {
294  state_set* ss = new state_set;
295  for (unsigned i = 0; i < names.size(); ++i)
296  ss->insert(add_state(names[i]));
297  state_set_vec_.push_back(ss);
298  return ss;
299  }
300 
301  std::string format_state_set(const taa_tgba::state_set* ss) const
302  {
303  state_set::const_iterator i1 = ss->begin();
304  typename sn_map::const_iterator i2;
305  if (ss->empty())
306  return std::string("{}");
307  if (ss->size() == 1)
308  {
309  i2 = state_name_map_.find(*i1);
310  assert(i2 != state_name_map_.end());
311  return "{" + label_to_string(i2->second) + "}";
312  }
313  else
314  {
315  std::string res("{");
316  while (i1 != ss->end())
317  {
318  i2 = state_name_map_.find(*i1++);
319  assert(i2 != state_name_map_.end());
320  res += label_to_string(i2->second);
321  res += ",";
322  }
323  res[res.size() - 1] = '}';
324  return res;
325  }
326  }
327  };
328 
330  public taa_tgba_labelled<std::string, string_hash>
331  {
332  public:
334  taa_tgba_labelled<std::string, string_hash>(dict) {};
336  protected:
337  virtual std::string label_to_string(const std::string& label) const;
338  virtual std::string clone_if(const std::string& label) const;
339  };
340 
342  public taa_tgba_labelled<const ltl::formula*, ltl::formula_ptr_hash>
343  {
344  public:
346  taa_tgba_labelled<const ltl::formula*, ltl::formula_ptr_hash>(dict) {};
348  protected:
349  virtual std::string label_to_string(const label_t& label) const;
350  virtual const ltl::formula* clone_if(const label_t& label) const;
351  };
352 }
353 
354 #endif // SPOT_TGBA_TAATGBA_HH

Please comment this page and report errors about it on the RefDocComments page.
Generated on Mon Jul 2 2012 17:35:47 for spot by doxygen 1.8.1.1