17 #ifndef AWALI_ALGOS_COPY_HH
18 # define AWALI_ALGOS_COPY_HH
20 # include <unordered_map>
28 namespace awali {
namespace sttc {
39 template <
typename AutIn,
typename AutOut,
typename InOutMap=std::unordered_map<state_t, state_t>>
47 template <
typename Pred>
54 for (
auto s:
in_->states())
60 out_->set_state_name(s,
in_->get_state_name(s));
65 for (
auto t :
in_->all_transitions())
70 out_->new_transition_copy(src->second, dst->second,
75 template <
typename Pred>
82 for (
auto s:
in_->states())
88 out_->set_state_name(s,
in_->get_state_name(s));
93 for (
auto t :
in_->all_transitions())
98 out_->new_transition(src->second, dst->second,
110 res[p.second] = p.first;
120 <<
" node [shape = box, style = rounded]\n";
123 o <<
" " << p.first - 2
124 <<
" [label = \"" << p.second - 2 <<
"\"]\n";
130 auto history = std::make_shared<single_history<AutIn>>(
in_);
131 out_->set_history(history);
132 for (
auto p:
in_->all_states()) {
134 if(
in_->has_name(p)) {
155 template <
typename AutIn,
typename AutOut,
typename Pred>
158 copy_into(
const AutIn& in, AutOut& out, Pred keep_state,
bool keep_history=
true,
bool transpose=
false,
bool same_index=
false)
166 template <
typename AutIn,
typename AutOut>
169 copy_into(
const AutIn& in, AutOut& out,
bool keep_history=
true,
bool transpose=
false,
bool same_index=
false)
174 template <
typename AutIn,
typename AutOut,
typename Pred>
177 copy_support(
const AutIn& in, AutOut& out, Pred keep_state,
bool keep_history=
true,
bool same_index=
false)
180 copy.no_weight(keep_state, same_index);
185 template <
typename AutIn,
typename AutOut>
188 copy_support(
const AutIn& in, AutOut& out,
bool keep_history=
true,
bool same_index=
false)
191 copy.no_weight([](
state_t) {
return true; }, same_index);
198 template <
typename AutIn,
199 typename AutOut =
typename AutIn::element_type::automaton_nocv_t,
203 copy(
const AutIn& input, Pred keep_state,
bool keep_history=
true,
bool transpose=
false,
bool same_index=
false)
210 res->set_name(input->get_name());
211 res->set_desc(input->get_desc());
216 template <
typename AutIn,
217 typename AutOut =
typename AutIn::element_type::automaton_nocv_t>
220 copy(
const AutIn& input,
bool keep_history=
true,
bool transpose=
false,
bool same_index=
false)
222 return sttc::copy<AutIn, AutOut>(input,
228 template <
typename AutIn,
229 typename AutOut =
typename AutIn::element_type::automaton_nocv_t>
232 copy(
const AutIn& input,
const std::set<state_t>& keep,
bool keep_history=
true,
bool transpose=
false,
bool same_index=
false)
234 return sttc::copy<AutIn, AutOut>
236 [&keep](
state_t s) {
return keep.find(s)!=keep.end(); }, keep_history,
transpose, same_index);
void copy_into(const AutIn &in, AutOut &out, Pred keep_state, bool keep_history=true, bool transpose=false, bool same_index=false)
Copy an automaton.
Definition: copy.hh:158
AutOut copy(const AutIn &input, Pred keep_state, bool keep_history=true, bool transpose=false, bool same_index=false)
A copy of input keeping only its states that are accepted by keep_state.
Definition: copy.hh:203
void copy_support(const AutIn &in, AutOut &out, Pred keep_state, bool keep_history=true, bool same_index=false)
Definition: copy.hh:177
AutOut transpose(Aut &aut, bool keep_history=true)
Definition: transpose.hh:79
mutable_automaton< Context > make_mutable_automaton(const Context &ctx)
Definition: mutable_automaton.hh:931
Main namespace of Awali.
Definition: ato.hh:22
unsigned state_t
Definition: types.hh:21
Copy an automaton.
Definition: copy.hh:41
const AutIn & in_
Input automaton.
Definition: copy.hh:145
static std::ostream & print(const origins_t &orig, std::ostream &o)
Print the origins.
Definition: copy.hh:117
origins_t origins() const
Definition: copy.hh:106
const InOutMap & in_out_map() const
Definition: copy.hh:140
InOutMap out_state
input state -> output state.
Definition: copy.hh:149
copier(const AutIn &in, AutOut &out)
Definition: copy.hh:42
std::map< state_t, state_t > origins_t
A map from result state to original state.
Definition: copy.hh:104
void no_weight(Pred keep_state, bool same_index)
Definition: copy.hh:76
AutOut & out_
Output automaton.
Definition: copy.hh:147
void operator()(Pred keep_state, bool transpose, bool same_index)
Definition: copy.hh:48
void set_history()
Definition: copy.hh:129