The automaton object is the core of Awali. An automaton is a labelled directed graph; the vertices of this graph are states, the edges are transitions.
Each transition carries a label and a weight; the types of these labels and weights depend on the context of the automaton. There may exist several transitions with the same ends, but there can not exist distinct transitions with the same ends and the same label.
Initial and final status of states are internally represented by special states and transitions, that can be ignored at first glance. The automaton offers specific method to handle them.
Every state and transition has an identifier that is a nonnegative integer. Every operation on some state or transition must be operated through the automaton. The identifier of a given state never changes, but if a state is removed from the automaton, its identifier can be reused for a fresh state. The same holds for transitions. The identifiers are allocated sequentially by the automaton and they can not be chosen.
The weights on transitions belong to some semiring. No transition can exist with a weight equal to the zero of the semiring; setting the weight of a transition to zero amounts to remove it. Deleting a state causes the deletion of every incoming or outgoing transition.
The automata objects share the same API in the static library, the dynamic library and the python module, even if the syntax is slightly different. We describe here the main methods. To work with a specific library please consult the dedicated description.
num_states()
returns the number of states;num_transitions()
returns the number of transition;num_initials()
returns the number of initial states;num_finals()
returns the number of final states;max_states()
returns the largest identifier of states;states()
allows to iterate over states;
transitions()
allows to iterate over transitions.
The four first methods are accessible as commands with Cora; they are the only "services" which are directly
accessible with Cora; the edit
command of Cora allows to visit and modify an automaton.
In the static library, these two last methods return internal iterators on the structure; in the dynamic lybrary and the python module, it returns a list of state (resp. transition) identifiers.
add_state()
creates a new state and returns its id;has_state(id)
returns true if there exists a state with this id;del_state(id)
deletes the state;is_initial(id)
returns true if the state is initial;set_initial(id)
makes the state initial (with unit as weight);unset_initial(id)
makes the state non-initialis_final(id)
returns true if the state is final;set_final(id)
makes the state final (with unit as weight);unset_final(id)
makes the state non-final.initial_states()
returns the list of initial state identifiers;final_states()
returns the list of final state identifiers.initial_transitions()
allows to iterate over initial transitons;final_transitions()
allows to iterate over final transitons.set_initial(id, w)
makes the state initial with weight w;
if w is zero, the state is made non-initial;
add_initial(id, w)
add w to the initial weight;
if state id
was already initial with weight h, its initial weight is now w+h
otherwise it makes it initial with weight w;
in case w+h is zero, the state is made non-initial;
get_initial_weight(id)
returns the initial weight of the state (zero if the state is not initial);set_final(id, w)
makes the state final with weight w;
if w is zero, the state is made non-final;
add_final(id, w)
add w to the final weight;
if state id
was already final with weight h, its final weight is now w+h
otherwise it makes it final with weight w;
in case w+h is zero, the state is made non-final;
get_final_weight(id)
returns the final weight of the state (zero if the state is not initial).has_transition(id)
returns true if there exists a transition with this id;has_transition(src_id, dst_id, label)
returns true if there exists a transition with these ends and label;get_transition(src_id, dst_id, label)
returns the id of the transition with these ends and label;
if such a transition does not exist, an invalid id is returned.
del_transition(id)
delete the transition; there is an assert
on the validity of the id;del_transition(src_id, dst_id, label)
delete, if it exists, the transition with these ends and label;set_transition(src_id, dst_id, label)
creates a transition with these ends and label (with unit as weight) and returns its id;
if there was a transition with the same ends and label, it is replaced;
src_of(id)
returns the id of the source state of the transition;dst_of(id)
returns the id of the destination state of the transition;label_of(id)
returns the label of the transition.transitions()
method which allows to iterate over all the transitions, there exist several
method to iterate transitions adjacent to a given state.
out(src_id)
iterates over transitions outgoing from the state;out(src_id, label)
iterates over transitions with the given label outgoing from the state;in(dst_id)
iterates over transitions incoming to the state;in(dst_id, label)
iterates over transitions with the given label incoming to the state;outin(src_id, dst_id)
iterates over transitions with the given end.weight_of(id)
returns the weight of the transition.set_transition(src_id, dst_id, label, weight)
creates a transition with these ends, label and weight and returns its id;
if there was a transition with the same ends and label, it is replaced;
it the weight is zero, it deletes any potential transition with the same ends and label.
add_transition(src_id, dst_id, label [,weight = unit])
add a transition with these ends, label and weight and returns its id;
if there was a transition with the same ends and label and weight h, its weight is incremented by the given weight;
if the sum is zero, the transition is deleted;
set_weight(id, w)
fixes a new weight w for the transition; if w is zero, the transition is deleted;add_weight(id, w)
adds w to the weight of the transition;
if the sum is zero, the transition is deleted;
lmul_weight(id, w)
multiply the weight of the transition by w to the left
if the product is zero, the transition is deleted;
rmul_weight(id, w)
multiply the weight of the transition by w to the right
if the product is zero, the transition is deleted.
get_state_name(id)
returns the name of the state;set_state_name(id, name)
sets the name of the state;get_state_by_name(id, name)
returns a state with the given name, if some exists;has_explicit_name(id)
returns true if the name of this state has been explicitely given, false if it is automatically forged from the identifier;strip_names(id, name)
removes all explicit names.SINGLE
: the automaton refers to another automaton B and every state may refer to exactly one state of B; this is for instance the case when the automaton is a subautomaton of B;TUPLE
: the automaton refers to several automata and every state may refer to a tuple of states of these automata; this is for instance the case when the automaton is a product of automata, or when a transducer is a composition of transducers;PARTITION
: the automaton refers to another automaton B and every state may refer to a subset of states of B; this is for instance the case with the subset construction or with the merging of states (minimization for instance).RATEXP
: the automaton refers to no automaton and every state may refer to a rational expression;
this is for instance in the construction of the derivation automaton.STRING
: the automaton refers to no automaton and every state may carry an information as a string, different from its name.NO_HISTORY
: there is no history information for the automaton.
These hidden states and transitions are not counted in the return of num_states()
and num_transitions()
. Likewise, the iterators described above do not iterate over hidden states or hidden transitions.
Nevertheless, in some algorithms, it is convenient to consider that the automaton has a unique initial state pre and
a unique final state post, and several methods give access to these states and transitions:
num_all_states()
returns the number of states, including hidden states;all_states()
allows to iterate over all states, including hidden states;all_transitions()
allows to iterate over all transitions, including hidden transitions;all_out(src)
allows to iterate over all transitions outgoing from a state, including hidden transitions;all_in(src)
allows to iterate over all transitions incoming to a state, including hidden transitions;