spot  2.3.3.dev
utils.hh
1 // -*- coding: utf-8 -*-
2 // Copyright (C) 2016 Laboratoire de Recherche et
3 // Developpement de l'Epita
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 <spot/mc/reachability.hh>
23 #include <spot/mc/intersect.hh>
24 #include <spot/twa/twa.hh>
25 #include <spot/twacube_algos/convert.hh>
26 
27 namespace spot
28 {
29  template<typename State, typename SuccIterator,
30  typename StateHash, typename StateEqual>
31  class SPOT_API kripke_to_twa :
32  public seq_reach_kripke<State, SuccIterator,
33  StateHash, StateEqual,
34  kripke_to_twa<State, SuccIterator,
35  StateHash, StateEqual>>
36  {
37  public:
38  kripke_to_twa(kripkecube<State, SuccIterator>& sys, bdd_dict_ptr dict)
39  : seq_reach_kripke<State, SuccIterator, StateHash, StateEqual,
40  kripke_to_twa<State, SuccIterator,
41  StateHash, StateEqual>>(sys),
42  dict_(dict)
43  {}
44 
45  ~kripke_to_twa()
46  {
47  }
48 
49  void setup()
50  {
51  res_ = make_twa_graph(dict_);
52  names_ = new std::vector<std::string>();
53 
54  // padding to simplify computation.
55  res_->new_state();
56 
57  // Compute the reverse binder.
58  auto aps = this->sys_.get_ap();
59  for (unsigned i = 0; i < aps.size(); ++i)
60  {
61  auto k = res_->register_ap(aps[i]);
62  reverse_binder_.insert({i, k});
63  }
64  }
65 
66  void push(State s, unsigned i)
67  {
68  unsigned st = res_->new_state();
69  names_->push_back(this->sys_.to_string(s));
70  SPOT_ASSERT(st == i);
71  }
72 
73  void edge(unsigned src, unsigned dst)
74  {
75  cubeset cs(this->sys_.get_ap().size());
76  bdd cond = cube_to_bdd(this->todo.back().it->condition(),
77  cs, reverse_binder_);
78  res_->new_edge(src, dst, cond);
79  }
80 
81  void finalize()
82  {
83  res_->set_init_state(1);
84  res_->purge_unreachable_states();
85  res_->set_named_prop<std::vector<std::string>>("state-names", names_);
86  }
87 
88  twa_graph_ptr twa()
89  {
90  return res_;
91  }
92 
93  private:
94  spot::twa_graph_ptr res_;
95  std::vector<std::string>* names_;
96  bdd_dict_ptr dict_;
97  std::unordered_map<int, int> reverse_binder_;
98  };
99 
100 
101 
102  template<typename State, typename SuccIterator,
103  typename StateHash, typename StateEqual>
104  class SPOT_API product_to_twa :
105  public intersect<State, SuccIterator,
106  StateHash, StateEqual,
107  product_to_twa<State, SuccIterator,
108  StateHash, StateEqual>>
109  {
110  // Ease the manipulation
111  using typename intersect<State, SuccIterator, StateHash, StateEqual,
112  product_to_twa<State, SuccIterator,
113  StateHash,
114  StateEqual>>::product_state;
115 
116  public:
118  twacube_ptr twa)
119  : intersect<State, SuccIterator, StateHash, StateEqual,
120  product_to_twa<State, SuccIterator,
121  StateHash, StateEqual>>(sys, twa)
122  {
123  }
124 
125  ~product_to_twa()
126  {
127  }
128 
129  twa_graph_ptr twa()
130  {
131  res_->set_named_prop<std::vector<std::string>>("state-names", names_);
132  return res_;
133  }
134 
135  void setup()
136  {
137  auto d = spot::make_bdd_dict();
138  res_ = make_twa_graph(d);
139  names_ = new std::vector<std::string>();
140 
141  int i = 0;
142  for (auto ap : this->twa_->get_ap())
143  {
144  auto idx = res_->register_ap(ap);
145  reverse_binder_[i++] = idx;
146  }
147  }
148 
149  bool push_state(product_state s, unsigned i, acc_cond::mark_t)
150  {
151  // push also implies edge (when it's not the initial state)
152  if (this->todo.size())
153  {
154  auto c = this->twa_->get_cubeset()
155  .intersection(this->twa_->trans_data
156  (this->todo.back().it_prop).cube_,
157  this->todo.back().it_kripke->condition());
158 
159  bdd x = spot::cube_to_bdd(c, this->twa_->get_cubeset(),
160  reverse_binder_);
161  this->twa_->get_cubeset().release(c);
162  res_->new_edge(this->map[this->todo.back().st]-1, i-1, x,
163  this->twa_->trans_data
164  (this->todo.back().it_prop).acc_);
165  }
166 
167  unsigned st = res_->new_state();
168  names_->push_back(this->sys_.to_string(s.st_kripke) +
169  ('*' + std::to_string(s.st_prop)));
170  SPOT_ASSERT(st+1 == i);
171  return true;
172  }
173 
174 
175  bool update(product_state, unsigned src,
176  product_state, unsigned dst,
177  acc_cond::mark_t cond)
178  {
179  auto c = this->twa_->get_cubeset()
180  .intersection(this->twa_->trans_data
181  (this->todo.back().it_prop).cube_,
182  this->todo.back().it_kripke->condition());
183 
184  bdd x = spot::cube_to_bdd(c, this->twa_->get_cubeset(),
185  reverse_binder_);
186  this->twa_->get_cubeset().release(c);
187  res_->new_edge(src-1, dst-1, x, cond);
188  return false;
189  }
190 
191  // These callbacks are useless here
192  bool counterexample_found()
193  {
194  return false;
195  }
196 
197  std::string trace()
198  {
199  return "";
200  }
201 
202  bool pop_state(product_state, unsigned, bool, product_state, unsigned)
203  {
204  return true;
205  }
206 
207  private:
208  spot::twa_graph_ptr res_;
209  std::vector<std::string>* names_;
210  std::unordered_map<int, int> reverse_binder_;
211  };
212 }
Definition: graph.hh:33
A Transition-based ω-Automaton.
Definition: twa.hh:622
This class explores (with a DFS) a product between a system and a twa. This exploration is performed ...
Definition: intersect.hh:59
This class is a template representation of a Kripke structure. It is composed of two template paramet...
Definition: kripke.hh:37
Definition: cube.hh:68
Definition: utils.hh:104
bdd cube_to_bdd(spot::cube cube, const cubeset &cubeset, std::unordered_map< int, int > &reverse_binder)
Transform a cube cube into bdd using the map that bind cube indexes to bdd indexes.
Atomic proposition.
Definition: utils.hh:31
This template class provide a sequential reachability of a kripkecube. The algorithm uses a single DF...
Definition: reachability.hh:33
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