spot 2.16
Loading...
Searching...
No Matches
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
27namespace spot
28{
29
33 class SPOT_API backprop_graph final
34 {
35 static constexpr unsigned target = (1U << (sizeof(unsigned)*8 - 4)) - 1;
36
37 struct backprop_state
38 {
39 int counter; // number of unknown successors
40 bool owner:1;
41 bool frozen:1;
42 bool determined:1;
43 bool winner:1; // meaningful only if determined is true
44 unsigned choice: sizeof(unsigned)*8 - 4;
45
46 backprop_state(bool owner)
47 : counter(0),
48 owner(owner),
49 frozen(false),
50 determined(false),
51 winner(false),
52 choice(0)
53 {
54 }
55 };
56 public:
58 backprop_graph(bool stop_asap = true)
59 : stop_asap_(stop_asap)
60 {
61 }
62
64 int new_state(bool owner)
65 {
66 return reverse_.new_state(owner);
67 }
68
70 void set_name(unsigned state, const std::string& s)
71 {
72 names_.emplace(state, s);
73 }
74
76 bool new_edge(unsigned src, unsigned dst);
77
83 bool freeze_state(unsigned state);
84
90 bool is_frozen(unsigned state) const
91 {
92 return (*this)[state].frozen;
93 }
94
96 bool is_determined(unsigned state) const
97 {
98 return (*this)[state].determined;
99 }
100
102 bool winner(unsigned state) const
103 {
104 return (*this)[state].winner;
105 }
106
108 unsigned choice(unsigned state) const
109 {
110 return (*this)[state].choice;
111 }
112
114 bool set_winner(unsigned state, bool winner)
115 {
116 return set_winner(state, winner, target);
117 }
118
120 std::ostream& print_dot(std::ostream& os) const;
121
123 unsigned num_edges() const
124 {
125 return reverse_.num_edges();
126 }
127
128 private:
129 bool set_winner(unsigned state, bool winner, unsigned choice_state);
130
132 bool stop_asap_;
133 std::unordered_map<unsigned, std::string> names_;
134
135 const backprop_state& operator[](unsigned state) const
136 {
137 return reverse_.state_data(state);
138 }
139
140 backprop_state& operator[](unsigned state)
141 {
142 return reverse_.state_data(state);
143 }
144 };
145
146
147}
A compact adjacency list representation for directed graphs.
Definition adjlist.hh:41
internal::boxed_label< State_Data >::data_t & state_data(unsigned s)
Return the state data for state s.
Definition adjlist.hh:114
Graph used for backward propagation of winning conditions in parity games.
Definition backprop.hh:34
unsigned num_edges() const
Return the number of edges.
Definition backprop.hh:123
bool is_frozen(unsigned state) const
Check if a state is frozen.
Definition backprop.hh:90
bool winner(unsigned state) const
Return the winner of a state (true = Player 0).
Definition backprop.hh:102
void set_name(unsigned state, const std::string &s)
Set the name of the given state.
Definition backprop.hh:70
bool is_determined(unsigned state) const
Check if the winner of a state has been determined.
Definition backprop.hh:96
backprop_graph(bool stop_asap=true)
Construct the backpropagation graph.
Definition backprop.hh:58
unsigned choice(unsigned state) const
Return the chosen successor for a state.
Definition backprop.hh:108
bool new_edge(unsigned src, unsigned dst)
Add an edge from src to dst.
int new_state(bool owner)
Add a new state; owner is true if owned by Player 1.
Definition backprop.hh:64
bool set_winner(unsigned state, bool winner)
Set the winner of a state.
Definition backprop.hh:114
std::ostream & print_dot(std::ostream &os) const
Print the graph in dot format.
bool freeze_state(unsigned state)
Mark a state as frozen (no more incoming edges).
Abstract class for states.
Definition twa.hh:49
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.8