From ab4989bd7fe013851f11839952e52e0cff901c78 Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Tue, 3 Dec 2019 19:16:21 +0100 Subject: [PATCH] improve NFTA determinisation --- .../automaton/determinize/DeterminizeNFTAPart.hxx | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/alib2algo/src/automaton/determinize/DeterminizeNFTAPart.hxx b/alib2algo/src/automaton/determinize/DeterminizeNFTAPart.hxx index 2e165d3826..5853e929d0 100644 --- a/alib2algo/src/automaton/determinize/DeterminizeNFTAPart.hxx +++ b/alib2algo/src/automaton/determinize/DeterminizeNFTAPart.hxx @@ -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 ) { -- GitLab