Skip to content
Snippets Groups Projects
Commit 2c4b3310 authored by Jan Trávníček's avatar Jan Trávníček
Browse files

add retrieval of transitions from state to DPDA

parent 9bf100cc
No related branches found
No related tags found
No related merge requests found
...@@ -194,6 +194,34 @@ const std::map<std::tuple<State, std::variant<string::Epsilon, alphabet::Symbol> ...@@ -194,6 +194,34 @@ const std::map<std::tuple<State, std::variant<string::Epsilon, alphabet::Symbol>
return transitions; return transitions;
} }
   
std::map<std::tuple<State, std::variant<string::Epsilon, alphabet::Symbol>, std::vector<alphabet::Symbol> >, std::pair<State, std::vector<alphabet::Symbol> > > DPDA::getTransitionsFromState(const State& from) const {
if( states.find(from) == states.end())
throw AutomatonException("State \"" + (std::string) from.getName() + "\" doesn't exist");
std::map<std::tuple<State, std::variant<string::Epsilon, alphabet::Symbol>, std::vector<alphabet::Symbol> >, std::pair<State, std::vector<alphabet::Symbol> > > transitionsFromState;
for (auto transition = transitions.begin(); transition != transitions.end(); transition++) {
if (std::get<0>(transition->first) == from) {
transitionsFromState.insert(std::make_pair(transition->first, transition->second));
}
}
return transitionsFromState;
}
std::map<std::tuple<State, std::variant<string::Epsilon, alphabet::Symbol>, std::vector<alphabet::Symbol> >, std::pair<State, std::vector<alphabet::Symbol> > > DPDA::getTransitionsToState(const State& to) const {
if( states.find(to) == states.end())
throw AutomatonException("State \"" + (std::string) to.getName() + "\" doesn't exist");
std::map<std::tuple<State, std::variant<string::Epsilon, alphabet::Symbol>, std::vector<alphabet::Symbol> >, std::pair<State, std::vector<alphabet::Symbol> > > transitionsToState;
for (auto transition = transitions.begin(); transition != transitions.end(); transition++) {
if (transition->second.first == to) {
transitionsToState.insert(std::make_pair(transition->first, transition->second));
}
}
return transitionsToState;
}
bool DPDA::operator==(const ObjectBase& other) const { bool DPDA::operator==(const ObjectBase& other) const {
return other == *this; return other == *this;
} }
......
...@@ -81,6 +81,16 @@ public: ...@@ -81,6 +81,16 @@ public:
*/ */
const std::map<std::tuple<State, std::variant<string::Epsilon, alphabet::Symbol>, std::vector<alphabet::Symbol> >, std::pair<State, std::vector<alphabet::Symbol> > >& getTransitions() const; const std::map<std::tuple<State, std::variant<string::Epsilon, alphabet::Symbol>, std::vector<alphabet::Symbol> >, std::pair<State, std::vector<alphabet::Symbol> > >& getTransitions() const;
   
/**
* @return automaton transitions from state
*/
std::map<std::tuple<State, std::variant<string::Epsilon, alphabet::Symbol>, std::vector<alphabet::Symbol> >, std::pair<State, std::vector<alphabet::Symbol> > > getTransitionsFromState(const State& from) const;
/**
* @return automaton transitions to state
*/
std::map<std::tuple<State, std::variant<string::Epsilon, alphabet::Symbol>, std::vector<alphabet::Symbol> >, std::pair<State, std::vector<alphabet::Symbol> > > getTransitionsToState(const State& from) const;
virtual bool operator<(const alib::ObjectBase& other) const; virtual bool operator<(const alib::ObjectBase& other) const;
virtual bool operator==(const alib::ObjectBase& other) const; virtual bool operator==(const alib::ObjectBase& other) const;
virtual bool operator>(const alib::ObjectBase& other) const; virtual bool operator>(const alib::ObjectBase& other) const;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment