spot  2.3.3.dev
spins_kripke.hh
1 // -*- coding: utf-8 -*-
2 // Copyright (C) 2017 Laboratoire de Recherche et Développement de
3 // 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 <bricks/brick-hash>
23 #include <bricks/brick-hashset>
24 #include <spot/kripke/kripke.hh>
25 #include <spot/ltsmin/spins_interface.hh>
26 #include <spot/misc/fixpool.hh>
27 #include <spot/misc/mspool.hh>
28 #include <spot/misc/intvcomp.hh>
29 #include <spot/misc/intvcmp2.hh>
30 #include <spot/twacube/cube.hh>
31 
34 namespace spot
35 {
36 
45  typedef int* cspins_state;
46 
49  {
50  bool operator()(const cspins_state lhs, const cspins_state rhs) const
51  {
52  return 0 == memcmp(lhs, rhs, (2+rhs[1])* sizeof(int));
53  }
54  };
55 
58  {
59  size_t operator()(const cspins_state that) const
60  {
61  return that[0];
62  }
63  };
64 
67  {
68  cspins_state_hasher(cspins_state&) { }
69  cspins_state_hasher() = default;
70  brick::hash::hash128_t hash(cspins_state t) const
71  {
72  // FIXME we should compute a better hash value for this particular
73  // case. Shall we use two differents hash functions?
74  return std::make_pair(t[0], t[0]);
75  }
76  bool equal(cspins_state lhs, cspins_state rhs) const
77  {
78  return 0 == memcmp(lhs, rhs, (2+rhs[1])* sizeof(int));
79  }
80  };
81 
83  typedef brick::hashset::FastConcurrent<cspins_state, cspins_state_hasher>
85 
90  {
91  public:
92  cspins_state_manager(unsigned int state_size, int compress);
93  int* unbox_state(cspins_state s) const;
94  // cmp is the area we can use to compute the compressed rep of dst.
95  cspins_state alloc_setup(int *dst, int* cmp, size_t cmpsize);
96  void decompress(cspins_state s, int* uncompressed, unsigned size) const;
97  void dealloc(cspins_state s);
98  unsigned int size() const;
99 
100  private:
101  fixed_size_pool p_;
102  multiple_size_pool msp_;
103  bool compress_;
104  const unsigned int state_size_;
105  void (*fn_compress_)(const int*, size_t, int*, size_t&);
106  void (*fn_decompress_)(const int*, size_t, int*, size_t);
107  };
108 
109 
110  // This structure is used as a parameter during callback when
111  // generating states from the shared librarie produced by LTSmin
113  {
114  cspins_state_manager* manager; // The state manager
115  std::vector<cspins_state>* succ; // The successors of a state
116  cspins_state_map map; // Must be a copy and only one copy/thread
117  int* compressed_;
118  int* uncompressed_;
119  bool compress;
120  bool selfloopize;
121  };
122 
123  // This class provides an iterator over the successors of a state.
124  // All successors are computed once when an iterator is recycled or
125  // created.
126  class cspins_iterator final
127  {
128  public:
129  cspins_iterator(cspins_state s,
130  const spot::spins_interface* d,
131  cspins_state_manager& manager,
133  cube cond,
134  bool compress,
135  bool selfloopize,
136  cubeset& cubeset,
137  int dead_idx, unsigned tid);
138 
139  void recycle(cspins_state s,
140  const spot::spins_interface* d,
141  cspins_state_manager& manager,
143  cube cond,
144  bool compress,
145  bool selfloopize,
146  cubeset& cubeset, int dead_idx, unsigned tid);
147 
148  ~cspins_iterator();
149  void next();
150  bool done() const;
151  cspins_state state() const;
152  cube condition() const;
153 
154  private:
155  std::vector<cspins_state> successors_;
156  unsigned int current_;
157  cube cond_;
158  unsigned tid_;
159  };
160 
161 
162  // A specialisation of the template class kripke that is thread safe.
163  template<>
164  class kripkecube<cspins_state, cspins_iterator> final
165  {
166 
167  typedef enum {
168  OP_EQ_VAR, OP_NE_VAR, OP_LT_VAR, OP_GT_VAR, OP_LE_VAR, OP_GE_VAR,
169  VAR_OP_EQ, VAR_OP_NE, VAR_OP_LT, VAR_OP_GT, VAR_OP_LE, VAR_OP_GE,
170  VAR_OP_EQ_VAR, VAR_OP_NE_VAR, VAR_OP_LT_VAR,
171  VAR_OP_GT_VAR, VAR_OP_LE_VAR, VAR_OP_GE_VAR, VAR_DEAD
172  } relop;
173 
174  // Structure for complex atomic proposition
175  struct one_prop
176  {
177  int lval;
178  relop op;
179  int rval;
180  };
181 
182  // Data structure to store complex atomic propositions
183  typedef std::vector<one_prop> prop_set;
184  prop_set pset_;
185 
186  public:
187  kripkecube(spins_interface_ptr sip, bool compress,
188  std::vector<std::string> visible_aps,
189  bool selfloopize, std::string dead_prop,
190  unsigned int nb_threads);
191  ~kripkecube();
192  cspins_state initial(unsigned tid);
193  std::string to_string(const cspins_state s, unsigned tid = 0) const;
194  cspins_iterator* succ(const cspins_state s, unsigned tid);
195  void recycle(cspins_iterator* it, unsigned tid);
196  const std::vector<std::string> get_ap();
197  unsigned get_threads();
198  bool compress();
200  cspins_state_manager& manager(unsigned i = 0);
201 
202  private:
205  void match_aps(std::vector<std::string>& aps, std::string dead_prop);
206 
209  void compute_condition(cube c, cspins_state s, unsigned tid = 0);
210 
211  spins_interface_ptr sip_;
212  const spot::spins_interface* d_; // To avoid numerous sip_.get()
213  cspins_state_manager* manager_;
214  bool compress_;
215  std::vector<std::vector<cspins_iterator*>> recycle_;
217  cubeset cubeset_;
218  bool selfloopize_;
219  int dead_idx_;
220  std::vector<std::string> aps_;
221  cspins_state_map map_;
222  unsigned int nb_threads_;
223  };
224 
226  typedef std::shared_ptr<spot::kripkecube<spot::cspins_state,
229 
230 }
231 
232 #include <spot/ltsmin/spins_kripke.hxx>
Definition: graph.hh:33
Definition: spins_kripke.hh:126
Abstract class for states.
Definition: twa.hh:50
This class provides a hasher as required by the bricks classes.
Definition: spins_kripke.hh:66
This class is a template representation of a Kripke structure. It is composed of two template paramet...
Definition: kripke.hh:37
This class provides the ability to hash a state.
Definition: spins_kripke.hh:57
A multiple-size memory pool implementation.
Definition: mspool.hh:32
brick::hashset::FastConcurrent< cspins_state, cspins_state_hasher > cspins_state_map
Shortcut to avoid long names...
Definition: spins_kripke.hh:84
std::shared_ptr< spot::kripkecube< spot::cspins_state, spot::cspins_iterator > > ltsmin_kripkecube_ptr
shortcut to manipulate the kripke below
Definition: spins_kripke.hh:228
Definition: cube.hh:68
This class provides the ability to compare two states.
Definition: spins_kripke.hh:48
Definition: spins_kripke.hh:112
op
Operator types.
Definition: formula.hh:62
unsigned * cube
A cube is only a set of bits in memory.
Definition: cube.hh:66
int * cspins_state
A Spins state is represented as an array of integer Note that this array has two reserved slots (posi...
Definition: spins_kripke.hh:45
The management of states (i.e. allocation/deallocation) can be painless since every time we have to c...
Definition: spins_kripke.hh:89
Definition: spins_interface.hh:39
A fixed-size memory pool implementation.
Definition: fixpool.hh:31

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