spot  2.15.1
mtdswa.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 <spot/twa/twagraph.hh>
22 #include <spot/misc/bddlt.hh>
23 #include <unordered_map>
24 
25 namespace spot
26 {
29  struct SPOT_API mtdswa: public std::enable_shared_from_this<mtdswa>
30  {
31  public:
32  mtdswa(const bdd_dict_ptr& dict) noexcept
33  : dict_(dict)
34  {
35  }
36 
37  ~mtdswa()
38  {
39  dict_->unregister_all_my_variables(this);
40  }
41 
51  std::vector<formula> aps;
52 
53  std::vector<bdd> states;
54  std::vector<formula> names;
55  std::vector<acc_cond::mark_t> colors;
56  acc_cond acc;
57 
58  // If this map is non-empty, it is used to map terminal values
59  // to states while printing the automaton. Use this only for debugging,
60  // other algorithms will ignore it.
61  std::unordered_map<int, int> terminal_to_state_map;
62  // colors some nodes
63  std::unordered_map<int, unsigned> highlight_nodes;
64  // for each element (A, B) put state A in cluster B
65  std::unordered_map<int, int> highlight_groups;
66 
68  bdd_dict_ptr get_dict() const
69  {
70  return dict_;
71  }
72 
73  unsigned num_roots() const
74  {
75  return states.size();
76  }
77 
83  unsigned num_states() const
84  {
85  return states.size() + bdd_has_true(states);
86  }
87 
91  std::ostream& print_dot(std::ostream& os, const char* opts = nullptr) const;
92 
94  twa_graph_ptr as_twa(bool state_based = false,
95  bool labels = true,
96  bool complete = false) const;
97 
113 
121  void sinks_as_constants(bool keep_all_states = false);
122 
136  void set_controllable_variables(const std::vector<std::string>& vars,
137  bool ignore_non_registered_ap = false);
140 
143  {
144  return controllable_variables_;
145  }
146 
147  private:
148  bdd_dict_ptr dict_;
149  bdd controllable_variables_ = bddtrue;
150  };
151 
152 
153  typedef std::shared_ptr<mtdswa> mtdswa_ptr;
154  typedef std::shared_ptr<const mtdswa> const_mtdswa_ptr;
155 
158  SPOT_API mtdswa_ptr dtwa_to_mtdswa(const twa_graph_ptr& aut);
159 
168  SPOT_API std::vector<int> scc_vector(const mtdswa_ptr& aut);
169 
193  SPOT_API std::vector<unsigned> loding_weak_ranking(const mtdswa_ptr& aut,
194  bool fix = false);
195 
222  SPOT_API
223  mtdswa_ptr minimize_mtdswa(const mtdswa_ptr& dfa);
224  SPOT_API
225  mtdswa_ptr minimize_mtdswa(const mtdswa_ptr& dfa,
226  const std::vector<unsigned>& initial_partition);
228 
235  class SPOT_API simple_ltl_translator
236  {
237  public:
238  simple_ltl_translator(const bdd_dict_ptr& dict,
239  bool simplify_terms = true);
240 
241  mtdswa_ptr ltl_to_mtdswa(formula f, bool fuse_same_bdds);
242  mtdswa_ptr ltl_to_mtdswa_synthesis(formula f,
243  const std::vector<std::string>& outvars,
244  bool realizability, int debug = -1);
245 
246  bdd ltl_to_mtbdd(formula f);
247  formula leaf_to_formula(int b, int term) const;
248 
249  formula terminal_to_formula(int t) const;
250  int formula_to_int(formula f);
251  int formula_propeq_to_int(formula f);
252  int formula_to_terminal(formula f);
253  bdd formula_to_terminal_bdd(formula f);
254  int formula_to_terminal_bdd_as_int(formula f);
255  int formula_propeq_to_terminal_bdd_as_int(formula f);
256 
257  bdd combine_and(bdd left, bdd right);
258  bdd combine_or(bdd left, bdd right);
259  bdd combine_implies(bdd left, bdd right);
260  bdd combine_equiv(bdd left, bdd right);
261  bdd combine_xor(bdd left, bdd right);
262  bdd combine_not(bdd b);
263 
264  bdd propeq_encode(formula f, int level = 0);
265  formula propeq_representative(formula f, bool isacc);
266 
267  bddExtCache* get_cache()
268  {
269  return &cache_;
270  }
271 
273  private:
274  // Pair representing a formula at a given X-nesting level
275  struct formula_level_pair
276  {
277  formula f;
278  int level;
279 
280  bool operator==(const formula_level_pair& other) const
281  {
282  return f == other.f && level == other.level;
283  }
284  };
285 
286  struct formula_level_pair_hash
287  {
288  std::size_t operator()(const formula_level_pair& p) const
289  {
290  return p.f.id() ^ (p.level * 0x9e3779b9);
291  }
292  };
293 
294  std::unordered_map<formula_level_pair, bdd,
295  formula_level_pair_hash> propositional_equiv_bdd_;
296  std::unordered_map<bdd, formula, bdd_hash> propositional_equiv_[2];
297 
298  std::unordered_map<formula, bdd> formula_to_bdd_;
299  std::unordered_map<formula, int> formula_to_int_;
300  std::unordered_map<formula, int> propeq_to_int_;
301  std::vector<formula> int_to_formula_;
302  bdd_dict_ptr dict_;
303  bddExtCache cache_;
304  bool simplify_terms_;
305  };
306 
309  SPOT_API
310  mtdswa_ptr obligation_to_mtdswa(formula f, const bdd_dict_ptr& dict,
311  bool fuse_same_bdds = true,
312  bool simplify_terms = true);
313 
318  SPOT_API
319  mtdswa_ptr obligation_synthesis(formula f, const bdd_dict_ptr& dict,
320  const std::vector<std::string>& outvars,
321  bool realizability = false,
322  bool simplify_terms = true,
323  int debug = -1);
324 
330  SPOT_API twa_graph_ptr
331  mtdswa_strategy_to_mealy(mtdswa_ptr strategy, bool labels = true,
332  bool loop = false);
333 }
An acceptance condition.
Definition: acc.hh:61
Main class for temporal logic formula.
Definition: formula.hh:850
size_t id() const
Return the id of a formula.
Definition: formula.hh:1772
"Semi-internal" for translating LTL using MTBDDs
Definition: mtdswa.hh:236
twa_graph_ptr complete(const const_twa_ptr &aut)
Clone a twa and complete it.
Definition: automata.hh:26
std::vector< unsigned > loding_weak_ranking(const mtdswa_ptr &aut, bool fix=false)
preprocess a weak MTDSwA before minimization
std::vector< int > scc_vector(const mtdswa_ptr &aut)
find the SCC of each state
twa_graph_ptr mtdswa_strategy_to_mealy(mtdswa_ptr strategy, bool labels=true, bool loop=false)
Convert a strategy represented as MTDSwA into a Mealy machine.
mtdswa_ptr obligation_to_mtdswa(formula f, const bdd_dict_ptr &dict, bool fuse_same_bdds=true, bool simplify_terms=true)
Convert a syntactic-obligation to an MTDSwA.
mtdswa_ptr minimize_mtdswa(const mtdswa_ptr &dfa)
Minimization of MTDSwA.
mtdswa_ptr obligation_synthesis(formula f, const bdd_dict_ptr &dict, const std::vector< std::string > &outvars, bool realizability=false, bool simplify_terms=true, int debug=-1)
Reactive synthesis of syntactic-obligations.
mtdswa_ptr dtwa_to_mtdswa(const twa_graph_ptr &aut)
convert deterministic TwA to MTDSwA
MTBDD-based representation of a state-based ω-automaton.
Definition: mtdswa.hh:30
void set_controllable_variables(bdd vars)
declare a list of controllable variables
void set_controllable_variables(const std::vector< std::string > &vars, bool ignore_non_registered_ap=false)
declare a list of controllable variables
std::vector< formula > aps
The list of atomic propositions possibly used by the automaton.
Definition: mtdswa.hh:51
unsigned num_states() const
The number of states in the automaton.
Definition: mtdswa.hh:83
void sinks_as_constants(bool keep_all_states=false)
converse sink states to bddtrue/bddfalse constants
std::ostream & print_dot(std::ostream &os, const char *opts=nullptr) const
Print the MTBDD.
bdd get_controllable_variables() const
Returns the conjunction of controllable variables.
Definition: mtdswa.hh:142
void sinks_as_states()
convert bddtrue/bddfalse nodes to actual states
bdd_dict_ptr get_dict() const
get the bdd_dict associated to this automaton
Definition: mtdswa.hh:68
twa_graph_ptr as_twa(bool state_based=false, bool labels=true, bool complete=false) const
convert to twa

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