spot 2.16
Loading...
Searching...
No Matches
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
33namespace spot
34{
37
47 typedef int* cspins_state;
48
52 {
54 bool operator()(const cspins_state lhs, const cspins_state rhs) const
55 {
56 return 0 == memcmp(lhs, rhs, (2+rhs[1])* sizeof(int));
57 }
58 };
59
63 {
65 size_t operator()(const cspins_state that) const
66 {
67 return that[0];
68 }
69 };
70
76 {
77 public:
82 cspins_state_manager(unsigned int state_size, int compress);
83
86
92 cspins_state alloc_setup(int* dst, int* cmp, size_t cmpsize);
93
95 void decompress(cspins_state s, int* uncompressed, unsigned size) const;
96
99
101 unsigned int size() const;
102
103 private:
106 bool compress_;
107 const unsigned int state_size_;
108 void (*fn_compress_)(const int*, size_t, int*, size_t&);
109 void (*fn_decompress_)(const int*, size_t, int*, size_t);
110 };
111
123
129 class cspins_iterator final
130 {
131 public:
147
148 cspins_iterator(const cspins_iterator&) = delete;
150
156
158 void next();
160 bool done() const;
165
166 private:
168 unsigned compute_index() const;
169
170 inline void setup_iterator(cspins_state s,
171 const spot::spins_interface* d,
172 cspins_state_manager& manager,
174 cube& cond,
175 bool compress,
176 bool selfloopize,
178 int dead_idx);
179
180 std::vector<cspins_state> successors_;
181 unsigned int current_;
182 cube cond_;
183 unsigned tid_;
184 };
185
186
189 template<>
191 {
192 // Define operators that are available for atomic proposition
193 enum class relop
194 {
195 OP_EQ_VAR, // 1 == a
196 OP_NE_VAR, // 1 != a
197 OP_LT_VAR, // 1 < a
198 OP_GT_VAR, // 1 > a
199 OP_LE_VAR, // 1 <= a
200 OP_GE_VAR, // 1 >= a
201 VAR_OP_EQ, // a == 1
202 VAR_OP_NE, // a != 1
203 VAR_OP_LT, // a < 1
204 VAR_OP_GT, // a >= 1
205 VAR_OP_LE, // a <= 1
206 VAR_OP_GE, // a >= 1
207 VAR_OP_EQ_VAR, // a == b
208 VAR_OP_NE_VAR, // a != b
209 VAR_OP_LT_VAR, // a < b
210 VAR_OP_GT_VAR, // a > b
211 VAR_OP_LE_VAR, // a <= b
212 VAR_OP_GE_VAR, // a >= b
213 VAR_DEAD // The atomic proposition used to label deadlock
214 };
215
216 // Structure for complex atomic proposition
217 struct one_prop
218 {
219 int lval; // Index of left variable or raw number
220 relop op; // The operator
221 int rval; // Index or right variable or raw number
222 };
223
224 // Data structure to store complex atomic propositions
225 typedef std::vector<one_prop> prop_set;
226 prop_set pset_;
227
228 public:
230 kripkecube(spins_interface_ptr sip, bool compress,
231 std::vector<std::string> visible_aps,
232 bool selfloopize, std::string dead_prop,
233 unsigned int nb_threads);
237 cspins_state initial(unsigned tid);
239 std::string to_string(const cspins_state s, unsigned tid = 0) const;
241 cspins_iterator* succ(const cspins_state s, unsigned tid);
243 void recycle(cspins_iterator* it, unsigned tid);
244
246 const std::vector<std::string> ap();
247
249 unsigned get_threads();
250
251 private:
254 void match_aps(std::vector<std::string>& aps, std::string dead_prop);
255
258 void compute_condition(cube c, cspins_state s, unsigned tid = 0);
259
261 const spot::spins_interface* d_;
262 cspins_state_manager* manager_;
263 bool compress_;
264
265 // One per threads to store no longer used iterators (and save memory)
266 std::vector<std::vector<cspins_iterator*>> recycle_;
267
269 cubeset cubeset_;
270 bool selfloopize_;
271 int dead_idx_;
272 std::vector<std::string> aps_;
273 unsigned int nb_threads_;
274 };
275
277 typedef std::shared_ptr<spot::kripkecube<spot::cspins_state,
280
282}
283
284#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:130
bool done() const
Whether all successors were visited.
void next()
Move to the next successor.
void recycle(cspins_iterator_param &p)
Recycle an iterator from parameters.
cspins_iterator(cspins_iterator_param &p)
Build an iterator from parameters.
cspins_state state() const
Return the current successor state.
cube condition() const
Return the current transition condition.
The management of states (i.e. allocation/deallocation) can be painless since every time we have to c...
Definition spins_kripke.hh:76
void dealloc(cspins_state s)
Help the manager to reclaim the memory of a state.
int * unbox_state(cspins_state s) const
Get Rid of the internal representation of the 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:
unsigned int size() const
The size of a state.
Manager for allocating and manipulating cubes (bit-encoded partial assignments over APs).
Definition cube.hh:72
A fixed-size memory pool implementation.
Definition fixpool.hh:46
std::string to_string(const cspins_state s, unsigned tid=0) const
Convert a state to a string.
kripkecube(spins_interface_ptr sip, bool compress, std::vector< std::string > visible_aps, bool selfloopize, std::string dead_prop, unsigned int nb_threads)
Build a kripkecube from a Spins interface.
cspins_state initial(unsigned tid)
Return the initial state for thread tid.
void recycle(cspins_iterator *it, unsigned tid)
Recycle an iterator.
cspins_iterator * succ(const cspins_state s, unsigned tid)
Return the iterator for a state.
unsigned get_threads()
The number of thread used by this kripke.
const std::vector< std::string > ap()
List the atomic propositions 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
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:48
std::shared_ptr< const spins_interface > spins_interface_ptr
Shared pointer to a Spins interface.
Definition spins_interface.hh:84
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:47
std::shared_ptr< spot::kripkecube< spot::cspins_state, spot::cspins_iterator > > ltsmin_kripkecube_ptr
shortcut to manipulate the kripke below
Definition spins_kripke.hh:279
op
Operator types.
Definition formula.hh:85
unsigned * cube
A cube is only a set of bits in memory.
Definition cube.hh:66
Definition automata.hh:26
Arguments bundle passed to construct or recycle a cspins_iterator.
Definition spins_kripke.hh:135
bool compress
Whether compression is used.
Definition spins_kripke.hh:141
spot::cubeset & cubeset
Cube set.
Definition spins_kripke.hh:143
cspins_state s
Current state.
Definition spins_kripke.hh:136
cube cond
Current cube condition.
Definition spins_kripke.hh:140
bool selfloopize
Whether to selfloopize.
Definition spins_kripke.hh:142
cspins_state_manager & manager
State manager.
Definition spins_kripke.hh:138
int dead_idx
Deadlock AP index.
Definition spins_kripke.hh:144
unsigned tid
Thread identifier.
Definition spins_kripke.hh:145
const spot::spins_interface * d
Spins interface.
Definition spins_kripke.hh:137
inner_callback_parameters & inner
Callback arguments.
Definition spins_kripke.hh:139
This class provides the ability to compare two states.
Definition spins_kripke.hh:52
bool operator()(const cspins_state lhs, const cspins_state rhs) const
Compare two states for equality.
Definition spins_kripke.hh:54
This class provides the ability to hash a state.
Definition spins_kripke.hh:63
size_t operator()(const cspins_state that) const
Return the cached hash of a state.
Definition spins_kripke.hh:65
Parameters passed to callbacks when generating successor states from the shared library produced by L...
Definition spins_kripke.hh:115
std::vector< cspins_state > * succ
Successors of a state.
Definition spins_kripke.hh:117
bool selfloopize
Whether to selfloopize.
Definition spins_kripke.hh:121
int * compressed
Buffer for compressed states.
Definition spins_kripke.hh:118
bool compress
Whether compression is used.
Definition spins_kripke.hh:120
int * uncompressed
Buffer for uncompressed states.
Definition spins_kripke.hh:119
cspins_state_manager * manager
State manager.
Definition spins_kripke.hh:116

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.8