Skip to content
Snippets Groups Projects
Commit ab4989bd authored by Jan Trávníček's avatar Jan Trávníček Committed by Tomáš Pecka
Browse files

improve NFTA determinisation

parent 34eec775
No related branches found
No related tags found
1 merge request!119Merge jt
......@@ -14,15 +14,13 @@ namespace automaton {
namespace determinize {
 
template < class SymbolType, class StateType >
void constructTransitions ( const std::pair < const ext::pair < common::ranked_symbol < SymbolType > , ext::vector < StateType > >, StateType > & transition, unsigned i, const ext::multimap < StateType, ext::set < StateType > > & nftaStateToDftaStates, ext::vector < ext::set < StateType > > & transitionLHS, ext::map < ext::pair < common::ranked_symbol < SymbolType >, ext::vector < ext::set < StateType > > >, ext::set < StateType > > & resultTransition ) {
if ( i == transition.first.second.size ( ) ) {
resultTransition [ ext::make_pair ( transition.first.first, transitionLHS ) ].insert ( transition.second );
void constructTransitions ( const common::ranked_symbol < SymbolType > & symbol, typename ext::vector < StateType >::const_iterator state, typename ext::vector < StateType >::const_iterator end, const StateType & rhs, const ext::multimap < StateType, ext::set < StateType > > & nftaStateToDftaStates, ext::vector < ext::set < StateType > > & transitionLHS, ext::map < ext::pair < common::ranked_symbol < SymbolType >, ext::vector < ext::set < StateType > > >, ext::set < StateType > > & resultTransition ) {
if ( state == end ) {
resultTransition [ ext::make_pair ( symbol, transitionLHS ) ].insert ( rhs );
} else {
const StateType & nftaState = transition.first.second [ i ];
for ( const std::pair < const StateType, ext::set < StateType > > & dftaState : nftaStateToDftaStates.equal_range ( nftaState ) ) {
for ( const std::pair < const StateType, ext::set < StateType > > & dftaState : nftaStateToDftaStates.equal_range ( * state ) ) {
transitionLHS.push_back ( dftaState.second );
constructTransitions ( transition, i + 1, nftaStateToDftaStates, transitionLHS, resultTransition );
constructTransitions ( symbol, std::next ( state ), end, rhs, nftaStateToDftaStates, transitionLHS, resultTransition );
transitionLHS.pop_back ( );
}
}
......@@ -61,7 +59,7 @@ automaton::DFTA < SymbolType, ext::set < StateType > > Determinize::determinize
 
for ( const auto & transition : nfta.getTransitions ( ) ) {
ext::vector < ext::set < StateType > > transitionLHS;
constructTransitions ( transition, 0, nftaStateToDftaStates, transitionLHS, transitions );
constructTransitions ( transition.first.first, transition.first.second.begin ( ), transition.first.second.end ( ), transition.second, nftaStateToDftaStates, transitionLHS, transitions );
}
 
for ( const std::pair < const ext::pair < common::ranked_symbol < SymbolType >, ext::vector < ext::set < StateType > > >, ext::set < StateType > > & transition : transitions ) {
......
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