Skip to content
Snippets Groups Projects
Commit 0f237038 authored by Martin Žák's avatar Martin Žák
Browse files

Adds isEpsilonFree & isDeterministic methods to FSM

parent f6aabc63
No related branches found
No related tags found
No related merge requests found
...@@ -100,4 +100,36 @@ void FSM::toXML(ostream& out) const { ...@@ -100,4 +100,36 @@ void FSM::toXML(ostream& out) const {
AutomatonPrinter::toXML(*this, out); 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 */ } /* namespace automaton */
...@@ -33,6 +33,9 @@ public: ...@@ -33,6 +33,9 @@ public:
void removeTransition(const TransitionFSM& transition); void removeTransition(const TransitionFSM& transition);
const set<TransitionFSM>& getTransitions() const; const set<TransitionFSM>& getTransitions() const;
   
bool isEpsilonFree() const;
bool isDeterministic() const;
virtual void toXML(ostream& out) const; virtual void toXML(ostream& out) const;
}; };
   
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment