Awali
Another Weighted Automata library
Data Structures | Public Member Functions | Static Public Member Functions
awali::dyn::automaton_t Class Reference

An automaton_t is essentially a shared pointer to an abstract_automaton_t, but also contains static functions serving as constructors. More...

#include <automaton.hh>

Inheritance diagram for awali::dyn::automaton_t:

Data Structures

struct  with_int_labels
 Helper class that contains convenience constructor for automata with int labels. More...
 

Public Member Functions

 automaton_t ()
 Buils an automaton_t that is essentially a nullptr; should generally not be used. More...
 
template<class T >
 automaton_t (const std::shared_ptr< T > &ptr, typename std::enable_if< std::is_base_of< abstract_automaton_t, T >::value, int >::type=0)
 Builds a automaton from a shared pointer to a class derived of abstract_automaton_t; should generally not be used. More...
 
 automaton_t (context::labelset_description ld, context::weightset_description wd)
 Builds a new empty automaton whose labelset is described by ld and weightset by wd. More...
 

Static Public Member Functions

static automaton_t from (std::string alphabet, bool allow_eps_transitions, std::string="B")
 Builds a boolean automaton over given alphabet, that possibly allows eps_transitions. More...
 
static automaton_t from (std::string alphabet, std::string weightset="B", bool allow_eps_transitions=false)
 Builds an automaton with labels in given alphabet possibly allowing epsilon transitions, and with weights in given weightset. More...
 
static automaton_t from_context (context_t ctx)
 Builds a new automaton whose labelset and weightset are given by ctx. More...
 

Detailed Description

An automaton_t is essentially a shared pointer to an abstract_automaton_t, but also contains static functions serving as constructors.

See the documentation of abstract_automaton_t for help on the methods on automata.

Example (Building an automaton)
automaton_t aut = automaton_t::from("ab"); // Builds an empty automaton over the alphabet
state_t s = aut->add_state(); // adding two states
state_t t = aut->add_state();
aut->set_initial(s); // making state `s` initial
aut->set_final(t); //making state `t` final
aut->set_transition(s,s,'b'); // A loop labelled by 'b' on both states
aut->set_transition(t,t,'b');
aut->set_transition(s,t,'a'); // Reading an 'a' changes the states
aut->set_transition(t,s,'a');
//aut now recognizes the words over {a,b} with an odd number of 'a's.
pdfdisplay(aut); // Outputs `aut` to a temporary file as a pdf image
// and opens it with the default pdf viewer.
automaton_t()
Buils an automaton_t that is essentially a nullptr; should generally not be used.
static automaton_t from(std::string alphabet, std::string weightset="B", bool allow_eps_transitions=false)
Builds an automaton with labels in given alphabet possibly allowing epsilon transitions,...
void pdfdisplay(automaton_t aut, options_t opts={})
Computes geometry of aut with program dot and displays with a pdf-viewer.
unsigned state_t
Type representing automata states; currently simply identifiers of type unsigned, but this might chan...
Definition: typedefs.hh:28
Example (Building an automaton from an expression)
ratexp_t exp = ratexp_t::from("(a+b)*bb(a+b)*");
automaton_t aut1 = exp_to_aut(exp);
aut1 = minimal_automaton(aut1); // determinizes and minimizes `aut`
// The same result may be obtained directly from the expression.
std::cout << are_isomorphic(aut1,aut2) << std::endl; // outputs 1
static ratexp_t from(std::string str, std::string weightset="B", std::string alphabet="auto")
Builds a rational expression from its string representation.
automaton_t exp_to_aut(ratexp_t ratexp, options_t opts={})
Computes an automaton equivalent to ratexp.
bool are_isomorphic(automaton_t aut1, automaton_t aut2)
Determines if two automata are isomorphic.
automaton_t minimal_automaton(automaton_t aut, options_t opts={})
Computes the minimal complete deterministic automaton of the language accepted by aut.
Example (Building a weighted automaton)
// Builds an automaton with transitions labelled in {a,b} and weighted in Z.
automaton_t aut = automaton_t::from("ab","Z", false);
state_t s = aut->add_state();
state_t t = aut->add_state();
aut->set_initial(s, 1); // Set initial weight of `s` to 1
aut->set_final(t, 1); // Set final weight of `t` to 1
aut->set_transition(s,s,'a',1);
aut->set_transition(s,s,'b',1);
aut->set_transition(t,t,'a',1);
aut->set_transition(t,t,'b',1);
aut->set_transition(s,t,'b',1);
// `aut` is an automaton that associate with every word the number of b' in it.
int i = (int) eval(aut,"bbbaaabbaaab"); // `i` equals 6
save(aut,"count-b.json"); // Saves `aut` in JSON format to file "count-b.json"
weight_t eval(automaton_t aut, any_t word)
Computes the weight associated with word by aut.
void save(const automaton_t aut, const std::string &path, options_t opts={})
Writes aut to file pointed by path.

See also group Factories.

Constructor & Destructor Documentation

◆ automaton_t() [1/2]

awali::dyn::automaton_t::automaton_t ( )

Buils an automaton_t that is essentially a nullptr; should generally not be used.

◆ automaton_t() [2/2]

template<class T >
awali::dyn::automaton_t::automaton_t ( const std::shared_ptr< T > &  ptr,
typename std::enable_if< std::is_base_of< abstract_automaton_t, T >::value, int >::type  = 0 
)

Builds a automaton from a shared pointer to a class derived of abstract_automaton_t; should generally not be used.

Both ptr and the built automaton_t will share ownership of pointed object.


The documentation for this class was generated from the following file: