Awali
Another Weighted Automata library
is_ambiguous.hh
Go to the documentation of this file.
1 // This file is part of Awali.
2 // Copyright 2016-2022 Sylvain Lombardy, Victor Marsault, Jacques Sakarovitch
3 //
4 // Awali is a free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 #ifndef AWALI_ALGOS_IS_AMBIGUOUS_HH
18 # define AWALI_ALGOS_IS_AMBIGUOUS_HH
19 
23 
24 namespace awali { namespace sttc {
25 
26  template <typename Aut>
27  bool is_ambiguous(const Aut& aut)
28  {
29  auto prod = product(aut, aut);
30  // Check if there useful states outside of the diagonal. Since
31  // the product is accessible, check only for coaccessibles states.
32  auto coaccessible = coaccessible_states(prod);
33  for (const auto& o: dynamic_cast<tuple_history<std::tuple<Aut,Aut>>*>(prod->history().get())->origins())
34  if (std::get<0>(o.second) != std::get<1>(o.second)
35  && coaccessible.find(o.first)!=coaccessible.end())
36  {
37  if (getenv("AWALI_DEBUG"))
38  std::cerr << "ambiguous: " << o.first - 2
39  << " (" << std::get<0>(o.second) - 2
40  << ", " << std::get<1>(o.second) - 2 << ")"
41  << std::endl;
42  return true;
43  }
44  return false;
45  }
46 
47 }}//end of ns awali::stc
48 
49 #endif // !AWALI_ALGOS_IS_AMBIGUOUS_HH
An automaton whose states are tuples of states of automata.
Definition: tuple_history.hh:49
const origins_t & origins() const
Definition: tuple_history.hh:85
auto product(const Lhs &lhs, const Rhs &rhs, bool keep_history=true) -> decltype(join_automata(lhs, rhs))
Definition: product.hh:394
std::set< state_t > coaccessible_states(const Aut &aut, bool include_pre_post=false)
List of coaccessible states.
Definition: accessible.hh:113
bool is_ambiguous(const Aut &aut)
Definition: is_ambiguous.hh:27
Aut::element_type::automaton_nocv_t coaccessible(const Aut &aut, bool keep_history=true)
Coaccessible subautomaton.
Definition: accessible.hh:245
Main namespace of Awali.
Definition: ato.hh:22