spot 2.16
Loading...
Searching...
No Matches
twacube.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 <vector>
22#include <iosfwd>
23#include <spot/graph/graph.hh>
24#include <spot/misc/hash.hh>
25#include <spot/twa/acc.hh>
26#include <spot/twacube/cube.hh>
27#include <spot/twacube/fwd.hh>
28
32
35
36namespace spot
37{
40 class SPOT_API cstate
41 {
42 public:
43 cstate() = default;
44 cstate(const cstate& s) = delete;
46 cstate(cstate&& s) noexcept;
47 ~cstate() = default;
48 };
49
52 class SPOT_API transition
53 {
54 public:
55 transition() = default;
56 transition(const transition& t) = delete;
58 transition(transition&& t) noexcept;
61 ~transition() = default;
62
65 };
66
69 class SPOT_API trans_index final:
70 public std::enable_shared_from_this<trans_index>
71 {
72 public:
77
78 trans_index(trans_index& ci) = delete;
80 trans_index(unsigned state, const graph_t& g):
81 st_(g.state_storage(state))
82 {
83 reset();
84 }
85
88 idx_(ci.idx_),
89 st_(ci.st_)
90 {
91 }
92
94 inline void reset()
95 {
96 idx_ = st_.succ;
97 }
98
100 inline void next()
101 {
102 ++idx_;
103 }
104
107 inline bool done() const
108 {
109 return !idx_ || idx_ > st_.succ_tail;
110 }
111
114 inline unsigned current(unsigned seed = 0) const
115 {
116 // no-swarming : since twacube are dedicated for parallelism, i.e.
117 // swarming, we expect swarming is activated.
118 if (SPOT_UNLIKELY(!seed))
119 return idx_;
120 // Here swarming performs a technique called "primitive
121 // root modulo n", i. e. for i in [1..n]: i*seed (mod n). We
122 // also must have seed prime with n: to solve this, we use
123 // precomputed primes and seed access one of this primes. Note
124 // that the chosen prime must be greater than n.
125 SPOT_ASSERT(primes[seed] > (st_.succ_tail-st_.succ+1));
126 unsigned long long c = (idx_-st_.succ) + 1;
127 unsigned long long p = primes[seed];
128 unsigned long long s = (st_.succ_tail-st_.succ+1);
129 return (unsigned) (((c*p) % s)+st_.succ);
130 }
131
132 private:
133 unsigned idx_;
134 const graph_t::state_storage_t& st_;
135 };
136
139 class SPOT_API twacube final: public std::enable_shared_from_this<twacube>
140 {
141 public:
142 twacube() = delete;
143
146 twacube(const std::vector<std::string> aps);
147
150
153
155 std::vector<std::string> ap() const;
156
158 unsigned new_state();
159
161 void set_initial(unsigned init);
162
164 unsigned get_initial() const;
165
167 cstate* state_from_int(unsigned i);
168
171 void create_transition(unsigned src,
172 const cube& cube,
173 const acc_cond::mark_t& mark,
174 unsigned dst);
175
177 const cubeset& get_cubeset() const;
178
181 bool succ_contiguous() const;
182
184 unsigned num_states() const
185 {
186 return theg_.num_states();
187 }
188
190 unsigned num_edges() const
191 {
192 return theg_.num_edges();
193 }
194
197
200 {
201 return theg_;
202 }
205
208 trans_storage(std::shared_ptr<trans_index> ci,
209 unsigned seed = 0) const
210 {
211 return theg_.edge_storage(ci->current(seed));
212 }
213
215 const transition& trans_data(std::shared_ptr<trans_index> ci,
216 unsigned seed = 0) const
217 {
218 return theg_.edge_data(ci->current(seed));
219 }
220
222 std::shared_ptr<trans_index> succ(unsigned i) const
223 {
224 return std::make_shared<trans_index>(i, theg_);
225 }
226
228 friend SPOT_API std::ostream& operator<<(std::ostream& os,
229 const twacube& twa);
230 private:
231 unsigned init_;
232 acc_cond acc_;
233 const std::vector<std::string> aps_;
234 graph_t theg_;
235 cubeset cubeset_;
236 };
237
240 inline twacube_ptr make_twacube(const std::vector<std::string> aps)
241 {
242 return std::make_shared<twacube>(aps);
243 }
244}
An acceptance condition.
Definition acc.hh:54
Class for thread-safe states.
Definition twacube.hh:41
cstate(cstate &&s) noexcept
Move a state.
Manager for allocating and manipulating cubes (bit-encoded partial assignments over APs).
Definition cube.hh:72
A directed graph.
Definition graph.hh:605
internal::edge_storage< state, state, edge, internal::boxed_label< transition > > edge_storage_t
Edge storage type.
Definition graph.hh:632
Abstract class for states.
Definition twa.hh:49
Class for iterators over transitions.
Definition twacube.hh:71
graph_t::edge_storage_t edge_storage_t
Edge storage type.
Definition twacube.hh:76
bool done() const
Returns a boolean indicating whether all the transitions have been iterated.
Definition twacube.hh:107
unsigned current(unsigned seed=0) const
Returns the current transition according to a specific seed. The seed is traditionally the thread ide...
Definition twacube.hh:114
trans_index(trans_index &&ci)
Move an iterator.
Definition twacube.hh:87
void reset()
Reset the iterator on the first element.
Definition twacube.hh:94
void next()
Iterate over the next transition.
Definition twacube.hh:100
trans_index(unsigned state, const graph_t &g)
Build an iterator for state state.
Definition twacube.hh:80
digraph< cstate, transition > graph_t
Underlying graph type.
Definition twacube.hh:74
Class for representing a transition.
Definition twacube.hh:53
acc_cond::mark_t acc_
Acceptance mark.
Definition twacube.hh:64
cube cube_
Transition cube.
Definition twacube.hh:63
transition(const cube &cube, acc_cond::mark_t acc)
Build a transition from a cube and an acceptance mark.
transition(transition &&t) noexcept
Move a transition.
A Transition-based ω-Automaton.
Definition twa.hh:648
Class for representing a thread-safe twa.
Definition twacube.hh:140
unsigned num_edges() const
Return the number of edges.
Definition twacube.hh:190
graph_t::edge_storage_t edge_storage_t
Edge storage type.
Definition twacube.hh:204
unsigned new_state()
This method creates a new state.
std::shared_ptr< trans_index > succ(unsigned i) const
Returns the successor of state i.
Definition twacube.hh:222
acc_cond & acc()
Returns the acceptance condition associated to the automaton.
std::vector< std::string > ap() const
Returns the names of the atomic propositions.
~twacube()
Destroy the automaton.
void create_transition(unsigned src, const cube &cube, const acc_cond::mark_t &mark, unsigned dst)
Create a transition between state src and state dst, using cube as the labelling cube and mark as the...
unsigned get_initial() const
Returns the id of the initial state in the automaton.
bool succ_contiguous() const
Check if all the successors of a state are located contiguously in memory. This is mandatory for swar...
const graph_t::edge_storage_t & trans_storage(std::shared_ptr< trans_index > ci, unsigned seed=0) const
Returns the storage associated to a transition.
Definition twacube.hh:208
const cubeset & get_cubeset() const
Accessor for the cube's manipulator.
friend std::ostream & operator<<(std::ostream &os, const twacube &twa)
Stream a twacube.
const transition & trans_data(std::shared_ptr< trans_index > ci, unsigned seed=0) const
Returns the data associated to a transition.
Definition twacube.hh:215
cstate * state_from_int(unsigned i)
Accessor for a state from its id.
digraph< cstate, transition > graph_t
Underlying graph type.
Definition twacube.hh:196
unsigned num_states() const
Return the number of states.
Definition twacube.hh:184
const graph_t & get_graph()
Returns the underlying graph for this automaton.
Definition twacube.hh:199
twacube(const std::vector< std::string > aps)
Build a new automaton from a list of atomic propositions.
void set_initial(unsigned init)
Updates the initial state to init.
std::shared_ptr< twacube > twacube_ptr
Definition fwd.hh:28
unsigned * cube
A cube is only a set of bits in memory.
Definition cube.hh:66
twacube_ptr make_twacube(const std::vector< std::string > aps)
Build a shared twacube automaton.
Definition twacube.hh:240
Definition automata.hh:26
An acceptance mark.
Definition acc.hh:76

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