21 #include <spot/twa/twagraph.hh>
53 template<
typename Trans>
56 Trans trans,
unsigned int init,
57 bool drop_univ_branches =
false)
59 std::vector<unsigned> todo;
60 std::vector<unsigned> seen(old->num_states(), -1U);
62 auto orig_states =
new std::vector<unsigned>();
63 orig_states->reserve(old->num_states());
64 cpy->set_named_prop(
"original-states", orig_states);
67 [&](
unsigned old_state) ->
unsigned
69 unsigned tmp = seen[old_state];
72 tmp = cpy->new_state();
73 seen[old_state] = tmp;
74 orig_states->emplace_back(old_state);
75 todo.emplace_back(old_state);
81 std::map<std::vector<unsigned>,
unsigned> uniq;
83 [&](
unsigned old_state) ->
unsigned
85 if (!old->is_univ_dest(old_state))
86 return new_state(old_state);
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);
96 cpy->get_graph().new_univ_dests(tmp.begin(), tmp.end());
97 return p.first->second;
100 cpy->set_init_state(new_univ_state(init));
102 throw std::runtime_error
103 (
"the destination automaton of transform_accessible() should be empty");
105 while (!todo.empty())
107 unsigned old_src = todo.back();
110 unsigned new_src = seen[old_src];
111 SPOT_ASSERT(new_src != -1U);
113 for (
auto& t: old->out(old_src))
117 trans(t.src, cond, acc, t.dst);
118 if (cond == bddfalse)
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);
124 cpy->new_edge(new_src, new_univ_state(t.dst), cond, acc);
127 orig_states->shrink_to_fit();
148 template<
typename Trans>
151 Trans trans,
unsigned int init)
153 if (!old->is_existential())
154 throw std::runtime_error
155 (
"transform_copy() does not support alternation");
158 cpy->new_states(old->num_states());
159 cpy->set_init_state(init);
161 for (
auto& t: old->edges())
165 trans(t.src, cond, acc, t.dst);
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);
179 template<
typename Trans>
192 template<
typename Trans>
219 std::vector<bool>& to_keep,
236 std::vector<bool>& to_keep,
238 bool drop_univ_branches =
false);
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:38
Definition: automata.hh:26
An acceptance mark.
Definition: acc.hh:76