17 #ifndef AWALI_ALGOS_LIFT_HH
18 # define AWALI_ALGOS_LIFT_HH
30 namespace awali {
namespace sttc {
39 template <
typename ValueSet>
42 using type =
typename ValueSet::context_t;
45 template <
typename Context>
51 template <
typename ValueSet>
54 template <
typename Context>
58 template <
typename Aut>
62 template <
typename RatExpSet>
67 template <
typename LabelSet,
typename WeightSet>
78 template <
typename Context>
79 lifted_ratexpset_t<ratexpset<Context>>
85 template <
typename Aut>
90 using auto_in_t =
typename Aut::element_type;
95 rs_in_t rs_in{
get_rat_context(a->context()), rs_in_t::identities_t::trivial};
99 auto_out_t res = make_shared_ptr<auto_out_t>(ctx_out);
100 std::map<state_t, state_t>
map;
101 map[a->pre()] = res->pre();
102 map[a->post()] = res->post();
103 for (
auto s: a->states())
104 map[s] = res->add_state();
106 for (
auto t: a->all_transitions())
107 if (a->src_of(t) == a->pre())
108 res->add_initial(
map[a->dst_of(t)],
109 rs_in.lmul(a->weight_of(t), rs_in.one()));
110 else if (a->dst_of(t) == a->post())
111 res->add_final(
map[a->src_of(t)],
112 rs_in.lmul(a->weight_of(t), rs_in.one()));
113 else if (a->context().labelset()->is_one(a->label_of(t)))
116 (
map[a->src_of(t)],
map[a->dst_of(t)],
118 rs_in.lmul(a->weight_of(t), rs_in.one()));
122 (
map[a->src_of(t)],
map[a->dst_of(t)],
124 rs_in.lmul(a->weight_of(t), rs_in.atom(a->label_of(t))));
126 auto history = std::make_shared<single_history<Aut>>(a);
128 history->add_state(p.second,p.first);
129 res->set_history(history);
156 template <
typename Aut>
158 internal::lifted_automaton_t<Aut>
159 lift(
const Aut& a,
bool keep_history=
true) {
163 std::list<state_t> li;
164 for(
auto tr : aut->initial_transitions()) {
165 aut->new_transition(i, aut->dst_of(tr), {}, aut->weight_of(tr));
166 li.emplace_back(aut->dst_of(tr));
169 aut->set_state_name(i,
"I");
172 aut->unset_initial(s);
174 std::list<state_t> lt;
175 for(
auto tr : aut->final_transitions()) {
176 aut->new_transition(aut->src_of(tr), t, {}, aut->weight_of(tr));
177 lt.emplace_back(aut->src_of(tr));
180 aut->set_state_name(t,
"T");
192 template <
typename Exp>
197 template <
typename RatExpSet>
200 lift(
const RatExpSet& rs,
const typename RatExpSet::ratexp_t& e)
203 return lrs.lmul(e, lrs.one());
carries the algebraic settings of automata
Definition: context.hh:40
Implementation of labels are ones: there is a single instance of label.
Definition: oneset.hh:38
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.
Definition: tuple.hh:134
mutable_automaton< lifted_context_t< context_t_of< Aut > >> lifted_automaton_t
Definition: lift.hh:60
internal::lifted_automaton_t< Aut > unnormalized_lift(const Aut &a, bool keep_history=true)
Definition: lift.hh:88
typename ValueSet::context_t type
Definition: lift.hh:42
lifted_context_t< context< LabelSet, WeightSet > > lift_context(const context< LabelSet, WeightSet > &ctx)
Definition: lift.hh:69
Context type
Definition: lift.hh:48
typename context_of< ValueSet >::type context_of_t
Definition: lift.hh:52
lifted_ratexpset_t< ratexpset< Context > > lift_ratexpset(const ratexpset< Context > &rs)
Definition: lift.hh:80
typename lifted_context_t< context_t_of< Exp > >::ratexp_t lifted_ratexp_t
Definition: lift.hh:194
@ trivial
Trivial identities only.
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
internal::lifted_automaton_t< Aut > lift(const Aut &a, bool keep_history=true)
Lift labels to weights.
Definition: lift.hh:159
std::shared_ptr< internal::mutable_automaton_impl< Context > > mutable_automaton
Definition: mutable_automaton.hh:45
ratexp_context_of< Context > get_rat_context(const Context &ctx)
Definition: traits.hh:295
Main namespace of Awali.
Definition: ato.hh:22
unsigned state_t
Definition: types.hh:21
Provide a variadic mul on top of a binary mul(), and one().
Definition: weightset.hh:38