Skip to content
Snippets Groups Projects
Commit 81afeebd authored by Jan Travnicek's avatar Jan Travnicek
Browse files

use multimap in multi initial state epsilon nfa

parent 76fe40ef
No related branches found
No related tags found
No related merge requests found
Pipeline #35824 passed
......@@ -184,7 +184,7 @@ const regexp::UnboundedRegExpStructure < SymbolType > ToRegExpKleene::transition
ret.setStructure ( regexp::UnboundedRegExpEpsilon < SymbolType > ( ) );
 
for ( const auto & transition: automaton.getTransitionsFromState ( from ) ) {
if ( transition.second.count ( to ) ) {
if ( transition.second == to ) {
if ( transition.first.second.template is < SymbolType > ( ) )
ret = regexp::RegExpAlternate::alternate ( ret, regexp::UnboundedRegExpStructure < SymbolType > ( regexp::UnboundedRegExpSymbol < SymbolType > ( transition.first.second.template get < SymbolType > ( ) ) ) );
else
......
......@@ -142,12 +142,10 @@ automaton::EpsilonNFA < SymbolType, EpsilonType, StateType > SingleInitialState:
// step 2
for ( const auto & q : automaton.getInitialStates ( ) )
for(const auto & kv : automaton.getTransitionsFromState ( q ) )
for ( const StateType & to : kv.second )
res.addTransition ( q0, kv.first.second, to );
res.addTransition ( q0, kv.first.second, kv.second );
 
for ( const auto & t : automaton.getTransitions ( ) )
for ( const StateType & q : t.second )
res.addTransition ( t.first.first, t.first.second, q );
res.addTransition ( t.first.first, t.first.second, t.second );
 
// step 4, 5
ext::set < StateType > intersection;
......
......@@ -134,8 +134,7 @@ automaton::EpsilonNFA < SymbolType, EpsilonType, StateType > SingleInitialStateE
res.addTransition ( q0, q );
 
for ( const auto & t : automaton.getTransitions ( ) )
for ( const StateType & q : t.second )
res.addTransition ( t.first.first, t.first.second, q );
res.addTransition ( t.first.first, t.first.second, t.second );
 
// step 4, 5
res.setFinalStates ( automaton.getFinalStates ( ) );
......
......@@ -441,11 +441,10 @@ template < class SymbolType, class StateType >
template < class EpsilonType >
CompactNFA < SymbolType, StateType >::CompactNFA ( const MultiInitialStateEpsilonNFA < SymbolType, EpsilonType, StateType > & other ) : CompactNFA ( other.getStates ( ) + ext::set < StateType > { common::createUnique ( label::InitialStateLabel::instance < StateType > ( ), other.getStates ( ) ) }, other.getInputAlphabet ( ), common::createUnique ( label::InitialStateLabel::instance < StateType > ( ), other.getStates ( ) ), other.getFinalStates ( ) ) {
for ( const auto & transition : other.getTransitions ( ) )
for ( const auto & to : transition.second )
if ( transition.first.second.template is < EpsilonType > ( ) )
transitions.insert ( ext::make_pair ( transition.first.first, ext::vector < SymbolType > { } ), to );
else
transitions.insert ( ext::make_pair ( transition.first.first, ext::vector < SymbolType > { transition.first.second.template get < SymbolType > ( ) } ), to );
if ( transition.first.second.template is < EpsilonType > ( ) )
transitions.insert ( ext::make_pair ( transition.first.first, ext::vector < SymbolType > { } ), transition.second );
else
transitions.insert ( ext::make_pair ( transition.first.first, ext::vector < SymbolType > { transition.first.second.template get < SymbolType > ( ) } ), transition.second );
 
for ( const auto & state : other.getInitialStates ( ) )
transitions.insert ( ext::make_pair ( this->getInitialState ( ), ext::vector < SymbolType > { } ), state );
......@@ -478,8 +477,7 @@ CompactNFA < SymbolType, StateType >::CompactNFA ( const NFA < SymbolType, State
 
template < class SymbolType, class StateType >
CompactNFA < SymbolType, StateType >::CompactNFA ( const CompactDFA < SymbolType, StateType > & other ) : CompactNFA ( other.getStates ( ), other.getInputAlphabet ( ), other.getInitialState ( ), other.getFinalStates ( ) ) {
for ( const auto & transition : other.getTransitions ( ) )
transitions.insert ( transition );
transitions.insert ( other.getTransitions ( ).begin ( ), other.getTransitions ( ).end ( ) );
}
 
template < class SymbolType, class StateType >
......
......@@ -457,12 +457,10 @@ ExtendedNFA < SymbolType, StateType >::ExtendedNFA ( const MultiInitialStateEpsi
for ( const auto & transition : other.getTransitions ( ) ) {
if ( transition.first.second.template is < EpsilonType > ( ) ) {
ext::pair < StateType, regexp::UnboundedRegExpStructure < SymbolType > > key = ext::make_pair ( transition.first.first, regexp::UnboundedRegExpStructure < SymbolType > ( regexp::UnboundedRegExpEpsilon < SymbolType > ( ) ) );
for ( const StateType & to : transition.second )
transitions.insert ( key, to );
transitions.insert ( key, transition.second );
} else {
ext::pair < StateType, regexp::UnboundedRegExpStructure < SymbolType > > key = ext::make_pair ( transition.first.first, regexp::UnboundedRegExpStructure < SymbolType > ( regexp::UnboundedRegExpSymbol < SymbolType > ( transition.first.second.template get < SymbolType > ( ) ) ) );
for ( const StateType & to : transition.second )
transitions.insert ( key, to );
transitions.insert ( key, transition.second );
}
}
 
......
This diff is collapsed.
......@@ -446,14 +446,12 @@ MultiInitialStateNFA < SymbolType, StateType >::MultiInitialStateNFA ( ) : Multi
 
template < class SymbolType, class StateType >
MultiInitialStateNFA < SymbolType, StateType >::MultiInitialStateNFA ( const DFA < SymbolType, StateType > & other ) : MultiInitialStateNFA ( other.getStates ( ), other.getInputAlphabet ( ), { other.getInitialState ( ) }, other.getFinalStates ( ) ) {
for ( const auto & transition : other.getTransitions ( ) )
transitions.insert ( transition );
transitions.insert ( other.getTransitions ( ).begin ( ), other.getTransitions ( ).end ( ) );
}
 
template < class SymbolType, class StateType >
MultiInitialStateNFA < SymbolType, StateType >::MultiInitialStateNFA ( const NFA < SymbolType, StateType > & other ) : MultiInitialStateNFA ( other.getStates ( ), other.getInputAlphabet ( ), { other.getInitialState ( ) }, other.getFinalStates ( ) ) {
for ( const auto & transition : other.getTransitions ( ) )
transitions.insert ( transition );
transitions = other.getTransitions ( );
}
 
template < class SymbolType, class StateType >
......@@ -530,8 +528,11 @@ ext::multimap < ext::pair < StateType, SymbolType >, StateType > MultiInitialSta
 
template < class SymbolType, class StateType >
bool MultiInitialStateNFA < SymbolType, StateType >::isDeterministic ( ) const {
for ( const std::pair < const ext::pair < StateType, SymbolType >, ext::set < StateType > > & transition : transitions )
if ( transition.second.size ( ) > 1 )
if ( transitions.empty ( ) )
return true;
for ( auto iter = transitions.begin ( ); std::next ( iter ) != transitions.end ( ); ++ iter )
if ( iter->first == std::next ( iter )->first )
return false;
 
return getInitialStates ( ).size ( ) == 1;
......
......@@ -407,8 +407,7 @@ NFA < SymbolType, StateType >::NFA ( StateType initialState ) : NFA ( ext::set <
 
template<class SymbolType, class StateType >
NFA < SymbolType, StateType >::NFA ( const DFA < SymbolType, StateType > & other ) : NFA ( other.getStates ( ), other.getInputAlphabet ( ), other.getInitialState ( ), other.getFinalStates ( ) ) {
for ( const auto & transition : other.getTransitions ( ) )
transitions.insert ( transition );
transitions.insert ( other.getTransitions ( ).begin ( ), other.getTransitions ( ).end ( ) );
}
 
template<class SymbolType, class StateType >
......
......@@ -139,16 +139,15 @@ template < class SymbolType, class EpsilonType, class StateType >
void xmlApi < automaton::MultiInitialStateEpsilonNFA < SymbolType, EpsilonType, StateType > >::composeTransitions ( ext::deque < sax::Token > & out, const automaton::MultiInitialStateEpsilonNFA < SymbolType, EpsilonType, StateType > & automaton ) {
out.emplace_back ( "transitions", sax::Token::TokenType::START_ELEMENT );
 
for ( const auto & transition : automaton.getTransitions ( ) )
for ( const auto & targetState : transition.second ) {
out.emplace_back ( "transition", sax::Token::TokenType::START_ELEMENT );
for ( const auto & transition : automaton.getTransitions ( ) ) {
out.emplace_back ( "transition", sax::Token::TokenType::START_ELEMENT );
 
automaton::AutomatonToXMLComposer::composeTransitionFrom ( out, transition.first.first );
automaton::AutomatonToXMLComposer::composeTransitionInputEpsilonSymbol ( out, transition.first.second );
automaton::AutomatonToXMLComposer::composeTransitionTo ( out, targetState );
automaton::AutomatonToXMLComposer::composeTransitionFrom ( out, transition.first.first );
automaton::AutomatonToXMLComposer::composeTransitionInputEpsilonSymbol ( out, transition.first.second );
automaton::AutomatonToXMLComposer::composeTransitionTo ( out, transition.second );
 
out.emplace_back ( "transition", sax::Token::TokenType::END_ELEMENT );
}
out.emplace_back ( "transition", sax::Token::TokenType::END_ELEMENT );
}
 
out.emplace_back ( "transitions", sax::Token::TokenType::END_ELEMENT );
}
......
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