1 #ifndef VCSN_ALGOS_SCC_HH
2 # define VCSN_ALGOS_SCC_HH
23 template <
typename Aut>
27 template <
typename Aut>
32 template <
typename Aut>
42 for (
auto s : aut->states())
60 for (
auto t : aut->out(s))
62 auto dst = aut->dst_of(t);
83 low_[w] = aut->num_states() + 1;
98 std::unordered_map<state_t, std::size_t>
low_;
113 template <
typename Aut>
121 for (
auto s : aut->all_states())
135 for (
auto t : aut->out(s))
137 auto dst = aut->dst_of(t);
150 template <
typename Aut>
151 std::stack<state_t_of<Aut>>
167 template <
typename Aut>
179 while (!todo.empty())
205 for (
auto t : aut->out(s))
207 auto dst = aut->dst_of(t);
227 template <
typename Aut>
228 const detail::components_t<Aut>
248 template <
typename Aut>
249 typename Aut::element_type::automaton_nocv_t
252 using res_t =
typename Aut::element_type::automaton_nocv_t;
253 res_t res = make_shared_ptr<res_t>(aut->context());
255 auto s0 = *com.begin();
256 map[s0] = res->new_state();
257 res->set_initial(map[s0]);
261 map[s] = res->new_state();
262 for (
auto t : aut->out(s))
264 auto dst = aut->dst_of(t);
268 map[dst] = res->new_state();
269 res->new_transition(map[s], map[dst], aut->label_of(t));
277 template <
typename Aut>
280 return scc(aut).size();
288 template <
typename Aut>
291 const auto& a = aut->as<Aut>();
301 #endif // !VCSN_ALGOS_SCC_HH
void dfs(state_t s, const Aut &aut)
std::size_t num_sccs(const automaton &aut)
REGISTER_DECLARE(accessible,(const automaton &) -> automaton)
std::shared_ptr< detail::automaton_base > automaton
std::size_t curr_comp_num_
The current component number.
std::stack< state_t > stack_
Contains list vertices same the component.
Aut::element_type::automaton_nocv_t aut_of_component(const detail::component_t< Aut > &com, const Aut &aut)
Generate a subautomaton corresponding to an SCC.
void dfs(state_t s, const Aut &aut)
std::stack< state_t > & reverse_post()
detail::component_t< Aut > component_t
std::size_t num_
The current component number.
std::stack< state_t_of< Aut > > reverse_postorder(const Aut &aut)
Get all vertices in reverse postorder.
detail::components_t< Aut > components_t
std::size_t num_sccs(const Aut &aut)
Get number of strongly connected components.
Use Tarjan's algorithm to find all strongly connected components.
std::set< state_t_of< Aut >> component_t
An strongly-connected component: list of states.
std::set< state_t > marked_
void dfs(state_t s, const Aut &aut)
reverse_postorder_impl(const Aut &aut)
std::unordered_map< state_t, std::size_t > low_
low_[s] is minimum of vertex that it can go
std::stack< state_t > rvp_
std::set< state_t > marked_
List visited vertices.
scc_kosaraju_impl(const Aut &aut)
state_t_of< Aut > state_t
auto map(const std::tuple< Ts...> &ts, Fun f) -> decltype(map_tuple_(f, ts, make_index_sequence< sizeof...(Ts)>()))
Map a function on a tuple, return tuple of the results.
const components_t components()
detail::component_t< Aut > component_t
detail::components_t< Aut > components_t
std::stack< state_t > todo_
const detail::components_t< Aut > scc(const Aut &aut, SCC_ALGO algo=SCC_ALGO::TARJAN)
Find all strongly connected components of aut.
Use Kosajaju algorithm for finding all of strongly connected components.
Get all vertices in reverse postorder by using depth first search.
components_t components_
All compnents.
Aut transpose(const transpose_automaton< Aut > &aut)
state_t_of< Aut > state_t
std::size_t curr_vertex_num_
The current visited vertex.
state_t_of< Aut > state_t
typename detail::state_t_of_impl< base_t< ValueSet >>::type state_t_of
std::set< state_t > marked_
const components_t components()
#define BUILTIN_UNREACHABLE()
scc_tarjan_impl(const Aut &aut)
std::vector< component_t< Aut >> components_t
A set of strongly-connected components.
bool has(const std::map< Key, Value, Compare, Alloc > &s, const Key &e)