spot  2.15.1
spins_kripke.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/bricks/brick-hash>
22 #include <spot/bricks/brick-hashset>
23 #include <spot/kripke/kripke.hh>
24 #include <spot/ltsmin/spins_interface.hh>
25 #include <spot/misc/fixpool.hh>
26 #include <spot/misc/mspool.hh>
27 #include <spot/misc/intvcomp.hh>
28 #include <spot/misc/intvcmp2.hh>
29 #include <spot/twacube/cube.hh>
30 
33 namespace spot
34 {
44  typedef int* cspins_state;
45 
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 
59  {
60  size_t operator()(const cspins_state that) const
61  {
62  return that[0];
63  }
64  };
65 
71  {
72  public:
77  cspins_state_manager(unsigned int state_size, int compress);
78 
80  int* unbox_state(cspins_state s) const;
81 
87  cspins_state alloc_setup(int* dst, int* cmp, size_t cmpsize);
88 
90  void decompress(cspins_state s, int* uncompressed, unsigned size) const;
91 
94 
96  unsigned int size() const;
97 
98  private:
100  multiple_size_pool msp_;
101  bool compress_;
102  const unsigned int state_size_;
103  void (*fn_compress_)(const int*, size_t, int*, size_t&);
104  void (*fn_decompress_)(const int*, size_t, int*, size_t);
105  };
106 
107  // \brief This structure is used as a parameter during callback when
108  // generating states from the shared librarie produced by LTSmin.
110  {
111  cspins_state_manager* manager; // The state manager
112  std::vector<cspins_state>* succ; // The successors of a state
113  int* compressed; // Area to store compressed state
114  int* uncompressed; // Area to store uncompressed state
115  bool compress; // Should the state be compressed?
116  bool selfloopize; // Should the state be selfloopized
117  };
118 
124  class cspins_iterator final
125  {
126  public:
127  // Inner struct used to pack the various arguments required by the iterator
129  {
130  cspins_state s;
131  const spot::spins_interface* d;
132  cspins_state_manager& manager;
134  cube cond;
135  bool compress;
136  bool selfloopize;
138  int dead_idx;
139  unsigned tid;
140  };
141 
142  cspins_iterator(const cspins_iterator&) = delete;
143  cspins_iterator(cspins_iterator&) = delete;
144 
146  void recycle(cspins_iterator_param& p);
147  ~cspins_iterator();
148 
149  void next();
150  bool done() const;
151  cspins_state state() const;
152  cube condition() const;
153 
154  private:
156  unsigned compute_index() const;
157 
158  inline void setup_iterator(cspins_state s,
159  const spot::spins_interface* d,
160  cspins_state_manager& manager,
162  cube& cond,
163  bool compress,
164  bool selfloopize,
165  cubeset& cubeset,
166  int dead_idx);
167 
168  std::vector<cspins_state> successors_;
169  unsigned int current_;
170  cube cond_;
171  unsigned tid_;
172  };
173 
174 
175  // A specialisation of the template class kripke that is thread safe.
176  template<>
178  {
179  // Define operators that are available for atomic proposition
180  enum class relop
181  {
182  OP_EQ_VAR, // 1 == a
183  OP_NE_VAR, // 1 != a
184  OP_LT_VAR, // 1 < a
185  OP_GT_VAR, // 1 > a
186  OP_LE_VAR, // 1 <= a
187  OP_GE_VAR, // 1 >= a
188  VAR_OP_EQ, // a == 1
189  VAR_OP_NE, // a != 1
190  VAR_OP_LT, // a < 1
191  VAR_OP_GT, // a >= 1
192  VAR_OP_LE, // a <= 1
193  VAR_OP_GE, // a >= 1
194  VAR_OP_EQ_VAR, // a == b
195  VAR_OP_NE_VAR, // a != b
196  VAR_OP_LT_VAR, // a < b
197  VAR_OP_GT_VAR, // a > b
198  VAR_OP_LE_VAR, // a <= b
199  VAR_OP_GE_VAR, // a >= b
200  VAR_DEAD // The atomic proposition used to label deadlock
201  };
202 
203  // Structure for complex atomic proposition
204  struct one_prop
205  {
206  int lval; // Index of left variable or raw number
207  relop op; // The operator
208  int rval; // Index or right variable or raw number
209  };
210 
211  // Data structure to store complex atomic propositions
212  typedef std::vector<one_prop> prop_set;
213  prop_set pset_;
214 
215  public:
216  kripkecube(spins_interface_ptr sip, bool compress,
217  std::vector<std::string> visible_aps,
218  bool selfloopize, std::string dead_prop,
219  unsigned int nb_threads);
220  ~kripkecube();
221  cspins_state initial(unsigned tid);
222  std::string to_string(const cspins_state s, unsigned tid = 0) const;
223  cspins_iterator* succ(const cspins_state s, unsigned tid);
224  void recycle(cspins_iterator* it, unsigned tid);
225 
227  const std::vector<std::string> ap();
228 
230  unsigned get_threads();
231 
232  private:
235  void match_aps(std::vector<std::string>& aps, std::string dead_prop);
236 
239  void compute_condition(cube c, cspins_state s, unsigned tid = 0);
240 
241  spins_interface_ptr sip_; // The interface to the shared library
242  const spot::spins_interface* d_; // To avoid numerous sip_.get()
243  cspins_state_manager* manager_; // One manager per thread
244  bool compress_; // Should a compression be performed
245 
246  // One per threads to store no longer used iterators (and save memory)
247  std::vector<std::vector<cspins_iterator*>> recycle_;
248 
249  inner_callback_parameters* inner_; // One callback per thread
250  cubeset cubeset_; // A single cubeset to manipulate cubes
251  bool selfloopize_; // Should selfloopize be performed
252  int dead_idx_; // If yes, index of the "dead ap"
253  std::vector<std::string> aps_; // All the atomic propositions
254  unsigned int nb_threads_; // The number of threads used
255  };
256 
258  typedef std::shared_ptr<spot::kripkecube<spot::cspins_state,
261 
262 }
263 
264 #include <spot/ltsmin/spins_kripke.hxx>
This class provides an iterator over the successors of a state. All successors are computed once when...
Definition: spins_kripke.hh:125
The management of states (i.e. allocation/deallocation) can be painless since every time we have to c...
Definition: spins_kripke.hh:71
void dealloc(cspins_state s)
Help the manager to reclam the memory of a state.
void decompress(cspins_state s, int *uncompressed, unsigned size) const
Helper to decompress a state.
cspins_state alloc_setup(int *dst, int *cmp, size_t cmpsize)
Builder for a state from a raw description given in dst.
cspins_state_manager(unsigned int state_size, int compress)
Build a manager for a state of state_size variables and indicate wether compression should be used:
int * unbox_state(cspins_state s) const
Get Rid of the internal representation of the state.
unsigned int size() const
The size of a state.
Definition: cube.hh:68
const std::vector< std::string > ap()
List the atomic propositions used by this kripke.
unsigned get_threads()
The number of thread used by this kripke.
This class is a template representation of a Kripke structure. It is composed of two template paramet...
Definition: kripke.hh:40
std::string to_string(const State, unsigned tid) const
Provides a string representation of the parameter state.
SuccIterator * succ(const State, unsigned tid)
Returns an iterator over the successors of the parameter state.
State initial(unsigned tid)
Returns the initial State of the System. The tid parameter is used internally for sharing this struct...
void recycle(SuccIterator *, unsigned tid)
Allocation and deallocation of iterator is costly. This method allows to reuse old iterators.
A multiple-size memory pool implementation.
Definition: mspool.hh:35
Implementation of the PINS interface. This class is a wrapper that, given a file, will compile it w....
Definition: spins_interface.hh:45
Abstract class for states.
Definition: twa.hh:47
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:44
op
Operator types.
Definition: formula.hh:79
Definition: automata.hh:26
unsigned * cube
A cube is only a set of bits in memory.
Definition: cube.hh:65
std::shared_ptr< spot::kripkecube< spot::cspins_state, spot::cspins_iterator > > ltsmin_kripkecube_ptr
shortcut to manipulate the kripke below
Definition: spins_kripke.hh:260
Definition: spins_kripke.hh:129
This class provides the ability to compare two states.
Definition: spins_kripke.hh:49
This class provides the ability to hash a state.
Definition: spins_kripke.hh:59
Definition: spins_kripke.hh:110

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