Commit cfa4c4d8 authored by Michaël Cadilhac's avatar Michaël Cadilhac
Browse files

2005-06-05 Michael Cadilhac <michael.cadilhac@lrde.epita.fr>

	* bootstrap.sh: Add the bootstrapping of bench files.

	* src/benchs: New. Bench suite directory.
	* src/benchs/generate_benchs.sh: New.   This script  generates .cc
	files associated  with _bench.hh files,  and creates corresponding
	Makefile.am's.
	* src/benchs/generate_all_benchs.sh:  New.   Wrapper    that  call
	generate_benchs.sh for all bench directories.
	
	* src/benchs/minimization_stroppa/minimization_bench_fsm.cc,
	* src/benchs/minimization_stroppa/usual.hxx,
	* src/benchs/minimization_stroppa/init.hh,
	* src/benchs/minimization_stroppa/fsm_minimize.hh,
	* src/benchs/minimization_stroppa/tools.hxx,
	* src/benchs/minimization_stroppa/data,
	* src/benchs/minimization_stroppa/init.hxx,
	* src/benchs/minimization_stroppa/Makefile.bench,
	* src/benchs/minimization_stroppa/minimization_bench_moore.cc,
	* src/benchs/minimization_stroppa/int_traits.hh,
	* src/benchs/minimization_stroppa/minimization_bench_hopcroft.cc,
	* src/benchs/minimization_stroppa/tools.hh,
	* src/benchs/minimization_stroppa/usual_ana_predefs.hh,
	* src/benchs/minimization_stroppa:   New.  A   minimization  bench
	thanks to Nicolas Stroppa.

	* src/benchs/determinization/determinization_bench.hh,
	* src/benchs/determinization/Makefile.bench,
	* src/benchs/determinization/determinization_bench_fsm.cc,
	* src/benchs/determinization: New. A  bench which determinize an n
	states automaton to a 2^n automaton.

	* src/benchs/minimization_2n/minimization_2n_moore_bench.hh,
	* src/benchs/minimization_2n/minimization_2n_hopcroft_bench.hh,
	* src/benchs/minimization_2n/Makefile.bench,
	* src/benchs/minimization_2n: New.  A   minimization bench  on the
	resulting automaton of the determinization previously described.

	* src/benchs/quotient/quotient_bench.hh,
	* src/benchs/quotient/Makefile.bench,
	* src/benchs/quotient: New. A quotient bench.
	
	* src/benchs/minimization_nd/minimization_nd_bench.hh,
	* src/benchs/minimization_nd/Makefile.bench,
	* src/benchs/minimization_nd:  New.  A  minimization bench  over a
	nondeterministic automaton.
	
	* src/benchs/minimization_debruijn/minimization_debruijn_moore_bench.hh,
	* src/benchs/minimization_debruijn/minimization_debruijn_hopcroft_bench.hh,
	* src/benchs/minimization_debruijn/Makefile.bench,
	* src/benchs/minimization_debruijn: New. A minimization bench over
	the De Bruijn automaton, thanks to Sylvain Lombardy.

	* src/benchs/derived_terms/derived_terms_dt_bench.hh,
	* src/benchs/derived_terms/derived_terms_so_bench.hh,
	* src/benchs/derived_terms/Makefile.bench,
	* src/benchs/derived_terms:  New. A bench  to compare consequences
	of the `derived terms' algorithm, and the `standard_of' one.

	* src/benchs/common/alpha.syms: New. Alpha mapping for FSM.
	* src/benchs/common/algorithm.hh: New. Algorithm used in benchs.
	* src/benchs/common/bench_automaton.hh: New. The `bench_automaton'
	is   a   light    automaton   with   `label_are_letters'   and   a
	`small_alpha_letter'.
	* src/benchs/common/bench_constructs.hh:   New.   Basic  automaton
	constructions used in the benchs.
	* src/benchs/common/Makefile.flags,
	* src/benchs/common/Makefile.am,
	* src/benchs/common: New.
	
	* src/benchs/Makefile.am: New. Define a `bench' rule and subdirs.
	* src/Makefile.am: Add `bench' as a subdir.
	* configure.ac: Add Makefiles in src/bench to be generated.
	* Makefile.am: Add a `bench' rule.
parent 468a0c23
2005-06-05 Michael Cadilhac <michael.cadilhac@lrde.epita.fr>
* bootstrap.sh: Add the bootstrapping of bench files.
* src/benchs: New. Bench suite directory.
* src/benchs/generate_benchs.sh: New. This script generates .cc
files associated with _bench.hh files, and creates corresponding
Makefile.am's.
* src/benchs/generate_all_benchs.sh: New. Wrapper that call
generate_benchs.sh for all bench directories.
* src/benchs/minimization_stroppa/minimization_bench_fsm.cc,
* src/benchs/minimization_stroppa/usual.hxx,
* src/benchs/minimization_stroppa/init.hh,
* src/benchs/minimization_stroppa/fsm_minimize.hh,
* src/benchs/minimization_stroppa/tools.hxx,
* src/benchs/minimization_stroppa/data,
* src/benchs/minimization_stroppa/init.hxx,
* src/benchs/minimization_stroppa/Makefile.bench,
* src/benchs/minimization_stroppa/minimization_bench_moore.cc,
* src/benchs/minimization_stroppa/int_traits.hh,
* src/benchs/minimization_stroppa/minimization_bench_hopcroft.cc,
* src/benchs/minimization_stroppa/tools.hh,
* src/benchs/minimization_stroppa/usual_ana_predefs.hh,
* src/benchs/minimization_stroppa: New. A minimization bench
thanks to Nicolas Stroppa.
* src/benchs/determinization/determinization_bench.hh,
* src/benchs/determinization/Makefile.bench,
* src/benchs/determinization/determinization_bench_fsm.cc,
* src/benchs/determinization: New. A bench which determinize an n
states automaton to a 2^n automaton.
* src/benchs/minimization_2n/minimization_2n_moore_bench.hh,
* src/benchs/minimization_2n/minimization_2n_hopcroft_bench.hh,
* src/benchs/minimization_2n/Makefile.bench,
* src/benchs/minimization_2n: New. A minimization bench on the
resulting automaton of the determinization previously described.
* src/benchs/quotient/quotient_bench.hh,
* src/benchs/quotient/Makefile.bench,
* src/benchs/quotient: New. A quotient bench.
* src/benchs/minimization_nd/minimization_nd_bench.hh,
* src/benchs/minimization_nd/Makefile.bench,
* src/benchs/minimization_nd: New. A minimization bench over a
nondeterministic automaton.
* src/benchs/minimization_debruijn/minimization_debruijn_moore_bench.hh,
* src/benchs/minimization_debruijn/minimization_debruijn_hopcroft_bench.hh,
* src/benchs/minimization_debruijn/Makefile.bench,
* src/benchs/minimization_debruijn: New. A minimization bench over
the De Bruijn automaton, thanks to Sylvain Lombardy.
* src/benchs/derived_terms/derived_terms_dt_bench.hh,
* src/benchs/derived_terms/derived_terms_so_bench.hh,
* src/benchs/derived_terms/Makefile.bench,
* src/benchs/derived_terms: New. A bench to compare consequences
of the `derived terms' algorithm, and the `standard_of' one.
* src/benchs/common/alpha.syms: New. Alpha mapping for FSM.
* src/benchs/common/algorithm.hh: New. Algorithm used in benchs.
* src/benchs/common/bench_automaton.hh: New. The `bench_automaton'
is a light automaton with `label_are_letters' and a
`small_alpha_letter'.
* src/benchs/common/bench_constructs.hh: New. Basic automaton
constructions used in the benchs.
* src/benchs/common/Makefile.flags,
* src/benchs/common/Makefile.am,
* src/benchs/common: New.
* src/benchs/Makefile.am: New. Define a `bench' rule and subdirs.
* src/Makefile.am: Add `bench' as a subdir.
* configure.ac: Add Makefiles in src/bench to be generated.
* Makefile.am: Add a `bench' rule.
2005-06-05 Michael Cadilhac <michael.cadilhac@lrde.epita.fr>
 
* include/vaucanson/tools/bencher.hh: Add macros to bench silently
......
......@@ -18,6 +18,12 @@ CONFIGURE_DEPENDENCIES = $(srcdir)/config/vcsn.m4 $(srcdir)/config/vaucanson_xml
m4datadir = $(datadir)/aclocal
dist_m4data_DATA = config/vcsn.m4 config/vaucanson_xml.m4
###
### For benchs.
###
bench:
cd $(srcdir)/src/benchs && make bench
###
### Check headers for sanity.
###
......
......@@ -10,6 +10,7 @@ fi
(cd src/tests/test-suites && /bin/sh ./generate-all.sh)
(cd src/tests/sanity && /bin/sh ./generate_files.sh .)
(cd src/demos/vaucanswig && /bin/sh ./expand.sh .)
(cd src/benchs && /bin/sh ./generate_all_benchs.sh)
./find_tests.sh
$AUTORECONF -v -f -i
......
......@@ -155,6 +155,15 @@ AC_CONFIG_FILES([
src/demos/samples/algorithms/Makefile
src/demos/xml/Makefile
src/demos/xml/samples/Makefile
src/benchs/Makefile
src/benchs/common/Makefile
src/benchs/determinization/Makefile
src/benchs/minimization_debruijn/Makefile
src/benchs/minimization_stroppa/Makefile
src/benchs/minimization_2n/Makefile
src/benchs/minimization_nd/Makefile
src/benchs/quotient/Makefile
src/benchs/derived_terms/Makefile
doc/Makefile
doc/tutorial/Makefile
doc/beginner/Makefile
......
......@@ -3,4 +3,4 @@
#
# $Id$
SUBDIRS = tests demos
SUBDIRS = benchs tests demos
SUBDIRS = common determinization minimization_stroppa \
minimization_debruijn minimization_2n derived_terms \
quotient minimization_nd
BENCHDIRS = determinization minimzation_stroppa \
minimization_debruijn derived_terms minimization_2n \
quotient minimization_nd
bench:
for f in $(BENCHDIRS); do \
(cd $$f && make bench) \
done
EXTRA_DIST = algorithm.hh alpha.syms bench_automaton.hh \
bench_constructs.hh Makefile.flags
test:
echo hella
# Makefile.flags -*- Makefile -*-
# $Id$
AM_CXXFLAGS = $(CXXFLAGS_STRICT)
AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src/benchs \
-I$(top_builddir)/include -I$(top_builddir)/src/bench
AM_CPPFLAGS += $(INCLUDES)
AM_CPPFLAGS += -DEXCEPTION_TRAPS
AM_CPPFLAGS += -DVCSN_SRC_DIR=\"'\$(top_srcdir)'\"
AM_CPPFLAGS += -DNDEBUG -O3 -DVCSN_BENCH
#ifndef ALGORITHM_HH
# define ALGORITHM_HH
template <typename St, typename auto_t>
void fsm_dump(St& out, const auto_t& a)
{
AUTOMATON_TYPES(auto_t);
typename auto_t::initial_iterator initial = a.initial().begin();
std::set<hedge_t> succ;
a.deltac(succ, *initial, delta_kind::edges());
for_all_const_(std::set<hedge_t>, e, succ)
out << *initial << "\t" << a.aim_of(*e) << "\t"
<< a.series_of(*e) << "\t 0"
<< std::endl;
for_each_state(s, a)
if (!a.is_initial(*s))
{
succ.clear();
a.deltac(succ, *s, delta_kind::edges());
for_all_const_(std::set<hedge_t>, e, succ)
out << *s << "\t" << a.aim_of(*e) << "\t"
<< a.series_of(*e) << "\t 0"
<< std::endl;
}
for_each_final_state(f, a)
out << *f << "\t 0" << std::endl;
}
#endif
A 1
B 2
C 3
D 4
E 5
F 6
G 7
H 8
I 9
J 10
K 11
L 12
M 13
N 14
O 15
P 16
Q 17
R 18
S 19
T 20
U 21
V 22
W 23
X 24
Y 25
Z 26
a 27
b 28
c 29
d 30
e 31
f 32
g 33
h 34
i 35
j 36
k 37
l 38
m 39
n 40
o 41
p 42
q 43
r 44
s 45
t 46
u 47
v 48
w 49
x 50
y 51
z 52
- 53
_ 54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
' 69
70
71
72
73
74
75
. 76
#ifndef BENCH_AUTOMATON_HH
# define BENCH_AUTOMATON_HH
#include <vaucanson/boolean_automaton.hh>
#include <vaucanson/algebra/implementation/predefs.hh>
namespace vcsn {
namespace bench_automaton {
using namespace vcsn;
using namespace vcsn::algebra;
using namespace vcsn::algebra::small_alpha_letter;
typedef polynom<WordValue, bool> series_set_elt_value_t;
typedef Series<NumericalSemiring, Words> series_set_t;
typedef Graph
<
labels_are_letters,
WordValue,
bool,
series_set_elt_value_t,
char,
NoTag>
automaton_impl_t;
typedef Element<Automata<series_set_t>, automaton_impl_t>
automaton_t;
AUTOMATON_TYPES_EXACT(automaton_t);
AUTOMATON_FREEMONOID_TYPES_EXACT(automaton_t);
template <class T>
automaton_t new_automaton(const T& alphabet);
template <class InputIterator>
automaton_t new_automaton(InputIterator begin,
InputIterator end);
template <class InputIterator>
automata_set_t new_automata_set(InputIterator begin,
InputIterator end)
{
alphabet_t alpha;
for (InputIterator e = begin; e != end; ++e)
alpha.insert(*e);
semiring_t semiring;
monoid_t freemonoid (alpha);
series_set_t series (semiring, freemonoid);
return automata_set_t (series);
}
template <class InputIterator>
automaton_t new_automaton(InputIterator begin,
InputIterator end)
{
return automaton_t (new_automata_set(begin, end));
}
template <class T>
automaton_t new_automaton(const T& alphabet)
{
return new_automaton(alphabet.begin(), alphabet.end());
}
} // bench_automaton
} // vcsn
#endif
#ifndef BENCH_CONSTRUCTS_HH
# define BENCH_CONSTRUCTS_HH
/// Create a nice automaton which will have 2^n states once determinized.
void aut_2n(unsigned n, automaton_t& a)
{
std::vector<hstate_t> c(n);
for (unsigned i = 0; i < n; ++i)
c[i] = a.add_state();
for (unsigned i = 0; i < n - 1; ++i)
a.add_letter_edge(c[i], c[i+1], 'a');
a.add_letter_edge(c[n-1], c[0], 'a');
for (unsigned i = 1; i < n; ++i)
{
a.add_letter_edge(c[i], c[i], 'b');
a.add_letter_edge(c[i], c[i], 'c');
a.add_letter_edge(c[i], c[0], 'b');
}
a.set_initial(c[0]);
a.set_final(c[0]);
}
void debruijn(unsigned n_value, automaton_t& an)
{
unsigned n = 1 << n_value;
for (unsigned i = 0; i < n; ++i)
an.add_state();
an.set_initial(0);
for (unsigned i = 0; i < n; ++i)
{
an.add_letter_edge(i, (i*2)%n, 'a');
an.add_letter_edge(i, (i*2+1)%n, 'b');
if ((i << 1) & n)
an.set_final(i);
}
}
void binary(automaton_t& an)
{
std::vector<hstate_t> c(2);
c[0] = an.add_state();
c[1] = an.add_state();
an.set_initial(c[0]);
an.set_final(c[1]);
an.add_letter_edge(c[0], c[0], 'a');
an.add_letter_edge(c[0], c[0], 'b');
an.add_letter_edge(c[0], c[1], 'b');
an.add_letter_edge(c[1], c[1], 'a');
an.add_letter_edge(c[1], c[1], 'a');
an.add_letter_edge(c[1], c[1], 'b');
an.add_letter_edge(c[1], c[1], 'b');
}
#endif
# derived_terms/Makefile.bench * -*- Makefile -*-
bench: $(noinst_PROGRAMS)
@echo '====================='; \
echo '|Derived Terms bench|'; \
echo '====================='; \
for n_states in $$(seq 3 3); do \
echo "----------------------For $$n_states states"; \
echo "--------------VCSN (standard_of):"; \
./derived_terms_so-bench $$n_states; \
echo "--------------VCSN (derived_terms):"; \
./derived_terms_dt-bench $$n_states; \
done
#include <vaucanson/boolean_automaton.hh>
#include <vaucanson/algorithms/minimization_hopcroft.hh>
#include <vaucanson/algorithms/determinize.hh>
#include <vaucanson/algorithms/derivatives_automaton.hh>
#include <vaucanson/algebra/implementation/series/krat.hh>
#include <vaucanson/algorithms/aut_to_exp.hh>
#include <iostream>
#include <fstream>
using namespace vcsn;
using namespace vcsn::tools;
using namespace vcsn::boolean_automaton;
#include <common/bench_constructs.hh>
void derived_terms_dt_bench(int n_states)
{
AUTOMATON_TYPES_EXACT(automaton_t);
AUTOMATON_FREEMONOID_TYPES_EXACT(automaton_t);
alphabet_t alpha;
alpha.insert('a');
alpha.insert('b');
alpha.insert('c');
typedef vcsn::rat::exp<monoid_elt_value_t, semiring_elt_value_t> exp_t;
typedef vcsn::Element<series_set_t, exp_t> krat_t;
automaton_t a = new_automaton(alpha);
aut_2n(n_states, a);
krat_t e = aut_to_exp(a);
VCSN_BENCH_START;
std::cout << "derivatives_automaton:" << std::endl;
VCSN_BENCH_START;
derivatives_automaton(a, e);
VCSN_BENCH_STOP_AND_PRINT;
std::cout << "determinize:" << std::endl;
VCSN_BENCH_START;
a = determinize(a);
VCSN_BENCH_STOP_AND_PRINT;
std::cout << "minimization_hopcroft:" << std::endl;
VCSN_BENCH_START;
a = minimization_hopcroft(a);
VCSN_BENCH_STOP_AND_PRINT;
VCSN_BENCH_STOP_AND_PRINT;
}
#include <vaucanson/boolean_automaton.hh>
#include <vaucanson/algorithms/minimization_hopcroft.hh>
#include <vaucanson/algorithms/determinize.hh>
#include <vaucanson/algorithms/standard_of.hh>
#include <vaucanson/algebra/implementation/series/krat.hh>
#include <vaucanson/algorithms/aut_to_exp.hh>
#include <iostream>
#include <fstream>
using namespace vcsn;
using namespace vcsn::tools;
using namespace vcsn::boolean_automaton;
#include <common/bench_constructs.hh>
void derived_terms_so_bench(int n_states)
{
AUTOMATON_TYPES_EXACT(automaton_t);
AUTOMATON_FREEMONOID_TYPES_EXACT(automaton_t);
alphabet_t alpha;
alpha.insert('a');
alpha.insert('b');
alpha.insert('c');
typedef vcsn::rat::exp<monoid_elt_value_t, semiring_elt_value_t> exp_t;
typedef vcsn::Element<series_set_t, exp_t> krat_t;
automaton_t a = new_automaton(alpha);
aut_2n(n_states, a);
krat_t e = aut_to_exp(a);
VCSN_BENCH_START;
std::cout << "standard_of:" << std::endl;
VCSN_BENCH_START;
a = standard_of(e);
VCSN_BENCH_STOP_AND_PRINT;
std::cout << "determinize:" << std::endl;
VCSN_BENCH_START;
a = determinize(a);
VCSN_BENCH_STOP_AND_PRINT;
std::cout << "minimization_hopcroft:" << std::endl;
VCSN_BENCH_START;
a = minimization_hopcroft(a);
VCSN_BENCH_STOP_AND_PRINT;
VCSN_BENCH_STOP_AND_PRINT;
}
# determinization/Makefile.bench * -*- Makefile -*-
noinst_PROGRAMS += determinization_bench_fsm
determinization_bench_fsm_SOURCES = determinization_bench_fsm.cc
bench: $(noinst_PROGRAMS)
@echo '======================='; \
echo '|Determinization bench|'; \
echo '======================='; \
echo "./determinization_bench_fsm \$1 | $$FSM_PATH/fsmcompile |"\
"$$FSM_PATH/fsmdeterminize > /dev/null" > tmp.det; \
for n_states in $$(seq 5 6); do \
echo "----------------------For $$n_states states"; \
echo "--------------VCSN:"; \
./determinization-bench $$n_states; \
if [ ! -z "$$FSM_PATH" ]; then \
echo "--------------FSM:"; \
time sh tmp.det $$n_states; \
fi; \
done; \
rm -f tmp.det
#include <common/bench_automaton.hh>
#include <vaucanson/algorithms/determinize.hh>
#include <iostream>
using namespace vcsn;
using namespace vcsn::tools;
using namespace vcsn::bench_automaton;
#include <common/bench_constructs.hh>
void determinization_bench(int n_states)
{
if (not n_states)
return;
AUTOMATON_TYPES_EXACT(automaton_t);
alphabet_t alpha;
alpha.insert('a');
alpha.insert('b');
alpha.insert('c');
automaton_t a = new_automaton(alpha);
aut_2n(n_states, a);
VCSN_BENCH_START;
automaton_t ret = determinize(a);
VCSN_BENCH_STOP_AND_PRINT;
}
#include <iostream>
#include <cstdlib>
int main(int argc, char** argv)
{
unsigned n = atoi(argv[1]);
for (unsigned i = 1; i < n; ++i)
{
std::cout << i - 1 << " " << i << " 1" << std::endl;
std::cout << i << " " << i << " 2" << std::endl;
std::cout << i << " " << i << " 3" << std::endl;
std::cout << i << " " << 0 << " 2" << std::endl;
}
std::cout << n-1 << " " << 0 << " 1" << std::endl;
std::cout << 0 << std::endl;
}
#!/bin/sh
./generate_benchs.sh determinization minimization_stroppa \
minimization_debruijn derived_terms minimization_2n \
quotient minimization_nd
#!/bin/sh
if [ $# -eq 0 ]; then
echo 'usage:'
echo 'create_benchs.sh bench_dirs'
exit 1
fi
BENCH_DIRS=$@
ALL_BENCH=''
# Go through all benchs
for BENCH_DIR in $BENCH_DIRS; do
# Initialize Makefile.am.
cat > $BENCH_DIR/Makefile.am <<EOF
include \$(top_srcdir)/src/benchs/common/Makefile.flags
noinst_PROGRAMS =
EOF
for BENCH in $(ls $BENCH_DIR/*_bench.hh 2> /dev/null); do
BENCH_HEADER="$(basename $BENCH)"
BENCH_NAME="$(echo $BENCH_HEADER | sed 's/_bench\.hh$//')"
# Claim that we are under LGPL.
cat > $BENCH_DIR/$BENCH_NAME-bench.cc <<EOF