diff --git a/alib2algo/src/automaton/transform/AutomataConcatenation.h b/alib2algo/src/automaton/transform/AutomataConcatenation.h index 9f6cfad00b554eed371d2a216c012389132aae0b..69717cea029b6891663b63117e65d484ed7932fa 100644 --- a/alib2algo/src/automaton/transform/AutomataConcatenation.h +++ b/alib2algo/src/automaton/transform/AutomataConcatenation.h @@ -48,47 +48,43 @@ public: template < class AutomatonType > requires isDFA < AutomatonType > || isNFA < AutomatonType > automaton::NFA < typename AutomatonType::SymbolType, ext::pair < typename AutomatonType::StateType, unsigned > > AutomataConcatenation::concatenation ( const AutomatonType & first, const AutomatonType & second ) { - unsigned firstDefault = 1; - unsigned secondDefault = 2; + static const unsigned NONE = 0; + static const unsigned FIRST = 1; + static const unsigned SECOND = 2; - using SymbolType = typename AutomatonType::SymbolType; - using StateType = typename AutomatonType::StateType; + automaton::NFA < typename AutomatonType::SymbolType, ext::pair < typename AutomatonType::StateType, unsigned > > res ( { first.getInitialState ( ), FIRST } ); - automaton::NFA < SymbolType, ext::pair < StateType, unsigned > > res ( ext::make_pair ( first.getInitialState ( ), firstDefault ) ); - - for ( const StateType & q : first.getStates ( ) ) - res.addState ( ext::make_pair ( q, firstDefault ) ); - for ( const StateType & q : second.getStates ( ) ) - res.addState ( ext::make_pair ( q, secondDefault ) ); + for ( const auto & q : first.getStates ( ) ) + res.addState ( { q, FIRST } ); + for ( const auto & q : second.getStates ( ) ) + res.addState ( { q, SECOND } ); res.addInputSymbols ( first.getInputAlphabet ( ) ); res.addInputSymbols ( second.getInputAlphabet ( ) ); for ( const auto & t : first.getTransitions ( ) ) { - res.addTransition ( ext::make_pair ( t.first.first, firstDefault ), t.first.second, ext::make_pair ( t.second, firstDefault ) ); + res.addTransition ( { t.first.first, FIRST }, t.first.second, { t.second, FIRST } ); - if(first.getFinalStates().count(t.second) > 0) - res.addTransition ( ext::make_pair ( t.first.first, firstDefault ), t.first.second, ext::make_pair ( second.getInitialState ( ), secondDefault ) ); + if ( first.getFinalStates ( ).contains ( t.second ) ) + res.addTransition ( { t.first.first, FIRST }, t.first.second, { second.getInitialState ( ), SECOND } ); } for ( const auto& t : second.getTransitions ( ) ) - res.addTransition ( ext::make_pair ( t.first.first, secondDefault ), t.first.second, ext::make_pair ( t.second, secondDefault ) ); - - for ( const StateType & q : second.getFinalStates ( ) ) - res.addFinalState ( ext::make_pair ( q, secondDefault ) ); + res.addTransition ( { t.first.first, SECOND }, t.first.second, { t.second, SECOND } ); - if ( first.getFinalStates ( ).count ( first.getInitialState ( ) ) > 0 ) { - ext::pair < StateType, unsigned > q01q02 ( label::InitialStateLabel::instance < StateType > ( ), 0 ); + for ( const auto & q : second.getFinalStates ( ) ) + res.addFinalState ( { q, SECOND } ); + if ( first.getFinalStates ( ).contains ( first.getInitialState ( ) ) ) { + ext::pair < typename AutomatonType::StateType, unsigned > q01q02 ( label::InitialStateLabel::instance < typename AutomatonType::StateType > ( ), NONE ); res.addState ( q01q02 ); - res.setInitialState ( q01q02 ); for ( const auto & t : first.getTransitionsFromState ( first.getInitialState ( ) ) ) - res.addTransition ( q01q02, t.first.second, ext::make_pair ( t.second, firstDefault ) ); + res.addTransition ( q01q02, t.first.second, { t.second, FIRST } ); for ( const auto & t : second.getTransitionsFromState ( second.getInitialState ( ) ) ) - res.addTransition ( q01q02, t.first.second, ext::make_pair ( t.second, secondDefault ) ); + res.addTransition ( q01q02, t.first.second, { t.second, SECOND } ); res.addFinalState ( q01q02 ); }