spot 2.16
Loading...
Searching...
No Matches
mask.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 <spot/twa/twagraph.hh>
22
23namespace spot
24{
53 template<typename Trans>
55 twa_graph_ptr& cpy,
56 Trans trans, unsigned int init,
57 bool drop_univ_branches = false)
58 {
59 std::vector<unsigned> todo;
60 std::vector<unsigned> seen(old->num_states(), -1U);
61
62 auto orig_states = new std::vector<unsigned>();
63 orig_states->reserve(old->num_states()); // maybe less are needed.
64 cpy->set_named_prop("original-states", orig_states);
65
66 auto new_state =
67 [&](unsigned old_state) -> unsigned
68 {
69 unsigned tmp = seen[old_state];
70 if (tmp == -1U)
71 {
72 tmp = cpy->new_state();
73 seen[old_state] = tmp;
74 orig_states->emplace_back(old_state);
75 todo.emplace_back(old_state);
76 }
77 return tmp;
78 };
79
80 // Deal with alternating automata, possibly.
81 std::map<std::vector<unsigned>, unsigned> uniq;
82 auto new_univ_state =
83 [&](unsigned old_state) -> unsigned
84 {
85 if (!old->is_univ_dest(old_state))
86 return new_state(old_state);
87
88 std::vector<unsigned> tmp;
89 for (auto s: old->univ_dests(old_state))
90 tmp.emplace_back(new_state(s));
91 std::sort(tmp.begin(), tmp.end());
92 tmp.erase(std::unique(tmp.begin(), tmp.end()), tmp.end());
93 auto p = uniq.emplace(tmp, 0);
94 if (p.second)
95 p.first->second =
96 cpy->get_graph().new_univ_dests(tmp.begin(), tmp.end());
97 return p.first->second;
98 };
99
100 cpy->set_init_state(new_univ_state(init));
101 if (seen[init] != 0)
102 throw std::runtime_error
103 ("the destination automaton of transform_accessible() should be empty");
104
105 while (!todo.empty())
106 {
107 unsigned old_src = todo.back();
108 todo.pop_back();
109
110 unsigned new_src = seen[old_src];
111 SPOT_ASSERT(new_src != -1U);
112
113 for (auto& t: old->out(old_src))
114 {
115 bdd cond = t.cond;
116 acc_cond::mark_t acc = t.acc;
117 trans(t.src, cond, acc, t.dst);
118 if (cond == bddfalse)
119 continue;
120 if (drop_univ_branches)
121 for (unsigned d: old->univ_dests(t.dst))
122 cpy->new_edge(new_src, new_state(d), cond, acc);
123 else
124 cpy->new_edge(new_src, new_univ_state(t.dst), cond, acc);
125 }
126 }
127 orig_states->shrink_to_fit();
128 }
129
148 template<typename Trans>
150 twa_graph_ptr& cpy,
151 Trans trans, unsigned int init)
152 {
153 if (!old->is_existential())
154 throw std::runtime_error
155 ("transform_copy() does not support alternation");
156
157 // Each state in cpy corresponds to a unique state in old.
158 cpy->new_states(old->num_states());
159 cpy->set_init_state(init);
160
161 for (auto& t: old->edges())
162 {
163 bdd cond = t.cond;
164 acc_cond::mark_t acc = t.acc;
165 trans(t.src, cond, acc, t.dst);
166 // Having the same number of states should assure that state ids are
167 // equivalent in old and cpy.
168 SPOT_ASSERT(t.src < cpy->num_states() && t.dst < cpy->num_states());
169 if (cond != bddfalse)
170 cpy->new_edge(t.src, t.dst, cond, acc);
171 }
172 }
173
179 template<typename Trans>
181 twa_graph_ptr& cpy,
182 Trans trans)
183 {
184 transform_accessible(old, cpy, trans, old->get_init_state_number());
185 }
186
192 template<typename Trans>
194 twa_graph_ptr& cpy,
195 Trans trans)
196 {
197 transform_copy(old, cpy, trans, old->get_init_state_number());
198 }
199
202 SPOT_API
204 acc_cond::mark_t to_remove);
205
217 SPOT_API
219 std::vector<bool>& to_keep,
220 unsigned int init);
221
234 SPOT_API
236 std::vector<bool>& to_keep,
237 unsigned int init,
238 bool drop_univ_branches = false);
239}
twa_graph_ptr mask_acc_sets(const const_twa_graph_ptr &in, acc_cond::mark_t to_remove)
Remove all edges that belong to some given acceptance sets.
twa_graph_ptr mask_keep_accessible_states(const const_twa_graph_ptr &in, std::vector< bool > &to_keep, unsigned int init, bool drop_univ_branches=false)
Keep only the states specified by to_keep that are accessible.
void transform_accessible(const const_twa_graph_ptr &old, twa_graph_ptr &cpy, Trans trans, unsigned int init, bool drop_univ_branches=false)
Clone and mask an automaton.
Definition mask.hh:54
twa_graph_ptr mask_keep_states(const const_twa_graph_ptr &in, std::vector< bool > &to_keep, unsigned int init)
Keep only the states as specified by to_keep.
void transform_copy(const const_twa_graph_ptr &old, twa_graph_ptr &cpy, Trans trans, unsigned int init)
Copy an automaton and update each edge.
Definition mask.hh:149
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:41
Definition automata.hh:26
An acceptance mark.
Definition acc.hh:76

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