From 35e1e5ece7742232b58930dbbe607f4d43399a2a Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Tue, 27 Oct 2015 21:11:55 +0100 Subject: [PATCH] return pushdown store from computation --- alib2algo/src/automaton/run/Accept.cpp | 12 ++++++------ alib2algo/src/automaton/run/Occurrences.cpp | 8 ++++---- alib2algo/src/automaton/run/Result.cpp | 8 ++++---- alib2algo/src/automaton/run/Run.cpp | 16 ++++++++-------- alib2algo/src/automaton/run/Run.h | 9 +++++---- 5 files changed, 27 insertions(+), 26 deletions(-) diff --git a/alib2algo/src/automaton/run/Accept.cpp b/alib2algo/src/automaton/run/Accept.cpp index 618dd93ef1..d10cb113aa 100644 --- a/alib2algo/src/automaton/run/Accept.cpp +++ b/alib2algo/src/automaton/run/Accept.cpp @@ -73,15 +73,15 @@ bool Accept::accept ( const automaton::NFTA & automaton, const tree::RankedTree auto AcceptNFTARankedTree = Accept::RegistratorWrapper < bool, automaton::NFTA, tree::RankedTree > ( Accept::getInstance ( ), Accept::accept ); bool Accept::accept ( const automaton::InputDrivenDPDA & automaton, const string::LinearString & string ) { - std::tuple < bool, automaton::State, std::set < unsigned > > res = Run::calculateState ( automaton, string ); + std::tuple < bool, automaton::State, std::set < unsigned >, std::deque < alphabet::Symbol > > res = Run::calculateState ( automaton, string ); - return std::get < 0 > ( res ) && automaton.getFinalStates ( ).count ( std::get < 1 > ( res ) ); + return std::get < 0 > ( res ) && ( automaton.getFinalStates ( ).count ( std::get < 1 > ( res ) ) || ( automaton.getFinalStates ( ).size ( ) == 0 && std::get < 3 > ( res ).size ( ) == 0 ) ); } auto AcceptInputDrivenDPDALinearString = Accept::RegistratorWrapper < bool, automaton::InputDrivenDPDA, string::LinearString > ( Accept::getInstance ( ), Accept::accept ); bool Accept::accept ( const automaton::VisiblyPushdownDPDA & automaton, const string::LinearString & string ) { - std::tuple < bool, automaton::State, std::set < unsigned > > res = Run::calculateState ( automaton, string ); + std::tuple < bool, automaton::State, std::set < unsigned >, std::deque < alphabet::Symbol > > res = Run::calculateState ( automaton, string ); return std::get < 0 > ( res ) && automaton.getFinalStates ( ).count ( std::get < 1 > ( res ) ); } @@ -89,7 +89,7 @@ bool Accept::accept ( const automaton::VisiblyPushdownDPDA & automaton, const st auto AcceptVisiblyPushdownDPDALinearString = Accept::RegistratorWrapper < bool, automaton::VisiblyPushdownDPDA, string::LinearString > ( Accept::getInstance ( ), Accept::accept ); bool Accept::accept ( const automaton::RealTimeHeightDeterministicDPDA & automaton, const string::LinearString & string ) { - std::tuple < bool, automaton::State, std::set < unsigned > > res = Run::calculateState ( automaton, string ); + std::tuple < bool, automaton::State, std::set < unsigned >, std::deque < alphabet::Symbol > > res = Run::calculateState ( automaton, string ); return std::get < 0 > ( res ) && automaton.getFinalStates ( ).count ( std::get < 1 > ( res ) ); } @@ -97,9 +97,9 @@ bool Accept::accept ( const automaton::RealTimeHeightDeterministicDPDA & automat auto AcceptRealTimeHeightDeterministicDPDALinearString = Accept::RegistratorWrapper < bool, automaton::RealTimeHeightDeterministicDPDA, string::LinearString > ( Accept::getInstance ( ), Accept::accept ); bool Accept::accept ( const automaton::DPDA & automaton, const string::LinearString & string ) { - std::tuple < bool, automaton::State, std::set < unsigned > > res = Run::calculateState ( automaton, string ); + std::tuple < bool, automaton::State, std::set < unsigned >, std::deque < alphabet::Symbol > > res = Run::calculateState ( automaton, string ); - return std::get < 0 > ( res ) && automaton.getFinalStates ( ).count ( std::get < 1 > ( res ) ); + return std::get < 0 > ( res ) && ( automaton.getFinalStates ( ).count ( std::get < 1 > ( res ) ) || ( automaton.getFinalStates ( ).size ( ) == 0 && std::get < 3 > ( res ).size ( ) == 0 ) ); } auto AcceptDPDALinearString = Accept::RegistratorWrapper < bool, automaton::DPDA, string::LinearString > ( Accept::getInstance ( ), Accept::accept ); diff --git a/alib2algo/src/automaton/run/Occurrences.cpp b/alib2algo/src/automaton/run/Occurrences.cpp index 1530f533a1..3518905331 100644 --- a/alib2algo/src/automaton/run/Occurrences.cpp +++ b/alib2algo/src/automaton/run/Occurrences.cpp @@ -51,7 +51,7 @@ std::set < unsigned > Occurrences::occurrences ( const automaton::DFTA & automat auto OccurrencesDFTARankedTree = Occurrences::RegistratorWrapper < std::set < unsigned >, automaton::DFTA, tree::RankedTree > ( Occurrences::getInstance ( ), Occurrences::occurrences ); std::set < unsigned > Occurrences::occurrences ( const automaton::InputDrivenDPDA & automaton, const string::LinearString & string ) { - std::tuple < bool, automaton::State, std::set < unsigned > > res = Run::calculateState ( automaton, string ); + std::tuple < bool, automaton::State, std::set < unsigned >, std::deque < alphabet::Symbol > > res = Run::calculateState ( automaton, string ); return std::get < 2 > ( res ); } @@ -59,7 +59,7 @@ std::set < unsigned > Occurrences::occurrences ( const automaton::InputDrivenDPD auto OccurrencesInputDrivenDPDALinearString = Occurrences::RegistratorWrapper < std::set < unsigned >, automaton::InputDrivenDPDA, string::LinearString > ( Occurrences::getInstance ( ), Occurrences::occurrences ); std::set < unsigned > Occurrences::occurrences ( const automaton::VisiblyPushdownDPDA & automaton, const string::LinearString & string ) { - std::tuple < bool, automaton::State, std::set < unsigned > > res = Run::calculateState ( automaton, string ); + std::tuple < bool, automaton::State, std::set < unsigned >, std::deque < alphabet::Symbol > > res = Run::calculateState ( automaton, string ); return std::get < 2 > ( res ); } @@ -67,7 +67,7 @@ std::set < unsigned > Occurrences::occurrences ( const automaton::VisiblyPushdow auto OccurrencesVisiblyPushdownDPDALinearString = Occurrences::RegistratorWrapper < std::set < unsigned >, automaton::VisiblyPushdownDPDA, string::LinearString > ( Occurrences::getInstance ( ), Occurrences::occurrences ); std::set < unsigned > Occurrences::occurrences ( const automaton::RealTimeHeightDeterministicDPDA & automaton, const string::LinearString & string ) { - std::tuple < bool, automaton::State, std::set < unsigned > > res = Run::calculateState ( automaton, string ); + std::tuple < bool, automaton::State, std::set < unsigned >, std::deque < alphabet::Symbol > > res = Run::calculateState ( automaton, string ); return std::get < 2 > ( res ); } @@ -75,7 +75,7 @@ std::set < unsigned > Occurrences::occurrences ( const automaton::RealTimeHeight auto OccurrencesRealTimeHeightDeterministicDPDALinearString = Occurrences::RegistratorWrapper < std::set < unsigned >, automaton::RealTimeHeightDeterministicDPDA, string::LinearString > ( Occurrences::getInstance ( ), Occurrences::occurrences ); std::set < unsigned > Occurrences::occurrences ( const automaton::DPDA & automaton, const string::LinearString & string ) { - std::tuple < bool, automaton::State, std::set < unsigned > > res = Run::calculateState ( automaton, string ); + std::tuple < bool, automaton::State, std::set < unsigned >, std::deque < alphabet::Symbol > > res = Run::calculateState ( automaton, string ); return std::get < 2 > ( res ); } diff --git a/alib2algo/src/automaton/run/Result.cpp b/alib2algo/src/automaton/run/Result.cpp index 52a269eae7..d41f0c8939 100644 --- a/alib2algo/src/automaton/run/Result.cpp +++ b/alib2algo/src/automaton/run/Result.cpp @@ -47,7 +47,7 @@ label::Label Result::result ( const automaton::DFTA & automaton, const tree::Ran auto ResultDFTARankedTree = Result::RegistratorWrapper < label::Label, automaton::DFTA, tree::RankedTree > ( Result::getInstance ( ), Result::result ); label::Label Result::result ( const automaton::InputDrivenDPDA & automaton, const string::LinearString & string ) { - std::tuple < bool, automaton::State, std::set < unsigned > > res = Run::calculateState ( automaton, string ); + std::tuple < bool, automaton::State, std::set < unsigned >, std::deque < alphabet::Symbol > > res = Run::calculateState ( automaton, string ); if ( std::get < 0 > ( res ) ) return std::get < 1 > ( res ).getName ( ); @@ -57,7 +57,7 @@ label::Label Result::result ( const automaton::InputDrivenDPDA & automaton, cons auto ResultInputDrivenDPDALinearString = Result::RegistratorWrapper < label::Label, automaton::InputDrivenDPDA, string::LinearString > ( Result::getInstance ( ), Result::result ); label::Label Result::result ( const automaton::VisiblyPushdownDPDA & automaton, const string::LinearString & string ) { - std::tuple < bool, automaton::State, std::set < unsigned > > res = Run::calculateState ( automaton, string ); + std::tuple < bool, automaton::State, std::set < unsigned >, std::deque < alphabet::Symbol > > res = Run::calculateState ( automaton, string ); if ( std::get < 0 > ( res ) ) return std::get < 1 > ( res ).getName ( ); @@ -67,7 +67,7 @@ label::Label Result::result ( const automaton::VisiblyPushdownDPDA & automaton, auto ResultVisiblyPushdownDPDALinearString = Result::RegistratorWrapper < label::Label, automaton::VisiblyPushdownDPDA, string::LinearString > ( Result::getInstance ( ), Result::result ); label::Label Result::result ( const automaton::RealTimeHeightDeterministicDPDA & automaton, const string::LinearString & string ) { - std::tuple < bool, automaton::State, std::set < unsigned > > res = Run::calculateState ( automaton, string ); + std::tuple < bool, automaton::State, std::set < unsigned >, std::deque < alphabet::Symbol > > res = Run::calculateState ( automaton, string ); if ( std::get < 0 > ( res ) ) return std::get < 1 > ( res ).getName ( ); @@ -77,7 +77,7 @@ label::Label Result::result ( const automaton::RealTimeHeightDeterministicDPDA & auto ResultRealTimeHeightDeterministicDPDALinearString = Result::RegistratorWrapper < label::Label, automaton::RealTimeHeightDeterministicDPDA, string::LinearString > ( Result::getInstance ( ), Result::result ); label::Label Result::result ( const automaton::DPDA & automaton, const string::LinearString & string ) { - std::tuple < bool, automaton::State, std::set < unsigned > > res = Run::calculateState ( automaton, string ); + std::tuple < bool, automaton::State, std::set < unsigned >, std::deque < alphabet::Symbol > > res = Run::calculateState ( automaton, string ); if ( std::get < 0 > ( res ) ) return std::get < 1 > ( res ).getName ( ); diff --git a/alib2algo/src/automaton/run/Run.cpp b/alib2algo/src/automaton/run/Run.cpp index 5b3d003d0d..288c4dce29 100644 --- a/alib2algo/src/automaton/run/Run.cpp +++ b/alib2algo/src/automaton/run/Run.cpp @@ -213,7 +213,7 @@ bool Run::canPop ( const std::deque < alphabet::Symbol > & pushdownStore, const // ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -std::tuple < bool, State, std::set < unsigned > > Run::calculateState ( const automaton::InputDrivenDPDA & automaton, const string::LinearString & string ) { +std::tuple < bool, State, std::set < unsigned >, std::deque < alphabet::Symbol > > Run::calculateState ( const automaton::InputDrivenDPDA & automaton, const string::LinearString & string ) { automaton::State state = automaton.getInitialState ( ); std::deque < alphabet::Symbol > pushdownStore { automaton.getInitialSymbol ( ) @@ -257,12 +257,12 @@ std::tuple < bool, State, std::set < unsigned > > Run::calculateState ( const au std::clog << state << std::endl; } - return std::make_tuple ( res, state, occ ); + return std::make_tuple ( res, state, occ, pushdownStore ); } // ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -std::tuple < bool, State, std::set < unsigned > > Run::calculateState ( const automaton::VisiblyPushdownDPDA & automaton, const string::LinearString & string ) { +std::tuple < bool, State, std::set < unsigned >, std::deque < alphabet::Symbol > > Run::calculateState ( const automaton::VisiblyPushdownDPDA & automaton, const string::LinearString & string ) { automaton::State state = automaton.getInitialState ( ); std::deque < alphabet::Symbol > pushdownStore { automaton.getBottomOfTheStackSymbol ( ) @@ -322,12 +322,12 @@ std::tuple < bool, State, std::set < unsigned > > Run::calculateState ( const au std::clog << state << std::endl; } - return std::make_tuple ( res, state, occ ); + return std::make_tuple ( res, state, occ, pushdownStore ); } // ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -std::tuple < bool, State, std::set < unsigned > > Run::calculateState ( const automaton::RealTimeHeightDeterministicDPDA & automaton, const string::LinearString & string ) { +std::tuple < bool, State, std::set < unsigned >, std::deque < alphabet::Symbol > > Run::calculateState ( const automaton::RealTimeHeightDeterministicDPDA & automaton, const string::LinearString & string ) { automaton::State state = automaton.getInitialState ( ); std::deque < alphabet::Symbol > pushdownStore { automaton.getBottomOfTheStackSymbol ( ) @@ -400,12 +400,12 @@ std::tuple < bool, State, std::set < unsigned > > Run::calculateState ( const au std::clog << state << std::endl; } - return std::make_tuple ( res, state, occ ); + return std::make_tuple ( res, state, occ, pushdownStore ); } // ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -std::tuple < bool, State, std::set < unsigned > > Run::calculateState ( const automaton::DPDA & automaton, const string::LinearString & string ) { +std::tuple < bool, State, std::set < unsigned >, std::deque < alphabet::Symbol > > Run::calculateState ( const automaton::DPDA & automaton, const string::LinearString & string ) { automaton::State state = automaton.getInitialState ( ); std::deque < alphabet::Symbol > pushdownStore { automaton.getInitialSymbol ( ) @@ -460,7 +460,7 @@ std::tuple < bool, State, std::set < unsigned > > Run::calculateState ( const au } } - return std::make_tuple ( res, state, occ ); + return std::make_tuple ( res, state, occ, pushdownStore ); } // ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- diff --git a/alib2algo/src/automaton/run/Run.h b/alib2algo/src/automaton/run/Run.h index 6344f4116c..aae715ebec 100644 --- a/alib2algo/src/automaton/run/Run.h +++ b/alib2algo/src/automaton/run/Run.h @@ -12,6 +12,7 @@ #include <automaton/AutomatonFeatures.h> #include <string/LinearString.h> #include <tree/ranked/RankedTree.h> +#include <alphabet/Symbol.h> namespace automaton { @@ -27,10 +28,10 @@ public: static std::tuple < bool, std::set < State >, std::set < unsigned > > calculateStates ( const automaton::NFA & automaton, const string::LinearString & string ); static std::tuple < bool, State, std::set < unsigned > > calculateState ( const automaton::DFTA & automaton, const tree::RankedTree & tree ); static std::tuple < bool, std::set < State >, std::set < unsigned > > calculateStates ( const automaton::NFTA & automaton, const tree::RankedTree & tree ); - static std::tuple < bool, State, std::set < unsigned > > calculateState ( const automaton::InputDrivenDPDA & automaton, const string::LinearString & string ); - static std::tuple < bool, State, std::set < unsigned > > calculateState ( const automaton::VisiblyPushdownDPDA & automaton, const string::LinearString & string ); - static std::tuple < bool, State, std::set < unsigned > > calculateState ( const automaton::RealTimeHeightDeterministicDPDA & automaton, const string::LinearString & string ); - static std::tuple < bool, State, std::set < unsigned > > calculateState ( const automaton::DPDA & automaton, const string::LinearString & string ); + static std::tuple < bool, State, std::set < unsigned >, std::deque < alphabet::Symbol > > calculateState ( const automaton::InputDrivenDPDA & automaton, const string::LinearString & string ); + static std::tuple < bool, State, std::set < unsigned >, std::deque < alphabet::Symbol > > calculateState ( const automaton::VisiblyPushdownDPDA & automaton, const string::LinearString & string ); + static std::tuple < bool, State, std::set < unsigned >, std::deque < alphabet::Symbol > > calculateState ( const automaton::RealTimeHeightDeterministicDPDA & automaton, const string::LinearString & string ); + static std::tuple < bool, State, std::set < unsigned >, std::deque < alphabet::Symbol > > calculateState ( const automaton::DPDA & automaton, const string::LinearString & string ); }; } /* namespace run */ -- GitLab