17 #ifndef AWALI_ALGOS_HAS_TWINS_PROPERTY_HH
18 # define AWALI_ALGOS_HAS_TWINS_PROPERTY_HH
22 # include <unordered_set>
23 # include <unordered_map>
31 namespace awali {
namespace sttc {
38 template <
typename Aut>
42 const auto& ws = *aut->weightset();
43 for (
auto t : aut->all_transitions())
44 aut->set_weight(t, ws.rdiv(ws.one(), aut->weight_of(t)));
48 template <
typename Aut>
66 template <
typename Aut>
73 for (
auto s : aut->all_states())
84 void dfs(
state_t s,
const Aut& aut)
87 for (
auto t : aut->out(s))
89 auto dst = aut->dst_of(t);
90 if (!
has(marked_, dst))
95 std::stack<state_t> rvp_;
96 std::unordered_set<state_t> marked_;
97 std::stack<state_t> todo_;
103 template <
typename Aut>
119 template <
typename Aut>
130 while (!todo.empty())
134 if (!
has(marked_, s))
148 void dfs(
state_t s,
const Aut& aut)
151 if (num_ == components_.size())
154 components_[num_].emplace(s);
156 for (
auto t : aut->out(s))
158 auto dst = aut->dst_of(t);
159 if (!
has(marked_, dst))
167 std::unordered_set<state_t> marked_;
173 template <
typename Aut>
174 const std::vector<std::unordered_set<state_t>>
190 template <
typename Aut>
203 std::unordered_map<state_t, weight_t> wm;
204 const auto& ws = *aut->weightset();
205 auto s0 = *component.begin();
208 for (
auto t : transitions_by_dfs_(component, aut))
210 auto src = aut->src_of(t);
211 auto dst = aut->dst_of(t);
213 wm.emplace(dst, ws.mul(wm[src], aut->weight_of(t)));
214 if (!ws.equals(wm[dst], ws.mul(wm[src], aut->weight_of(t))))
221 using transitions_t = std::vector<transition_t>;
228 std::set<transition_t> marked;
229 std::stack<transition_t> todo;
231 auto s0 = *component.begin();
232 for (
auto t : aut->out(s0))
234 if (
has(component, aut->dst_of(t)))
241 while (!todo.empty())
247 for (
auto f : aut->out(aut->dst_of(e)))
248 if (
has(component, aut->dst_of(f))
261 template <
typename Aut>
275 template <
typename Aut>
The semiring of complex numbers.
Definition: c.hh:44
Whether the weight of beetween two states on component, it is always unique.
Definition: has_twins_property.hh:192
bool check(const component_t &component, const Aut &aut)
Definition: has_twins_property.hh:201
weight_t_of< Aut > weight_t
Definition: has_twins_property.hh:194
std::unordered_set< state_t > component_t
Definition: has_twins_property.hh:195
cycle_identity_impl()
Definition: has_twins_property.hh:197
Get all vertexs in reverse postorder by using depth first search.
Definition: has_twins_property.hh:68
std::stack< state_t > & reverse_post()
Definition: has_twins_property.hh:78
reverse_postorder_impl(const Aut &aut)
Definition: has_twins_property.hh:71
Use Kosajaju algorithm for finding all of strongly connected components.
Definition: has_twins_property.hh:121
scc_kosaraju(const Aut &aut)
Definition: has_twins_property.hh:126
const components_t components()
Definition: has_twins_property.hh:142
std::vector< component_t > components_t
Definition: has_twins_property.hh:124
std::unordered_set< state_t > component_t
Definition: has_twins_property.hh:123
bool has(const std::map< Key, Value, Compare, Alloc > &s, const Key &e)
Definition: map.hh:53
const std::vector< std::unordered_set< state_t > > components(const Aut &aut)
Find all strongly connected components of aut.
Definition: has_twins_property.hh:175
auto inverse(const Aut &aut) -> decltype(::sttc::copy(aut))
Definition: has_twins_property.hh:50
auto product(const Lhs &lhs, const Rhs &rhs, bool keep_history=true) -> decltype(join_automata(lhs, rhs))
Definition: product.hh:394
typename internal::weight_t_of_impl< internal::base_t< ValueSet > >::type weight_t_of
Helper to retrieve the type of the weights of a value set.
Definition: traits.hh:81
Aut::element_type::automaton_nocv_t trim(const Aut &aut, bool keep_history=true)
Trim subautomaton.
Definition: accessible.hh:278
AutOut transpose(Aut &aut, bool keep_history=true)
Definition: transpose.hh:79
AutOut copy(const AutIn &input, Pred keep_state, bool keep_history=true, bool transpose=false)
A copy of input keeping only its states that are accepted by keep_state.
Definition: copy.hh:189
bool cycle_identity(const std::unordered_set< state_t > &c, const Aut &aut)
Check the weight of two states on this component is unique.
Definition: has_twins_property.hh:262
bool has_twins_property(const Aut &aut)
Whether aut has the twins property.
Definition: has_twins_property.hh:276
Aut & inverse_here(Aut &aut)
Inverse the weight of all edges of aut.
Definition: has_twins_property.hh:40
std::stack< state_t > reverse_postorder(const Aut &aut)
Get all vertices in reverse postorder.
Definition: has_twins_property.hh:105
Main namespace of Awali.
Definition: ato.hh:22
unsigned state_t
Definition: types.hh:21