#include<sttc/core/mutable_automaton.hh>Namespace: awali::sttc
mutable_automaton<Context>
,
and every method is accessible with operator ->
.
unsigned int
; for readability, there exist aliases
state_t
and transition_t
Factory:
template <typename Context> mutable_automaton<Context> make_mutable_automaton(const Context& ctx);
ctx
: A static Awali contextContext
type which is a parameter of an automaton
implies a number of types defined in the automaton class (left column)
and that are accessible from the mutable_automaton<Context>
type
(right collumn):
context_t | context_t_of< mutable automaton> |
label_t | label_t_of< mutable automaton> |
labelset_t | labelset_t_of< mutable automaton> |
weight_t | weight_t_of< mutable automaton> |
weightset_t | weightset_t_of< mutable automaton> |
const context_t& context() const; const weightset_ptr& weightset() const; const labelset_ptr& labelset() const;
size_t num_states() const; size_t num_transitions() const; size_t num_initials() const; size_t num_finals() const;
state_t max_state() const;
states_output_t states() const; transitions_output_t transitions() const;
states_output_t
and transitions_output_t
are internal types;
which are "facades" in front of the automaton structure. They are containers with the minimal API
which allows to use the C++ 11 forall syntax, for instance
for(state_t s : aut->states()) //...
state_t add_state();Create a new state in the automaton.
bool has_state(state_t s);Test whether the state exists.
s
: A state identifier
void del_state(state_t s);Delete the state. There are
assert
testing that the state id is valid and that the state
is different from the pre-initial and the post-final states.
s
: A state identifier
bool is_initial(state_t s); bool is_final(state_t s);Test whether the state is initial (resp. final). There is an
assert
testing that the state id is valid.
s
: A state identifier
void set_initial(state_t s, weight_t w); weight_t add_initial(state_t s, weight_t w); void set_initial(state_t s); void unset_initial(state_t s); void set_final(state_t s, weight_t w); weight_t add_final(state_t s, weight_t w); void set_final(state_t s); void unset_final(state_t s);Change the initial (resp. final) status of the state. There is an
assert
testing that the state id is valid.
set_initial(s, w)
sets the initial weight to w
.set_initial(s)
is equivalent to set_initial(s, weightset()->one())
.unset_initial(s)
is equivalent to set_initial(s, weightset()->zero())
.add_initial(s, w)
adds w
to the initial weight.s
: A state identifier
w
: A weight
add_initial
and add_final
, the weight after modification
weight_t get_initial_weight(state_t s); weight_t get_final_weight(state_t s);Gets the initial (resp. final) weight of the state,
weightset()->zero()
if the state is not initial (resp. final).
There is an assert
testing that the state id is valid.
s
: A state identifier
transitions_s_output_t initial_transitions() const; transitions_s_output_t final_transitions() const;
transitions_s_output_t
is an internal type
which is a "facade" in front of the automaton structure. It is a container with the minimal API
which allows to use the C++ 11 forall syntax.
bool has_transition(transition_t tr) const; bool has_transition(state_t src, state_t dst, label_t l) const; transition_t get_transition(state_t src, state_t dst, label_t l) const;
has_transition
tests whether there exists such a transition;
the potential transition can be characterized either by its identifier tr
or by a tuple specifying its ends and label (src, dst, l)
.
get_transition(src, dst, l)
returns the identifier of the specified transition.
assert
testing that src
and dst
are valid state identifiers.
(src, dst, l)
, get_transition(src, dst, l)
returns
an invalid transition identifier.
tr
: A transition identifier
src
, dst
: State identifiers
l
: A label
transition_t set_transition(state_t src, state_t dst, label_t l, weight_t w); transition_t new_transition(state_t src, state_t dst, label_t l, weight_t w); weight_t add_transition(state_t src, state_t dst, label_t l, weight_t w); template <typename Aut> transition_t set_transition_copy(state_t src, state_t dst, const Aut& aut, transition_t tr); template <typename Aut> transition_t new_transition_copy(state_t src, state_t dst, const Aut& aut, transition_t tr); template <typename Aut> weight_t add_transition_copy(state_t src, state_t dst, const Aut& aut, transition_t tr); transition_t set_transition(state_t src, state_t dst, label_t l); transition_t new_transition(state_t src, state_t dst, label_t l); weight_t add_transition(state_t src, state_t dst, label_t l);Create or modify transitions.
set_transition
sets a transition with the given parameters;
if a transition with the same ends and the same label already exists, it is replaced.new_transition
creates a transition with the given parameters;
there is an assert
that a transition with the same ends and the same label does not already exist.add_transition
adds a transition with the given parameters;
if a transition with the same ends and the same label already exists, w
is added to the existing weight.src
,dst
), its label l
, and its weight w
.
weightset()->one()
.
src
, dst
: State identifiers
l
: A label
w
: A weight
tr
: A transition identifier
set_transition
and new_transition
return the identifier of the new transition.
void del_transition(transition_t tr); transition_t del_transition(state_t src, state_t dst, label_t l); void del_transition(state_t src, state_t dst);Remove transitions.
assert
that the identifier is valid;
if the transition is specified by its ends, all the transitions with these ends are removed.
tr
: A transition identifiersrc
, dst
: State identifiersl
: A labeldel_transition
returns the identifier of the deleted transition, and an invalid identifier if such a transition does not exist.
state_t src_of(transition_t tr) const; state_t dst_of(transition_t tr) const; label_t label_of(transition_t tr) const; weight_t weight_of(transition_t tr) const;Characteristics of transition.
tr
: A transition identifiersrc_of
), destination identifier (dst_of
),
label (label_of
), or the weight (weight_of
) of the transition.
weight_t set_weight(transition_t tr, weight_t w); weight_t add_weight(transition_t tr, weight_t w); weight_t lmul_weight(transition_t tr, weight_t w); weight_t rmul_weight(transition_t tr, weight_t w);Modify the weight of a transition.
set_weight
sets the weight of a transition to w
.
add_weight
adds w
to the weight of a transition.
lmul_weight
multiply the weight of the transition by w
to the left.
rmul_weight
multiply the weight of the transition by w
to the right.
tr
: A transition identifierw
: A weightconst std::string& get_state_name(state_t s) const; std::ostream& print_state_name(state_t s, std::ostream& o) const; bool has_explicit_name(state_t s) const; void set_state_name(state_t s, const std::string& n); state_t get_state_by_name(const std::string& name) const;
history_t
history_t history() const; void set_history(history_t h); void strip_history(); std::ostream& print_state_history(state_t s, std::ostream& o) const; bool has_history(state_t s) const;
state_t pre(); state_t post();The identifiers of the pre-initial and the post-final states are usually 0 and 1.
size_t num_all_states() const;
states_output_t all_states() const; transitions_output_t all_transitions() const; const tr_cont_t& all_out(state_t s) const; const tr_cont_t& all_in(state_t s) const;