Commit 2ae73da3 authored by Lombardy Sylvain's avatar Lombardy Sylvain Committed by Alexandre Duret-Lutz
Browse files

New taf-kit commands : coquotient, alphabet, partial-erase

One_eps_closure bug fix : no more creation of transition with label 0
Fmp-transducers bugs fixs : dealing with labels which are linear combinations of pairs
parent feb028d7
......@@ -91,8 +91,10 @@ namespace vcsn
{
const trans_series_set_elt_t trans_series_elt = src.series_of(*fmp_e);
trans_support_t trans_supp = trans_series_elt.supp();
for_all_const_(trans_support_t, trans_value, trans_supp)
{
const trans_monoid_elt_t trans_monoid_elt(trans_monoid,
*(trans_supp.begin()));
*trans_value);
const monoid_elt_value_t word(trans_monoid_elt.value().first);
series_set_elt_t series_elt(series);
......@@ -103,6 +105,7 @@ namespace vcsn
dst.add_series_transition(stmap[src.src_of(*fmp_e)],
stmap[src.dst_of(*fmp_e)], series_elt);
}
}
}
......
......@@ -90,8 +90,10 @@ namespace vcsn
const trans_series_set_elt_t trans_series_elt =
fmp_trans.series_of(*fmp_e);
trans_support_t trans_supp = trans_series_elt.supp();
for_all_const_(trans_support_t, trans_value, trans_supp)
{
const trans_monoid_elt_t trans_monoid_elt(trans_monoid,
*(trans_supp.begin()));
*trans_value);
const monoid_elt_value_t word(trans_monoid_elt.value().second);
......@@ -103,7 +105,8 @@ namespace vcsn
res.add_series_transition(stmap[fmp_trans.src_of(*fmp_e)],
stmap[fmp_trans.dst_of(*fmp_e)], series_elt);
}
}
}
}
......
......@@ -227,57 +227,63 @@ namespace vcsn {
for (delta_iterator l(lhs.value(), lhs_s); ! l.done(); l.next())
{
const lhs_series_set_elt_t left_series = lhs.series_of(*l);
const lhs_monoid_elt_t left_supp_elt (lhs_monoid,
*left_series.supp().begin());
// (i)
// If the outgoing transition is of type (*, 1).
if (left_supp_elt.value().second == lhs_second_identity.value())
for_all_const_(lhs_support_t, left_supp_value,left_series.supp())
{
const lhs_monoid_elt_t left_supp_elt (lhs_monoid, *left_supp_value);
// (i)
// If the outgoing transition is of type (*, 1).
if (left_supp_elt.value().second == lhs_second_identity.value())
{
series_set_elt_t s =
series_product (left_supp_elt.value().first,
series_product (left_supp_elt.value().first,
rhs_second_identity.value(),
left_series.get(left_supp_elt));
add_transition (current_state,
lhs.dst_of(*l), rhs_s, s);
}
// (iii')
else
// (iii')
else
{
for (delta_iterator r(rhs.value(), rhs_s); ! r.done(); r.next())
{
const rhs_series_set_elt_t right_series =
rhs.series_of(*r);
const rhs_monoid_elt_t right_supp_elt
(rhs_monoid, *right_series.supp().begin());
// If the incoming transition is not of type (1, *).
if (right_supp_elt.value().first !=
rhs_first_identity.value())
// we try to connect a transition of lhs and
// a transition of rhs.
if (left_supp_elt.value().second ==
right_supp_elt.value().first)
for (delta_iterator r(rhs.value(), rhs_s); ! r.done(); r.next())
{
const rhs_series_set_elt_t right_series =
rhs.series_of(*r);
for_all_const_(rhs_support_t, right_supp_value, right_series.supp())
{
const rhs_monoid_elt_t right_supp_elt
(rhs_monoid, *right_supp_value);
// If the incoming transition is not of type (1, *).
if (right_supp_elt.value().first !=
rhs_first_identity.value())
// we try to connect a transition of lhs and
// a transition of rhs.
if (left_supp_elt.value().second ==
right_supp_elt.value().first)
{
series_set_elt_t s =
series_product (left_supp_elt.value().first,
series_set_elt_t s =
series_product (left_supp_elt.value().first,
right_supp_elt.value().second,
left_series.get(left_supp_elt)
* right_series.get(right_supp_elt));
add_transition
add_transition
(current_state,
lhs.dst_of(*l), rhs.dst_of(*r),
s);
}
}
}
}
}
}
}
for (delta_iterator r(rhs.value(), rhs_s); ! r.done(); r.next())
{
const rhs_series_set_elt_t right_series = rhs.series_of(*r);
const rhs_monoid_elt_t right_supp_elt (rhs_monoid,
*right_series.supp().begin());
for_all_const_(rhs_support_t, right_supp_value, right_series.supp())
{
const rhs_monoid_elt_t right_supp_elt (rhs_monoid,
*right_supp_value);
// (ii)
if (right_supp_elt.value().first == rhs_first_identity.value())
......@@ -289,6 +295,7 @@ namespace vcsn {
add_transition (current_state,
lhs_s, rhs.dst_of(*r), s);
}
}
}
}
......
......@@ -52,7 +52,8 @@ namespace vcsn
break;
}
}
a.add_series_transition(src, dst, val);
if (val != a.series().zero_)
a.add_series_transition(src, dst, val);
}
/*-------------------------------------------.
......
......@@ -21,13 +21,13 @@
/**
* @file projection.hh
*
* @brief Build an FMP transducer that realizes the identity relation.
* x -> (x,x)
* @brief Build FMP transducers from automata.
*
*/
/** @} */
// INTERFACE: void identity(const InputProjection& a, Automaton& b) { return vcsn::identity(*a, *b); }
// INTERFACE: void partial_erase(const InputProjection& a, Automaton& b) { return vcsn::identity(*a, *b); }
# include <vaucanson/algebra/concept/freemonoid_product.hh>
# include <vaucanson/automata/concept/transducer.hh>
......@@ -45,10 +45,23 @@ namespace vcsn {
| Identity |
`---------*/
/** @brief Build an FMP transducer that realizes the identity relation.
* x -> (x,x)
*/
template <typename S, typename S2, typename T, typename T2>
void
identity(const Element<S,T>& aut, Element<S2, T2>& res);
/*--------------.
| Partial erase |
`--------------*/
/** @brief Build an FMP transducer that realizes the projection on the empty word.
* x -> (x,1)
*/
template <typename S, typename S2, typename T, typename T2>
void
partial_erase(const Element<S,T>& aut, Element<S2, T2>& res);
/** @} */
} // ! vcsn
......
......@@ -133,6 +133,65 @@ namespace vcsn
res.structure(), res.structure().series().monoid(), aut, res);
}
/*--------------.
| Partial erase |
`--------------*/
template <typename S1, typename S2, typename M1, typename M2,
typename auto_t, typename trans_t>
void
do_partial_erase(const AutomataBase<S1>&,
const algebra::FreeMonoidBase<M1>&,
const AutomataBase<S2>&,
const algebra::FreeMonoidProduct<M1,M2>&,
const auto_t& aut, trans_t& res)
{
BENCH_TASK_SCOPED("partial erase");
AUTOMATON_TYPES_(auto_t, aut_);
AUTOMATON_TYPES(trans_t);
std::map<hstate_t, aut_hstate_t> stmap;
typedef typename aut_series_set_elt_t::support_t aut_support_t;
const series_set_t& series = res.structure().series();
const monoid_t& monoid = res.structure().series().monoid();
const aut_monoid_t& aut_monoid = aut.structure().series().monoid();
aut_monoid_elt_value_t empty_word =
algebra::identity_as<aut_monoid_elt_value_t>::of(aut_monoid).value();
set_states(aut, res, stmap);
for_all_const_transitions_(aut_, aut_e, aut)
{
const aut_series_set_elt_t aut_series_elt = aut.series_of(*aut_e);
// If the transition is labeled by a+bc, we want to output
// two transitions labeled by (a,a) and (bc,bc).
aut_support_t aut_supp = aut_series_elt.supp();
for_all_const_(aut_support_t, label, aut_supp)
{
const aut_monoid_elt_t aut_monoid_elt(aut_monoid, *label);
const monoid_elt_value_t word(aut_monoid_elt.value(),
empty_word);
series_set_elt_t series_elt(series);
series_elt.assoc(monoid_elt_t(monoid, word),
aut_series_elt.get(aut_monoid_elt));
res.add_series_transition(stmap[aut.src_of(*aut_e)],
stmap[aut.dst_of(*aut_e)], series_elt);
}
}
}
template <typename S, typename S2, typename T, typename T2>
void
partial_erase(const Element<S,T>& aut, Element<S2, T2>& res)
{
do_partial_erase(aut.structure(), aut.structure().series().monoid(),
res.structure(), res.structure().series().monoid(), aut, res);
}
} // ! vcsn
#endif // ! VCSN_ALGORITHMS_PROJECTION_HXX
......@@ -60,6 +60,13 @@ quotient_command(const arguments_t& args)
return 0;
};
static int
coquotient_command(const arguments_t& args)
{
g_res.keep(transpose(quotient(transpose(get_aut(args, 1)))));
return 0;
};
static int
quotient_S_command(const arguments_t& args)
{
......@@ -88,6 +95,27 @@ partial_identity_command(const arguments_t& args)
g_res.keep(fmp);
return 0;
}
static int
partial_erase_command(const arguments_t& args)
{
automaton_t a = get_aut(args, 1);
alphabet_t A = a.structure().series().monoid().alphabet();
FMPI_CONTEXT::monoid_rep_t new_mrep;
FMPI_CONTEXT::series_rep_t new_srep;
new_srep.first_representation() =
*(a.structure().series().representation());
new_srep.second_representation() =
*(a.structure().series().representation());
FMPI_CONTEXT::automaton_t fmp =
FMPI_CONTEXT::make_automaton(A, A, new_mrep,
*(a.structure().series().monoid().representation()),
*(a.structure().series().monoid().representation()),
new_srep);
partial_erase(a, fmp);
g_res.keep(fmp);
return 0;
}
#endif
static int
......@@ -192,6 +220,24 @@ star_alphabet_command(const arguments_t& args)
return 0;
}
static int
alphabet_command(const arguments_t& args)
{
alphabet_t alpha= get_alphabet(args.alphabet);
// Create a single state automaton
automaton_t a = make_automaton(alpha);
hstate_t q = a.add_state();
hstate_t r = a.add_state();
a.set_initial(q);
a.set_final(r);
// Add a loop on the single state labeled by every letter of the alphabet
for(alphabet_iterator i = alpha.begin() ; i != alpha.end(); ++i)
a.add_letter_transition(q, r, *i);
g_res.keep(a);
return 0;
}
static int
power_command(const arguments_t& args)
{
......@@ -257,11 +303,17 @@ COMMAND_ENTRY(is_realtime, Aut, Boolean, "Tell whether `aut' is realtime.");
COMMAND_ENTRY(realtime, Aut, Aut, "Build a realtime version of `aut'.");
COMMAND_ENTRY(quotient, Aut, Aut,
"Build the quotient of the realtime automaton `aut'.");
COMMAND_ENTRY(coquotient, Aut, Aut,
"Build the coquotient of the realtime automaton `aut'.");
#ifdef FMPI_CONTEXT
COMMAND_ENTRY(partial_identity, Aut, AutM,
"Transform an automaton into an FMP "
"transducer by creating, for each word, "
"a pair containing twice this word.");
COMMAND_ENTRY(partial_erase, Aut, AutM,
"Transform an automaton into an FMP "
"transducer by creating, for each word, "
"a pair containing the word and the empty word.");
#endif
COMMAND_ENTRY(eval, AutWord, Text,
"Evaluate `word' on the realtime automaton `aut'.");
......@@ -287,4 +339,6 @@ COMMAND_ENTRY(support, Aut, AutB,
"Build a Boolean automaton from `aut'.");
COMMAND_ENTRY(star_alphabet, None, Aut,
"Build an automaton recognizing the free monoid generated by the alphabet.");
COMMAND_ENTRY(alphabet, None, Aut,
"Build an automaton recognizing the alphabet.");
END_COMMAND_GROUP
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment