diff --git a/alib2algo/src/conversions/fa2re/formal/StateEliminationFormal.cpp b/alib2algo/src/conversions/fa2re/formal/StateEliminationFormal.cpp index 6e8da9ec6b79d39cb1988043ddf5a8f2e38fa96e..388aea0a0cbfda8856c75c40d149c3c2b9a8c81e 100644 --- a/alib2algo/src/conversions/fa2re/formal/StateEliminationFormal.cpp +++ b/alib2algo/src/conversions/fa2re/formal/StateEliminationFormal.cpp @@ -19,11 +19,20 @@ namespace conversions namespace fa2re { +regexp::RegExp StateEliminationFormal::convert(const automaton::Automaton& automaton) +{ + regexp::RegExp* out = NULL; + automaton.getData().Accept((void*) &out, StateEliminationFormal::STATE_ELIMINATION_FORMAL); + regexp::RegExp res = std::move(*out); + delete out; + return res; +} + template<class T> -regexp::RegExp StateEliminationFormal::convert(const T& automaton) +regexp::FormalRegExp StateEliminationFormal::convert(const T& automaton) { if(automaton.getFinalStates().size() == 0) - return regexp::RegExp{regexp::FormalRegExp(regexp::FormalRegExpEmpty())}; + return regexp::FormalRegExp(regexp::FormalRegExpEmpty()); // steps 1 + 2 automaton::ExtendedNFA extendedAutomaton = constructExtendedNFA(automaton); @@ -46,21 +55,10 @@ regexp::RegExp StateEliminationFormal::convert(const T& automaton) regexp::FormalRegExpIteration(std::move(*transition(extendedAutomaton, *extendedAutomaton.getFinalStates().begin(), *extendedAutomaton.getFinalStates().begin()))) ); //return regexp::RegExp{opt.optimize(regexp::FormalRegExp(concat))}; - return regexp::RegExp{regexp::FormalRegExp(concat)}; -} - -template<> -regexp::RegExp StateEliminationFormal::convert(const automaton::Automaton& automaton) -{ - regexp::RegExp* out = NULL; - automaton.getData().Accept((void*) &out, StateEliminationFormal::STATE_ELIMINATION_FORMAL); - regexp::RegExp res = std::move(*out); - delete out; - return res; + return regexp::FormalRegExp(concat); } - void StateEliminationFormal::Visit(void*, const automaton::UnknownAutomaton&) const { throw exception::AlibException("Unsupported automaton type UnknownAutomaton"); diff --git a/alib2algo/src/conversions/fa2re/formal/StateEliminationFormal.h b/alib2algo/src/conversions/fa2re/formal/StateEliminationFormal.h index 7a1119185e93b88bbc8211f028fdacec7ab4b70c..75abb0b846a29630d4eb39b160ccd65ea901ebe0 100644 --- a/alib2algo/src/conversions/fa2re/formal/StateEliminationFormal.h +++ b/alib2algo/src/conversions/fa2re/formal/StateEliminationFormal.h @@ -34,8 +34,10 @@ public: * Performs conversion. * @return regular expression equivalent to source NFA. */ + static regexp::RegExp convert(const automaton::Automaton& automaton); + template<class T> - static regexp::RegExp convert(const T& automaton); + static regexp::FormalRegExp convert(const T& automaton); private: void Visit(void*, const automaton::UnknownAutomaton& automaton) const; diff --git a/alib2algo/src/conversions/fa2re/unbounded/StateEliminationUnbounded.cpp b/alib2algo/src/conversions/fa2re/unbounded/StateEliminationUnbounded.cpp index c468c21e16c1ea2339a974e3a626806c6504f59b..f4ad4b3737feb152ba8c61e60e53eaec8eb99a92 100644 --- a/alib2algo/src/conversions/fa2re/unbounded/StateEliminationUnbounded.cpp +++ b/alib2algo/src/conversions/fa2re/unbounded/StateEliminationUnbounded.cpp @@ -19,11 +19,20 @@ namespace conversions namespace fa2re { +regexp::RegExp StateEliminationUnbounded::convert(const automaton::Automaton& automaton) +{ + regexp::RegExp* out = NULL; + automaton.getData().Accept((void*) &out, StateEliminationUnbounded::STATE_ELIMINATION_UNBOUNDED); + regexp::RegExp res = std::move(*out); + delete out; + return res; +} + template<class T> -regexp::RegExp StateEliminationUnbounded::convert(const T& automaton) +regexp::UnboundedRegExp StateEliminationUnbounded::convert(const T& automaton) { if(automaton.getFinalStates().size() == 0) - return regexp::RegExp{regexp::UnboundedRegExp(regexp::UnboundedRegExpEmpty())}; + return regexp::UnboundedRegExp(regexp::UnboundedRegExpEmpty()); // steps 1 + 2 automaton::ExtendedNFA extendedAutomaton = constructExtendedNFA(automaton); @@ -44,21 +53,10 @@ regexp::RegExp StateEliminationUnbounded::convert(const T& automaton) regexp::UnboundedRegExpConcatenation concat; concat.appendElement(std::move(*transition(extendedAutomaton, *extendedAutomaton.getInitialStates().begin(), *extendedAutomaton.getFinalStates().begin()))); concat.appendElement(regexp::UnboundedRegExpIteration(std::move(*transition(extendedAutomaton, *extendedAutomaton.getFinalStates().begin(), *extendedAutomaton.getFinalStates().begin())))); - return regexp::RegExp{opt.optimize(regexp::UnboundedRegExp(concat))}; -} - -template<> -regexp::RegExp StateEliminationUnbounded::convert(const automaton::Automaton& automaton) -{ - regexp::RegExp* out = NULL; - automaton.getData().Accept((void*) &out, StateEliminationUnbounded::STATE_ELIMINATION_UNBOUNDED); - regexp::RegExp res = std::move(*out); - delete out; - return res; + return opt.optimize(regexp::UnboundedRegExp(concat)); } - void StateEliminationUnbounded::Visit(void*, const automaton::UnknownAutomaton&) const { throw exception::AlibException("Unsupported automaton type UnknownAutomaton"); diff --git a/alib2algo/src/conversions/fa2re/unbounded/StateEliminationUnbounded.h b/alib2algo/src/conversions/fa2re/unbounded/StateEliminationUnbounded.h index 337758bbeba5e8027b89a5ae0ef465dae6caf408..640ba2e3636d13290776ed965bb5192c1110d37b 100644 --- a/alib2algo/src/conversions/fa2re/unbounded/StateEliminationUnbounded.h +++ b/alib2algo/src/conversions/fa2re/unbounded/StateEliminationUnbounded.h @@ -32,10 +32,13 @@ class StateEliminationUnbounded : public automaton::VisitableAutomatonBase::cons public: /** * Performs conversion. + * @param automaton automaton to convert * @return regular expression equivalent to source NFA. */ + static regexp::RegExp convert(const automaton::Automaton& automaton); + template<class T> - static regexp::RegExp convert(const T& automaton); + static regexp::UnboundedRegExp convert(const T& automaton); private: void Visit(void*, const automaton::UnknownAutomaton& automaton) const;