spot  2.16
zlktree.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 <iosfwd>
22 #include <deque>
23 #include <memory>
24 #include <spot/misc/bitvect.hh>
25 #include <spot/twa/twagraph.hh>
26 #include <spot/twaalgos/sccinfo.hh>
27 
28 namespace spot
29 {
33  {
35  NONE = 0,
39  CHECK_RABIN = 1,
43  CHECK_STREETT = 2,
55  MERGE_SUBTREES = 8,
59  NO_EMPTY_LAYER = 16,
60  };
61 
62 #ifndef SWIG
64  inline
66  {
67  return me == zielonka_tree_options::NONE;
68  }
69 
71  inline
74  {
75  typedef std::underlying_type_t<zielonka_tree_options> ut;
76  return static_cast<zielonka_tree_options>(static_cast<ut>(left)
77  & static_cast<ut>(right));
78  }
79 
81  inline
84  {
85  typedef std::underlying_type_t<zielonka_tree_options> ut;
86  return static_cast<zielonka_tree_options>(static_cast<ut>(left)
87  | static_cast<ut>(right));
88  }
89 
91  inline
94  {
95  typedef std::underlying_type_t<zielonka_tree_options> ut;
96  return static_cast<zielonka_tree_options>(static_cast<ut>(left)
97  & ~static_cast<ut>(right));
98  }
99 #endif
109  class SPOT_API zielonka_tree
110  {
111  public:
113  zielonka_tree(const acc_cond& cond,
115 
120  unsigned num_branches() const
121  {
122  return num_branches_;
123  }
124 
128  unsigned first_branch() const
129  {
130  return one_branch_;
131  }
132 
152  std::pair<unsigned, unsigned>
153  step(unsigned branch, acc_cond::mark_t colors) const;
154 
171  bool is_even() const
172  {
173  return is_even_;
174  }
175 
183  bool empty_layer_is_even() const
184  {
185  return empty_is_even_;
186  }
187 
192  bool has_rabin_shape() const
193  {
194  return has_rabin_shape_;
195  }
196 
201  bool has_streett_shape() const
202  {
203  return has_streett_shape_;
204  }
205 
209  bool has_parity_shape() const
210  {
211  return has_streett_shape_ && has_rabin_shape_;
212  }
213 
215  void dot(std::ostream&) const;
216 
220  {
221  unsigned parent;
222  unsigned next_sibling = 0;
223  unsigned first_child = 0;
224  unsigned level;
226  };
228  std::vector<zielonka_node> nodes_;
229  private:
230  unsigned one_branch_ = 0;
231  unsigned num_branches_ = 0;
232  bool is_even_;
233  bool empty_is_even_;
234  bool has_rabin_shape_ = true;
235  bool has_streett_shape_ = true;
236  };
237 
249  SPOT_API
251 
252 
255  enum class acd_options
256  {
258  NONE = 0,
260  CHECK_RABIN = 1,
262  CHECK_STREETT = 2,
268  ABORT_WRONG_SHAPE = 4,
273  ORDER_HEURISTIC = 8,
274  };
275 
276 #ifndef SWIG
278  inline
280  {
281  return me == acd_options::NONE;
282  }
283 
285  inline
287  {
288  typedef std::underlying_type_t<acd_options> ut;
289  return static_cast<acd_options>(static_cast<ut>(left)
290  & static_cast<ut>(right));
291  }
292 
294  inline
296  {
297  typedef std::underlying_type_t<acd_options> ut;
298  return static_cast<acd_options>(static_cast<ut>(left)
299  | static_cast<ut>(right));
300  }
301 
303  inline
305  {
306  typedef std::underlying_type_t<acd_options> ut;
307  return static_cast<acd_options>(static_cast<ut>(left)
308  & ~static_cast<ut>(right));
309  }
310 
311 #endif
312 
322  class SPOT_API acd
323  {
324  public:
329 
330  ~acd();
331 
340  std::pair<unsigned, unsigned>
341  step(unsigned branch, unsigned edge) const;
342 
349  unsigned state_step(unsigned node, unsigned edge) const;
350 
354  std::vector<unsigned> edges_of_node(unsigned n) const;
355 
357  unsigned node_count() const
358  {
359  return nodes_.size();
360  }
361 
365  bool node_acceptance(unsigned n) const;
366 
368  unsigned node_level(unsigned n) const;
369 
371  const acc_cond::mark_t& node_colors(unsigned n) const;
372 
375  bool is_even(unsigned scc) const
376  {
377  if (scc >= scc_count_)
378  report_invalid_scc_number(scc, "is_even");
379  return trees_[scc].is_even;
380  }
381 
388  bool is_even() const
389  {
390  return is_even_;
391  }
392 
394  unsigned first_branch(unsigned state) const;
395 
397  unsigned scc_max_level(unsigned scc) const
398  {
399  if (scc >= scc_count_)
400  report_invalid_scc_number(scc, "scc_max_level");
401  return trees_[scc].max_level;
402  }
403 
409  bool has_rabin_shape() const;
410 
416  bool has_streett_shape() const;
417 
423  bool has_parity_shape() const;
424 
427  {
428  return aut_;
429  }
430 
435  void dot(std::ostream&, const char* id = nullptr) const;
436 
437  private:
438  const scc_info* si_;
439  bool own_si_ = false;
440  acd_options opt_;
441 
442  // This structure is used to represent one node in the ACD forest.
443  // The tree use a left-child / right-sibling representation
444  // (called here first_child, next_sibling). Each node
445  // additionally store a level (depth in the ACD, adjusted at the
446  // end of the construction so that all node on the same level have
447  // the same parity), the SCC (which is also it's tree number), and
448  // some bit vectors representing the edges and states of that
449  // node. Those bit vectors are as large as the original
450  // automaton, and they are shared among nodes from the different
451  // trees of the ACD forest (since each tree corresponds to a
452  // different SCC, they cannot share state or edges).
453  struct acd_node
454  {
455  unsigned parent;
456  unsigned next_sibling = 0;
457  unsigned first_child = 0;
458  unsigned level;
459  unsigned scc;
460  acc_cond::mark_t colors;
461  unsigned minstate;
462  bitvect& edges;
463  bitvect& states;
464  acd_node(bitvect& e, bitvect& s) noexcept
465  : edges(e), states(s)
466  {
467  }
468  };
469  // We store the nodes in a deque so that their addresses do not
470  // change.
471  std::deque<acd_node> nodes_;
472  // Likewise for bitvectors: this is the support for all edge vectors
473  // and state vectors used in acd_node.
474  std::deque<std::unique_ptr<bitvect>> bitvectors;
475  // Information about a tree of the ACD. Each treinserte correspond
476  // to an SCC.
477  struct scc_data
478  {
479  bool trivial; // whether the SCC is trivial we do
480  // not store any node for trivial
481  // SCCs.
482  unsigned root = 0; // root node of a non-trivial SCC.
483  bool is_even; // parity of the tree, used at the end
484  // of the construction to adjust
485  // levels.
486  unsigned max_level = 0; // Maximum level for this SCC.
487  unsigned num_nodes = 0; // Number of node in this tree. This
488  // is only used to share bitvectors
489  // between SCC: node with the same
490  // "rank" in each tree share the same
491  // bitvectors.
492  };
493  std::vector<scc_data> trees_;
494  unsigned scc_count_;
495  const_twa_graph_ptr aut_;
496  // Information about the overall ACD.
497  bool is_even_;
498  bool has_rabin_shape_ = true;
499  bool has_streett_shape_ = true;
500 
501  // Build the ACD structure. Called by the constructors.
502  void build_();
503 
504  // leftmost branch of \a node that contains \a state
505  unsigned leftmost_branch_(unsigned node, unsigned state) const;
506 
507 #ifndef SWIG
508  [[noreturn]] static
509  void report_invalid_scc_number(unsigned num, const char* fn);
510  [[noreturn]] static void report_need_opt(const char* opt);
511  [[noreturn]] static void report_empty_acd(const char* fn);
512 #endif
513  };
514 
537  SPOT_API
539  bool colored = false);
540  SPOT_API
542  bool colored = false,
543  bool order_heuristic = true);
545 }
An acceptance condition.
Definition: acc.hh:54
Alternating Cycle Decomposition implementation.
Definition: zlktree.hh:323
bool has_parity_shape() const
Whether the ACD has parity shape.
unsigned first_branch(unsigned state) const
Return the first branch for state.
bool node_acceptance(unsigned n) const
const const_twa_graph_ptr get_aut() const
Return the automaton on which the ACD is defined.
Definition: zlktree.hh:426
bool is_even(unsigned scc) const
Whether the ACD corresponds to a min even or min odd parity acceptance in SCC scc.
Definition: zlktree.hh:375
bool has_rabin_shape() const
Whether the ACD has Rabin shape.
const acc_cond::mark_t & node_colors(unsigned n) const
Return the colors of a node.
std::pair< unsigned, unsigned > step(unsigned branch, unsigned edge) const
Step through the ACD.
unsigned node_level(unsigned n) const
Return the level of a node.
acd(const const_twa_graph_ptr &aut, acd_options opt=acd_options::NONE)
Build an ACD directly from an automaton.
std::vector< unsigned > edges_of_node(unsigned n) const
Return the list of edges covered by node n of the ACD.
unsigned node_count() const
Return the number of nodes in the ACD forest.
Definition: zlktree.hh:357
void dot(std::ostream &, const char *id=nullptr) const
Render the ACD as in GraphViz format.
bool is_even() const
Whether the ACD globally corresponds to a min even or min odd parity acceptance.
Definition: zlktree.hh:388
unsigned state_step(unsigned node, unsigned edge) const
Step through the ACD, with rules for state-based output.
acd(const scc_info &si, acd_options opt=acd_options::NONE)
Build an Alternating Cycle Decomposition an SCC decomposition.
unsigned scc_max_level(unsigned scc) const
Return the maximum parity level in the given SCC.
Definition: zlktree.hh:397
bool has_streett_shape() const
Whether the ACD has Streett shape.
A bit vector.
Definition: bitvect.hh:51
Compute an SCC map and gather assorted information.
Definition: sccinfo.hh:465
Abstract class for states.
Definition: twa.hh:49
Zielonka Tree implementation.
Definition: zlktree.hh:110
std::vector< zielonka_node > nodes_
All nodes of the Zielonka tree.
Definition: zlktree.hh:228
bool has_rabin_shape() const
Whether the Zielonka tree has Rabin shape.
Definition: zlktree.hh:192
bool has_parity_shape() const
Whether the Zielonka tree has parity shape.
Definition: zlktree.hh:209
bool has_streett_shape() const
Whether the Zielonka tree has Streett shape.
Definition: zlktree.hh:201
std::pair< unsigned, unsigned > step(unsigned branch, acc_cond::mark_t colors) const
Walk through the Zielonka tree.
zielonka_tree(const acc_cond &cond, zielonka_tree_options opt=zielonka_tree_options::NONE)
Build a Zielonka tree from the acceptance condition.
bool is_even() const
Whether the tree corresponds to a min even parity acceptance.
Definition: zlktree.hh:171
void dot(std::ostream &) const
Render the tree as in GraphViz format.
unsigned first_branch() const
The number of one branch in the tree.
Definition: zlktree.hh:128
bool empty_layer_is_even() const
Whether the layer corresponding to {} is even.
Definition: zlktree.hh:183
unsigned num_branches() const
The number of branches in the Zielonka tree.
Definition: zlktree.hh:120
zielonka_tree_options
Options to alter the behavior of acd.
Definition: zlktree.hh:33
acd_options
Options to alter the behavior of acd.
Definition: zlktree.hh:256
twa_graph_ptr zielonka_tree_transform(const const_twa_graph_ptr &aut)
Paritize an automaton using Zielonka tree.
twa_graph_ptr acd_transform(const const_twa_graph_ptr &aut, bool colored=false)
Paritize an automaton using ACD.
twa_graph_ptr acd_transform_sbacc(const const_twa_graph_ptr &aut, bool colored=false, bool order_heuristic=true)
Paritize an automaton using ACD.
@ NONE
Build the ZlkTree, without checking its shape.
@ CHECK_STREETT
Check if the ACD has Streett shape.
@ CHECK_RABIN
Check if the ACD has Rabin shape.
@ CHECK_PARITY
Check if the ACD has Parity shape.
@ NONE
Build the ACD, without checking its shape.
scc_info_options operator&(scc_info_options left, scc_info_options right)
Bitwise AND of two scc_info_options values.
Definition: sccinfo.hh:427
bool operator!(scc_info_options me)
Test if an scc_info_options value equals NONE.
Definition: sccinfo.hh:419
std::shared_ptr< twa_graph > twa_graph_ptr
Shared pointer to a mutable twa_graph.
Definition: fwd.hh:44
std::shared_ptr< const twa_graph > const_twa_graph_ptr
Shared pointer to a const twa_graph.
Definition: fwd.hh:38
Definition: automata.hh:26
zielonka_tree_options operator-(zielonka_tree_options left, zielonka_tree_options right)
Remove options from a zielonka_tree_options set (bitwise AND NOT).
Definition: zlktree.hh:92
const mc_rvalue operator|(const mc_rvalue &lhs, const mc_rvalue &rhs)
This function helps to find the output value from a set of threads that may have different values.
Definition: mc.hh:140
An acceptance mark.
Definition: acc.hh:76
A node in the Zielonka tree, storing parent, sibling, child links, level, and color set.
Definition: zlktree.hh:220
unsigned level
Depth level of this node in the tree.
Definition: zlktree.hh:224
acc_cond::mark_t colors
Set of colors associated with this node.
Definition: zlktree.hh:225
unsigned parent
Index of parent node (0 for root).
Definition: zlktree.hh:221

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