From c8aa8e878be7a14dd61c3a127fd5a187a330f5ef Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Wed, 24 Apr 2019 09:11:46 +0200 Subject: [PATCH] shorten reachable and useful states computation code --- .../automaton/properties/ReachableStates.h | 28 ++++++++----------- .../src/automaton/properties/UsefulStates.h | 22 +++++++-------- 2 files changed, 22 insertions(+), 28 deletions(-) diff --git a/alib2algo/src/automaton/properties/ReachableStates.h b/alib2algo/src/automaton/properties/ReachableStates.h index 452a2f0942..b3591c905f 100644 --- a/alib2algo/src/automaton/properties/ReachableStates.h +++ b/alib2algo/src/automaton/properties/ReachableStates.h @@ -161,21 +161,19 @@ ext::set<StateType> ReachableStates::reachableStates( const automaton::DFTA < Sy ext::deque<ext::set<StateType>> Qi; Qi.push_back( ext::set<StateType>( ) ); - int i = 1; + int i = 0; // 1bc - while( true ) { - Qi.push_back( Qi.at( i - 1 ) ); + do { + i = i + 1; + + Qi.push_back( Qi.at( i - 1) ); for( const auto & transition : fta.getTransitions ( ) ) if ( std::all_of ( transition.first.second.begin ( ), transition.first.second.end ( ), [ & ] ( const StateType & state ) { return Qi.at ( i - 1 ).count ( state ); } ) ) Qi.at( i ).insert ( transition.second ); - if( Qi.at( i ) == Qi.at( i - 1 ) ) - break; - - i = i + 1; - } + } while ( Qi.at( i ) != Qi.at( i - 1 ) ); return Qi.at( i ); } @@ -186,21 +184,19 @@ ext::set<StateType> ReachableStates::reachableStates( const automaton::NFTA < Sy ext::deque<ext::set<StateType>> Qi; Qi.push_back( ext::set<StateType>( ) ); - int i = 1; + int i = 0; // 1bc - while( true ) { - Qi.push_back( Qi.at( i - 1 ) ); + do { + i = i + 1; + + Qi.push_back( Qi.at( i - 1) ); for( const auto & transition : fta.getTransitions ( ) ) if ( std::all_of ( transition.first.second.begin ( ), transition.first.second.end ( ), [ & ] ( const StateType & state ) { return Qi.at ( i - 1 ).count ( state ); } ) ) Qi.at( i ).insert ( transition.second ); - if( Qi.at( i ) == Qi.at( i - 1 ) ) - break; - - i = i + 1; - } + } while ( Qi.at( i ) != Qi.at( i - 1 ) ); return Qi.at( i ); } diff --git a/alib2algo/src/automaton/properties/UsefulStates.h b/alib2algo/src/automaton/properties/UsefulStates.h index da3610dac3..6d40b0a874 100644 --- a/alib2algo/src/automaton/properties/UsefulStates.h +++ b/alib2algo/src/automaton/properties/UsefulStates.h @@ -122,20 +122,19 @@ ext::set<StateType> UsefulStates::usefulStates( const automaton::DFTA < SymbolTy Qi.push_back( ext::set<StateType>( ) ); Qi.at( 0 ) = fta.getFinalStates( ); - int i = 1; + int i = 0; // 1bc - while( true ) { + do { + i = i + 1; + Qi.push_back( Qi.at( i - 1 ) ); // copy Qi-1 into Qi for( const auto & p : Qi.at( i - 1 ) ) for( const auto & t : fta.getTransitionsToState ( p ) ) Qi.at( i ).insert( t.first.second.begin ( ), t.first.second.end ( ) ); - if( Qi.at( i ) == Qi.at( i - 1 ) ) - break; + } while ( Qi.at( i ) != Qi.at( i - 1 ) ); - i = i + 1; - } return Qi.at( i ); } @@ -146,20 +145,19 @@ ext::set<StateType> UsefulStates::usefulStates( const automaton::NFTA < SymbolTy Qi.push_back( ext::set<StateType>( ) ); Qi.at( 0 ) = fta.getFinalStates( ); - int i = 1; + int i = 0; // 1bc - while( true ) { + do { + i = i + 1; + Qi.push_back( Qi.at( i - 1 ) ); // copy Qi-1 into Qi for( const auto & p : Qi.at( i - 1 ) ) for( const auto & t : fta.getTransitionsToState ( p ) ) Qi.at( i ).insert( t.first.second.begin ( ), t.first.second.end ( ) ); - if( Qi.at( i ) == Qi.at( i - 1 ) ) - break; + } while ( Qi.at( i ) != Qi.at( i - 1 ) ); - i = i + 1; - } return Qi.at( i ); } -- GitLab