21#include <spot/twa/twagraph.hh>
50 template<
typename Trans>
53 Trans trans,
unsigned int init,
54 bool drop_univ_branches =
false)
56 std::vector<unsigned> todo;
57 std::vector<unsigned> seen(old->num_states(), -1U);
59 auto orig_states =
new std::vector<unsigned>();
60 orig_states->reserve(old->num_states());
61 cpy->set_named_prop(
"original-states", orig_states);
64 [&](
unsigned old_state) ->
unsigned
66 unsigned tmp = seen[old_state];
69 tmp = cpy->new_state();
70 seen[old_state] = tmp;
71 orig_states->emplace_back(old_state);
72 todo.emplace_back(old_state);
78 std::map<std::vector<unsigned>,
unsigned> uniq;
80 [&](
unsigned old_state) ->
unsigned
82 if (!old->is_univ_dest(old_state))
83 return new_state(old_state);
85 std::vector<unsigned> tmp;
86 for (
auto s: old->univ_dests(old_state))
87 tmp.emplace_back(new_state(s));
88 std::sort(tmp.begin(), tmp.end());
89 tmp.erase(std::unique(tmp.begin(), tmp.end()), tmp.end());
90 auto p = uniq.emplace(tmp, 0);
93 cpy->get_graph().new_univ_dests(tmp.begin(), tmp.end());
94 return p.first->second;
97 cpy->set_init_state(new_univ_state(init));
99 throw std::runtime_error
100 (
"the destination automaton of transform_accessible() should be empty");
102 while (!todo.empty())
104 unsigned old_src = todo.back();
107 unsigned new_src = seen[old_src];
108 SPOT_ASSERT(new_src != -1U);
110 for (
auto& t: old->out(old_src))
114 trans(t.src, cond, acc, t.dst);
115 if (cond == bddfalse)
117 if (drop_univ_branches)
118 for (
unsigned d: old->univ_dests(t.dst))
119 cpy->new_edge(new_src, new_state(d), cond, acc);
121 cpy->new_edge(new_src, new_univ_state(t.dst), cond, acc);
124 orig_states->shrink_to_fit();
141 template<
typename Trans>
144 Trans trans,
unsigned int init)
146 if (!old->is_existential())
147 throw std::runtime_error
148 (
"transform_copy() does not support alternation");
151 cpy->new_states(old->num_states());
152 cpy->set_init_state(init);
154 for (
auto& t: old->edges())
158 trans(t.src, cond, acc, t.dst);
161 SPOT_ASSERT(t.src < cpy->num_states() && t.dst < cpy->num_states());
162 if (cond != bddfalse)
163 cpy->new_edge(t.src, t.dst, cond, acc);
167 template<
typename Trans>
175 template<
typename Trans>
200 std::vector<bool>& to_keep,
216 std::vector<bool>& to_keep,
218 bool drop_univ_branches =
false);
Definition: automata.hh:26
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:51
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:142
An acceptance mark.
Definition: acc.hh:84