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

addTransitions in tree automata

parent 3250c491
No related branches found
No related tags found
No related merge requests found
...@@ -107,6 +107,15 @@ public: ...@@ -107,6 +107,15 @@ public:
*/ */
bool addTransition ( std::ranked_symbol < SymbolType, RankType > current, std::vector < StateType > children, StateType next ); bool addTransition ( std::ranked_symbol < SymbolType, RankType > current, std::vector < StateType > children, StateType next );
   
/**
* Adds transition defined by parameters to the automaton.
* @param current current symbol in node
* @param children states of children of current node
* @param next next state
* @throws AutomatonException when transition already exists or when transition contains state or symbol not present in the automaton
*/
void addTransitions ( std::ranked_symbol < SymbolType, RankType > current, std::vector < StateType > children, std::set < StateType > next );
/** /**
* Removes transition from the automaton. * Removes transition from the automaton.
* @throws AutomatonException when transition doesn't exists. * @throws AutomatonException when transition doesn't exists.
...@@ -206,7 +215,27 @@ bool NFTA < SymbolType, RankType, StateType >::addTransition ( std::ranked_symbo ...@@ -206,7 +215,27 @@ bool NFTA < SymbolType, RankType, StateType >::addTransition ( std::ranked_symbo
} }
   
std::pair<std::ranked_symbol < SymbolType, RankType >, std::vector < StateType > > key = std::make_pair ( std::move ( symbol ), std::move ( prevStates ) ); std::pair<std::ranked_symbol < SymbolType, RankType >, std::vector < StateType > > key = std::make_pair ( std::move ( symbol ), std::move ( prevStates ) );
return transitions [ key ].insert ( std::move ( next ) ).second; return transitions [ std::move ( key ) ].insert ( std::move ( next ) ).second;
}
template < class SymbolType, class RankType, class StateType >
void NFTA < SymbolType, RankType, StateType >::addTransitions ( std::ranked_symbol < SymbolType, RankType > symbol, std::vector<StateType> prevStates, std::set < StateType > next) {
if (prevStates.size() != ( size_t ) symbol.getRank() )
throw AutomatonException("Number of states doesn't match rank of the symbol");
if (! getInputAlphabet().count(symbol))
throw AutomatonException("Input symbol \"" + std::to_string ( symbol ) + "\" doesn't exist.");
if ( !std::includes ( getStates ( ).begin ( ), getStates ( ).end ( ), next.begin ( ), next.end ( ) ) )
throw AutomatonException ( "Some target states don't exist." );
for (const StateType& it : prevStates) {
if (! getStates().count(it))
throw AutomatonException("State \"" + std::to_string ( it ) + "\" doesn't exist.");
}
std::pair<std::ranked_symbol < SymbolType, RankType >, std::vector < StateType > > key = std::make_pair ( std::move ( symbol ), std::move ( prevStates ) );
transitions [ std::move ( key ) ].insert ( std::make_moveable_set ( next ).begin ( ), std::make_moveable_set ( next ).end ( ) );
} }
   
template < class SymbolType, class RankType, class StateType > template < class SymbolType, class RankType, class StateType >
......
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