Commit a4068a53 authored by Alexandre Duret-Lutz's avatar Alexandre Duret-Lutz

Initial commit

parents
*~
build-aux/
*.in
aclocal.m4
autom4te.cache
config.log
config.status
configure
Makefile
*.o
\#*#
.#*
.deps
# Vaucanson 2, a generic library for finite state machines.
# Copyright (C) 2012 Vaucanson Group.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# The complete GNU General Public Licence Notice can be found as the
# `COPYING' file in the root directory.
#
# The Vaucanson Group consists of people listed in the `AUTHORS' file.
ACLOCAL_AMFLAGS = -I m4
SUBDIRS = vcsn tests
# Vaucanson 2, a generic library for finite state machines.
# Copyright (C) 2012 Vaucanson Group.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# The complete GNU General Public Licence Notice can be found as the
# `COPYING' file in the root directory.
#
# The Vaucanson Group consists of people listed in the `AUTHORS' file.
m4_pattern_forbid([^VCSN_])
# VCSN_HEADER
AC_PREREQ([2.61])
AC_INIT([vaucanson], [2.0a], [vaucanson-bugs@lrde.epita.fr])
AC_CONFIG_AUX_DIR([build-aux])
AM_INIT_AUTOMAKE([1.11 tar-ustar no-define foreign dist-xz color-tests parallel-tests])
AC_PROG_CC
AC_PROG_CXX
AC_LANG(C++)
AX_CHECK_COMPILE_FLAG([-std=c++11],
[stdfailed=false CXXFLAGS="$CXXFLAGS -std=c++11"])
if test "${stdfailed-true}"; then
AX_CHECK_COMPILE_FLAG([-std=c++0x],
[stdfailed=false CXXFLAGS="$CXXFLAGS -std=c++0x"])
fi
if "${stdfailed-true}"; then
AC_ERROR([Unable to turn on C++11 mode with this compiler.])
fi
AC_CONFIG_FILES([
Makefile
vcsn/Makefile
tests/Makefile
tests/unit/Makefile
])
AC_OUTPUT
# ===========================================================================
# http://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html
# ===========================================================================
#
# SYNOPSIS
#
# AX_CHECK_COMPILE_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS])
#
# DESCRIPTION
#
# Check whether the given FLAG works with the current language's compiler
# or gives an error. (Warnings, however, are ignored)
#
# ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on
# success/failure.
#
# If EXTRA-FLAGS is defined, it is added to the current language's default
# flags (e.g. CFLAGS) when the check is done. The check is thus made with
# the flags: "CFLAGS EXTRA-FLAGS FLAG". This can for example be used to
# force the compiler to issue an error when a bad flag is given.
#
# NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this
# macro in sync with AX_CHECK_{PREPROC,LINK}_FLAG.
#
# LICENSE
#
# Copyright (c) 2008 Guido U. Draheim <guidod@gmx.de>
# Copyright (c) 2011 Maarten Bosmans <mkbosmans@gmail.com>
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation, either version 3 of the License, or (at your
# option) any later version.
#
# This program 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 General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
# As a special exception, the respective Autoconf Macro's copyright owner
# gives unlimited permission to copy, distribute and modify the configure
# scripts that are the output of Autoconf when processing the Macro. You
# need not follow the terms of the GNU General Public License when using
# or distributing such scripts, even though portions of the text of the
# Macro appear in them. The GNU General Public License (GPL) does govern
# all other use of the material that constitutes the Autoconf Macro.
#
# This special exception to the GPL applies to versions of the Autoconf
# Macro released by the Autoconf Archive. When you make and distribute a
# modified version of the Autoconf Macro, you may extend this special
# exception to the GPL to apply to your modified version as well.
#serial 2
AC_DEFUN([AX_CHECK_COMPILE_FLAG],
[AC_PREREQ(2.59)dnl for _AC_LANG_PREFIX
AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl
AC_CACHE_CHECK([whether _AC_LANG compiler accepts $1], CACHEVAR, [
ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS
_AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
[AS_VAR_SET(CACHEVAR,[yes])],
[AS_VAR_SET(CACHEVAR,[no])])
_AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags])
AS_IF([test x"AS_VAR_GET(CACHEVAR)" = xyes],
[m4_default([$2], :)],
[m4_default([$3], :)])
AS_VAR_POPDEF([CACHEVAR])dnl
])dnl AX_CHECK_COMPILE_FLAGS
SUBDIRS = unit
AM_CPPFLAGS = -I$(top_srcdir)
noinst_PROGRAMS = simpleaut
simpleaut_SOURCES = simpleaut.cc
#include <vcsn/weights/z.hh>
#include <vcsn/alphabets/char.hh>
#include <vcsn/alphabets/setalpha.hh>
#include <vcsn/core/mutable_automaton.hh>
#include <vcsn/algos/dotty.hh>
#include <iostream>
int main()
{
typedef vcsn::set_alphabet<vcsn::char_letters> alpha_t;
alpha_t alpha;
alpha
.add_letter('a')
.add_letter('b')
.add_letter('c')
.add_letter('d');
//for (auto c : alpha)
//std::cerr << c << std::endl;
// b semiring;
vcsn::mutable_automaton<alpha_t, vcsn::z, vcsn::labels_are_letter> aut(alpha); // deuxième paramettre par défaut
//mutable_automaton<alpha_t, RatExp<b, alpha_t> >, labels_are_letter> aut(alpha, semiring);
auto s1 = aut.add_state();
auto s2 = aut.add_state();
auto s3 = aut.add_state();
aut.set_initial(s1);
aut.set_final(s2, 10);
aut.set_transition(s1, s2, 'c', 42);
aut.set_transition(s2, s3, 'a', 1);
aut.set_transition(s2, s1, 'b', 1);
aut.set_transition(s1, s1, 'd', 2);
vcsn::dotty(aut, std::cout);
}
# Vaucanson 2, a generic library for finite state machines.
# Copyright (C) 2012 Vaucanson Group.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# The complete GNU General Public Licence Notice can be found as the
# `COPYING' file in the root directory.
#
# The Vaucanson Group consists of people listed in the `AUTHORS' file.
#ifndef VCSN_ALGOS_DOTTY_HH
#define VCSN_ALGOS_DOTTY_HH
#include <iostream>
#include <unordered_map>
namespace vcsn
{
template <class A>
void
dotty(A& aut, std::ostream& out)
{
typedef typename A::state_t state_t;
std::unordered_map<state_t, unsigned> names;
auto& w = aut.get_weights();
bool show_unit = w.show_unit();
out << "digraph {\n rankdir=LR\n node [shape=circle];\n";
for (auto s : aut.states())
{
unsigned n = names[s] = names.size();
out << " " << n << "\n";
if (aut.is_initial(s))
{
auto k = aut.get_initial_weight(s);
out << " I" << n
<< " [style=invis,shape=none,label=\"\",width=0,height=0]\n";
out << " I" << n << " -> " << n;
if (show_unit || !w.is_unit(k))
out << " [label=\"{" << k << "}\"]";
out << "\n";
}
if (aut.is_final(s))
{
auto k = aut.get_final_weight(s);
out << " F" << n
<< " [style=invis,shape=none,label=\"\",width=0,height=0]\n";
out << " " << n << " -> F" << n;
if (show_unit || !w.is_unit(k))
out << " [label=\"{" << k << "}\"]";
out << "\n";
}
}
for (auto t : aut.transitions())
{
unsigned src = names[aut.src_of(t)];
unsigned dst = names[aut.dst_of(t)];
out << " " << src << " -> " << dst
<< " [label=\"";
auto k = aut.weight_of(t);
if (show_unit || !w.is_unit(k))
out << "{" << k << "}";
out << aut.label_of(t) << "\"]\n";
}
out << "}" << std::endl;
}
}
#endif // VCSN_ALGOS_DOTTY_HH
#ifndef VCSN_ALPHABETS_CHAR_HH
#define VCSN_ALPHABETS_CHAR_HH
#include <string>
namespace vcsn
{
class char_letters
{
public:
typedef char letter_t;
typedef std::string word_t;
word_t
to_word(const letter_t l) const
{
return word_t(l, 1);
}
word_t
concat(const letter_t l, const letter_t r) const
{
word_t w(l, 2);
w[1] = r;
return w;
}
word_t
concat(const word_t l, const letter_t r) const
{
return l + r;
}
word_t
concat(const letter_t l, const word_t r) const
{
return l + r;
}
word_t
concat(const word_t l, const word_t r) const
{
return l + r;
}
word_t
identity() const
{
return std::string();
}
bool
is_identity(const word_t& w) const
{
return w.empty();
}
bool
equals(const word_t& w1, const word_t& w2) const
{
return w1 == w2;
}
bool
equals(const letter_t& l1, const letter_t& l2) const
{
return l1 == l2;
}
// word_t mirror(const word_t& w)
};
}
#endif // VCSN_ALPHABETS_CHAR_HH
#ifndef VCSN_ALPHABETS_SETALPHA_HH
#define VCSN_ALPHABETS_SETALPHA_HH
#include <set>
namespace vcsn
{
template <class L>
class set_alphabet: public L
{
private:
typedef std::set<typename L::letter_t> alphabet_t;
alphabet_t alphabet_;
public:
set_alphabet&
add_letter(typename L::letter_t l)
{
alphabet_.insert(l);
return *this;
}
typedef typename alphabet_t::const_iterator iterator_t;
iterator_t begin() const
{
return alphabet_.begin();
}
iterator_t end() const
{
return alphabet_.end();
}
};
}
#endif // VCSN_ALPHABETS_SETALPHA_HH
#ifndef VCSN_CORE_KIND_HH
#define VCSN_CORE_KIND_HH
namespace vcsn
{
struct labels_are_letter
{
};
struct labels_are_words
{
};
template <class Kind, class Alphabet>
struct label_trait
{
};
template <class Alphabet>
struct label_trait<labels_are_letter, Alphabet>
{
typedef typename Alphabet::letter_t label_t;
};
template <class Alphabet>
struct label_trait<labels_are_words, Alphabet>
{
typedef typename Alphabet::word_t label_t;
};
}
#endif // VCSN_CORE_KIND_HH
#ifndef VCSN_CORE_MUTABLE_AUTOMATON_HH
#define VCSN_CORE_MUTABLE_AUTOMATON_HH
#include "kind.hh"
#include <vector>
#include <unordered_set>
#include <algorithm>
namespace vcsn
{
template<class Alphabet, class Weights, class Kind>
class mutable_automaton
{
protected:
class stored_state_t;
class stored_transition_t;
public:
typedef Alphabet alphabet_t;
typedef Weights weights_t;
typedef typename weights_t::value_t weight_t;
typedef typename label_trait<Kind, Alphabet>::label_t label_t;
typedef stored_state_t* state_t;
typedef stored_transition_t* transition_t;
protected:
const alphabet_t& a_;
const weights_t& w_;
struct stored_transition_t
{
state_t src;
label_t label;
weight_t weight;
state_t dst;
};
typedef std::vector<transition_t> tr_vector_t;
struct stored_state_t
{
weight_t initial;
weight_t final;
tr_vector_t succ;
tr_vector_t pred;
};
typedef std::unordered_set<state_t> st_cont_t;
typedef std::unordered_set<transition_t> tr_cont_t;
public:
mutable_automaton(const alphabet_t& a, const weights_t& w = weights_t())
: a_(a), w_(w)
{
}
~mutable_automaton()
{
for (auto t : transitions_)
delete t;
for (auto s : states_)
delete s;
}
const weights_t&
get_weights() const
{
return w_;
}
const alphabet_t&
get_alphabet() const
{
return a_;
}
state_t
add_state()
{
state_t res = new stored_state_t;
res->final = res->initial = w_.zero();
states_.insert(res);
return res;
}
bool
has_state(state_t s) const
{
return states_.find(s) != states_.end();
}
void
del_state(state_t s)
{
auto i = states_.find(s);
assert(i != states_.end());
states_.erase(i);
}
weight_t
get_initial_weight(state_t s)
{
return s->initial;
}
weight_t
get_final_weight(state_t s)
{
return s->final;
}
void
set_initial(state_t s, weight_t k)
{
s->initial = k;
if (w_.is_zero(k))
initials_.erase(s);
else
initials_.insert(s);
}
void
set_initial(state_t s)
{
set_initial(s, w_.unit());
}
void
add_initial(state_t s, weight_t k)
{
set_initial(s, w_.add(s->initial, k));
}
bool
is_initial(state_t s)
{
return !w_.is_zero(s->initial);
}
void
set_final(state_t s, weight_t k)
{
s->final = k;
if (w_.is_zero(k))
finals_.erase(s);
else
finals_.insert(s);
}
void
set_final(state_t s)
{
set_final(s, w_.unit());
}
void
add_final(state_t s, weight_t k)
{
set_final(s, w_.add(s->final, k));
}
bool
is_final(state_t s)
{
return !w_.is_zero(s->final);
}
size_t nb_states() const { return states_.size(); }
size_t nb_transitions() const { return transitions_.size(); }
size_t nb_initials() const { return initials_.size(); }
size_t nb_finals() const { return finals_.size(); }
transition_t
set_transition(state_t src, state_t dst, label_t w, weight_t k)
{
transition_t t = get_transition(src, dst, w);
if (t)
{
t->label = w;
t->weight = k;
}
else
{
t = new stored_transition_t;
t->src = src;
t->dst = dst;
t->label = w;
t->weight = k;
transitions_.insert(t);
src->succ.push_back(t);
dst->pred.push_back(t);
}
return t;
}
transition_t