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

use ext::excludes instead of intersection computation

parent b1d4373e
No related branches found
No related tags found
1 merge request!102Merge jt
......@@ -121,10 +121,8 @@ automaton::NFA < SymbolType, StateType > EpsilonRemoverIncoming::remove( const a
const ext::set<StateType> & F = fsm.getFinalStates( );
for( const auto & q : res.getStates( ) ) {
const ext::set<StateType> & cl = automaton::properties::EpsilonClosure::epsilonClosure( fsm, q );
ext::set<StateType> intersect;
 
set_intersection( cl.begin(), cl.end(), F.begin(), F.end(), std::inserter( intersect, intersect.begin() ) );
if( !intersect.empty ( ) )
if ( ! ext::excludes ( cl.begin(), cl.end(), F.begin(), F.end() ) )
res.addFinalState( q );
}
 
......
......@@ -116,12 +116,10 @@ automaton::NFA < SymbolType, StateType > SingleInitialState::convert(const autom
for ( const auto & t : automaton.getTransitions ( ) )
res.addTransition ( t.first.first, t.first.second, t.second );
 
// step 4, 5
ext::set < StateType > intersection;
std::set_intersection ( res.getFinalStates ( ).begin ( ), res.getFinalStates ( ).end ( ), automaton.getInitialStates ( ).begin ( ), automaton.getInitialStates ( ).end ( ), std::inserter ( intersection, intersection.begin ( ) ) );
res.setFinalStates ( automaton.getFinalStates ( ) );
if ( !intersection.empty ( ) )
// step 4, 5
if ( ! ext::excludes ( automaton.getFinalStates ( ).begin ( ), automaton.getFinalStates ( ).end ( ), automaton.getInitialStates ( ).begin ( ), automaton.getInitialStates ( ).end ( ) ) )
res.addFinalState ( q0 );
 
return res;
......@@ -146,12 +144,10 @@ automaton::EpsilonNFA < SymbolType, StateType > SingleInitialState::convert(cons
for ( const auto & t : automaton.getTransitions ( ) )
res.addTransition ( t.first.first, t.first.second, t.second );
 
// step 4, 5
ext::set < StateType > intersection;
std::set_intersection ( res.getFinalStates ( ).begin ( ), res.getFinalStates ( ).end ( ), automaton.getInitialStates ( ).begin ( ), automaton.getInitialStates ( ).end ( ), std::inserter ( intersection, intersection.begin ( ) ) );
res.setFinalStates ( automaton.getFinalStates ( ) );
if ( !intersection.empty ( ) )
// step 4, 5
if ( ! ext::excludes ( automaton.getFinalStates ( ).begin ( ), automaton.getFinalStates ( ).end ( ), automaton.getInitialStates ( ).begin ( ), automaton.getInitialStates ( ).end ( ) ) )
res.addFinalState ( q0 );
 
return res;
......
......@@ -44,4 +44,31 @@ TEST_CASE ( "FSM Single initial state", "[unit][algo][automaton][simplify]" ) {
 
CHECK (automaton::simplify::Normalize::normalize(dfa2) == automaton::simplify::Normalize::normalize(dfa3));
}
SECTION ( "MISNFA to single initial state NFA final state initial" ) {
DefaultStateType q = DefaultStateType ("q");
DefaultStateType q0 = DefaultStateType ("q0");
DefaultStateType q1 = DefaultStateType ("q1");
DefaultStateType q2 = DefaultStateType ("q2");
DefaultStateType q3 = DefaultStateType ("q3");
DefaultSymbolType a = DefaultSymbolType('a');
DefaultSymbolType b = DefaultSymbolType('b');
automaton::MultiInitialStateNFA < > automaton1;
automaton1.setStates({q0, q1, q2, q3});
automaton1.setInitialStates({q0, q1, q3});
automaton1.setFinalStates({q3});
automaton1.setInputAlphabet({a, b});
automaton1.addTransition(q0, a, q1);
automaton1.addTransition(q1, b, q2);
automaton1.addTransition(q2, a, q3);
automaton::NFA < > automaton2 = automaton::simplify::SingleInitialState::convert(automaton1);
automaton::DFA < DefaultSymbolType, ext::set < DefaultStateType > > dfa2 = automaton::simplify::Minimize::minimize(automaton::determinize::Determinize::determinize(automaton2));
automaton::DFA < DefaultSymbolType, ext::set < DefaultStateType > > dfa3 = automaton::simplify::Minimize::minimize(automaton::determinize::Determinize::determinize(automaton1));
CHECK (automaton::simplify::Normalize::normalize(dfa2) == automaton::simplify::Normalize::normalize(dfa3));
}
}
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