diff --git a/alib2algo/src/automaton/run/Result.cpp b/alib2algo/src/automaton/run/Result.cpp index bd29e88d4fea8ee5752e59e9f1fc59fe09634c29..a4e6fd2705eb3e7316d3c3972e8bbf11727aaa80 100644 --- a/alib2algo/src/automaton/run/Result.cpp +++ b/alib2algo/src/automaton/run/Result.cpp @@ -21,66 +21,66 @@ namespace automaton { namespace run { -label::Label Result::result ( const automaton::Automaton & automaton, const alib::Object & object ) { - return dispatch ( automaton.getData ( ), object.getData ( ) ); +label::Label Result::result ( const automaton::Automaton & automaton, const alib::Object & object, const label::Label & failLabel ) { + return dispatch ( automaton.getData ( ), object.getData ( ), failLabel ); } -label::Label Result::result ( const automaton::DFA & automaton, const string::LinearString & string ) { +label::Label Result::result ( const automaton::DFA & automaton, const string::LinearString & string, const label::Label & failLabel ) { std::tuple < bool, automaton::State, std::set < unsigned > > res = Run::calculateState ( automaton, string ); if ( std::get < 0 > ( res ) ) return std::get < 1 > ( res ).getName ( ); - return label::labelFrom ( "fail" ); + return failLabel; } auto ResultDFALinearString = Result::RegistratorWrapper < label::Label, automaton::DFA, string::LinearString > ( Result::result ); -label::Label Result::result ( const automaton::DFTA & automaton, const tree::RankedTree & tree ) { +label::Label Result::result ( const automaton::DFTA & automaton, const tree::RankedTree & tree, const label::Label & failLabel ) { std::tuple < bool, automaton::State, std::set < unsigned > > res = Run::calculateState ( automaton, tree ); if ( std::get < 0 > ( res ) ) return std::get < 1 > ( res ).getName ( ); - return label::labelFrom ( "fail" ); + return failLabel; } auto ResultDFTARankedTree = Result::RegistratorWrapper < label::Label, automaton::DFTA, tree::RankedTree > ( Result::result ); -label::Label Result::result ( const automaton::InputDrivenDPDA & automaton, const string::LinearString & string ) { +label::Label Result::result ( const automaton::InputDrivenDPDA & automaton, const string::LinearString & string, const label::Label & failLabel ) { 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 ( ); - return label::labelFrom ( "fail" ); + return failLabel; } auto ResultInputDrivenDPDALinearString = Result::RegistratorWrapper < label::Label, automaton::InputDrivenDPDA, string::LinearString > ( Result::result ); -label::Label Result::result ( const automaton::VisiblyPushdownDPDA & automaton, const string::LinearString & string ) { +label::Label Result::result ( const automaton::VisiblyPushdownDPDA & automaton, const string::LinearString & string, const label::Label & failLabel ) { 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 ( ); - return label::labelFrom ( "fail" ); + return failLabel; } auto ResultVisiblyPushdownDPDALinearString = Result::RegistratorWrapper < label::Label, automaton::VisiblyPushdownDPDA, string::LinearString > ( Result::result ); -label::Label Result::result ( const automaton::RealTimeHeightDeterministicDPDA & automaton, const string::LinearString & string ) { +label::Label Result::result ( const automaton::RealTimeHeightDeterministicDPDA & automaton, const string::LinearString & string, const label::Label & failLabel ) { 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 ( ); - return label::labelFrom ( "fail" ); + return failLabel; } auto ResultRealTimeHeightDeterministicDPDALinearString = Result::RegistratorWrapper < label::Label, automaton::RealTimeHeightDeterministicDPDA, string::LinearString > ( Result::result ); -label::Label Result::result ( const automaton::DPDA & automaton, const string::LinearString & string ) { +label::Label Result::result ( const automaton::DPDA & automaton, const string::LinearString & string, const label::Label & failLabel ) { 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 ( ); - return label::labelFrom ( "fail" ); + return failLabel; } auto ResultDPDALinearString = Result::RegistratorWrapper < label::Label, automaton::DPDA, string::LinearString > ( Result::result ); diff --git a/alib2algo/src/automaton/run/Result.h b/alib2algo/src/automaton/run/Result.h index b4c5456a0899e65b24d4dba36740d0bce08e1eed..ace2ff0f89a4a351171e3410e207839208fc613e 100644 --- a/alib2algo/src/automaton/run/Result.h +++ b/alib2algo/src/automaton/run/Result.h @@ -19,20 +19,20 @@ namespace automaton { namespace run { -class Result : public std::DoubleDispatch < Result, label::Label, automaton::AutomatonBase, alib::ObjectBase > { +class Result : public std::DoubleDispatchLastStaticParam < Result, label::Label, automaton::AutomatonBase, alib::ObjectBase, const label::Label & > { public: /** * Performs conversion. * @return left regular grammar equivalent to source automaton. */ - static label::Label result ( const automaton::Automaton & automaton, const alib::Object & object ); - - static label::Label result ( const automaton::DFA & automaton, const string::LinearString & string ); - static label::Label result ( const automaton::DFTA & automaton, const tree::RankedTree & tree ); - static label::Label result ( const automaton::InputDrivenDPDA & automaton, const string::LinearString & string ); - static label::Label result ( const automaton::VisiblyPushdownDPDA & automaton, const string::LinearString & string ); - static label::Label result ( const automaton::RealTimeHeightDeterministicDPDA & automaton, const string::LinearString & string ); - static label::Label result ( const automaton::DPDA & automaton, const string::LinearString & string ); + static label::Label result ( const automaton::Automaton & automaton, const alib::Object & object, const label::Label & failLabel = label::labelFrom ( "fail" ) ); + + static label::Label result ( const automaton::DFA & automaton, const string::LinearString & string, const label::Label & failLabel = label::labelFrom ( "fail" ) ); + static label::Label result ( const automaton::DFTA & automaton, const tree::RankedTree & tree, const label::Label & failLabel = label::labelFrom ( "fail" ) ); + static label::Label result ( const automaton::InputDrivenDPDA & automaton, const string::LinearString & string, const label::Label & failLabel = label::labelFrom ( "fail" ) ); + static label::Label result ( const automaton::VisiblyPushdownDPDA & automaton, const string::LinearString & string, const label::Label & failLabel = label::labelFrom ( "fail" ) ); + static label::Label result ( const automaton::RealTimeHeightDeterministicDPDA & automaton, const string::LinearString & string, const label::Label & failLabel = label::labelFrom ( "fail" ) ); + static label::Label result ( const automaton::DPDA & automaton, const string::LinearString & string, const label::Label & failLabel = label::labelFrom ( "fail" ) ); }; diff --git a/arun2/src/arun.cpp b/arun2/src/arun.cpp index c871afe9520a484c25dec945a300af04e6d8b5e3..f0109fe6ea8df82df9cc4ab2689102bd87cc15b1 100644 --- a/arun2/src/arun.cpp +++ b/arun2/src/arun.cpp @@ -46,6 +46,9 @@ int main(int argc, char* argv[]) { TCLAP::ValueArg<std::string> input( "i", "input", "Input from file", false, "-", "file"); cmd.add( input ); + TCLAP::ValueArg<std::string> failState( "f", "fail_state", "Override default fail state", false, "-", "file"); + cmd.add( failState ); + TCLAP::ValueArg<std::string> automaton( "a", "automaton", "Automaton to run", false, "-", "file"); cmd.add( automaton ); @@ -85,7 +88,15 @@ int main(int argc, char* argv[]) { measurements::start("Output write", measurements::Type::AUXILIARY); alib::XmlDataFactory::toStdout( res ); - } else if( type.getValue() == "result") { + } else if( type.getValue() == "result" && failState.isSet ( ) ) { + label::Label failStateLabel = alib::XmlDataFactory::fromTokens<label::Label>(sax::FromXMLParserHelper::parseInput(failState)); + label::Label res = automaton::run::Result::result(automatonData, inputData, failStateLabel); + + measurements::end(); + measurements::start("Output write", measurements::Type::AUXILIARY); + + alib::XmlDataFactory::toStdout( res ); + } else if( type.getValue() == "result" ) { label::Label res = automaton::run::Result::result(automatonData, inputData); measurements::end();