17 #ifndef AWALI_ALGOS_MERGE_HH
18 # define AWALI_ALGOS_MERGE_HH
21 # include <unordered_map>
22 # include <unordered_set>
35 template <
typename Aut,
typename StateList>
50 : class_to_set_(class_to_set)
51 , num_classes_(class_to_set_.size())
52 , keep_history_(keep_history)
59 for (
unsigned c = 0;
c < num_classes_; ++
c)
60 for (
auto s: class_to_set_[
c])
61 state_to_class[s] =
c;
63 automaton_t res = make_shared_ptr<automaton_t>(aut->context());
64 class_to_res_state_.resize(num_classes_);
65 for (
unsigned c = 0;
c < num_classes_; ++
c)
67 const set_t& set = class_to_set_[
c];
70 class_to_res_state_[
c]=res->pre();
71 else if(s == aut->post())
72 class_to_res_state_[
c]=res->post();
74 class_to_res_state_[
c]=res->add_state();
75 res->set_state_name(class_to_res_state_[
c],
76 aut->get_state_name(*std::min_element(begin(class_to_set_[
c]),
77 end(class_to_set_[
c]))));
80 for (
unsigned c = 0;
c < num_classes_; ++
c)
84 state_t s = *class_to_set_[
c].begin();
85 state_t src = class_to_res_state_[
c];
86 for (
auto t : aut->all_out(s))
89 state_t dst = class_to_res_state_[state_to_class[d]];
90 res->add_transition(src, dst, aut->label_of(t), aut->weight_of(t));
94 auto history = std::make_shared<partition_history<automaton_t>>(aut);
95 res->set_history(history);
96 for (
unsigned c = 0;
c < num_classes_; ++
c){
97 std::set<state_t>
from;
98 for(
auto s : class_to_set_[
c])
100 history->add_state(class_to_res_state_[
c],
from);
114 unsigned num_classes_;
120 template <
typename Aut,
typename StateList>
123 merge(
const Aut& a, std::vector<StateList>& classes,
bool keep_history=
true)
The semiring of complex numbers.
Definition: c.hh:44
std::vector< StateList > class_to_set_t
Definition: merge.hh:41
std::unordered_map< state_t, class_t > state_to_class_t
Definition: merge.hh:43
automaton_t build_result_(const automaton_t &aut)
Build the resulting automaton.
Definition: merge.hh:56
Aut automaton_t
Definition: merge.hh:39
merger(class_to_set_t &class_to_set, bool keep_history)
Definition: merge.hh:49
unsigned class_t
Definition: merge.hh:40
std::vector< state_t > class_to_state_t
Definition: merge.hh:44
automaton_t operator()(const automaton_t &aut)
The minimized automaton.
Definition: merge.hh:107
StateList set_t
Definition: merge.hh:42
json_ast_t from(std::istream &i)
Builds a json_ast_t from an input stream.
auto merge(const Aut &a, std::vector< StateList > &classes, bool keep_history=true) -> Aut
Definition: merge.hh:123
Main namespace of Awali.
Definition: ato.hh:22
unsigned state_t
Definition: types.hh:21