Commit a2ee5820 authored by Alexandre Duret-Lutz's avatar Alexandre Duret-Lutz
Browse files

Implement w-image and w-domain.

* include/vaucanson/algorithms/image.hxx,
include/vaucanson/algorithms/image.hh (image): Add an optional
parameter to keep the weights.
* include/vaucanson/algorithms/domain.hxx,
include/vaucanson/algorithms/domain.hh (domain): Likewise.
(do_fmp_weighted_domain): Remove this copy of do_fmp_domain()
which now has a Boolean parameter to decide what to do with
weights.
* taf-kit/src/cmd_fmp.cc (image, domain): Remove weights.
(w_image, w_domain): New commands that keep weights.
* taf-kit/tests/vcsn-int-fmp-z.test: Adjust test.
parent b4c2a94e
2011-09-13 Alexandre Duret-Lutz <adl@lrde.epita.fr>
Implement w-image and w-domain.
* include/vaucanson/algorithms/image.hxx,
include/vaucanson/algorithms/image.hh (image): Add an optional
parameter to keep the weights.
* include/vaucanson/algorithms/domain.hxx,
include/vaucanson/algorithms/domain.hh (domain): Likewise.
(do_fmp_weighted_domain): Remove this copy of do_fmp_domain()
which now has a Boolean parameter to decide what to do with
weights.
* taf-kit/src/cmd_fmp.cc (image, domain): Remove weights.
(w_image, w_domain): New commands that keep weights.
* taf-kit/tests/vcsn-int-fmp-z.test: Adjust test.
2011-09-13 Alexandre Duret-Lutz <adl@lrde.epita.fr>
 
The input of evaluation_fmp should be subnormalized.
......
......@@ -2,7 +2,7 @@
//
// Vaucanson, a generic library for finite state machines.
//
// Copyright (C) 2006, 2008 The Vaucanson Group.
// Copyright (C) 2006, 2008, 2011 The Vaucanson Group.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
......@@ -27,7 +27,7 @@
*/
/** @} */
// INTERFACE: void domain(const Automaton& a1, InputProjection& a2) { return vcsn::domain(*a1, *a2); }
// INTERFACE: void domain(const Automaton& a1, InputProjection& a2, bool w) { return vcsn::domain(*a1, *a2); }
# include <vaucanson/automata/concept/automata.hh>
# include <vaucanson/algebra/concept/freemonoid_product.hh>
......@@ -48,7 +48,7 @@ namespace vcsn
template <typename S, typename S2, typename T, typename T2>
void
domain(const Element<S,T>& src, Element<S2, T2>& dst);
domain(const Element<S,T>& src, Element<S2, T2>& dst, bool weighted = true);
// FMP version of domain.
template <typename src_t, typename dst_t>
......
......@@ -2,7 +2,7 @@
//
// Vaucanson, a generic library for finite state machines.
//
// Copyright (C) 2006 The Vaucanson Group.
// Copyright (C) 2006, 2011 The Vaucanson Group.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
......@@ -28,7 +28,7 @@ namespace vcsn
template <typename src_t, typename dst_t>
void
do_fmp_domain(const src_t& input, dst_t& dst)
do_fmp_domain(const src_t& src, dst_t& dst, bool weighted)
{
BENCH_TASK_SCOPED("fmp_domain");
AUTOMATON_TYPES_(src_t, trans_);
......@@ -37,141 +37,66 @@ namespace vcsn
typedef typename trans_series_set_elt_t::support_t trans_support_t;
std::map<trans_hstate_t, hstate_t> stmap;
const series_set_t& series = dst.structure().series();
const monoid_t& monoid = dst.structure().series().monoid();
const trans_monoid_t& trans_monoid =
input.structure().series().monoid();
const semiring_elt_t& unit = input.structure().series().semiring().wone_;
const series_set_t& series = dst.structure().series();
const monoid_t& monoid = dst.structure().series().monoid();
const trans_monoid_t& trans_monoid = src.structure().series().monoid();
const semiring_elt_t& unit = src.structure().series().semiring().wone_;
src_t src=cut_up(input);
for_all_const_states(fmp_s, src)
{
hstate_t s = dst.add_state();
stmap[*fmp_s] = s;
if (src.is_initial(*fmp_s))
{
const trans_series_set_elt_t trans_series_elt =
src.get_initial(*fmp_s);
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), unit);
dst.set_initial(s, series_elt);
}
if (src.is_final(*fmp_s))
{
const trans_series_set_elt_t trans_series_elt =
src.get_final(*fmp_s);
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), unit);
dst.set_final(s, series_elt);
}
}
for_all_const_transitions_(trans_, fmp_e, src)
{
const trans_series_set_elt_t trans_series_elt =
src.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), unit);
dst.add_series_transition(stmap[src.src_of(*fmp_e)],
stmap[src.dst_of(*fmp_e)], series_elt);
}
}
template <typename src_t, typename dst_t>
void
do_fmp_weighted_domain(const src_t& src, dst_t& dst)
{
BENCH_TASK_SCOPED("fmp_domain");
AUTOMATON_TYPES_(src_t, trans_);
AUTOMATON_TYPES(dst_t);
typedef typename trans_series_set_elt_t::support_t trans_support_t;
std::map<trans_hstate_t, hstate_t> stmap;
const series_set_t& series = dst.structure().series();
const monoid_t& monoid = dst.structure().series().monoid();
const trans_monoid_t& trans_monoid =
src.structure().series().monoid();
for_all_const_states(fmp_s, src)
for_all_const_states(fmp_s, src)
{
hstate_t s = dst.add_state();
stmap[*fmp_s] = s;
if (src.is_initial(*fmp_s))
{
const trans_series_set_elt_t trans_series_elt =
src.get_initial(*fmp_s);
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));
dst.set_initial(s, series_elt);
}
{
const trans_series_set_elt_t trans_series_elt =
src.get_initial(*fmp_s);
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),
weighted ?
trans_series_elt.get(trans_monoid_elt) : unit);
dst.set_initial(s, series_elt);
}
if (src.is_final(*fmp_s))
{
const trans_series_set_elt_t trans_series_elt =
src.get_final(*fmp_s);
trans_support_t trans_supp = trans_series_elt.supp();
const trans_monoid_elt_t trans_monoid_elt
(trans_monoid, *(trans_supp.begin()));
{
const trans_series_set_elt_t trans_series_elt =
src.get_final(*fmp_s);
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);
const monoid_elt_value_t word(trans_monoid_elt.value().first);
series_set_elt_t series_elt(series);
series_set_elt_t series_elt(series);
series_elt.assoc(monoid_elt_t(monoid, word),
trans_series_elt.get(trans_monoid_elt));
series_elt.assoc(monoid_elt_t(monoid, word),
weighted ?
trans_series_elt.get(trans_monoid_elt) : unit);
dst.set_final(s, series_elt);
}
dst.set_final(s, series_elt);
}
}
for_all_const_transitions_(trans_, fmp_e, src)
{
const trans_series_set_elt_t trans_series_elt =
src.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);
const trans_series_set_elt_t trans_series_elt = src.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_set_elt_t series_elt(series);
series_elt.assoc(monoid_elt_t(monoid, word),
trans_series_elt.get(trans_monoid_elt));
weighted ? trans_series_elt.get(trans_monoid_elt)
: unit);
dst.add_series_transition(stmap[src.src_of(*fmp_e)],
stmap[src.dst_of(*fmp_e)], series_elt);
......@@ -219,23 +144,23 @@ namespace vcsn
template <typename S, typename S2, typename T, typename T2>
void
domain_dispatch(const AutomataBase<S>&, const Element<S,T>& src, Element<S2, T2>& dst)
domain_dispatch(const AutomataBase<S>&, const Element<S,T>& src, Element<S2, T2>& dst, bool weighted)
{
do_fmp_domain(src, dst);
do_fmp_domain(src, dst, weighted);
}
template <typename S, typename S2, typename T, typename T2>
void
domain_dispatch(const TransducerBase<S>&, const Element<S,T>& src, Element<S2, T2>& dst)
domain_dispatch(const TransducerBase<S>&, const Element<S,T>& src, Element<S2, T2>& dst, bool)
{
do_rw_domain(src, dst);
}
template <typename S, typename S2, typename T, typename T2>
void
domain(const Element<S,T>& src, Element<S2, T2>& dst)
domain(const Element<S,T>& src, Element<S2, T2>& dst, bool weighted)
{
domain_dispatch(src.structure(), src, dst);
domain_dispatch(src.structure(), src, dst, weighted);
}
} // End of namespace vcsn.
......
......@@ -2,7 +2,7 @@
//
// Vaucanson, a generic library for finite state machines.
//
// Copyright (C) 2006 The Vaucanson Group.
// Copyright (C) 2006, 2011 The Vaucanson Group.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
......@@ -28,7 +28,7 @@
*/
/** @} */
// INTERFACE: void image(const Automaton& a, OutputProjection& b) { return vcsn::image(*a, *b); }
// INTERFACE: void image(const Automaton& a, OutputProjection& b, bool w) { return vcsn::image(*a, *b, w); }
# include <map>
......@@ -46,7 +46,9 @@ namespace vcsn
template <typename S, typename T>
void
image(const Element<S, T>& aut, typename output_projection_helper<S, T>::ret& res);
image(const Element<S, T>& aut,
typename output_projection_helper<S, T>::ret& res,
bool weighted = true);
template <class S, class T>
typename output_projection_helper<S, T>::ret
......
......@@ -2,7 +2,7 @@
//
// Vaucanson, a generic library for finite state machines.
//
// Copyright (C) 2006, 2008 The Vaucanson Group.
// Copyright (C) 2006, 2008, 2011 The Vaucanson Group.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
......@@ -19,13 +19,14 @@
# define VCSN_ALGORITHMS_IMAGE_HXX
# include <vaucanson/algorithms/image.hh>
# include <vaucanson/algorithms/cut_up.hh>
# include <vaucanson/algorithms/projection.hh>
namespace vcsn
{
template <typename auto_t, typename trans_t>
static void
do_fmp_image(const trans_t& fmp_trans, auto_t& res)
do_fmp_image(const trans_t& fmp_trans, auto_t& res, bool weighted)
{
BENCH_TASK_SCOPED("image");
AUTOMATON_TYPES_(trans_t, trans_);
......@@ -34,74 +35,76 @@ namespace vcsn
typedef typename trans_series_set_elt_t::support_t trans_support_t;
std::map<trans_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 =
const series_set_t& series = res.structure().series();
const monoid_t& monoid = res.structure().series().monoid();
const semiring_elt_t& unit = res.structure().series().semiring().wone_;
const trans_monoid_t& trans_monoid =
fmp_trans.structure().series().monoid();
for_all_const_states(fmp_s, fmp_trans)
{
hstate_t s = res.add_state();
stmap[*fmp_s] = s;
if (fmp_trans.is_initial(*fmp_s))
for_all_const_states(fmp_s, fmp_trans)
{
const trans_series_set_elt_t trans_series_elt =
fmp_trans.get_initial(*fmp_s);
trans_support_t trans_supp = trans_series_elt.supp();
const trans_monoid_elt_t trans_monoid_elt
(trans_monoid, *(trans_supp.begin()));
hstate_t s = res.add_state();
stmap[*fmp_s] = s;
const monoid_elt_value_t word(trans_monoid_elt.value().second);
if (fmp_trans.is_initial(*fmp_s))
{
const trans_series_set_elt_t trans_series_elt =
fmp_trans.get_initial(*fmp_s);
trans_support_t trans_supp = trans_series_elt.supp();
const trans_monoid_elt_t trans_monoid_elt(trans_monoid,
*(trans_supp.begin()));
series_set_elt_t series_elt(series);
const monoid_elt_value_t word(trans_monoid_elt.value().second);
series_elt.assoc(monoid_elt_t(monoid, word),
trans_series_elt.get(trans_monoid_elt));
series_set_elt_t series_elt(series);
res.set_initial(s, series_elt);
}
if (fmp_trans.is_final(*fmp_s))
{
const trans_series_set_elt_t trans_series_elt =
fmp_trans.get_final(*fmp_s);
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));
series_elt.assoc(monoid_elt_t(monoid, word),
weighted ?
trans_series_elt.get(trans_monoid_elt) : unit);
res.set_initial(s, series_elt);
}
if (fmp_trans.is_final(*fmp_s))
{
const trans_series_set_elt_t trans_series_elt =
fmp_trans.get_final(*fmp_s);
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),
weighted ? trans_series_elt.get(trans_monoid_elt)
: unit);
res.set_final(s, series_elt);
}
}
}
for_all_const_transitions_(trans_, 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 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);
const monoid_elt_value_t word(trans_monoid_elt.value().second);
series_set_elt_t series_elt(series);
series_set_elt_t series_elt(series);
series_elt.assoc(monoid_elt_t(monoid, word),
trans_series_elt.get(trans_monoid_elt));
series_elt.assoc(monoid_elt_t(monoid, word),
weighted ? trans_series_elt.get(trans_monoid_elt)
: unit);
res.add_series_transition(stmap[fmp_trans.src_of(*fmp_e)],
stmap[fmp_trans.dst_of(*fmp_e)], series_elt);
}
res.add_series_transition(stmap[fmp_trans.src_of(*fmp_e)],
stmap[fmp_trans.dst_of(*fmp_e)], series_elt);
}
}
template<typename Trans_t, typename Auto_t>
static void
do_rw_image(const Trans_t& t,
......@@ -202,7 +205,7 @@ namespace vcsn
image_dispatch(const Element<S,T>& src,
const TransducerBase<ST>&,
const algebra::FreeMonoidBase<M1>&,
Element<S2, T2>& dst)
Element<S2, T2>& dst, bool)
{
do_rw_image(src, dst);
}
......@@ -248,7 +251,7 @@ namespace vcsn
output_projection_helper<S, T>::make_output_projection_automaton(src);
image_dispatch(src, src.structure(),
src.structure().series().monoid(), dst);
src.structure().series().monoid(), dst, true);
return dst;
}
......@@ -260,24 +263,24 @@ namespace vcsn
image_dispatch(const Element<S,T>& src,
const AutomataBase<ST>&,
const algebra::FreeMonoidProductBase<M1>&,
Element<S2, T2>& dst)
Element<S2, T2>& dst, bool weighted)
{
do_fmp_image(src, dst);
do_fmp_image(src, dst, weighted);
}
/*---------------.
| IMAGE FACADES. |
`---------------*/
template <typename S, typename T>
void
image(const Element<S, T>& src, typename output_projection_helper<S, T>::ret& dst)
image(const Element<S, T>& src,
typename output_projection_helper<S, T>::ret& dst,
bool weighted)
{
image_dispatch(src, src.structure(),
src.structure().series().monoid(),
dst);
dst, weighted);
}
template <typename S, typename T>
......
......@@ -157,7 +157,21 @@ domain_command(const arguments_t& args)
(src.structure().series().monoid().first_monoid().alphabet(),
*(src.structure().series().monoid().first_monoid().representation()),
src.structure().series().representation()->first_representation());
domain(src, a);
domain(src, a, false);
g_res.keep(a);
return 0;
}
static int
w_domain_command(const arguments_t& args)
{
automaton_t src = get_aut(args, 1);
IOAUT_CONTEXT::automaton_t a =
IOAUT_CONTEXT::make_automaton
(src.structure().series().monoid().first_monoid().alphabet(),
*(src.structure().series().monoid().first_monoid().representation()),
src.structure().series().representation()->first_representation());
domain(src, a, true);
g_res.keep(a);
return 0;
}
......@@ -171,7 +185,21 @@ image_command(const arguments_t& args)
(src.structure().series().monoid().second_monoid().alphabet(),
*(src.structure().series().monoid().second_monoid().representation()),
src.structure().series().representation()->second_representation());
image(src, a);
image(src, a, false);
g_res.keep(a);
return 0;
}
static int
w_image_command(const arguments_t& args)
{
automaton_t src = get_aut(args, 1);
IOAUT_CONTEXT::automaton_t a =
IOAUT_CONTEXT::make_automaton
(src.structure().series().monoid().second_monoid().alphabet(),
*(src.structure().series().monoid().second_monoid().representation()),
src.structure().series().representation()->second_representation());
image(src, a, true);
g_res.keep(a);
return 0;
}
......@@ -253,9 +281,13 @@ COMMAND_ENTRY(composition_R, AutAut,
"Compose two transducers, preserving the number of paths.");
COMMAND_ENTRY(domain, Aut,
"Give the automaton that accepts all inputs accepted by `aut'.");
"Give an automaton that accepts all inputs accepted by `aut'.");
COMMAND_ENTRY(w_domain, Aut,
"Give a weighted automaton that accepts all inputs accepted by `aut'.");
COMMAND_ENTRY(image, Aut,
"Give an automaton that accepts all output produced by `aut'.");
COMMAND_ENTRY(w_image, Aut,
"Give a weighted automaton that accepts all output produced by `aut'.");
COMMAND_ENTRY(evaluation, AutAut,
"Evaluate the language described by the "
IOAUT_NAME " automaton `aut2' on the transducer `aut1'.");
......
......@@ -77,7 +77,7 @@ res=`$VCSN eval xs.xml 10#11.11#10.11`
res=`vcsn-int-z expand --alphabet=20,22 "$res"`
test "x$res" = "x{150} 22#22#20#22"
res=`$VCSN image x.xml | vcsn-int-z aut-to-exp-DM -`
res=`$VCSN w-image x.xml | vcsn-int-z aut-to-exp-DM -`
res=`vcsn-int-z expand --alphabet=22,20 "$res"`
test "x$res" = "x{30} (({5} 22#22#20)*.22)"
......
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