diff --git a/alib2data/src/automaton/PDA/DPDA.cpp b/alib2data/src/automaton/PDA/DPDA.cpp index 7769791ae0f0be0c440d6adcb66e182dbf7264b4..08bf733a06bbaf279eedd5decc193561218ba4e0 100644 --- a/alib2data/src/automaton/PDA/DPDA.cpp +++ b/alib2data/src/automaton/PDA/DPDA.cpp @@ -194,6 +194,34 @@ const std::map<std::tuple<State, std::variant<string::Epsilon, alphabet::Symbol> 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 { return other == *this; } diff --git a/alib2data/src/automaton/PDA/DPDA.h b/alib2data/src/automaton/PDA/DPDA.h index 195f2d44ed04cf1f9a62c157d407e451c41451de..4cd0154110fcb9a25aafe2152e0a69c9c6e8b7ca 100644 --- a/alib2data/src/automaton/PDA/DPDA.h +++ b/alib2data/src/automaton/PDA/DPDA.h @@ -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; + /** + * @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;