Awali
Another Weighted Automata library
partition_automaton.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_CORE_PARTITION_AUTOMATON_HH
18 # define AWALI_CORE_PARTITION_AUTOMATON_HH
19 
20 # include <map>
21 # include <set>
22 # include <vector>
23 
25 
26 namespace awali { namespace sttc {
27 
28 
29  namespace internal
30  {
31  template <typename Aut>
33  : public automaton_decorator<typename Aut::element_type::automaton_nocv_t>
34  {
35  public:
36  using automaton_t = Aut;
37  using automaton_nocv_t = typename automaton_t::element_type::automaton_nocv_t;
41 
43  using state_set_t = std::set<state_t>;
44 
45  private:
47  using origins_t = std::map<state_t, state_set_t>;
48  origins_t origins_;
49 
50  const automaton_t input_;
51 
52  public:
54  : super_t(input->context())
55  , input_(input)
56  {}
57 
58  // FIXME: do we want this, or should we leave it to the
59  // underlying automaton, as super_t does? Or is this always
60  // subclassed anyway?
61  static std::string sname()
62  {
63  return "partition_automaton<" + automaton_t::element_type::sname() + ">";
64  }
65 
66  std::string vname(bool full = true) const
67  {
68  return "partition_automaton<" + input_->vname(full) + ">";
69  }
70 
71  std::ostream&
72  print_state_name(state_t s, std::ostream& o,
73  const std::string& fmt = "text") const
74  {
75  const auto& set = origins_.at(s);
76  const char* separator = "{";
77  for (auto s : set)
78  {
79  o << separator;
80  input_->print_state_name(s, o, fmt);
81  separator = ", ";
82  }
83  return o << "}";
84  }
85 
89  state_t
90  add_state(const state_set_t& set)
91  {
92  state_t res = add_state();
93  origins_[res] = set;
94  return res;
95  }
96 
97  state_t
98  add_state(const std::vector<state_t>& v)
99  {
100  state_set_t set;
101  for (auto s: v)
102  set.emplace(s);
103  return add_state(std::move(set));
104  }
105 
106  state_t
108  {
109  return super_t::add_state();
110  }
111  }; // class
112  } // namespace internal
113 
115  template <typename Aut>
117  = std::shared_ptr<internal::partition_automaton_impl<Aut>>;
118 
119 }}//end of ns awali::stc
120 
121 #endif // !AWALI_CORE_PARTITION_AUTOMATON_HH
carries the algebraic settings of automata
Definition: context.hh:40
Aggregate an automaton, and forward calls to it.
Definition: automaton_decorator.hh:36
auto add_state(Args &&... args) -> decltype(aut_-> add_state(std::forward< Args >(args)...))
Definition: automaton_decorator.hh:187
Definition: partition_automaton.hh:34
label_t_of< automaton_t > label_t
Definition: partition_automaton.hh:39
typename automaton_t::element_type::automaton_nocv_t automaton_nocv_t
Definition: partition_automaton.hh:37
context_t_of< automaton_t > context_t
Definition: partition_automaton.hh:38
static std::string sname()
Definition: partition_automaton.hh:61
Aut automaton_t
Definition: partition_automaton.hh:36
state_t add_state(const std::vector< state_t > &v)
Definition: partition_automaton.hh:98
std::ostream & print_state_name(state_t s, std::ostream &o, const std::string &fmt="text") const
Definition: partition_automaton.hh:72
std::set< state_t > state_set_t
A set of the original automaton states.
Definition: partition_automaton.hh:43
state_t add_state()
Definition: partition_automaton.hh:107
partition_automaton_impl(const automaton_t &input)
Definition: partition_automaton.hh:53
state_t add_state(const state_set_t &set)
Make a new state representing the given input state set, which is required to be new – no error-check...
Definition: partition_automaton.hh:90
std::string vname(bool full=true) const
Definition: partition_automaton.hh:66
typename internal::label_t_of_impl< internal::base_t< ValueSet > >::type label_t_of
Helper to retrieve the type of the labels of a value set.
Definition: traits.hh:71
typename internal::context_t_of_impl< internal::base_t< ValueSet > >::type context_t_of
Helper to retrieve the type of the context of a value set.
Definition: traits.hh:66
std::shared_ptr< internal::partition_automaton_impl< Aut > > partition_automaton
A subset automaton as a shared pointer.
Definition: partition_automaton.hh:117
static const std::string full
Completely version of Awali as a std::string.
Definition: version.hh:42
Main namespace of Awali.
Definition: ato.hh:22
unsigned state_t
Definition: types.hh:21