diff --git a/alib/src/automaton/FSM/FSM.cpp b/alib/src/automaton/FSM/FSM.cpp index 9cc2d61a6b7116b3bdb94426dd4d52d841907be2..6a90f060c6d6654ba7559976eb6b174bd2505943 100644 --- a/alib/src/automaton/FSM/FSM.cpp +++ b/alib/src/automaton/FSM/FSM.cpp @@ -100,4 +100,36 @@ void FSM::toXML(ostream& out) const { AutomatonPrinter::toXML(*this, out); } +bool FSM::isEpsilonFree() const { + for (auto const& transition : transitions) { + if (transition.getInput() == Symbol("")) { + return false; + } + } + return true; +} + +bool FSM::isDeterministic() const { + if (initialStates.size() != 1) { + return false; + } + + if (!isEpsilonFree()) { + return false; + } + + for (auto transition = transitions.begin(); transition != transitions.end(); transition++) { + auto subTransition = transition; + subTransition++; + for (; subTransition != transitions.end(); subTransition++) { + if (subTransition->getFrom() == transition->getFrom() + && subTransition->getInput() == transition->getInput()) { + return false; + } + } + } + + return true; +} + } /* namespace automaton */ diff --git a/alib/src/automaton/FSM/FSM.h b/alib/src/automaton/FSM/FSM.h index d4bae197ebfc23c5dcbca3889276632a514129fd..373819c2a7313fe88f951dead87faf26d5ffeeb6 100644 --- a/alib/src/automaton/FSM/FSM.h +++ b/alib/src/automaton/FSM/FSM.h @@ -33,6 +33,9 @@ public: void removeTransition(const TransitionFSM& transition); const set<TransitionFSM>& getTransitions() const; + bool isEpsilonFree() const; + bool isDeterministic() const; + virtual void toXML(ostream& out) const; };