From bd67beb3417b5d395d24805f68f83abf72451f4b Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Fri, 16 Dec 2016 22:28:38 +0100 Subject: [PATCH] simplify automata transform algorithms --- .../transform/AutomataConcatenation.cpp | 41 +++++++------- ...AutomataConcatenationEpsilonTransition.cpp | 47 ++++++++-------- .../AutomataIntersectionCartesianProduct.cpp | 21 ++++---- .../AutomataUnionCartesianProduct.cpp | 25 ++++----- .../AutomataUnionEpsilonTransition.cpp | 53 +++++++++---------- .../automaton/transform/common/PairLabel.cpp | 20 ------- .../automaton/transform/common/PairLabel.h | 23 -------- 7 files changed, 89 insertions(+), 141 deletions(-) delete mode 100644 alib2algo/src/automaton/transform/common/PairLabel.cpp delete mode 100644 alib2algo/src/automaton/transform/common/PairLabel.h diff --git a/alib2algo/src/automaton/transform/AutomataConcatenation.cpp b/alib2algo/src/automaton/transform/AutomataConcatenation.cpp index 579be7d3d4..517384911e 100644 --- a/alib2algo/src/automaton/transform/AutomataConcatenation.cpp +++ b/alib2algo/src/automaton/transform/AutomataConcatenation.cpp @@ -7,7 +7,6 @@ #include "AutomataConcatenation.h" #include <label/Label.h> -#include "common/PairLabel.h" #define AUTOMATON_FIRST (label::Label(1)) #define AUTOMATON_SECOND (label::Label(2)) @@ -21,13 +20,13 @@ automaton::Automaton AutomataConcatenation::concatenation(const automaton::Autom } automaton::NFA < > AutomataConcatenation::concatenation(const automaton::NFA < > & first, const automaton::NFA < > & second) { - label::Label q01q02(pairLabel(first.getInitialState(), second.getInitialState())); - automaton::NFA < > res(pairLabel(AUTOMATON_FIRST, first.getInitialState())); + label::Label q01q02(first.getInitialState(), second.getInitialState()); + automaton::NFA < > res(label::Label(AUTOMATON_FIRST, first.getInitialState())); for(const auto& q : first.getStates()) - res.addState(pairLabel(AUTOMATON_FIRST, q)); + res.addState(label::Label(AUTOMATON_FIRST, q)); for(const auto& q : second.getStates()) - res.addState(pairLabel(AUTOMATON_SECOND, q)); + res.addState(label::Label(AUTOMATON_SECOND, q)); res.addState(q01q02); for(const auto& symbol : first.getInputAlphabet()) @@ -40,25 +39,25 @@ automaton::NFA < > AutomataConcatenation::concatenation(const automaton::NFA < > for(const auto& t : first.getTransitions()) { for(const auto& q : t.second) { - res.addTransition(pairLabel(AUTOMATON_FIRST, t.first.first), t.first.second, pairLabel(AUTOMATON_FIRST, q)); + res.addTransition(label::Label(AUTOMATON_FIRST, t.first.first), t.first.second, label::Label(AUTOMATON_FIRST, q)); if(first.getFinalStates().count(q) > 0) - res.addTransition(pairLabel(AUTOMATON_FIRST, t.first.first), t.first.second, pairLabel(AUTOMATON_SECOND, second.getInitialState())); + res.addTransition(label::Label(AUTOMATON_FIRST, t.first.first), t.first.second, label::Label(AUTOMATON_SECOND, second.getInitialState())); } } for(const auto& t : second.getTransitions()) for(const auto& q : t.second) - res.addTransition(pairLabel(AUTOMATON_SECOND, t.first.first), t.first.second, pairLabel(AUTOMATON_SECOND, q)); + res.addTransition(label::Label(AUTOMATON_SECOND, t.first.first), t.first.second, label::Label(AUTOMATON_SECOND, q)); for(const auto& t : first.getTransitionsFromState(first.getInitialState())) for(const auto& q : t.second) - res.addTransition(q01q02, t.first.second, pairLabel(AUTOMATON_FIRST, q)); + res.addTransition(q01q02, t.first.second, label::Label(AUTOMATON_FIRST, q)); for(const auto& t : second.getTransitionsFromState(second.getInitialState())) for(const auto& q : t.second) - res.addTransition(q01q02, t.first.second, pairLabel(AUTOMATON_SECOND, q)); + res.addTransition(q01q02, t.first.second, label::Label(AUTOMATON_SECOND, q)); for(const auto& q : second.getFinalStates()) - res.addFinalState(pairLabel(AUTOMATON_SECOND, q)); + res.addFinalState(label::Label(AUTOMATON_SECOND, q)); if(first.getFinalStates().count(first.getInitialState()) > 0) res.addFinalState(q01q02); @@ -68,13 +67,13 @@ automaton::NFA < > AutomataConcatenation::concatenation(const automaton::NFA < > auto AutomataConcatenationNFA = AutomataConcatenation::RegistratorWrapper<automaton::NFA < > , automaton::NFA < > >(AutomataConcatenation::concatenation); automaton::NFA < > AutomataConcatenation::concatenation(const automaton::DFA<>& first, const automaton::DFA<>& second) { - label::Label q01q02(pairLabel(first.getInitialState(), second.getInitialState())); - automaton::NFA < > res(pairLabel(AUTOMATON_FIRST, first.getInitialState())); + label::Label q01q02(first.getInitialState(), second.getInitialState()); + automaton::NFA < > res(label::Label(AUTOMATON_FIRST, first.getInitialState())); for(const auto& q : first.getStates()) - res.addState(pairLabel(AUTOMATON_FIRST, q)); + res.addState(label::Label(AUTOMATON_FIRST, q)); for(const auto& q : second.getStates()) - res.addState(pairLabel(AUTOMATON_SECOND, q)); + res.addState(label::Label(AUTOMATON_SECOND, q)); res.addState(q01q02); for(const auto& symbol : first.getInputAlphabet()) @@ -86,21 +85,21 @@ automaton::NFA < > AutomataConcatenation::concatenation(const automaton::DFA<>& res.setInitialState(q01q02); for(const auto& t : first.getTransitions()) { - res.addTransition(pairLabel(AUTOMATON_FIRST, t.first.first), t.first.second, pairLabel(AUTOMATON_FIRST, t.second)); + res.addTransition(label::Label(AUTOMATON_FIRST, t.first.first), t.first.second, label::Label(AUTOMATON_FIRST, t.second)); if(first.getFinalStates().count(t.second) > 0) - res.addTransition(pairLabel(AUTOMATON_FIRST, t.first.first), t.first.second, pairLabel(AUTOMATON_SECOND, second.getInitialState())); + res.addTransition(label::Label(AUTOMATON_FIRST, t.first.first), t.first.second, label::Label(AUTOMATON_SECOND, second.getInitialState())); } for(const auto& t : second.getTransitions()) - res.addTransition(pairLabel(AUTOMATON_SECOND, t.first.first), t.first.second, pairLabel(AUTOMATON_SECOND, t.second)); + res.addTransition(label::Label(AUTOMATON_SECOND, t.first.first), t.first.second, label::Label(AUTOMATON_SECOND, t.second)); for(const auto& t : first.getTransitionsFromState(first.getInitialState())) - res.addTransition(q01q02, t.first.second, pairLabel(AUTOMATON_FIRST, t.second)); + res.addTransition(q01q02, t.first.second, label::Label(AUTOMATON_FIRST, t.second)); for(const auto& t : second.getTransitionsFromState(second.getInitialState())) - res.addTransition(q01q02, t.first.second, pairLabel(AUTOMATON_SECOND, t.second)); + res.addTransition(q01q02, t.first.second, label::Label(AUTOMATON_SECOND, t.second)); for(const auto& q : second.getFinalStates()) - res.addFinalState(pairLabel(AUTOMATON_SECOND, q)); + res.addFinalState(label::Label(AUTOMATON_SECOND, q)); if(first.getFinalStates().count(first.getInitialState()) > 0) res.addFinalState(q01q02); diff --git a/alib2algo/src/automaton/transform/AutomataConcatenationEpsilonTransition.cpp b/alib2algo/src/automaton/transform/AutomataConcatenationEpsilonTransition.cpp index b5a4ec0b77..508b5b5f41 100644 --- a/alib2algo/src/automaton/transform/AutomataConcatenationEpsilonTransition.cpp +++ b/alib2algo/src/automaton/transform/AutomataConcatenationEpsilonTransition.cpp @@ -7,10 +7,9 @@ #include "AutomataConcatenationEpsilonTransition.h" #include <label/Label.h> -#include "common/PairLabel.h" -#define AUTOMATON_FIRST 1 -#define AUTOMATON_SECOND 2 +#define AUTOMATON_FIRST (label::Label(1)) +#define AUTOMATON_SECOND (label::Label(2)) namespace automaton { @@ -21,7 +20,7 @@ automaton::Automaton AutomataConcatenationEpsilonTransition::concatenation(const } automaton::EpsilonNFA < > AutomataConcatenationEpsilonTransition::concatenation(const automaton::DFA<>& first, const automaton::DFA<>& second) { - automaton::EpsilonNFA < > res(pairLabel(label::Label(AUTOMATON_FIRST), first.getInitialState())); + automaton::EpsilonNFA < > res(label::Label(AUTOMATON_FIRST, first.getInitialState())); for(const auto& symbol : first.getInputAlphabet()) res.addInputSymbol(symbol); @@ -29,21 +28,21 @@ automaton::EpsilonNFA < > AutomataConcatenationEpsilonTransition::concatenation( res.addInputSymbol(symbol); for(const auto& q : first.getStates()) - res.addState(pairLabel(label::Label(AUTOMATON_FIRST), q)); + res.addState(label::Label(AUTOMATON_FIRST, q)); for(const auto& q : second.getStates()) - res.addState(pairLabel(label::Label(AUTOMATON_SECOND), q)); + res.addState(label::Label(AUTOMATON_SECOND, q)); for(const auto& q : second.getFinalStates()) - res.addFinalState(pairLabel(label::Label(AUTOMATON_SECOND), q)); + res.addFinalState(label::Label(AUTOMATON_SECOND, q)); for(const auto& t : first.getTransitions()) - res.addTransition(pairLabel(label::Label(AUTOMATON_FIRST), t.first.first), t.first.second, pairLabel(label::Label(AUTOMATON_FIRST), t.second)); + res.addTransition(label::Label(AUTOMATON_FIRST, t.first.first), t.first.second, label::Label(AUTOMATON_FIRST, t.second)); for(const auto& t : second.getTransitions()) - res.addTransition(pairLabel(label::Label(AUTOMATON_SECOND), t.first.first), t.first.second, pairLabel(label::Label(AUTOMATON_SECOND), t.second)); + res.addTransition(label::Label(AUTOMATON_SECOND, t.first.first), t.first.second, label::Label(AUTOMATON_SECOND, t.second)); for(const auto& q : first.getFinalStates()) - res.addTransition(pairLabel(label::Label(AUTOMATON_FIRST), q), pairLabel(label::Label(AUTOMATON_SECOND), second.getInitialState())); + res.addTransition(label::Label(AUTOMATON_FIRST, q), label::Label(AUTOMATON_SECOND, second.getInitialState())); return res; } @@ -51,7 +50,7 @@ automaton::EpsilonNFA < > AutomataConcatenationEpsilonTransition::concatenation( auto AutomataConcatenationEpsilonTransitionDFA = AutomataConcatenationEpsilonTransition::RegistratorWrapper<automaton::EpsilonNFA < >, automaton::DFA<>>(AutomataConcatenationEpsilonTransition::concatenation); automaton::EpsilonNFA < > AutomataConcatenationEpsilonTransition::concatenation(const automaton::NFA < > & first, const automaton::NFA < > & second) { - automaton::EpsilonNFA < > res(pairLabel(label::Label(AUTOMATON_FIRST), first.getInitialState())); + automaton::EpsilonNFA < > res(label::Label(AUTOMATON_FIRST, first.getInitialState())); for(const auto& symbol : first.getInputAlphabet()) res.addInputSymbol(symbol); @@ -59,23 +58,23 @@ automaton::EpsilonNFA < > AutomataConcatenationEpsilonTransition::concatenation( res.addInputSymbol(symbol); for(const auto& q : first.getStates()) - res.addState(pairLabel(label::Label(AUTOMATON_FIRST), q)); + res.addState(label::Label(AUTOMATON_FIRST, q)); for(const auto& q : second.getStates()) - res.addState(pairLabel(label::Label(AUTOMATON_SECOND), q)); + res.addState(label::Label(AUTOMATON_SECOND, q)); for(const auto& q : second.getFinalStates()) - res.addFinalState(pairLabel(label::Label(AUTOMATON_SECOND), q)); + res.addFinalState(label::Label(AUTOMATON_SECOND, q)); for(const auto& t : first.getTransitions()) for(const auto& q : t.second) - res.addTransition(pairLabel(label::Label(AUTOMATON_FIRST), t.first.first), t.first.second, pairLabel(label::Label(AUTOMATON_FIRST), q)); + res.addTransition(label::Label(AUTOMATON_FIRST, t.first.first), t.first.second, label::Label(AUTOMATON_FIRST, q)); for(const auto& t : second.getTransitions()) for(const auto& q : t.second) - res.addTransition(pairLabel(label::Label(AUTOMATON_SECOND), t.first.first), t.first.second, pairLabel(label::Label(AUTOMATON_SECOND), q)); + res.addTransition(label::Label(AUTOMATON_SECOND, t.first.first), t.first.second, label::Label(AUTOMATON_SECOND, q)); for(const auto& q : first.getFinalStates()) - res.addTransition(pairLabel(label::Label(AUTOMATON_FIRST), q), pairLabel(label::Label(AUTOMATON_SECOND), second.getInitialState())); + res.addTransition(label::Label(AUTOMATON_FIRST, q), label::Label(AUTOMATON_SECOND, second.getInitialState())); return res; } @@ -83,7 +82,7 @@ automaton::EpsilonNFA < > AutomataConcatenationEpsilonTransition::concatenation( auto AutomataConcatenationEpsilonTransitionNFA = AutomataConcatenationEpsilonTransition::RegistratorWrapper<automaton::EpsilonNFA < >, automaton::NFA < > >(AutomataConcatenationEpsilonTransition::concatenation); automaton::EpsilonNFA < > AutomataConcatenationEpsilonTransition::concatenation(const automaton::EpsilonNFA < > & first, const automaton::EpsilonNFA < > & second) { - automaton::EpsilonNFA < > res(pairLabel(label::Label(AUTOMATON_FIRST), first.getInitialState())); + automaton::EpsilonNFA < > res(label::Label(AUTOMATON_FIRST, first.getInitialState())); for(const auto& symbol : first.getInputAlphabet()) res.addInputSymbol(symbol); @@ -91,23 +90,23 @@ automaton::EpsilonNFA < > AutomataConcatenationEpsilonTransition::concatenation( res.addInputSymbol(symbol); for(const auto& q : first.getStates()) - res.addState(pairLabel(label::Label(AUTOMATON_FIRST), q)); + res.addState(label::Label(AUTOMATON_FIRST, q)); for(const auto& q : second.getStates()) - res.addState(pairLabel(label::Label(AUTOMATON_SECOND), q)); + res.addState(label::Label(AUTOMATON_SECOND, q)); for(const auto& q : second.getFinalStates()) - res.addFinalState(pairLabel(label::Label(AUTOMATON_SECOND), q)); + res.addFinalState(label::Label(AUTOMATON_SECOND, q)); for(const auto& t : first.getTransitions()) for(const auto& q : t.second) - res.addTransition(pairLabel(label::Label(AUTOMATON_FIRST), t.first.first), t.first.second, pairLabel(label::Label(AUTOMATON_FIRST), q)); + res.addTransition(label::Label(AUTOMATON_FIRST, t.first.first), t.first.second, label::Label(AUTOMATON_FIRST, q)); for(const auto& t : second.getTransitions()) for(const auto& q : t.second) - res.addTransition(pairLabel(label::Label(AUTOMATON_SECOND), t.first.first), t.first.second, pairLabel(label::Label(AUTOMATON_SECOND), q)); + res.addTransition(label::Label(AUTOMATON_SECOND, t.first.first), t.first.second, label::Label(AUTOMATON_SECOND, q)); for(const auto& q : first.getFinalStates()) - res.addTransition(pairLabel(label::Label(AUTOMATON_FIRST), q), pairLabel(label::Label(AUTOMATON_SECOND), second.getInitialState())); + res.addTransition(label::Label(AUTOMATON_FIRST, q), label::Label(AUTOMATON_SECOND, second.getInitialState())); return res; } diff --git a/alib2algo/src/automaton/transform/AutomataIntersectionCartesianProduct.cpp b/alib2algo/src/automaton/transform/AutomataIntersectionCartesianProduct.cpp index e366848a4c..3d7b0a3386 100644 --- a/alib2algo/src/automaton/transform/AutomataIntersectionCartesianProduct.cpp +++ b/alib2algo/src/automaton/transform/AutomataIntersectionCartesianProduct.cpp @@ -6,10 +6,7 @@ */ #include "AutomataIntersectionCartesianProduct.h" -#include "common/PairLabel.h" - -#define AUTOMATON_FIRST 1 -#define AUTOMATON_SECOND 2 +#include <label/LabelPairLabel.h> namespace automaton { @@ -20,7 +17,7 @@ automaton::Automaton AutomataIntersectionCartesianProduct::intersection(const au } automaton::DFA<> AutomataIntersectionCartesianProduct::intersection(const automaton::DFA<>& first, const automaton::DFA<>& second) { - label::Label q0(pairLabel(first.getInitialState(), second.getInitialState())); + label::Label q0(first.getInitialState(), second.getInitialState()); automaton::DFA<> res(q0); for(const auto& a : first.getInputAlphabet()) @@ -30,11 +27,11 @@ automaton::DFA<> AutomataIntersectionCartesianProduct::intersection(const automa for(const auto& p : first.getStates()) for(const auto& q : second.getStates()) - res.addState(pairLabel(p, q)); + res.addState(label::Label(p, q)); for(const auto& p : first.getFinalStates()) for(const auto& q : second.getFinalStates()) - res.addFinalState(pairLabel(p, q)); + res.addFinalState(label::Label(p, q)); for(const auto& state : res.getStates()) { const label::Label& label_p = static_cast<const label::LabelPairLabel&>(state.getData()).getData().first; @@ -43,7 +40,7 @@ automaton::DFA<> AutomataIntersectionCartesianProduct::intersection(const automa for(const auto& tp : first.getTransitionsFromState(label::Label(label_p))) for(const auto& tq : second.getTransitionsFromState(label::Label(label_q))) if(tp.first.second == tq.first.second) - res.addTransition(state, tp.first.second, pairLabel(tp.second, tq.second)); + res.addTransition(state, tp.first.second, label::Label(tp.second, tq.second)); } return res; @@ -52,7 +49,7 @@ automaton::DFA<> AutomataIntersectionCartesianProduct::intersection(const automa auto AutomataIntersectionCartesianProductDFA = AutomataIntersectionCartesianProduct::RegistratorWrapper<automaton::DFA<>, automaton::DFA<>>(AutomataIntersectionCartesianProduct::intersection); automaton::NFA < > AutomataIntersectionCartesianProduct::intersection(const automaton::NFA < > & first, const automaton::NFA < > & second) { - label::Label q0(pairLabel(first.getInitialState(), second.getInitialState())); + label::Label q0(first.getInitialState(), second.getInitialState()); automaton::NFA < > res(q0); for(const auto& a : first.getInputAlphabet()) @@ -62,11 +59,11 @@ automaton::NFA < > AutomataIntersectionCartesianProduct::intersection(const auto for(const auto& p : first.getStates()) for(const auto& q : second.getStates()) - res.addState(pairLabel(p, q)); + res.addState(label::Label(p, q)); for(const auto& p : first.getFinalStates()) for(const auto& q : second.getFinalStates()) - res.addFinalState(pairLabel(p, q)); + res.addFinalState(label::Label(p, q)); for(const auto& state : res.getStates()) { const label::Label& label_p = static_cast<const label::LabelPairLabel&>(state.getData()).getData().first; @@ -77,7 +74,7 @@ automaton::NFA < > AutomataIntersectionCartesianProduct::intersection(const auto if(tp.first.second == tq.first.second) for(const auto& p : tp.second) for(const auto& q : tq.second) - res.addTransition(state, tp.first.second, pairLabel(p, q)); + res.addTransition(state, tp.first.second, label::Label(p, q)); } return res; diff --git a/alib2algo/src/automaton/transform/AutomataUnionCartesianProduct.cpp b/alib2algo/src/automaton/transform/AutomataUnionCartesianProduct.cpp index 58aee07430..f3811eef86 100644 --- a/alib2algo/src/automaton/transform/AutomataUnionCartesianProduct.cpp +++ b/alib2algo/src/automaton/transform/AutomataUnionCartesianProduct.cpp @@ -7,10 +7,7 @@ #include "AutomataUnionCartesianProduct.h" #include <exception/CommonException.h> -#include "common/PairLabel.h" - -#define AUTOMATON_FIRST 1 -#define AUTOMATON_SECOND 2 +#include <label/LabelPairLabel.h> namespace automaton { @@ -24,7 +21,7 @@ automaton::DFA<> AutomataUnionCartesianProduct::unification(const automaton::DFA if(!first.isTotal() || !second.isTotal()) throw exception::CommonException("Automata must be total to unify with cartesian product"); - label::Label q0(pairLabel(first.getInitialState(), second.getInitialState())); + label::Label q0(first.getInitialState(), second.getInitialState()); automaton::DFA<> res(q0); for(const auto& a : first.getInputAlphabet()) @@ -34,15 +31,15 @@ automaton::DFA<> AutomataUnionCartesianProduct::unification(const automaton::DFA for(const auto& p : first.getStates()) for(const auto& q : second.getStates()) - res.addState(pairLabel(p, q)); + res.addState(label::Label(p, q)); for(const auto& p : first.getFinalStates()) for(const auto& q : second.getStates()) - res.addFinalState(pairLabel(p, q)); + res.addFinalState(label::Label(p, q)); for(const auto& p : first.getStates()) for(const auto& q : second.getFinalStates()) - res.addFinalState(pairLabel(p, q)); + res.addFinalState(label::Label(p, q)); for(const auto& state : res.getStates()) { const label::Label& label_p = static_cast<const label::LabelPairLabel&>(state.getData()).getData().first; @@ -51,7 +48,7 @@ automaton::DFA<> AutomataUnionCartesianProduct::unification(const automaton::DFA for(const auto& tp : first.getTransitionsFromState(label::Label(label_p))) for(const auto& tq : second.getTransitionsFromState(label::Label(label_q))) if(tp.first.second == tq.first.second) - res.addTransition(state, tp.first.second, pairLabel(tp.second, tq.second)); + res.addTransition(state, tp.first.second, label::Label(tp.second, tq.second)); } return res; @@ -63,7 +60,7 @@ automaton::NFA < > AutomataUnionCartesianProduct::unification(const automaton::N if(!first.isTotal() || !second.isTotal()) throw exception::CommonException("Automata must be total to unify with cartesian product"); - label::Label q0(pairLabel(first.getInitialState(), second.getInitialState())); + label::Label q0(first.getInitialState(), second.getInitialState()); automaton::NFA < > res(q0); for(const auto& a : first.getInputAlphabet()) @@ -73,15 +70,15 @@ automaton::NFA < > AutomataUnionCartesianProduct::unification(const automaton::N for(const auto& p : first.getStates()) for(const auto& q : second.getStates()) - res.addState(pairLabel(p, q)); + res.addState(label::Label(p, q)); for(const auto& p : first.getFinalStates()) for(const auto& q : second.getStates()) - res.addFinalState(pairLabel(p, q)); + res.addFinalState(label::Label(p, q)); for(const auto& p : first.getStates()) for(const auto& q : second.getFinalStates()) - res.addFinalState(pairLabel(p, q)); + res.addFinalState(label::Label(p, q)); for(const auto& state : res.getStates()) { const label::Label& label_p = static_cast<const label::LabelPairLabel&>(state.getData()).getData().first; @@ -92,7 +89,7 @@ automaton::NFA < > AutomataUnionCartesianProduct::unification(const automaton::N if(tp.first.second == tq.first.second) for(const auto& p : tp.second) for(const auto& q : tq.second) - res.addTransition(state, tp.first.second, pairLabel(p, q)); + res.addTransition(state, tp.first.second, label::Label(p, q)); } return res; diff --git a/alib2algo/src/automaton/transform/AutomataUnionEpsilonTransition.cpp b/alib2algo/src/automaton/transform/AutomataUnionEpsilonTransition.cpp index a8daa8c1ca..6f886e6732 100644 --- a/alib2algo/src/automaton/transform/AutomataUnionEpsilonTransition.cpp +++ b/alib2algo/src/automaton/transform/AutomataUnionEpsilonTransition.cpp @@ -6,12 +6,11 @@ */ #include "AutomataUnionEpsilonTransition.h" -#include "common/PairLabel.h" #include <label/InitialStateLabel.h> #include <common/createUnique.hpp> -#define AUTOMATON_FIRST 1 -#define AUTOMATON_SECOND 2 +#define AUTOMATON_FIRST (label::Label(1)) +#define AUTOMATON_SECOND (label::Label(2)) namespace automaton { @@ -24,9 +23,9 @@ automaton::Automaton AutomataUnionEpsilonTransition::unification(const automaton automaton::EpsilonNFA < > AutomataUnionEpsilonTransition::unification(const automaton::EpsilonNFA < > & first, const automaton::EpsilonNFA < > & second) { std::set<label::Label> states; for(const auto& q : first.getStates()) - states.insert(pairLabel(label::Label(AUTOMATON_FIRST), q)); + states.insert(label::Label(AUTOMATON_FIRST, q)); for(const auto& q : second.getStates()) - states.insert(pairLabel(label::Label(AUTOMATON_SECOND), q)); + states.insert(label::Label(AUTOMATON_SECOND, q)); label::Label q0 = common::createUnique(label::InitialStateLabel::instance < label::Label > ( ), states); automaton::EpsilonNFA < > res(q0); @@ -40,20 +39,20 @@ automaton::EpsilonNFA < > AutomataUnionEpsilonTransition::unification(const auto res.addState(q); for(const auto& q : first.getFinalStates()) - res.addFinalState(pairLabel(label::Label(AUTOMATON_FIRST), q)); + res.addFinalState(label::Label(AUTOMATON_FIRST, q)); for(const auto& q : second.getFinalStates()) - res.addFinalState(pairLabel(label::Label(AUTOMATON_SECOND), q)); + res.addFinalState(label::Label(AUTOMATON_SECOND, q)); - res.addTransition(q0, pairLabel(label::Label(AUTOMATON_FIRST), first.getInitialState())); - res.addTransition(q0, pairLabel(label::Label(AUTOMATON_SECOND), second.getInitialState())); + res.addTransition(q0, label::Label(AUTOMATON_FIRST, first.getInitialState())); + res.addTransition(q0, label::Label(AUTOMATON_SECOND, second.getInitialState())); for(const auto& t : first.getTransitions()) for(const auto& q : t.second) - res.addTransition(pairLabel(label::Label(AUTOMATON_FIRST), t.first.first), t.first.second, pairLabel(label::Label(AUTOMATON_FIRST), q)); + res.addTransition(label::Label(AUTOMATON_FIRST, t.first.first), t.first.second, label::Label(AUTOMATON_FIRST, q)); for(const auto& t : second.getTransitions()) for(const auto& q : t.second) - res.addTransition(pairLabel(label::Label(AUTOMATON_SECOND), t.first.first), t.first.second, pairLabel(label::Label(AUTOMATON_SECOND), q)); + res.addTransition(label::Label(AUTOMATON_SECOND, t.first.first), t.first.second, label::Label(AUTOMATON_SECOND, q)); return res; } @@ -63,9 +62,9 @@ auto AutomataUnionEpsilonTransitionEpsilonNFA = AutomataUnionEpsilonTransition:: automaton::EpsilonNFA < > AutomataUnionEpsilonTransition::unification(const automaton::NFA < > & first, const automaton::NFA < > & second) { std::set<label::Label> states; for(const auto& q : first.getStates()) - states.insert(pairLabel(label::Label(AUTOMATON_FIRST), q)); + states.insert(label::Label(AUTOMATON_FIRST, q)); for(const auto& q : second.getStates()) - states.insert(pairLabel(label::Label(AUTOMATON_SECOND), q)); + states.insert(label::Label(AUTOMATON_SECOND, q)); label::Label q0 = common::createUnique(label::InitialStateLabel::instance < label::Label > ( ), states); automaton::EpsilonNFA < > res(q0); @@ -79,20 +78,20 @@ automaton::EpsilonNFA < > AutomataUnionEpsilonTransition::unification(const auto res.addState(q); for(const auto& q : first.getFinalStates()) - res.addFinalState(pairLabel(label::Label(AUTOMATON_FIRST), q)); + res.addFinalState(label::Label(AUTOMATON_FIRST, q)); for(const auto& q : second.getFinalStates()) - res.addFinalState(pairLabel(label::Label(AUTOMATON_SECOND), q)); + res.addFinalState(label::Label(AUTOMATON_SECOND, q)); - res.addTransition(q0, pairLabel(label::Label(AUTOMATON_FIRST), first.getInitialState())); - res.addTransition(q0, pairLabel(label::Label(AUTOMATON_SECOND), second.getInitialState())); + res.addTransition(q0, label::Label(AUTOMATON_FIRST, first.getInitialState())); + res.addTransition(q0, label::Label(AUTOMATON_SECOND, second.getInitialState())); for(const auto& t : first.getTransitions()) for(const auto& q : t.second) - res.addTransition(pairLabel(label::Label(AUTOMATON_FIRST), t.first.first), t.first.second, pairLabel(label::Label(AUTOMATON_FIRST), q)); + res.addTransition(label::Label(AUTOMATON_FIRST, t.first.first), t.first.second, label::Label(AUTOMATON_FIRST, q)); for(const auto& t : second.getTransitions()) for(const auto& q : t.second) - res.addTransition(pairLabel(label::Label(AUTOMATON_SECOND), t.first.first), t.first.second, pairLabel(label::Label(AUTOMATON_SECOND), q)); + res.addTransition(label::Label(AUTOMATON_SECOND, t.first.first), t.first.second, label::Label(AUTOMATON_SECOND, q)); return res; } @@ -102,9 +101,9 @@ auto AutomataUnionEpsilonTransitionNFA = AutomataUnionEpsilonTransition::Registr automaton::EpsilonNFA < > AutomataUnionEpsilonTransition::unification(const automaton::DFA<>& first, const automaton::DFA<>& second) { std::set<label::Label> states; for(const auto& q : first.getStates()) - states.insert(pairLabel(label::Label(AUTOMATON_FIRST), q)); + states.insert(label::Label(AUTOMATON_FIRST, q)); for(const auto& q : second.getStates()) - states.insert(pairLabel(label::Label(AUTOMATON_SECOND), q)); + states.insert(label::Label(AUTOMATON_SECOND, q)); label::Label q0 = common::createUnique(label::InitialStateLabel::instance < label::Label > ( ), states); automaton::EpsilonNFA < > res(q0); @@ -118,18 +117,18 @@ automaton::EpsilonNFA < > AutomataUnionEpsilonTransition::unification(const auto res.addState(q); for(const auto& q : first.getFinalStates()) - res.addFinalState(pairLabel(label::Label(AUTOMATON_FIRST), q)); + res.addFinalState(label::Label(AUTOMATON_FIRST, q)); for(const auto& q : second.getFinalStates()) - res.addFinalState(pairLabel(label::Label(AUTOMATON_SECOND), q)); + res.addFinalState(label::Label(AUTOMATON_SECOND, q)); - res.addTransition(q0, pairLabel(label::Label(AUTOMATON_FIRST), first.getInitialState())); - res.addTransition(q0, pairLabel(label::Label(AUTOMATON_SECOND), second.getInitialState())); + res.addTransition(q0, label::Label(AUTOMATON_FIRST, first.getInitialState())); + res.addTransition(q0, label::Label(AUTOMATON_SECOND, second.getInitialState())); for(const auto& t : first.getTransitions()) - res.addTransition(pairLabel(label::Label(AUTOMATON_FIRST), t.first.first), t.first.second, pairLabel(label::Label(AUTOMATON_FIRST), t.second)); + res.addTransition(label::Label(AUTOMATON_FIRST, t.first.first), t.first.second, label::Label(AUTOMATON_FIRST, t.second)); for(const auto& t : second.getTransitions()) - res.addTransition(pairLabel(label::Label(AUTOMATON_SECOND), t.first.first), t.first.second, pairLabel(label::Label(AUTOMATON_SECOND), t.second)); + res.addTransition(label::Label(AUTOMATON_SECOND, t.first.first), t.first.second, label::Label(AUTOMATON_SECOND, t.second)); return res; } diff --git a/alib2algo/src/automaton/transform/common/PairLabel.cpp b/alib2algo/src/automaton/transform/common/PairLabel.cpp deleted file mode 100644 index 4f00576882..0000000000 --- a/alib2algo/src/automaton/transform/common/PairLabel.cpp +++ /dev/null @@ -1,20 +0,0 @@ -/* - * PairLabel.cpp - * - * Created on: 20. 11. 2014 - * Author: Tomas Pecka - */ - -#include "PairLabel.h" - -namespace automaton { - -namespace transform { - -label::Label pairLabel(const label::Label& first, const label::Label& second) { - return label::Label(label::LabelPairLabel(std::make_pair(first, second))); -} - -} /* namespace transform */ - -} /* namespace automaton */ diff --git a/alib2algo/src/automaton/transform/common/PairLabel.h b/alib2algo/src/automaton/transform/common/PairLabel.h deleted file mode 100644 index d5aef6f8a1..0000000000 --- a/alib2algo/src/automaton/transform/common/PairLabel.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * PairLabel.h - * - * Created on: 20. 11. 2014 - * Author: Tomas Pecka - */ - -#ifndef PAIR_LABEL_H_ -#define PAIR_LABEL_H_ - -#include <label/LabelPairLabel.h> - -namespace automaton { - -namespace transform { - -label::Label pairLabel(const label::Label& first, const label::Label& second); - -} /* namespace transform */ - -} /* namespace automaton */ - -#endif /* PAIR_LABEL_H_ */ -- GitLab