Commit f77d8d09 authored by Ing. Jan Trávníček's avatar Ing. Jan Trávníček

intersect deterministic tree automata

parent e6cb7cd9
......@@ -24,4 +24,11 @@ auto AutomataIntersectionCartesianProductDFA2 = registration::AbstractRegister <
@param second Second automaton (A2)\n\
@return (non)deterministic FA representing the intersection of two automata" );
auto AutomataIntersectionCartesianProductDFTA = registration::AbstractRegister < automaton::transform::AutomataIntersectionCartesianProduct, automaton::DFTA < DefaultSymbolType, ext::pair < DefaultStateType, DefaultStateType > >, const automaton::DFTA < > &, const automaton::DFTA < > & > ( automaton::transform::AutomataIntersectionCartesianProduct::intersection ).setDocumentation (
"Intersects two finite automata.\n\
\n\
@param first First automaton (A1)\n\
@param second Second automaton (A2)\n\
@return (non)deterministic FA representing the intersection of two automata" );
} /* namespace */
......@@ -24,7 +24,10 @@
#ifndef AUTOMATA_INTERSECTION_CARTESIAN_H_
#define AUTOMATA_INTERSECTION_CARTESIAN_H_
#include <alib/foreach>
#include <automaton/FSM/EpsilonNFA.h>
#include <automaton/TA/NFTA.h>
namespace automaton {
......@@ -54,6 +57,12 @@ public:
*/
template < class SymbolType, class StateType1, class StateType2 >
static automaton::DFA < SymbolType, ext::pair < StateType1, StateType2 > > intersection(const automaton::DFA < SymbolType, StateType1 > & first, const automaton::DFA < SymbolType, StateType2 > & second);
/**
* @overload
*/
template < class SymbolType, class StateType1, class StateType2 >
static automaton::DFTA < SymbolType, ext::pair < StateType1, StateType2 > > intersection(const automaton::DFTA < SymbolType, StateType1 > & first, const automaton::DFTA < SymbolType, StateType2 > & second);
};
template < class SymbolType, class StateType1, class StateType2 >
......@@ -110,6 +119,36 @@ automaton::NFA < SymbolType, ext::pair < StateType1, StateType2 > > AutomataInte
return res;
}
template < class SymbolType, class StateType1, class StateType2 >
automaton::DFTA < SymbolType, ext::pair < StateType1, StateType2 > > AutomataIntersectionCartesianProduct::intersection(const automaton::DFTA < SymbolType, StateType1 > & first, const automaton::DFTA < SymbolType, StateType2 > & second) {
automaton::DFTA < SymbolType, ext::pair < StateType1, StateType2 > > res;
for(const auto& a : first.getInputAlphabet())
res.addInputSymbol(a);
for(const auto& a : second.getInputAlphabet())
res.addInputSymbol(a);
for(const auto& p : first.getStates())
for(const auto& q : second.getStates())
res.addState ( ext::make_pair ( p, q ) );
for(const auto& p : first.getFinalStates())
for(const auto& q : second.getFinalStates())
res.addFinalState ( ext::make_pair ( p, q ) );
for(const auto & tp : first.getTransitions ( ) )
for(const auto & tq : second.getTransitions ( ) )
if(tp.first.first == tq.first.first) {
ext::vector < ext::pair < StateType1, StateType2 > > source;
for ( ext::tuple < const StateType1 &, const StateType2 & > singleSourceState : ext::make_tuple_foreach ( tp.first.second, tq.first.second ) )
source.push_back ( ext::make_pair ( std::get < 0 > ( singleSourceState ), std::get < 1 > ( singleSourceState ) ) );
res.addTransition ( tp.first.first, source, ext::make_pair ( tp.second, tq.second ) );
}
return res;
}
} /* namespace transform */
} /* namespace automaton */
......
execute string::Parse @Automaton "DFTA alter 2 concat 2 iter 1 a 0 b 0 c 0 eps 0 emp 0
- - - [] - - - - al
- - - - [] [] [] [] as>
[al,al] [al,al] - - - - - - as
[as,as] [as,as] [as] - - - - - as
[al,as],[as,al] [al,as],[as,al] - - - - - - al" > $evenA
execute string::Parse @Automaton "DFTA alter 2 concat 2 iter 1 a 0 b 0 c 0 eps 0 emp 0
- - - - [] - - - bl>
- - - [] - [] [] [] bs
[bl,bl] [bl,bl] - - - - - - bs
[bs,bs] [bs,bs] [bs] - - - - - bs
[bl,bs],[bs,bl] [bl,bs],[bs,bl] - - - - - - bl" > $oddB
print automaton::transform::AutomataIntersectionCartesianProduct $evenA $oddB | string::Compose -
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment