spot  2.14.5
backprop.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 <unordered_map>
23 #include <spot/misc/common.hh>
24 #include <spot/misc/trival.hh>
25 #include <spot/graph/adjlist.hh>
26 
27 namespace spot
28 {
29 
30  class SPOT_API backprop_graph final
31  {
32  static constexpr unsigned target = (1U << (sizeof(unsigned)*8 - 4)) - 1;
33 
34  struct backprop_state
35  {
36  int counter; // number of unknown successors
37  bool owner:1;
38  bool frozen:1;
39  bool determined:1;
40  bool winner:1; // meaningful only if determined is true
41  unsigned choice: sizeof(unsigned)*8 - 4;
42 
43  backprop_state(bool owner)
44  : counter(0),
45  owner(owner),
46  frozen(false),
47  determined(false),
48  winner(false),
49  choice(0)
50  {
51  }
52  };
53  public:
54  backprop_graph(bool stop_asap = true)
55  : stop_asap_(stop_asap)
56  {
57  }
58 
59  int new_state(bool owner)
60  {
61  return reverse_.new_state(owner);
62  }
63 
64  void set_name(unsigned state, const std::string& s)
65  {
66  names_.emplace(state, s);
67  }
68 
69  // return true if the status of src is now known
70  bool new_edge(unsigned src, unsigned dst);
71 
72  // call once the successors of a state have all been declared to
73  // see if the status of that state can be determined already
74  bool freeze_state(unsigned state);
75 
76  bool is_frozen(unsigned state) const
77  {
78  return (*this)[state].frozen;
79  }
80 
81  bool is_determined(unsigned state) const
82  {
83  return (*this)[state].determined;
84  }
85 
86  bool winner(unsigned state) const
87  {
88  return (*this)[state].winner;
89  }
90 
91  unsigned choice(unsigned state) const
92  {
93  return (*this)[state].choice;
94  }
95 
96  bool set_winner(unsigned state, bool winner)
97  {
98  return set_winner(state, winner, target);
99  }
100 
101  std::ostream& print_dot(std::ostream& os) const;
102 
103  unsigned num_edges() const
104  {
105  return reverse_.num_edges();
106  }
107 
108  private:
109  bool set_winner(unsigned state, bool winner, unsigned choice_state);
110 
111  adjlist<backprop_state> reverse_;
112  bool stop_asap_;
113  std::unordered_map<unsigned, std::string> names_;
114 
115  const backprop_state& operator[](unsigned state) const
116  {
117  return reverse_.state_data(state);
118  }
119 
120  backprop_state& operator[](unsigned state)
121  {
122  return reverse_.state_data(state);
123  }
124  };
125 
126 
127 }
Definition: backprop.hh:31
Abstract class for states.
Definition: twa.hh:47
Definition: automata.hh:26

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