20 #ifndef LIMI_INTERNAL_META_AUTOMATON_H
21 #define LIMI_INTERNAL_META_AUTOMATON_H
25 #include "../automaton.h"
26 #include "meta_state.h"
42 template <
class InnerImplementationB,
class Independence = independence<
typename InnerImplementationB::Symbol_>>
43 class meta_automaton :
public Limi::automaton<std::shared_ptr<meta_state<typename InnerImplementationB::State_, typename InnerImplementationB::Symbol_, Independence>>,typename InnerImplementationB::Symbol_,meta_automaton<InnerImplementationB, Independence>> {
44 using InnerStateB =
typename InnerImplementationB::State_;
45 using Symbol =
typename InnerImplementationB::Symbol_;
48 typedef std::shared_ptr<StateB> StateI;
60 throw std::logic_error(
"For the automaton B in the language inclusion algorithm either collapse_epsilon must be true or no_epsilon_produced");
64 bool int_is_final_state(
const StateI& state)
const {
65 return (state->early().size()==0 && state->late().size()==0 && inner.
is_final_state(state->inner_state()));
68 void int_initial_states(State_vector& states)
const {
69 std::vector<InnerStateB> is;
71 for (
const auto& i:is) {
72 states.push_back(std::make_shared<StateB>(i));
85 int check_independence(
typename StateB::vector_iterator begin,
const typename StateB::vector_iterator& end,
const Symbol& symbol)
const {
87 for (; begin!=end; ++begin) {
88 if (std::equal_to<Symbol>()(*begin, symbol))
return counter;
89 if (!independence_(*begin, symbol))
return -2;
96 StateI successor(
const StateI& state,
const Symbol& sigmaA,
const Symbol& sigmaB)
const {
100 int pos_early, pos_late;
101 if ((pos_late = check_independence(state->late().begin(), state->late().end(), sigmaB)) == -2)
return StateI();
104 StateI newst = std::make_shared<StateB>(*state);
107 newst->erase_late(pos_late);
109 newst->add_early(sigmaB, independence_);
112 if ((pos_early = check_independence(newst->early().begin(), newst->early().end(), sigmaA)) == -2)
return StateI();
114 newst->erase_early(pos_early);
116 newst->add_late(sigmaA, independence_);
117 assert(newst->early().size() == newst->late().size());
124 void int_successors(
const StateI& state,
const Symbol& sigmaA, State_vector&
successors)
const {
125 for (
const Symbol& sigmaB : inner.
next_symbols(state->inner_state())) {
129 StateI succ = successor(state, sigmaA, sigmaB);
131 typename InnerAutomatonB::State_vector succs;
132 inner.
successors(state->inner_state(),sigmaB, succs);
133 for(
auto it = succs.begin(); it!=succs.end(); ++it) {
135 if (it!=succs.begin())
136 succ = std::make_shared<StateB>(*succ);
137 succ->inner_state(*it);
139 successors.push_back(succ);
146 inline void int_next_symbols(
const StateI& state, Symbol_vector& symbols)
const {
147 throw std::logic_error(
"The meta-automaton cannot produce a set of next symbols");
154 inline bool int_is_epsilon(
const Symbol& symbol)
const {
return inner.
is_epsilon(symbol); }
157 const InnerAutomatonB& inner;
158 const Independence& independence_;
164 #endif //LIMI_INTERNAL_META_AUTOMATON_H
The printer base is what custom printers need to inherit from.
Definition: generics.h:81
void next_symbols(const State &state, Symbol_vector &symbols) const
Returns possible successor symbols for a state.
Definition: automaton.h:256
The main namespace of the library.
Definition: antichain_algo.h:40
The template for the independence relation.
Definition: generics.h:53
const printer_base< State > & state_printer() const
Returns a printer for states.
Definition: automaton.h:292
bool is_epsilon(const Symbol &symbol) const
Determines if a symbol should be considered an epsilon transition.
Definition: automaton.h:320
bool is_final_state(const State &state) const
This function determines if a specific state is final.
Definition: automaton.h:160
void successors(const std::shared_ptr< meta_state< InnerImplementationB::State_, InnerImplementationB::Symbol_, Independence > > &state, const InnerImplementationB::Symbol_ &sigma, State_vector &successors1) const
Returns the successor for a specific state.
Definition: automaton.h:201
bool no_epsilon_produced
Indicates that the implementation of next_symbols(const State&,Symbol_set&) const will never produce ...
Definition: automaton.h:350
const printer_base< Symbol > & symbol_printer() const
Returns a printer for symbols.
Definition: automaton.h:304
The default implementation of Limi::printer_base.
Definition: generics.h:104
void initial_states(State_vector &states) const
Returns the initial states.
Definition: automaton.h:167
bool collapse_epsilon
If true during exploration of the next state the epsilons will be fully explored. If false then epsil...
Definition: automaton.h:344
Automata need to inherit from this class and implement certain methods.
Definition: automaton.h:49