17 #ifndef AWALI_ALGOS_CONCATENATE_HH 
   18 # define AWALI_ALGOS_CONCATENATE_HH 
   20 # include <unordered_set> 
   43       template <
typename A, 
typename B, 
typename P>
 
   50         auto& ws = *res->weightset();
 
   51         auto& ls = *res->labelset();
 
   52         auto& wsb = *
b->weightset();
 
   53         auto& lsb = *
b->labelset();
 
   56         auto ftr_ = res->final_transitions();
 
   58         using transs_t = std::vector<transition_t>;
 
   59         transs_t ftr{ begin(ftr_), end(ftr_) };
 
   61         state_t b_initial = 
b->dst_of(*(
b->initial_transitions().begin()));
 
   64         std::unordered_map<state_t, state_t> m;
 
   65         m.emplace(
b->post(), res->post());
 
   66         for (
auto s: 
b->states())
 
   67           if (!
b->is_initial(s))
 
   68             m.emplace(s, res->add_state());
 
   75         for (
auto t: 
b->all_transitions())
 
   76           if (
b->src_of(t) != 
b->pre() && 
b->src_of(t) != b_initial)
 
   77             res->new_transition_copy(m[
b->src_of(t)], m[
b->dst_of(t)], 
b, t);
 
   93             auto s1 = res->src_of(t1);
 
   94             auto w1 = res->weight_of(t1);
 
   95             res->del_transition(t1);
 
   96             for (
auto t2: 
b->all_out(b_initial))
 
   97               res->set_transition(s1,
 
   99                                   ls.conv(lsb,
b->label_of(t2)),
 
  100                                   ws.mul(w1, ws.conv(wsb,
b->weight_of(t2))));
 
  105       template <
typename A, 
typename B, 
typename P>
 
  110         const auto& ws = *res->weightset();
 
  112         auto one=res->labelset()->one();
 
  115         auto ftr_ = res->final_transitions();
 
  117         using transs_t = std::vector<transition_t>;
 
  118         transs_t ftr{ begin(ftr_), end(ftr_) };
 
  121         cp([](
state_t) { 
return true; });
 
  124           std::unordered_set<state_t> ist;
 
  125           for(
auto itb : 
b->initial_transitions())
 
  126             ist.emplace(iom.at(
b->dst_of(itb)));
 
  129           for(
auto tr : res->initial_transitions())
 
  130             if(ist.find(res->dst_of(tr))!=ist.end())
 
  131               itr.emplace_back(tr);
 
  135               res->new_transition(res->src_of(ft),
 
  138                                   ws.mul(res->weight_of(ft), res->weight_of(it)));
 
  140             res->del_transition(ft);
 
  142             res->del_transition(it);
 
  159   template <
typename A, 
typename B>
 
  188   template <
typename Aut1, 
typename Aut2>
 
  218   template <
typename Aut>
 
  223       make_shared_ptr<Aut>(aut->context());
 
  236             auto s = res->add_state();
 
  243             for (
unsigned n = 1; 
n < 
min; ++
n)
 
  249             Aut 
sum = make_shared_ptr<Aut>(aut->context());
 
  251               auto s = 
sum->add_state();
 
  278   template <
typename ValueSet>
 
  280   typename ValueSet::value_t
 
  282               const typename ValueSet::value_t& lhs,
 
  283               const typename ValueSet::value_t& rhs)
 
  285     return vs.mul(lhs, rhs);
 
  307   template <
typename RatExpSet>
 
  308   typename RatExpSet::ratexp_t
 
  309   chain(
const RatExpSet& rs, 
const typename RatExpSet::ratexp_t& 
r,
 
  312     typename RatExpSet::ratexp_t res;
 
  326             for (
unsigned n = 1; 
n < 
min; ++
n)
 
  327               res = rs.
mul(res, 
r);
 
  331             typename RatExpSet::ratexp_t 
sum = rs.one();
 
  334             res = rs.mul(res, 
sum);
 
The Boolean semring.
Definition: b.hh:38
The semiring of Natural numbers.
Definition: n.hh:34
The semiring of floating Numbers.
Definition: r.hh:35
static value_t mul(const value_t l, const value_t r)
Definition: r.hh:83
static constexpr TOP< void > value
Definition: priority.hh:93
Definition: priority.hh:52
A & concatenate_here(A &res, B b, priority::ONE< P >)
Definition: concatenate.hh:45
auto sum(const Aut1 &aut1, const Aut2 &aut2, bool sum_standard=false) -> decltype(join_automata(aut1, aut2))
sums two automata
Definition: sum.hh:137
auto concatenate(const Aut1 &aut1, const Aut2 &aut2) -> decltype(join_automata(aut1, aut2))
Concatenates two automata.
Definition: concatenate.hh:191
bool is_standard(const Aut &a)
Definition: standard.hh:40
Aut::element_type::automaton_nocv_t star(const Aut &aut)
Star of an automaton.
Definition: star.hh:100
A & concatenate_here(A &res, const B &aut)
Concatenation of an automaton to another one.
Definition: concatenate.hh:161
void copy_into(const AutIn &in, AutOut &out, Pred keep_state, bool keep_history=true, bool transpose=false)
Copy an automaton.
Definition: copy.hh:144
Aut standard(Aut &aut, bool keep_history=true)
Definition: standard.hh:92
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
auto join_automata(Auts &&... auts) -> decltype(make_mutable_automaton(join(auts->context()...)))
Join between automata.
Definition: product.hh:39
Aut chain(const Aut &aut, unsigned min, int max)
chains automata to compute powers of a series
Definition: concatenate.hh:220
ATTRIBUTE_CONST int max(int a, int b)
Definition: arith.hh:54
ATTRIBUTE_CONST int min(int a, int b)
Definition: arith.hh:48
Main namespace of Awali.
Definition: ato.hh:22
unsigned state_t
Definition: types.hh:21
Copy an automaton.
Definition: copy.hh:41
const InOutMap & in_out_map() const
Definition: copy.hh:126