spot  2.3.3.dev
twacube.hh
1 // -*- coding: utf-8 -*-
2 // Copyright (C) 2015, 2016 Laboratoire de Recherche
3 // et Développement de 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 <vector>
23 #include <iosfwd>
24 #include <spot/graph/graph.hh>
25 #include <spot/misc/hash.hh>
26 #include <spot/twa/acc.hh>
27 #include <spot/twacube/cube.hh>
28 #include <spot/twacube/fwd.hh>
29 
30 namespace spot
31 {
32  class SPOT_API cstate
33  {
34  public:
35  cstate() {}
36  cstate(const cstate& s) = delete;
37  cstate(cstate&& s) noexcept;
38  cstate(unsigned int id);
39  virtual ~cstate();
40  unsigned int label();
41  private:
42  unsigned int id_;
43  };
44 
45  class SPOT_API transition
46  {
47  public:
48  cube cube_;
49  acc_cond::mark_t acc_;
50  transition();
51  transition(const transition& t) = delete;
52  transition(transition&& t) noexcept;
53  transition(const cube& cube, acc_cond::mark_t acc);
54  virtual ~transition();
55  };
56 
57  class SPOT_API trans_index final
58  {
59  public:
62 
63  trans_index(trans_index& ci) = delete;
64  trans_index(unsigned int state, graph_t& g):
65  st_(g.state_storage(state))
66  {
67  reset();
68  }
69 
71  idx_(ci.idx_),
72  st_(ci.st_)
73  {
74  }
75 
76  inline void reset()
77  {
78  idx_ = st_.succ;
79  }
80 
81  inline void next()
82  {
83  ++idx_;
84  }
85 
86  inline bool done() const
87  {
88  return !idx_ || idx_ > st_.succ_tail;
89  }
90 
91  inline unsigned int current(unsigned int seed = 0) const
92  {
93  // no-swarming : since twacube are dedicated for parallelism, i.e.
94  // swarming, we expect swarming is activated.
95  if (SPOT_UNLIKELY(!seed))
96  return idx_;
97  // Here swarming performs a technique called "primitive
98  // root modulo n", i. e. for i in [1..n]: i*seed (mod n). We
99  // also must have seed prime with n: to solve this, we use
100  // precomputed primes and seed access one of this primes. Note
101  // that the chosen prime must be greater than n.
102  SPOT_ASSERT(primes[seed] > (st_.succ_tail-st_.succ+1));
103  return (((idx_-st_.succ+1)*primes[seed]) % (st_.succ_tail-st_.succ+1))
104  + st_.succ;
105  }
106 
107  private:
108  unsigned int idx_;
109  const graph_t::state_storage_t& st_;
110  };
111 
112  class SPOT_API twacube final: public std::enable_shared_from_this<twacube>
113  {
114  public:
115  twacube() = delete;
116  twacube(const std::vector<std::string> aps);
117  virtual ~twacube();
118  const acc_cond& acc() const;
119  acc_cond& acc();
120  std::vector<std::string> get_ap();
121  unsigned int new_state();
122  void set_initial(unsigned int init);
123  unsigned int get_initial();
124  cstate* state_from_int(unsigned int i);
125  void create_transition(unsigned int src, const cube& cube,
126  const acc_cond::mark_t& mark, unsigned int dst);
127  const cubeset& get_cubeset() const;
128  bool succ_contiguous() const;
130  const graph_t& get_graph()
131  {
132  return theg_;
133  }
136  trans_storage(std::shared_ptr<trans_index> ci,
137  unsigned int seed = 0) const
138  {
139  return theg_.edge_storage(ci->current(seed));
140  }
141  const transition& trans_data(std::shared_ptr<trans_index> ci,
142  unsigned int seed = 0) const
143  {
144  return theg_.edge_data(ci->current(seed));
145  }
146 
147  std::shared_ptr<trans_index> succ(unsigned int i)
148  {
149  return std::make_shared<trans_index>(i, theg_);
150  }
151 
152  friend SPOT_API std::ostream& operator<<(std::ostream& os,
153  const twacube& twa);
154  private:
155  unsigned int init_;
156  acc_cond acc_;
157  const std::vector<std::string> aps_;
158  graph_t theg_;
159  cubeset cubeset_;
160  };
161 
162  inline twacube_ptr make_twacube(const std::vector<std::string> aps)
163  {
164  return std::make_shared<twacube>(aps);
165  }
166 }
Definition: graph.hh:33
Definition: twacube.hh:32
A Transition-based ω-Automaton.
Definition: twa.hh:622
Abstract class for states.
Definition: twa.hh:50
Definition: twacube.hh:57
Definition: graph.hh:184
Definition: twacube.hh:45
Definition: graph.hh:159
state_storage_t & state_storage(state s)
return a reference to the storage of a state
Definition: graph.hh:712
Definition: acc.hh:31
Definition: cube.hh:68
Definition: twacube.hh:112
unsigned * cube
A cube is only a set of bits in memory.
Definition: cube.hh:66
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