Skip to content
Snippets Groups Projects
Commit b48cfb11 authored by Jan Trávníček's avatar Jan Trávníček
Browse files

verbose: print states pushdownStore and transition

parent 6638ed46
No related branches found
No related tags found
Loading
......@@ -15,6 +15,7 @@
#include <automaton/PDA/VisiblyPushdownDPDA.h>
#include <automaton/PDA/RealTimeHeightDeterministicDPDA.h>
#include <automaton/PDA/DPDA.h>
#include <common/GlobalData.h>
 
#include <deque>
 
......@@ -33,6 +34,9 @@ std::tuple < bool, State, std::set < unsigned > > Run::calculateState ( const au
if ( automaton.getFinalStates ( ).count ( state ) )
occurrences.insert ( i );
 
if ( common::GlobalData::verbose )
std::clog << state << std::endl;
for ( const alphabet::Symbol & symbol : string.getContent ( ) ) {
auto transition = automaton.getTransitions ( ).find ( std::make_pair ( state, symbol ) );
 
......@@ -46,6 +50,9 @@ std::tuple < bool, State, std::set < unsigned > > Run::calculateState ( const au
 
if ( automaton.getFinalStates ( ).count ( state ) )
occurrences.insert ( i );
if ( common::GlobalData::verbose )
std::clog << state << std::endl;
}
 
return std::make_tuple ( res, state, occurrences );
......@@ -65,6 +72,9 @@ std::tuple < bool, std::set < State >, std::set < unsigned > > Run::calculateSta
if ( automaton.getFinalStates ( ).count ( state ) )
occurrences.insert ( i );
 
if ( common::GlobalData::verbose )
std::clog << states << std::endl;
for ( const alphabet::Symbol & symbol : string.getContent ( ) ) {
std::set < State > next;
 
......@@ -83,6 +93,8 @@ std::tuple < bool, std::set < State >, std::set < unsigned > > Run::calculateSta
if ( automaton.getFinalStates ( ).count ( state ) )
occurrences.insert ( i );
 
if ( common::GlobalData::verbose )
std::clog << states << std::endl;
}
 
return std::make_tuple ( res, states, occurrences );
......@@ -119,6 +131,9 @@ std::pair < bool, State > Run::calculateState ( const automaton::DFTA & automato
 
if ( automaton.getFinalStates ( ).count ( state ) ) occ.insert ( tmp );
 
if ( common::GlobalData::verbose )
std::clog << state << std::endl;
return std::make_pair ( true, state );
}
 
......@@ -133,9 +148,9 @@ std::tuple < bool, State, std::set < unsigned > > Run::calculateState ( const au
// ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 
std::pair < bool, std::set < State > > Run::calculateStates ( const automaton::NFTA & automaton, const tree::RankedNode & node, std::set < unsigned > & occ, unsigned & i ) {
std::vector < std::set < State > > states;
std::vector < std::set < State > > resStates;
 
states.reserve ( node.getSymbol ( ).getRank ( ).getData ( ) );
resStates.reserve ( node.getSymbol ( ).getRank ( ).getData ( ) );
 
unsigned tmp = i;
i++;
......@@ -148,10 +163,10 @@ std::pair < bool, std::set < State > > Run::calculateStates ( const automaton::N
if ( childStates.second.empty ( ) )
sign = false;
 
states.push_back ( childStates.second );
resStates.push_back ( childStates.second );
}
 
std::set < State > res;
std::set < State > states;
 
for ( const auto & transition : automaton.getTransitions ( ) ) {
if ( transition.first.first != node.getSymbol ( ) ) continue;
......@@ -159,15 +174,18 @@ std::pair < bool, std::set < State > > Run::calculateStates ( const automaton::N
unsigned rank = transition.first.first.getRank ( ).getData ( );
 
for ( unsigned i = 0; i < rank; i++ )
if ( !states[i].count ( transition.first.second[i] ) ) break;
if ( !resStates[i].count ( transition.first.second[i] ) ) break;
 
if ( i == rank ) res.insert ( transition.second.begin ( ), transition.second.end ( ) );
if ( i == rank ) states.insert ( transition.second.begin ( ), transition.second.end ( ) );
}
 
for ( const State & state : res )
for ( const State & state : states )
if ( automaton.getFinalStates ( ).count ( state ) ) occ.insert ( tmp );
 
return std::make_pair ( sign, res );
if ( common::GlobalData::verbose )
std::clog << states << std::endl;
return std::make_pair ( sign, states );
}
 
std::tuple < bool, std::set < State >, std::set < unsigned > > Run::calculateStates ( const automaton::NFTA & automaton, const tree::RankedTree & tree ) {
......@@ -207,6 +225,9 @@ std::tuple < bool, State, std::set < unsigned > > Run::calculateState ( const au
if ( automaton.getFinalStates ( ).count ( state ) )
occ.insert ( i );
 
if ( common::GlobalData::verbose )
std::clog << state << std::endl;
for ( const alphabet::Symbol & symbol : string.getContent ( ) ) {
auto transition = automaton.getTransitions ( ).find ( std::make_pair ( state, symbol ) );
 
......@@ -231,6 +252,9 @@ std::tuple < bool, State, std::set < unsigned > > Run::calculateState ( const au
 
if ( automaton.getFinalStates ( ).count ( state ) )
occ.insert ( i );
if ( common::GlobalData::verbose )
std::clog << state << std::endl;
}
 
return std::make_tuple ( res, state, occ );
......@@ -250,6 +274,9 @@ std::tuple < bool, State, std::set < unsigned > > Run::calculateState ( const au
if ( automaton.getFinalStates ( ).count ( state ) )
occ.insert ( i );
 
if ( common::GlobalData::verbose )
std::clog << state << std::endl;
for ( const alphabet::Symbol & symbol : string.getContent ( ) ) {
if ( automaton.getCallInputAlphabet ( ).count ( symbol ) ) {
auto transition = automaton.getCallTransitions ( ).find ( std::make_pair ( state, symbol ) );
......@@ -290,6 +317,9 @@ std::tuple < bool, State, std::set < unsigned > > Run::calculateState ( const au
 
if ( automaton.getFinalStates ( ).count ( state ) )
occ.insert ( i );
if ( common::GlobalData::verbose )
std::clog << state << std::endl;
}
 
return std::make_tuple ( res, state, occ );
......@@ -309,6 +339,9 @@ std::tuple < bool, State, std::set < unsigned > > Run::calculateState ( const au
if ( automaton.getFinalStates ( ).count ( state ) )
occ.insert ( i );
 
if ( common::GlobalData::verbose )
std::clog << state << std::endl;
for ( auto symbolIter = string.getContent ( ).begin ( ); symbolIter != string.getContent ( ).end ( ); ) {
 
auto callTransition = automaton.getCallTransitions ( ).find ( std::make_pair ( state, * symbolIter ) );
......@@ -362,6 +395,9 @@ std::tuple < bool, State, std::set < unsigned > > Run::calculateState ( const au
 
if ( automaton.getFinalStates ( ).count ( state ) )
occ.insert ( i );
if ( common::GlobalData::verbose )
std::clog << state << std::endl;
}
 
return std::make_tuple ( res, state, occ );
......@@ -381,16 +417,19 @@ std::tuple < bool, State, std::set < unsigned > > Run::calculateState ( const au
if ( automaton.getFinalStates ( ).count ( state ) )
occ.insert ( i );
 
if ( common::GlobalData::verbose ) {
std::clog << "State : " << state << std::endl;
std::clog << "PushdownStore : " << pushdownStore << std::endl;
}
for ( auto symbolIter = string.getContent ( ).begin ( ); symbolIter != string.getContent ( ).end ( ); ) {
auto transitions = automaton.getTransitionsFromState ( state );
auto transition = transitions.begin ( );
 
for ( auto transition = transitions.begin ( ); transition != transitions.end ( ); transition++ ) {
for ( ; transition != transitions.end ( ); transition++ ) {
if ( ( std::get < 1 > ( transition->first ) != * symbolIter ) && !std::get < 1 > ( transition->first ).is < string::Epsilon > ( ) ) continue;
 
if ( !canPop ( pushdownStore, std::get < 2 > ( transition->first ) ) ) continue;
break;
if ( canPop ( pushdownStore, std::get < 2 > ( transition->first ) ) ) break;
}
 
if ( transition == transitions.end ( ) ) {
......@@ -398,6 +437,9 @@ std::tuple < bool, State, std::set < unsigned > > Run::calculateState ( const au
break;
}
 
if ( common::GlobalData::verbose )
std::clog << "Transition: " << * transition << std::endl;
for ( unsigned j = 0; j < std::get < 2 > ( transition->first ).size ( ); j++ ) pushdownStore.pop_back ( );
 
for ( auto iter = transition->second.second.rbegin ( ); iter != transition->second.second.rend ( ); ++iter ) pushdownStore.push_back ( * iter );
......@@ -411,6 +453,11 @@ std::tuple < bool, State, std::set < unsigned > > Run::calculateState ( const au
 
if ( automaton.getFinalStates ( ).count ( state ) )
occ.insert ( i );
if ( common::GlobalData::verbose ) {
std::clog << "State: " << state << std::endl;
std::clog << "PushdownStore: " << pushdownStore << std::endl;
}
}
 
return std::make_tuple ( res, state, occ );
......
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