Commit 5587a11c authored by Sarah O'Connor's avatar Sarah O'Connor
Browse files

2005-06-15 Sarah O'Connor <sarah.o-connor@lrde.epita.fr>

	This patch offers several new algorithms on transducers seen as
	automata over a free monoid product. Some projections are now
	available: 'domain' which creates an automaton which transitions
	are labeled by the first component of each word of the fmp
	transducer, 'image' which does the same with the second component
	and 'identity' which transforms an automaton in a fmp transducer
	by creating, for each word, a pair containing twice this word.
	Furthermore, evaluation is now available and a new function has
	been added to the fmp context headers in order to facilitate the
	call to the evaluation algorithm, just as it is already done for
	transducers.

	* include/vaucanson/algorithms/projections_fmp.hh,
	* include/vaucanson/algorithms/projections_fmp.hxx: New. Add 'domain',
	'image' and 'identity' projections for fmp transducers.
	* include/vaucanson/algorithms/evaluation_fmp.hh,
	* include/vaucanson/algorithms/evaluation_fmp.hxx: New. Add an
	evaluation algorithm for fmp transducers.
	* include/Makefile.am: Update accordingly.

	* src/tests/automata/algos/fmp_transducers/evaluation_fmp_test.hh: New.
	Write a test for the evaluation on fmp transducers.
	* src/tests/automata/algos/fmp_transducers/Makefile.am: Update
	accordingly.

	* include/vaucanson/contexts/fmp_transducer_functions.thh,
	* include/vaucanson/contexts/fmp_transducer_functions.thxx: Add the
	'evaluation' function to ease the interface with the user.
parent d1ca91dc
2005-06-15 Sarah O'Connor <sarah.o-connor@lrde.epita.fr>
This patch offers several new algorithms on transducers seen as
automata over a free monoid product. Some projections are now
available: 'domain' which creates an automaton which transitions
are labeled by the first component of each word of the fmp
transducer, 'image' which does the same with the second component
and 'identity' which transforms an automaton in a fmp transducer
by creating, for each word, a pair containing twice this word.
Furthermore, evaluation is now available and a new function has
been added to the fmp context headers in order to facilitate the
call to the evaluation algorithm, just as it is already done for
transducers.
* include/vaucanson/algorithms/projections_fmp.hh,
* include/vaucanson/algorithms/projections_fmp.hxx: New. Add 'domain',
'image' and 'identity' projections for fmp transducers.
* include/vaucanson/algorithms/evaluation_fmp.hh,
* include/vaucanson/algorithms/evaluation_fmp.hxx: New. Add an
evaluation algorithm for fmp transducers.
* include/Makefile.am: Update accordingly.
* src/tests/automata/algos/fmp_transducers/evaluation_fmp_test.hh: New.
Write a test for the evaluation on fmp transducers.
* src/tests/automata/algos/fmp_transducers/Makefile.am: Update
accordingly.
* include/vaucanson/contexts/fmp_transducer_functions.thh,
* include/vaucanson/contexts/fmp_transducer_functions.thxx: Add the
'evaluation' function to ease the interface with the user.
2005-06-09 Michael Cadilhac <michael.cadilhac@lrde.epita.fr>
 
* include/vaucanson/algorithms/aut_to_exp.hxx: As the user would
......@@ -52,7 +83,7 @@
* src/benchs/quotient/Makefile.bench: Bench the quotient
on the C_1 automaton (as described in Inside Vaucanson),
for both boolean and Z automata.
 
2005-06-06 Michael Cadilhac <michael.cadilhac@lrde.epita.fr>
 
......
......@@ -344,6 +344,10 @@ nobase_include_HEADERS = \
vaucanson/algorithms/normalized_composition.hxx \
vaucanson/algorithms/outsplitting.hh \
vaucanson/algorithms/outsplitting.hxx \
vaucanson/algorithms/projections_fmp.hh \
vaucanson/algorithms/projections_fmp.hxx \
vaucanson/algorithms/evaluation_fmp.hh \
vaucanson/algorithms/evaluation_fmp.hxx \
vaucanson/vaucanson.hh \
vaucanson/boolean_automaton.hh \
vaucanson/boolean_transducer.hh \
......
// evaluation_fmp.hh: this file is part of the Vaucanson project.
//
// Vaucanson, a generic library for finite state machines.
// Copyright (C) 2005 The Vaucanson Group.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// The Vaucanson Group consists of the following contributors:
// * Jacques Sakarovitch <sakarovitch@enst.fr>
// * Sylvain Lombardy <lombardy@liafa.jussieu.fr>
// * Thomas Claveirole <thomas.claveirole@lrde.epita.fr>
// * Loic Fosse <loic.fosse@lrde.epita.fr>
// * Thanh-Hoc Nguyen <nguyen@enst.fr>
// * Raphael Poss <raphael.poss@lrde.epita.fr>
// * Yann Regis-Gianas <yann.regis-gianas@lrde.epita.fr>
// * Maxime Rey <maxime.rey@lrde.epita.fr>
// * Sarah O'Connor <sarah.o-connor@lrde.epita.fr>
// * Louis-Noel Pouchet <louis-noel.pouchet@lrde.epita.fr>
//
#ifndef VCSN_ALGORITHMS_EVALUATION_FMP_HH
# define VCSN_ALGORITHMS_EVALUATION_FMP_HH
# include <vaucanson/automata/concept/automata_base.hh>
/** @addtogroup algorithms *//** @{ */
/**
* @file evaluation_fmp.hh
*
* @brief Evaluation over normalized and sub-normalized transducers
* seen as automata over a free monoid product.
*
* @author Sarah O'Connor <sarah.o-connor@lrde.epita.fr>
*
* @see evaluation_fmp()
*/
/** @} */
namespace vcsn {
/** @addtogroup algorithms *//** @{ */
/**
* Evaluation over normalized and sub-normalized transducers, seen
* as automata over a free monoid product.
*
* @param
*
*/
template<typename SA, typename TA,
typename ST, typename TT,
typename SARET, typename TARET>
void
evaluation_fmp(const Element<ST, TT>&,
const Element<SA, TA>&,
Element<SARET, TARET>&);
} // End of namespace vcsn.
# ifndef VCSN_USE_INTERFACE_ONLY
# include <vaucanson/algorithms/evaluation_fmp.hxx>
# endif // VCSN_USE_INTERFACE_ONLY
#endif // !VCSN_ALGORITHMS_FMP_EVALUATION_HH
// evaluation_fmp.hxx: this file is part of the Vaucanson project.
//
// Vaucanson, a generic library for finite state machines.
// Copyright (C) 2005 The Vaucanson Group.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// The Vaucanson Group consists of the following contributors:
// * Jacques Sakarovitch <sakarovitch@enst.fr>
// * Sylvain Lombardy <lombardy@liafa.jussieu.fr>
// * Thomas Claveirole <thomas.claveirole@lrde.epita.fr>
// * Loic Fosse <loic.fosse@lrde.epita.fr>
// * Thanh-Hoc Nguyen <nguyen@enst.fr>
// * Raphael Poss <raphael.poss@lrde.epita.fr>
// * Yann Regis-Gianas <yann.regis-gianas@lrde.epita.fr>
// * Maxime Rey <maxime.rey@lrde.epita.fr>
// * Sarah O'Connor <sarah.o-connor@lrde.epita.fr>
// * Louis-Noel Pouchet <louis-noel.pouchet@lrde.epita.fr>
//
#ifndef VCSN_ALGORITHMS_EVALUATION_FMP_HXX
# define VCSN_ALGORITHMS_EVALUATION_FMP_HXX
# include <vaucanson/algorithms/evaluation_fmp.hh>
# include <vaucanson/algorithms/projections_fmp.hh>
# include <vaucanson/algorithms/normalized_composition.hh>
# include <vaucanson/algebra/concept/freemonoid_product.hh>
namespace vcsn
{
template <typename S1, typename S2, typename S3,
typename M1, typename M2, typename M3, typename M4,
typename trans_t, typename auto_t, typename res_t>
void
do_evaluation_fmp(const AutomataBase<S1>&,
const algebra::FreeMonoidProduct<M1, M2>&,
const AutomataBase<S2>&, const algebra::FreeMonoid<M3>&,
const AutomataBase<S3>&, const algebra::FreeMonoid<M4>&,
const trans_t& trans, const auto_t& aut, res_t& res)
{
trans_t id_aut(trans);
identity(aut, id_aut);
trans_t res_composition = normalized_composition(trans, id_aut);
image(res_composition, res);
}
template<typename SA, typename TA,
typename ST, typename TT,
typename SARES, typename TARES>
void
evaluation_fmp(const Element<ST, TT>& trans,
const Element<SA, TA>& aut,
Element<SARES, TARES>& res)
{
do_evaluation_fmp(trans.structure(), trans.structure().series().monoid(),
aut.structure(), aut.structure().series().monoid(),
res.structure(), res.structure().series().monoid(),
trans, aut, res);
}
} // End of namespace vcsn.
#endif // !VCSN_ALGORITHMS_EVALUATION_FMP_HXX.
// projections_fmp.hh: this file is part of the Vaucanson project.
//
// Vaucanson, a generic library for finite state machines.
// Copyright (C) 2005 The Vaucanson Group.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// The Vaucanson Group consists of the following contributors:
// * Jacques Sakarovitch <sakarovitch@enst.fr>
// * Sylvain Lombardy <lombardy@liafa.jussieu.fr>
// * Thomas Claveirole <thomas.claveirole@lrde.epita.fr>
// * Loic Fosse <loic.fosse@lrde.epita.fr>
// * Thanh-Hoc Nguyen <nguyen@enst.fr>
// * Raphael Poss <raphael.poss@lrde.epita.fr>
// * Yann Regis-Gianas <yann.regis-gianas@lrde.epita.fr>
// * Maxime Rey <maxime.rey@lrde.epita.fr>
// * Sarah O'Connor <sarah.o-connor@lrde.epita.fr>
// * Louis-Noel Pouchet <louis-noel.pouchet@lrde.epita.fr>
//
#ifndef VCSN_ALGORITHMS_PROJECTIONS_FMP_HH
# define VCSN_ALGORITHMS_PROJECTIONS_FMP_HH
/** @addtogroup algorithms *//** @{ */
/**
* @file projections_fmp.hh
*
* @brief Domain and Image projection for transducers seen as automata
* over a free monoid product.
*
* @author Sarah O'Connor <sarah.o-connor@lrde.epita.fr>
*/
/** @} */
namespace vcsn
{
/*-------.
| Domain |
`-------*/
template <typename S, typename S2, typename T, typename T2>
void
domain(const Element<S,T>& aut, Element<S2, T2>& res);
template <typename S, typename S2, typename T, typename T2>
Element<S2, T2>
domain(const Element<S,T>& aut);
/*------.
| Image |
`------*/
template <typename S, typename S2, typename T, typename T2>
void
image(const Element<S,T>& aut, Element<S2, T2>& res);
template <typename S, typename S2, typename T, typename T2>
Element<S2, T2>
image(const Element<S,T>& aut);
/*---------.
| Identity |
`---------*/
template <typename S, typename S2, typename T, typename T2>
void
identity(const Element<S,T>& aut, Element<S2, T2>& res);
template <typename S, typename S2, typename T, typename T2>
Element<S2, T2>
identity(const Element<S,T>& aut);
} // End of namespace vcsn.
# ifndef VCSN_USE_INTERFACE_ONLY
# include <vaucanson/algorithms/projections_fmp.hxx>
# endif // VCSN_USE_INTERFACE_ONLY
#endif // ! VCSN_ALGORITHMS_PROJECTIONS_FMP_HH
// projections_fmp.hxx: this file is part of the Vaucanson project.
//
// Vaucanson, a generic library for finite state machines.
// Copyright (C) 2005 The Vaucanson Group.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// The Vaucanson Group consists of the following contributors:
// * Jacques Sakarovitch <sakarovitch@enst.fr>
// * Sylvain Lombardy <lombardy@liafa.jussieu.fr>
// * Thomas Claveirole <thomas.claveirole@lrde.epita.fr>
// * Loic Fosse <loic.fosse@lrde.epita.fr>
// * Thanh-Hoc Nguyen <nguyen@enst.fr>
// * Raphael Poss <raphael.poss@lrde.epita.fr>
// * Yann Regis-Gianas <yann.regis-gianas@lrde.epita.fr>
// * Maxime Rey <maxime.rey@lrde.epita.fr>
// * Sarah O'Connor <sarah.o-connor@lrde.epita.fr>
// * Louis-Noel Pouchet <louis-noel.pouchet@lrde.epita.fr>
//
#ifndef VCSN_ALGORITHMS_PROJECTIONS_FMP_HXX
# define VCSN_ALGORITHMS_PROJECTIONS_FMP_HXX
# include <vaucanson/algorithms/projections_fmp.hh>
namespace vcsn
{
template <typename auto_t, typename trans_t>
static void
set_states(const trans_t& fmp_trans, auto_t& res,
std::map<hstate_t, hstate_t>& stmap)
{
AUTOMATON_TYPES_(trans_t, trans_);
AUTOMATON_TYPES(auto_t);
typedef typename trans_series_set_elt_t::support_t trans_support_t;
const series_set_t& series = res.structure().series();
const monoid_t& monoid = res.structure().series().monoid();
for_each_state(fmp_s, fmp_trans)
{
hstate_t s = res.add_state();
stmap[*fmp_s] = s;
if (fmp_trans.is_initial(*fmp_s))
{
trans_series_set_elt_t in = fmp_trans.get_initial(*fmp_s);
trans_support_t supp = in.supp();
semiring_elt_t in_semi_elt = in.get(*(supp.begin()));
series_set_elt_t series_elt(series);
series_elt.assoc(monoid_elt_t(monoid,
algebra::identity_as<
monoid_elt_value_t>::
of(monoid).value()),
in_semi_elt);
res.set_initial(s, series_elt);
}
if (fmp_trans.is_final(*fmp_s))
{
trans_series_set_elt_t out = fmp_trans.get_final(*fmp_s);
trans_support_t supp = out.supp();
semiring_elt_t out_semi_elt =
out.get(*(supp.begin()));
series_set_elt_t series_elt(series);
series_elt.assoc(monoid_elt_t(monoid,
algebra::identity_as<
monoid_elt_value_t>::
of(monoid).value()),
out_semi_elt);
res.set_final(s, series_elt);
}
}
}
template <typename S1, typename S2, typename M1, typename M2,
typename auto_t, typename trans_t>
void
do_domain(const AutomataBase<S1>&, const algebra::FreeMonoidProduct<M1, M2>&,
const AutomataBase<S2>&, const algebra::FreeMonoid<M1>&,
const trans_t& fmp_trans, auto_t& res)
{
AUTOMATON_TYPES_(trans_t, trans_);
AUTOMATON_TYPES(auto_t);
typedef typename trans_series_set_elt_t::support_t trans_support_t;
std::map<hstate_t, hstate_t> stmap;
const series_set_t& series = res.structure().series();
const monoid_t& monoid = res.structure().series().monoid();
const trans_monoid_t& trans_monoid =
fmp_trans.structure().series().monoid();
set_states(fmp_trans, res, stmap);
for_each_edge(fmp_e, fmp_trans)
{
const trans_series_set_elt_t trans_series_elt =
fmp_trans.series_of(*fmp_e);
trans_support_t trans_supp = trans_series_elt.supp();
const trans_monoid_elt_t trans_monoid_elt
(trans_monoid, *(trans_supp.begin()));
const monoid_elt_value_t word(trans_monoid_elt.value().first);
series_set_elt_t series_elt(series);
series_elt.assoc(monoid_elt_t(monoid, word),
trans_series_elt.get(trans_monoid_elt));
res.add_series_edge(stmap[fmp_trans.origin_of(*fmp_e)],
stmap[fmp_trans.aim_of(*fmp_e)], series_elt);
}
}
template <typename S1, typename S2, typename M1, typename M2,
typename auto_t, typename trans_t>
void
do_image(const AutomataBase<S1>&, const algebra::FreeMonoidProduct<M1, M2>&,
const AutomataBase<S2>&, const algebra::FreeMonoidBase<M2>&,
const trans_t& fmp_trans, auto_t& res)
{
AUTOMATON_TYPES_(trans_t, trans_);
AUTOMATON_TYPES(auto_t);
typedef typename trans_series_set_elt_t::support_t trans_support_t;
std::map<hstate_t, hstate_t> stmap;
const series_set_t& series = res.structure().series();
const monoid_t& monoid = res.structure().series().monoid();
const trans_monoid_t& trans_monoid =
fmp_trans.structure().series().monoid();
set_states(fmp_trans, res, stmap);
for_each_edge(fmp_e, fmp_trans)
{
const trans_series_set_elt_t trans_series_elt =
fmp_trans.series_of(*fmp_e);
trans_support_t trans_supp = trans_series_elt.supp();
const trans_monoid_elt_t trans_monoid_elt
(trans_monoid, *(trans_supp.begin()));
const monoid_elt_value_t word(trans_monoid_elt.value().second);
series_set_elt_t series_elt(series);
series_elt.assoc(monoid_elt_t(monoid, word),
trans_series_elt.get(trans_monoid_elt));
res.add_series_edge(stmap[fmp_trans.origin_of(*fmp_e)],
stmap[fmp_trans.aim_of(*fmp_e)], series_elt);
}
}
template <typename S1, typename S2, typename M1, typename M2,
typename auto_t, typename trans_t>
void
do_identity(const AutomataBase<S1>&,
const algebra::FreeMonoidBase<M1>&,
const AutomataBase<S2>&,
const algebra::FreeMonoidProduct<M1,M2>&,
const auto_t& aut, trans_t& res)
{
AUTOMATON_TYPES_(auto_t, aut_);
AUTOMATON_TYPES(trans_t);
std::map<hstate_t, 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();
set_states(aut, res, stmap);
for_each_edge(aut_e, aut)
{
const aut_series_set_elt_t aut_series_elt =
aut.series_of(*aut_e);
aut_support_t aut_supp = aut_series_elt.supp();
const aut_monoid_elt_t aut_monoid_elt
(aut_monoid, *(aut_supp.begin()));
const monoid_elt_value_t word(aut_monoid_elt.value(),
aut_monoid_elt.value());
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_edge(stmap[aut.origin_of(*aut_e)],
stmap[aut.aim_of(*aut_e)], series_elt);
}
}
/*-------.
| Domain |
`-------*/
template <typename S, typename S2, typename T, typename T2>
void
domain(const Element<S,T>& trans, Element<S2, T2>& res)
{
do_domain(trans.structure(), trans.structure().series().monoid(),
res.structure(), res.structure().series().monoid(), trans, res);
}
template <typename S, typename S2, typename T, typename T2>
Element<S2, T2>
domain(const Element<S,T>& trans)
{
typedef Element<S, T> trans_t;
typedef algebra::FreeMonoid<
typename trans_t::series_set_t::monoid_t::first_monoid_t> monoid_t;
typedef algebra::Series<typename trans_t::series_set_t::semiring_t,
monoid_t>
series_set_t;
monoid_t monoid
(trans.structure().series().monoid().first_monoid());
series_set_t series
(trans.structure().series().semiring(), monoid);
Automata<series_set_t> aut_set(series);
Element< Automata<series_set_t>, T> res(aut_set);
do_domain(trans.structure(), trans.structure().series().monoid(),
res.structure(), res.structure().series().monoid(), trans, res);
return res;
}
/*------.
| Image |
`------*/
template <typename S, typename S2, typename T, typename T2>
void
image(const Element<S,T>& trans, Element<S2, T2>& res)
{
do_image(trans.structure(), trans.structure().series().monoid(),
res.structure(), res.structure().series().monoid(), trans, res);
}
template <typename S, typename S2, typename T, typename T2>
Element<S2, T2>
image(const Element<S,T>& trans)
{
typedef Element<S, T> trans_t;
typedef algebra::FreeMonoid<
typename trans_t::series_set_t::monoid_t::second_monoid_t> monoid_t;
typedef algebra::Series<typename trans_t::series_set_t::semiring_t,
monoid_t>
series_set_t;
monoid_t monoid
(trans.structure().series().monoid().second_monoid());
series_set_t series
(trans.structure().series().semiring(), monoid);
Automata<series_set_t> aut_set(series);
Element< Automata<series_set_t>, T> res(aut_set);
do_image(trans.structure(), trans.structure().series().monoid(),
res.structure(), res.structure().series().monoid(), trans, res);
return res;
}
/*---------.
| Identity |
`---------*/