spot  2.16
bdddict.hh
1 // -*- coding: utf-8 -*-
2 // Copyright (C) by the Spot authors, see the AUTHORS file for details.
3 //
4 // This file is part of Spot, a model checking library.
5 //
6 // Spot is free software; you can redistribute it and/or modify it
7 // under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // Spot is distributed in the hope that it will be useful, but WITHOUT
12 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14 // License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 
19 #pragma once
20 
21 #include <list>
22 #include <set>
23 #include <map>
24 #include <iosfwd>
25 #include <bddx.h>
26 #include <vector>
27 #include <memory>
28 #include <spot/tl/formula.hh>
29 
30 namespace spot
31 {
34  class bdd_dict_priv;
35 
52  class SPOT_API bdd_dict
53  {
54  bdd_dict_priv* priv_;
55  public:
56 
57  bdd_dict();
58 
64 
66  typedef std::map<formula, int> fv_map;
68  typedef std::map<int, formula> vf_map;
69 
72 
74  typedef std::set<const void*> ref_set;
75 
80  enum var_type
81  {
82  anon = 0,
83  var,
84  acc
85  };
86 
91  struct bdd_info {
92  bdd_info() noexcept: type(anon) {}
96  };
98  typedef std::vector<bdd_info> bdd_info_map;
101 
113  int register_proposition(formula f, const void* for_me);
114 
115  template <typename T>
116  int register_proposition(formula f, std::shared_ptr<T> for_me)
117  {
118  return register_proposition(f, for_me.get());
119  }
121 
128  int has_registered_proposition(formula f, const void* me);
129 
130  template <typename T>
131  int has_registered_proposition(formula f, std::shared_ptr<T> for_me)
132  {
133  return has_registered_proposition(f, for_me.get());
134  }
136 
137  // \brief Return the BDD variable number for a registered proposition.
138  //
139  // Throws std::out_of_range if \a f is not a known proposition.
145  {
146  return var_map.at(f);
147  }
148 
155  formula ap_from_var(int var) const
156  {
157  if (unsigned(var) < bdd_map.size()
158  && bdd_map[var].type == bdd_dict::var)
159  return bdd_map[var].f;
160  return nullptr;
161  }
162 
174  int register_acceptance_variable(formula f, const void* for_me);
175 
176  template <typename T>
177  int register_acceptance_variable(formula f, std::shared_ptr<T> for_me)
178  {
179  return register_acceptance_variable(f, for_me.get());
180  }
182 
191  int register_anonymous_variables(int n, const void* for_me);
192 
193  template <typename T>
194  int register_anonymous_variables(int n, std::shared_ptr<T> for_me)
195  {
196  return register_anonymous_variables(n, for_me.get());
197  }
199 
207  void register_all_variables_of(const void* from_other, const void* for_me);
208 
209  template <typename T>
210  void register_all_variables_of(const void* from_other,
211  std::shared_ptr<T> for_me)
212  {
213  register_all_variables_of(from_other, for_me.get());
214  }
215 
216  template <typename T>
217  void register_all_variables_of(std::shared_ptr<T> from_other,
218  const void* for_me)
219  {
220  register_all_variables_of(from_other.get(), for_me);
221  }
222 
223  template <typename T, typename U>
224  void register_all_variables_of(std::shared_ptr<T> from_other,
225  std::shared_ptr<U> for_me)
226  {
227  register_all_variables_of(from_other.get(), for_me.get());
228  }
230 
238  void register_all_propositions_of(const void* from_other,
239  const void* for_me);
240 
241  template <typename T>
242  void register_all_propositions_of(const void* from_other,
243  std::shared_ptr<T> for_me)
244  {
245  register_all_propositions_of(from_other, for_me.get());
246  }
247 
248  template <typename T>
249  void register_all_propositions_of(std::shared_ptr<T> from_other,
250  const void* for_me)
251  {
252  register_all_propotitions_of(from_other.get(), for_me);
253  }
254 
255  template <typename T, typename U>
256  void register_all_propositions_of(std::shared_ptr<T> from_other,
257  std::shared_ptr<U> for_me)
258  {
259  register_all_propositions_of(from_other.get(), for_me.get());
260  }
262 
266  void unregister_all_my_variables(const void* me);
267 
270  void unregister_variable(int var, const void* me);
271 
272  template <typename T>
273  void unregister_variable(int var, std::shared_ptr<T> me)
274  {
275  unregister_variable(var, me.get());
276  }
278 
281  std::ostream& dump(std::ostream& os) const;
282 
294  void assert_emptiness() const;
295 
296  private:
297  // Disallow copy.
298  bdd_dict(const bdd_dict& other) = delete;
299  bdd_dict& operator=(const bdd_dict& other) = delete;
300  };
301 
304  typedef std::shared_ptr<bdd_dict> bdd_dict_ptr;
305 
309  {
310  return std::make_shared<bdd_dict>();
311  }
312 
317  {
318  public:
319  bdd_dict_preorder() = default;
322  : dict_(dict)
323  {
324  }
325 
327  operator bdd_dict_ptr() const
328  {
329  return dict_;
330  }
331 
334  {
335  return dict_;
336  }
337 
341  {
342  return dict_->register_proposition(f, this);
343  }
344 
347  int register_proposition(const std::string& f)
348  {
350  }
351 
353  {
354  dict_->unregister_all_my_variables(this);
355  }
356 
357  private:
358  bdd_dict_ptr dict_ = make_bdd_dict();
359  };
360 
361 }
A BDD dictionary wrapper that pre-registers atomic propositions before use.
Definition: bdddict.hh:317
int register_proposition(const std::string &f)
Register atomic proposition f (by name) and return its BDD variable number.
Definition: bdddict.hh:347
int register_proposition(formula f)
Register atomic proposition f and return its BDD variable number.
Definition: bdddict.hh:340
bdd_dict_preorder(bdd_dict_ptr dict)
Construct from an existing bdd_dict.
Definition: bdddict.hh:321
bdd_dict_ptr get_dict() const
Return the underlying bdd_dict shared pointer.
Definition: bdddict.hh:333
Map BDD variables to formulas.
Definition: bdddict.hh:53
std::set< const void * > ref_set
BDD-variable reference counts.
Definition: bdddict.hh:74
void register_all_propositions_of(std::shared_ptr< T > from_other, std::shared_ptr< U > for_me)
Duplicate the proposition usage of another object.
Definition: bdddict.hh:256
void register_all_propositions_of(const void *from_other, std::shared_ptr< T > for_me)
Duplicate the proposition usage of another object.
Definition: bdddict.hh:242
int register_acceptance_variable(formula f, const void *for_me)
Register an acceptance variable.
void assert_emptiness() const
Make sure the dictionary is empty.
std::ostream & dump(std::ostream &os) const
Dump all variables for debugging.
void register_all_propositions_of(std::shared_ptr< T > from_other, const void *for_me)
Duplicate the proposition usage of another object.
Definition: bdddict.hh:249
void register_all_variables_of(std::shared_ptr< T > from_other, const void *for_me)
Duplicate the variable usage of another object.
Definition: bdddict.hh:217
std::map< int, formula > vf_map
BDD-variable-to-formula maps.
Definition: bdddict.hh:68
std::map< formula, int > fv_map
Formula-to-BDD-variable maps.
Definition: bdddict.hh:66
void unregister_variable(int var, std::shared_ptr< T > me)
Release a variable used by me.
Definition: bdddict.hh:273
int register_proposition(formula f, const void *for_me)
Register an atomic proposition.
void unregister_all_my_variables(const void *me)
Release all variables used by an object.
int register_proposition(formula f, std::shared_ptr< T > for_me)
Register an atomic proposition.
Definition: bdddict.hh:116
int register_anonymous_variables(int n, const void *for_me)
Register anonymous BDD variables.
int has_registered_proposition(formula f, std::shared_ptr< T > for_me)
Whether a proposition has already been registered.
Definition: bdddict.hh:131
void register_all_variables_of(const void *from_other, std::shared_ptr< T > for_me)
Duplicate the variable usage of another object.
Definition: bdddict.hh:210
bdd_info_map bdd_map
Table mapping BDD variable numbers to their meaning.
Definition: bdddict.hh:100
int has_registered_proposition(formula f, const void *me)
Whether a proposition has already been registered.
void register_all_propositions_of(const void *from_other, const void *for_me)
Duplicate the proposition usage of another object.
fv_map var_map
Maps atomic propositions to BDD variables.
Definition: bdddict.hh:70
void unregister_variable(int var, const void *me)
Release a variable used by me.
std::vector< bdd_info > bdd_info_map
Type of the per-variable information table.
Definition: bdddict.hh:98
int register_anonymous_variables(int n, std::shared_ptr< T > for_me)
Register anonymous BDD variables.
Definition: bdddict.hh:194
void register_all_variables_of(std::shared_ptr< T > from_other, std::shared_ptr< U > for_me)
Duplicate the variable usage of another object.
Definition: bdddict.hh:224
fv_map acc_map
Maps acceptance conditions to BDD variables.
Definition: bdddict.hh:71
formula ap_from_var(int var) const
Return the atomic proposition associated to a BDD variable.
Definition: bdddict.hh:155
int register_acceptance_variable(formula f, std::shared_ptr< T > for_me)
Register an acceptance variable.
Definition: bdddict.hh:177
int varnum(formula f)
Return the BDD variable number for a registered proposition.
Definition: bdddict.hh:144
~bdd_dict()
Destroy the BDD dict.
void register_all_variables_of(const void *from_other, const void *for_me)
Duplicate the variable usage of another object.
var_type
Type of a BDD variable in the dictionary.
Definition: bdddict.hh:81
@ var
Atomic-proposition variable.
Definition: bdddict.hh:83
Main class for temporal logic formula.
Definition: formula.hh:847
static formula ap(const std::string &name)
Build an atomic proposition.
Definition: formula.hh:1049
LTL/PSL formula interface.
bdd_dict_ptr make_bdd_dict()
Create a new, empty bdd_dict wrapped in a shared pointer.
Definition: bdddict.hh:308
std::shared_ptr< bdd_dict > bdd_dict_ptr
Shared pointer to a bdd_dict.
Definition: bdddict.hh:304
Definition: automata.hh:26
Information stored for one BDD variable.
Definition: bdddict.hh:91
ref_set refs
Set of objects referencing this variable.
Definition: bdddict.hh:95
formula f
Formula encoded (unused when type==anon).
Definition: bdddict.hh:94
var_type type
Type of this BDD variable.
Definition: bdddict.hh:93

Please direct any question, comment, or bug report to the Spot mailing list at spot@lrde.epita.fr.
Generated on Fri Feb 27 2015 10:00:07 for spot by doxygen 1.9.1