spot  1.2.1a
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
root_stack.hh
1 // Copyright (C) 2013 Laboratoire de Recherche et Développement
2 // de l'Epita (LRDE).
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 #ifndef SPOT_FASTTGBAALGOS_EC_ROOT_STACK_HH
20 # define SPOT_FASTTGBAALGOS_EC_ROOT_STACK_HH
21 
22 #include <stack>
23 #include <tuple>
24 #include <string>
25 #include "misc/hash.hh"
26 #include "union_find.hh"
27 #include "fasttgba/fasttgba.hh"
28 #include "ec.hh"
29 
30 namespace spot
31 {
34  // techniques
36  {
37  public:
39  empty_(new markset(acc)),
40  max_size_(0)
41  { }
42 
43  virtual ~stack_of_roots()
44  {
45  while (!stack_.empty())
46  {
47  pop();
48  }
49  delete empty_;
50  }
51 
52  virtual bool is_empty ()
53  {
54  return stack_.empty();
55  }
56 
57  virtual unsigned int size ()
58  {
59  return stack_.size();
60  }
61 
62  virtual void push_trivial (unsigned int root)
63  {
64  stack_.push(std::make_pair(root, empty_));
65  }
66 
67  virtual void push_non_trivial (unsigned int root,
68  markset m,
69  unsigned int)
70  {
71  if (m == *empty_)
72  stack_.push(std::make_pair(root, empty_));
73  else
74  stack_.push(std::make_pair(root, new markset(m)));
75  }
76 
77  virtual unsigned int root_of_the_top ()
78  {
79  return stack_.top().first;
80  }
81 
82  virtual void pop()
83  {
84  max_size_ = max_size_ > stack_.size()? max_size_ : stack_.size();
85  if (stack_.top().second != empty_)
86  delete stack_.top().second;
87  stack_.pop();
88  }
89 
90  virtual const markset& top_acceptance()
91  {
92  assert(!stack_.empty());
93  return *stack_.top().second;
94  }
95 
96  virtual unsigned int max_size()
97  {
98  return max_size_;
99  }
100 
101  private:
102  std::stack<std::pair<unsigned int, markset*>> stack_; // The stack
103  markset* empty_;
104  unsigned int max_size_;
105  };
106 
108  {
109  struct stack_entry
110  {
111  unsigned int root;
112  bool is_trivial;
113  markset *mark;
114  };
115 
116  // out, trivial, acc
117  std::vector<// std::tuple<unsigned int, bool, markset*>
118  stack_entry> stack_;
119  markset* empty_;
120  unsigned int max_size_;
121 
122  public:
124  stack_of_roots(acc),
125  empty_(new markset(acc)),
126  max_size_(0)
127  {
128  }
129 
130  virtual ~compressed_stack_of_roots()
131  {
132  while (!stack_.empty())
133  {
134  pop();
135  }
136  delete empty_;
137  }
138 
139  virtual bool is_empty ()
140  {
141  return stack_.empty();
142  }
143 
144  virtual unsigned int size ()
145  {
146  return stack_.size();
147  }
148 
149  virtual void push_trivial (unsigned int root)
150  {
151  // std::cout << "Push trivial " << root << std::endl;
152  // The stack is empty just push it!
153  if (is_empty())
154  {
155  assert(root == 0);
156  stack_.push_back({root, true, empty_});
157  }
158  // The stack is empty and the back is a trivial SCC
159  // Update it!
160  else if (stack_.back().is_trivial)
161  {
162  assert(root == stack_.back().root +1);
163  stack_.pop_back();
164  stack_.push_back({root, true, empty_});
165  }
166  // Otherwise it's a non trivial SCC fix out for this SCC
167  // and push the new one.
168  else {
169  assert(root_of_the_top() < root &&
170  root <= stack_.back().root +1);
171  stack_.back().root = root -1;
172  stack_.push_back({root, true, empty_});
173  }
174  }
175 
176  virtual void push_non_trivial (unsigned int root,
177  markset m,
178  unsigned int last = 0)
179  {
180  // std::cout << "Push non trivial " << root << std::endl;
181  assert(root <= last);
182  assert (!is_empty() || root == 0);
183  assert(is_empty() || root == stack_.back().root +1);
184 
185  if (m == *empty_)
186  stack_.push_back({last, false, empty_});
187  else
188  stack_.push_back({last, false, new markset(m)});
189  }
190 
193  virtual unsigned int root_of_the_top ()
194  {
195  assert (!is_empty());
196  if (stack_.back().is_trivial)
197  return stack_.back().root;
198  if (stack_.size() > 1)
199  return (stack_[stack_.size() - 2]).root + 1;
200  return 0;
201  }
202 
203  virtual void pop()
204  {
205  max_size_ = max_size_ > stack_.size()? max_size_ : stack_.size();
206  //std::cout << "Pop " << std::endl;
207  unsigned int r = root_of_the_top();
208 
209  if (stack_.back().is_trivial)
210  {
211  stack_.pop_back();
212  if (is_empty())
213  {
214  if (r > 0)
215  stack_.push_back({r-1, true, empty_});
216  }
217  else
218  {
219  if (r - 1 > stack_.back().root)
220  stack_.push_back({r-1, true, empty_});
221  }
222  }
223  else
224  {
225  if (stack_.back().mark != empty_)
226  delete stack_.back().mark;
227  stack_.pop_back();
228  }
229  }
230 
231  virtual const markset& top_acceptance()
232  {
233  assert(!stack_.empty());
234  return *stack_.back().mark;
235  }
236 
237  virtual unsigned int max_size()
238  {
239  return max_size_;
240  }
241  };
242 }
243 
244 
245 #endif // SPOT_FASTTGBAALGOS_EC_ROOT_STACK_HH
Definition: root_stack.hh:107
virtual void push_non_trivial(unsigned int root, markset m, unsigned int last=0)
&lt; Unused for this implem
Definition: root_stack.hh:176
Definition: root_stack.hh:35
int mark
the type that represents a mark
Definition: markset.hh:32
This class represents a set of acceptance marks.
Definition: markset.hh:35
Definition: acc_dict.hh:31
virtual unsigned int root_of_the_top()
Definition: root_stack.hh:193
virtual void push_non_trivial(unsigned int root, markset m, unsigned int)
&lt; Unused for this implem
Definition: root_stack.hh:67

Please direct any question, comment, or bug report to the Spot mailing list at spot@lrde.epita.fr.
Generated on Tue Jan 21 2014 16:52:01 for spot by doxygen 1.8.5