22 #include <spot/twa/twagraph.hh>
51 template<
typename Trans>
54 Trans trans,
unsigned int init,
55 bool drop_univ_branches =
false)
57 std::vector<unsigned> todo;
58 std::vector<unsigned> seen(old->num_states(), -1U);
60 auto orig_states =
new std::vector<unsigned>();
61 orig_states->reserve(old->num_states());
62 cpy->set_named_prop(
"original-states", orig_states);
65 [&](
unsigned old_state) ->
unsigned
67 unsigned tmp = seen[old_state];
70 tmp = cpy->new_state();
71 seen[old_state] = tmp;
72 orig_states->emplace_back(old_state);
73 todo.emplace_back(old_state);
79 std::map<std::vector<unsigned>,
unsigned> uniq;
81 [&](
unsigned old_state) ->
unsigned
83 if (!old->is_univ_dest(old_state))
84 return new_state(old_state);
86 std::vector<unsigned> tmp;
87 for (
auto s: old->univ_dests(old_state))
88 tmp.emplace_back(new_state(s));
89 std::sort(tmp.begin(), tmp.end());
90 tmp.erase(std::unique(tmp.begin(), tmp.end()), tmp.end());
91 auto p = uniq.emplace(tmp, 0);
94 cpy->get_graph().new_univ_dests(tmp.begin(), tmp.end());
95 return p.first->second;
98 cpy->set_init_state(new_univ_state(init));
100 throw std::runtime_error
101 (
"the destination automaton of transform_accessible() should be empty");
103 while (!todo.empty())
105 unsigned old_src = todo.back();
108 unsigned new_src = seen[old_src];
109 SPOT_ASSERT(new_src != -1U);
111 for (
auto& t: old->out(old_src))
115 trans(t.src, cond, acc, t.dst);
116 if (cond == bddfalse)
118 if (drop_univ_branches)
119 for (
unsigned d: old->univ_dests(t.dst))
120 cpy->new_edge(new_src, new_state(d), cond, acc);
122 cpy->new_edge(new_src, new_univ_state(t.dst), cond, acc);
125 orig_states->shrink_to_fit();
142 template<
typename Trans>
145 Trans trans,
unsigned int init)
147 if (!old->is_existential())
148 throw std::runtime_error
149 (
"transform_copy() does not support alternation");
152 cpy->new_states(old->num_states());
153 cpy->set_init_state(init);
155 for (
auto& t: old->edges())
159 trans(t.src, cond, acc, t.dst);
162 SPOT_ASSERT(t.src < cpy->num_states() && t.dst < cpy->num_states());
163 if (cond != bddfalse)
164 cpy->new_edge(t.src, t.dst, cond, acc);
168 template<
typename Trans>
176 template<
typename Trans>
201 std::vector<bool>& to_keep,
217 std::vector<bool>& to_keep,
219 bool drop_univ_branches =
false);
Definition: automata.hh:27
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:52
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:143
An acceptance mark.
Definition: acc.hh:85