From 260ca7c163b5e2de75f0baf2d6e0229b9a09d69e Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Fri, 2 Aug 2019 13:30:54 +0200 Subject: [PATCH] fix run of RHDPDA --- alib2algo/src/automaton/run/Run.h | 64 +++++++++++++++++++++++++------ 1 file changed, 52 insertions(+), 12 deletions(-) diff --git a/alib2algo/src/automaton/run/Run.h b/alib2algo/src/automaton/run/Run.h index afa42d77c1..de2a2adbc4 100644 --- a/alib2algo/src/automaton/run/Run.h +++ b/alib2algo/src/automaton/run/Run.h @@ -650,7 +650,6 @@ ext::tuple < bool, StateType, ext::set < unsigned >, ext::deque < PushdownStoreS }; unsigned i = 0; ext::set < unsigned > occ; - bool res = true; if ( automaton.getFinalStates ( ).count ( state ) ) occ.insert ( i ); @@ -660,6 +659,8 @@ ext::tuple < bool, StateType, ext::set < unsigned >, ext::deque < PushdownStoreS for ( auto symbolIter = string.getContent ( ).begin ( ); symbolIter != string.getContent ( ).end ( ); ) { + bool transitionFound = false; + auto callTransition = automaton.getCallTransitions ( ).find ( std::pair < StateType, common::symbol_or_epsilon < InputSymbolType > > ( state, * symbolIter ) ); if ( callTransition != automaton.getCallTransitions ( ).end ( ) ) { @@ -672,11 +673,10 @@ ext::tuple < bool, StateType, ext::set < unsigned >, ext::deque < PushdownStoreS if ( callTransition != automaton.getCallTransitions ( ).end ( ) ) { pushdownStore.push_back ( callTransition->second.second ); state = callTransition->second.first; - } else { - res = false; + transitionFound = true; } - if ( !res ) { + if ( ! transitionFound ) { auto returnTransition = automaton.getReturnTransitions ( ).find ( std::tuple < StateType, common::symbol_or_epsilon < InputSymbolType >, PushdownStoreSymbolType > ( state, * symbolIter, pushdownStore.back ( ) ) ); if ( returnTransition != automaton.getReturnTransitions ( ).end ( ) ) { @@ -689,12 +689,11 @@ ext::tuple < bool, StateType, ext::set < unsigned >, ext::deque < PushdownStoreS if ( returnTransition != automaton.getReturnTransitions ( ).end ( ) ) { pushdownStore.pop_back ( ); state = returnTransition->second; - } else { - res = false; + transitionFound = true; } } - if ( !res ) { + if ( ! transitionFound ) { auto localTransition = automaton.getLocalTransitions ( ).find ( std::pair < StateType, common::symbol_or_epsilon < InputSymbolType > > ( state, * symbolIter ) ); if ( localTransition != automaton.getLocalTransitions ( ).end ( ) ) { @@ -704,23 +703,64 @@ ext::tuple < bool, StateType, ext::set < unsigned >, ext::deque < PushdownStoreS localTransition = automaton.getLocalTransitions ( ).find ( std::make_pair ( state, common::symbol_or_epsilon < InputSymbolType > ( ) ) ); } - if ( localTransition != automaton.getLocalTransitions ( ).end ( ) ) + if ( localTransition != automaton.getLocalTransitions ( ).end ( ) ) { state = localTransition->second; - else - res = false; + transitionFound = true; + } } + if ( ! transitionFound ) + return ext::make_tuple ( false, state, occ, pushdownStore ); + if ( automaton.getFinalStates ( ).count ( state ) ) occ.insert ( i ); if ( common::GlobalData::verbose ) common::Streams::log << state << std::endl; + } + + while ( true ) { + + bool transitionFound = false; + + auto callTransition = automaton.getCallTransitions ( ).find ( std::make_pair ( state, common::symbol_or_epsilon < InputSymbolType > ( ) ) ); + + if ( callTransition != automaton.getCallTransitions ( ).end ( ) ) { + pushdownStore.push_back ( callTransition->second.second ); + state = callTransition->second.first; + transitionFound = true; + } + + if ( ! transitionFound ) { + auto returnTransition = automaton.getReturnTransitions ( ).find ( std::make_tuple ( state, common::symbol_or_epsilon < InputSymbolType > ( ), pushdownStore.back ( ) ) ); - if ( res == false ) + if ( returnTransition != automaton.getReturnTransitions ( ).end ( ) ) { + pushdownStore.pop_back ( ); + state = returnTransition->second; + transitionFound = true; + } + } + + if ( ! transitionFound ) { + auto localTransition = automaton.getLocalTransitions ( ).find ( std::make_pair ( state, common::symbol_or_epsilon < InputSymbolType > ( ) ) ); + + if ( localTransition != automaton.getLocalTransitions ( ).end ( ) ) { + state = localTransition->second; + transitionFound = true; + } + } + + if ( ! transitionFound ) break; + + if ( automaton.getFinalStates ( ).count ( state ) ) + occ.insert ( i ); + + if ( common::GlobalData::verbose ) + common::Streams::log << state << std::endl; } - return ext::make_tuple ( res, state, occ, pushdownStore ); + return ext::make_tuple ( true, state, occ, pushdownStore ); } // ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- GitLab