From f0ebb540ee62afb8b2fedf9a8866e94e7dd7a6db Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Mon, 14 Nov 2016 09:57:21 +0100 Subject: [PATCH] template Tikz, GasTex and Dot in convert binary --- aconvert2/src/DotConverter.cpp | 1855 +------------------ aconvert2/src/DotConverter.h | 2015 ++++++++++++++++++++- aconvert2/src/GasTexConverter.cpp | 1418 +-------------- aconvert2/src/GasTexConverter.h | 1553 +++++++++++++++- aconvert2/src/TikZConverter.cpp | 1955 +------------------- aconvert2/src/TikZConverter.h | 2101 +++++++++++++++++++++- aconvert2/src/common/converterCommon.hpp | 20 + 7 files changed, 5588 insertions(+), 5329 deletions(-) create mode 100644 aconvert2/src/common/converterCommon.hpp diff --git a/aconvert2/src/DotConverter.cpp b/aconvert2/src/DotConverter.cpp index 88bcd01755..aa281a9f88 100644 --- a/aconvert2/src/DotConverter.cpp +++ b/aconvert2/src/DotConverter.cpp @@ -7,1878 +7,27 @@ #include "DotConverter.h" -#include <automaton/FSM/NFA.h> -#include <automaton/FSM/EpsilonNFA.h> -#include <automaton/FSM/MultiInitialStateNFA.h> -#include <automaton/FSM/DFA.h> -#include <automaton/FSM/ExtendedNFA.h> -#include <automaton/FSM/CompactNFA.h> -#include <automaton/TA/NFTA.h> -#include <automaton/TA/DFTA.h> -#include <automaton/PDA/NPDA.h> -#include <automaton/PDA/SinglePopNPDA.h> -#include <automaton/PDA/InputDrivenDPDA.h> -#include <automaton/PDA/InputDrivenNPDA.h> -#include <automaton/PDA/VisiblyPushdownDPDA.h> -#include <automaton/PDA/VisiblyPushdownNPDA.h> -#include <automaton/PDA/RealTimeHeightDeterministicDPDA.h> -#include <automaton/PDA/RealTimeHeightDeterministicNPDA.h> -#include <automaton/PDA/DPDA.h> -#include <automaton/PDA/SinglePopDPDA.h> -#include <automaton/TM/OneTapeDTM.h> - -#include <factory/StringDataFactory.hpp> - -#include <exception/CommonException.h> - -#include <string/String.h> - -#include <set> -#include <map> -#include <list> -#include <utility> -#include <vector> -#include <typeinfo> - -auto replace = [](std::string& str, const std::string& what, const std::string& with) { - size_t index = 0; - while((index = str.find(what, index)) != std::string::npos) { - str.replace(index, what.length(), with); - index += with.length(); - } -}; - void DotConverter::convert(std::ostream& out, const automaton::Automaton& a) { dispatch(out, a.getData()); } -void DotConverter::convert(std::ostream& out, const automaton::EpsilonNFA < > & a) { - out << "digraph automaton {\n"; - out << "rankdir=LR;\n"; - int cnt = 1; - - //Map states to indices - std::map<label::Label, int> states; - for (const label::Label& state : a.getStates()) { - states.insert(std::make_pair(state, cnt++)); - } - - //Print final states - for (const label::Label& state : a.getFinalStates()) { - out << "node [shape = doublecircle, label=\"" << alib::StringDataFactory::toString(state) << "\"]; " << states.find(state)->second << ";\n"; - } - - //Print nonfinal states - for (const auto& state : states) { - if (!a.getFinalStates().count(state.first)) { - out << "node [shape = circle, label=\"" << alib::StringDataFactory::toString(state.first) << "\" ]; " << state.second << ";\n"; - } - } - - //Mark initial states - out << "node [shape = plaintext, label=\"start\"]; 0; \n"; - out << "0 -> " << states.find(a.getInitialState())->second << ";\n"; - - transitions(a, states, out); - out << "}"; -} - auto DotConverterEpsilonNFA = DotConverter::RegistratorWrapper<void, automaton::EpsilonNFA < > >(DotConverter::convert); - -void DotConverter::convert(std::ostream& out, const automaton::MultiInitialStateNFA < >& a) { - out << "digraph automaton {\n"; - out << "rankdir=LR;\n"; - int cnt = 1; - - //Map states to indices - std::map<label::Label, int> states; - for (const label::Label& state : a.getStates()) { - states.insert(std::make_pair(state, cnt++)); - } - - //Print final states - for (const label::Label& state : a.getFinalStates()) { - out << "node [shape = doublecircle, label=\"" << alib::StringDataFactory::toString(state) << "\"]; " << states.find(state)->second << ";\n"; - } - - //Print nonfinal states - for (const auto& state : states) { - if (!a.getFinalStates().count(state.first)) { - out << "node [shape = circle, label=\"" << alib::StringDataFactory::toString(state.first) << "\" ]; " << state.second << ";\n"; - } - } - - //Mark initial states - out << "node [shape = plaintext, label=\"start\"]; 0; \n"; - for (const label::Label& state : a.getInitialStates()) { - out << "0 -> " << states.find(state)->second << ";\n"; - } - - transitions(a, states, out); - out << "}"; -} - auto DotConverterMultiInitialStateNFA = DotConverter::RegistratorWrapper<void, automaton::MultiInitialStateNFA < >>(DotConverter::convert); - -void DotConverter::convert(std::ostream& out, const automaton::NFA < > & a) { - out << "digraph automaton {\n"; - out << "rankdir=LR;\n"; - int cnt = 1; - - //Map states to indices - std::map<label::Label, int> states; - for (const label::Label& state : a.getStates()) { - states.insert(std::make_pair(state, cnt++)); - } - - //Print final states - for (const label::Label& state : a.getFinalStates()) { - out << "node [shape = doublecircle, label=\"" << alib::StringDataFactory::toString(state) << "\"]; " << states.find(state)->second << ";\n"; - } - - //Print nonfinal states - for (const auto& state : states) { - if (!a.getFinalStates().count(state.first)) { - out << "node [shape = circle, label=\"" << alib::StringDataFactory::toString(state.first) << "\" ]; " << state.second << ";\n"; - } - } - - //Mark initial states - out << "node [shape = plaintext, label=\"start\"]; 0; \n"; - out << "0 -> " << states.find(a.getInitialState())->second << ";\n"; - - transitions(a, states, out); - out << "}"; -} - auto DotConverterNFA = DotConverter::RegistratorWrapper<void, automaton::NFA < > >(DotConverter::convert); - -void DotConverter::convert(std::ostream& out, const automaton::DFA<>& a) { - out << "digraph automaton {\n"; - out << "rankdir=LR;\n"; - int cnt = 1; - - //Map states to indices - std::map<label::Label, int> states; - for (const label::Label& state : a.getStates()) { - states.insert(std::make_pair(state, cnt++)); - } - - //Print final states - for (const label::Label& state : a.getFinalStates()) { - out << "node [shape = doublecircle, label=\"" << alib::StringDataFactory::toString(state) << "\"]; " << states.find(state)->second << ";\n"; - } - - //Print nonfinal states - for (const auto& state : states) { - if (!a.getFinalStates().count(state.first)) { - out << "node [shape = circle, label=\"" << alib::StringDataFactory::toString(state.first) << "\" ]; " << state.second << ";\n"; - } - } - - //Mark initial states - out << "node [shape = plaintext, label=\"start\"]; 0; \n"; - out << "0 -> " << states.find(a.getInitialState())->second << ";\n"; - - transitions(a, states, out); - out << "}"; -} - -auto DotConverterDFA = DotConverter::RegistratorWrapper<void, automaton::DFA<>>(DotConverter::convert); - -void DotConverter::convert(std::ostream& out, const automaton::ExtendedNFA < > & a) { - out << "digraph automaton {\n"; - out << "rankdir=LR;\n"; - int cnt = 1; - - //Map states to indices - std::map<label::Label, int> states; - for (const label::Label& state : a.getStates()) { - states.insert(std::make_pair(state, cnt++)); - } - - //Print final states - for (const label::Label& state : a.getFinalStates()) { - out << "node [shape = doublecircle, label=\"" << alib::StringDataFactory::toString(state) << "\"]; " << states.find(state)->second << ";\n"; - } - - //Print nonfinal states - for (const auto& state : states) { - if (!a.getFinalStates().count(state.first)) { - out << "node [shape = circle, label=\"" << alib::StringDataFactory::toString(state.first) << "\" ]; " << state.second << ";\n"; - } - } - - //Mark initial states - out << "node [shape = plaintext, label=\"start\"]; 0; \n"; - out << "0 -> " << states.find(a.getInitialState())->second << ";\n"; - - transitions(a, states, out); - out << "}"; -} - +auto DotConverterDFA = DotConverter::RegistratorWrapper<void, automaton::DFA < > >(DotConverter::convert); auto DotConverterExtendedNFA = DotConverter::RegistratorWrapper<void, automaton::ExtendedNFA < > >(DotConverter::convert); - -void DotConverter::convert(std::ostream& out, const automaton::CompactNFA < > & a) { - out << "digraph automaton {\n"; - out << "rankdir=LR;\n"; - int cnt = 1; - - //Map states to indices - std::map<label::Label, int> states; - for (const label::Label& state : a.getStates()) { - states.insert(std::make_pair(state, cnt++)); - } - - //Print final states - for (const label::Label& state : a.getFinalStates()) { - out << "node [shape = doublecircle, label=\"" << alib::StringDataFactory::toString(state) << "\"]; " << states.find(state)->second << ";\n"; - } - - //Print nonfinal states - for (const auto& state : states) { - if (!a.getFinalStates().count(state.first)) { - out << "node [shape = circle, label=\"" << alib::StringDataFactory::toString(state.first) << "\" ]; " << state.second << ";\n"; - } - } - - //Mark initial states - out << "node [shape = plaintext, label=\"start\"]; 0; \n"; - out << "0 -> " << states.find(a.getInitialState())->second << ";\n"; - - transitions(a, states, out); - out << "}"; -} - auto DotConverterCompactNFA = DotConverter::RegistratorWrapper<void, automaton::CompactNFA < > >(DotConverter::convert); - -void DotConverter::convert(std::ostream& out, const automaton::NFTA < > & a) { - out << "digraph automaton {\n"; - out << "rankdir=LR;\n"; - int cnt = 1; - - //Map states to indices - std::map<label::Label, int> states; - for (const label::Label& state : a.getStates()) { - states.insert(std::make_pair(state, cnt++)); - } - - //Print final states - for (const label::Label& state : a.getFinalStates()) { - out << "node [shape = doublecircle, label=\"" << alib::StringDataFactory::toString(state) << "\"]; " << states.find(state)->second << ";\n"; - } - - //Print nonfinal states - for (const auto& state : states) { - if (!a.getFinalStates().count(state.first)) { - out << "node [shape = circle, label=\"" << alib::StringDataFactory::toString(state.first) << "\" ]; " << state.second << ";\n"; - } - } - - transitions(a, states, out); - out << "}"; -} - auto DotConverterNFTA = DotConverter::RegistratorWrapper<void, automaton::NFTA < > >(DotConverter::convert); - -void DotConverter::convert(std::ostream& out, const automaton::DFTA < > & a) { - out << "digraph automaton {\n"; - out << "rankdir=LR;\n"; - int cnt = 1; - - //Map states to indices - std::map<label::Label, int> states; - for (const label::Label& state : a.getStates()) { - states.insert(std::make_pair(state, cnt++)); - } - - //Print final states - for (const label::Label& state : a.getFinalStates()) { - out << "node [shape = doublecircle, label=\"" << alib::StringDataFactory::toString(state) << "\"]; " << states.find(state)->second << ";\n"; - } - - //Print nonfinal states - for (const auto& state : states) { - if (!a.getFinalStates().count(state.first)) { - out << "node [shape = circle, label=\"" << alib::StringDataFactory::toString(state.first) << "\" ]; " << state.second << ";\n"; - } - } - - transitions(a, states, out); - out << "}"; -} - auto DotConverterDFTA = DotConverter::RegistratorWrapper<void, automaton::DFTA < > >(DotConverter::convert); - -void DotConverter::convert(std::ostream& out, const automaton::DPDA < > & a) { - out << "digraph automaton {\n"; - out << "rankdir=LR;\n"; - int cnt = 1; - - //Map states to indices - std::map<label::Label, int> states; - for (const label::Label& state : a.getStates()) { - states.insert(std::make_pair(state, cnt++)); - } - - //Print final states - for (const label::Label& state : a.getFinalStates()) { - out << "node [shape = doublecircle, label=\"" << alib::StringDataFactory::toString(state) << "\"]; " << states.find(state)->second << ";\n"; - } - - //Print nonfinal states - for (const auto& state : states) { - if (!a.getFinalStates().count(state.first)) { - out << "node [shape = circle, label=\"" << alib::StringDataFactory::toString(state.first) << "\" ]; " << state.second << ";\n"; - } - } - - //Mark initial states - out << "node [shape = plaintext, label=\"start\"]; 0; \n"; - out << "0 -> " << states.find(a.getInitialState())->second << ";\n"; - - transitions(a, states, out); - out << "}"; -} - auto DotConverterDPDA = DotConverter::RegistratorWrapper<void, automaton::DPDA < > >(DotConverter::convert); - -void DotConverter::convert(std::ostream& out, const automaton::SinglePopDPDA < > & a) { - out << "digraph automaton {\n"; - out << "rankdir=LR;\n"; - int cnt = 1; - - //Map states to indices - std::map<label::Label, int> states; - for (const label::Label& state : a.getStates()) { - states.insert(std::make_pair(state, cnt++)); - } - - //Print final states - for (const label::Label& state : a.getFinalStates()) { - out << "node [shape = doublecircle, label=\"" << alib::StringDataFactory::toString(state) << "\"]; " << states.find(state)->second << ";\n"; - } - - //Print nonfinal states - for (const auto& state : states) { - if (!a.getFinalStates().count(state.first)) { - out << "node [shape = circle, label=\"" << alib::StringDataFactory::toString(state.first) << "\" ]; " << state.second << ";\n"; - } - } - - //Mark initial states - out << "node [shape = plaintext, label=\"start\"]; 0; \n"; - out << "0 -> " << states.find(a.getInitialState())->second << ";\n"; - - transitions(a, states, out); - out << "}"; -} - auto DotConverterSinglePopDPDA = DotConverter::RegistratorWrapper<void, automaton::SinglePopDPDA < > >(DotConverter::convert); - -void DotConverter::convert(std::ostream& out, const automaton::InputDrivenDPDA < > & a) { - out << "digraph automaton {\n"; - out << "rankdir=LR;\n"; - int cnt = 1; - - //Map states to indices - std::map<label::Label, int> states; - for (const label::Label& state : a.getStates()) { - states.insert(std::make_pair(state, cnt++)); - } - - //Print final states - for (const label::Label& state : a.getFinalStates()) { - out << "node [shape = doublecircle, label=\"" << alib::StringDataFactory::toString(state) << "\"]; " << states.find(state)->second << ";\n"; - } - - //Print nonfinal states - for (const auto& state : states) { - if (!a.getFinalStates().count(state.first)) { - out << "node [shape = circle, label=\"" << alib::StringDataFactory::toString(state.first) << "\" ]; " << state.second << ";\n"; - } - } - - //Mark initial states - out << "node [shape = plaintext, label=\"start\"]; 0; \n"; - out << "0 -> " << states.find(a.getInitialState())->second << ";\n"; - - transitions(a, states, out); - out << "}"; -} - auto DotConverterInputDrivenDPDA = DotConverter::RegistratorWrapper<void, automaton::InputDrivenDPDA < > >(DotConverter::convert); - -void DotConverter::convert(std::ostream& out, const automaton::InputDrivenNPDA < > & a) { - out << "digraph automaton {\n"; - out << "rankdir=LR;\n"; - int cnt = 1; - - //Map states to indices - std::map<label::Label, int> states; - for (const label::Label& state : a.getStates()) { - states.insert(std::make_pair(state, cnt++)); - } - - //Print final states - for (const label::Label& state : a.getFinalStates()) { - out << "node [shape = doublecircle, label=\"" << alib::StringDataFactory::toString(state) << "\"]; " << states.find(state)->second << ";\n"; - } - - //Print nonfinal states - for (const auto& state : states) { - if (!a.getFinalStates().count(state.first)) { - out << "node [shape = circle, label=\"" << alib::StringDataFactory::toString(state.first) << "\" ]; " << state.second << ";\n"; - } - } - - //Mark initial states - out << "node [shape = plaintext, label=\"start\"]; 0; \n"; - out << "0 -> " << states.find(a.getInitialState())->second << ";\n"; - - transitions(a, states, out); - out << "}"; -} - auto DotConverterInputDrivenNPDA = DotConverter::RegistratorWrapper<void, automaton::InputDrivenNPDA < > >(DotConverter::convert); - -void DotConverter::convert(std::ostream& out, const automaton::VisiblyPushdownDPDA < > & a) { - out << "digraph automaton {\n"; - out << "rankdir=LR;\n"; - int cnt = 1; - - //Map states to indices - std::map<label::Label, int> states; - for (const label::Label& state : a.getStates()) { - states.insert(std::make_pair(state, cnt++)); - } - - //Print final states - for (const label::Label& state : a.getFinalStates()) { - out << "node [shape = doublecircle, label=\"" << alib::StringDataFactory::toString(state) << "\"]; " << states.find(state)->second << ";\n"; - } - - //Print nonfinal states - for (const auto& state : states) { - if (!a.getFinalStates().count(state.first)) { - out << "node [shape = circle, label=\"" << alib::StringDataFactory::toString(state.first) << "\" ]; " << state.second << ";\n"; - } - } - - //Mark initial states - out << "node [shape = plaintext, label=\"start\"]; 0; \n"; - out << "0 -> " << states.find(a.getInitialState())->second << ";\n"; - - transitions(a, states, out); - out << "}"; -} - auto DotConverterVisiblyPushdownDPDA = DotConverter::RegistratorWrapper<void, automaton::VisiblyPushdownDPDA < > >(DotConverter::convert); - -void DotConverter::convert(std::ostream& out, const automaton::VisiblyPushdownNPDA < > & a) { - out << "digraph automaton {\n"; - out << "rankdir=LR;\n"; - int cnt = 1; - - //Map states to indices - std::map<label::Label, int> states; - for (const label::Label& state : a.getStates()) { - states.insert(std::make_pair(state, cnt++)); - } - - //Print final states - for (const label::Label& state : a.getFinalStates()) { - out << "node [shape = doublecircle, label=\"" << alib::StringDataFactory::toString(state) << "\"]; " << states.find(state)->second << ";\n"; - } - - //Print nonfinal states - for (const auto& state : states) { - if (!a.getFinalStates().count(state.first)) { - out << "node [shape = circle, label=\"" << alib::StringDataFactory::toString(state.first) << "\" ]; " << state.second << ";\n"; - } - } - - //Mark initial states - out << "node [shape = plaintext, label=\"start\"]; 0; \n"; - for (const label::Label& state : a.getInitialStates()) { - out << "0 -> " << states.find(state)->second << ";\n"; - } - - transitions(a, states, out); - out << "}"; -} - auto DotConverterVisiblyPushdownNPDA = DotConverter::RegistratorWrapper<void, automaton::VisiblyPushdownNPDA < > >(DotConverter::convert); - -void DotConverter::convert(std::ostream& out, const automaton::RealTimeHeightDeterministicDPDA < > & a) { - out << "digraph automaton {\n"; - out << "rankdir=LR;\n"; - int cnt = 1; - - //Map states to indices - std::map<label::Label, int> states; - for (const label::Label& state : a.getStates()) { - states.insert(std::make_pair(state, cnt++)); - } - - //Print final states - for (const label::Label& state : a.getFinalStates()) { - out << "node [shape = doublecircle, label=\"" << alib::StringDataFactory::toString(state) << "\"]; " << states.find(state)->second << ";\n"; - } - - //Print nonfinal states - for (const auto& state : states) { - if (!a.getFinalStates().count(state.first)) { - out << "node [shape = circle, label=\"" << alib::StringDataFactory::toString(state.first) << "\" ]; " << state.second << ";\n"; - } - } - - //Mark initial states - out << "node [shape = plaintext, label=\"start\"]; 0; \n"; - out << "0 -> " << states.find(a.getInitialState())->second << ";\n"; - - transitions(a, states, out); - out << "}"; -} - auto DotConverterRealTimeHeightDeterministicDPDA = DotConverter::RegistratorWrapper<void, automaton::RealTimeHeightDeterministicDPDA < > >(DotConverter::convert); - -void DotConverter::convert(std::ostream& out, const automaton::RealTimeHeightDeterministicNPDA < > & a) { - out << "digraph automaton {\n"; - out << "rankdir=LR;\n"; - int cnt = 1; - - //Map states to indices - std::map<label::Label, int> states; - for (const label::Label& state : a.getStates()) { - states.insert(std::make_pair(state, cnt++)); - } - - //Print final states - for (const label::Label& state : a.getFinalStates()) { - out << "node [shape = doublecircle, label=\"" << alib::StringDataFactory::toString(state) << "\"]; " << states.find(state)->second << ";\n"; - } - - //Print nonfinal states - for (const auto& state : states) { - if (!a.getFinalStates().count(state.first)) { - out << "node [shape = circle, label=\"" << alib::StringDataFactory::toString(state.first) << "\" ]; " << state.second << ";\n"; - } - } - - //Mark initial states - out << "node [shape = plaintext, label=\"start\"]; 0; \n"; - for (const label::Label& state : a.getInitialStates()) { - out << "0 -> " << states.find(state)->second << ";\n"; - } - - transitions(a, states, out); - out << "}"; -} - auto DotConverterRealTimeHeightDeterministicNPDA = DotConverter::RegistratorWrapper<void, automaton::RealTimeHeightDeterministicNPDA < > >(DotConverter::convert); - -void DotConverter::convert(std::ostream& out, const automaton::NPDA < > & a) { - out << "digraph automaton {\n"; - out << "rankdir=LR;\n"; - int cnt = 1; - - //Map states to indices - std::map<label::Label, int> states; - for (const label::Label& state : a.getStates()) { - states.insert(std::make_pair(state, cnt++)); - } - - //Print final states - for (const label::Label& state : a.getFinalStates()) { - out << "node [shape = doublecircle, label=\"" << alib::StringDataFactory::toString(state) << "\"]; " << states.find(state)->second << ";\n"; - } - - //Print nonfinal states - for (const auto& state : states) { - if (!a.getFinalStates().count(state.first)) { - out << "node [shape = circle, label=\"" << alib::StringDataFactory::toString(state.first) << "\" ]; " << state.second << ";\n"; - } - } - - //Mark initial states - out << "node [shape = plaintext, label=\"start\"]; 0; \n"; - out << "0 -> " << states.find(a.getInitialState())->second << ";\n"; - - transitions(a, states, out); - out << "}"; -} - auto DotConverterNPDA = DotConverter::RegistratorWrapper<void, automaton::NPDA < > >(DotConverter::convert); - -void DotConverter::convert(std::ostream& out, const automaton::SinglePopNPDA < > & a) { - out << "digraph automaton {\n"; - out << "rankdir=LR;\n"; - int cnt = 1; - - //Map states to indices - std::map<label::Label, int> states; - for (const label::Label& state : a.getStates()) { - states.insert(std::make_pair(state, cnt++)); - } - - //Print final states - for (const label::Label& state : a.getFinalStates()) { - out << "node [shape = doublecircle, label=\"" << alib::StringDataFactory::toString(state) << "\"]; " << states.find(state)->second << ";\n"; - } - - //Print nonfinal states - for (const auto& state : states) { - if (!a.getFinalStates().count(state.first)) { - out << "node [shape = circle, label=\"" << alib::StringDataFactory::toString(state.first) << "\" ]; " << state.second << ";\n"; - } - } - - //Mark initial states - out << "node [shape = plaintext, label=\"start\"]; 0; \n"; - out << "0 -> " << states.find(a.getInitialState())->second << ";\n"; - - transitions(a, states, out); - out << "}"; -} - auto DotConverterSinglePopNPDA = DotConverter::RegistratorWrapper<void, automaton::SinglePopNPDA < > >(DotConverter::convert); - -void DotConverter::convert(std::ostream& out, const automaton::OneTapeDTM<>& a) { - out << "digraph automaton {\n"; - out << "rankdir=LR;\n"; - int cnt = 1; - - //Map states to indices - std::map<label::Label, int> states; - for (const label::Label& state : a.getStates()) { - states.insert(std::make_pair(state, cnt++)); - } - - //Print final states - for (const label::Label& state : a.getFinalStates()) { - out << "node [shape = doublecircle, label=\"" << alib::StringDataFactory::toString(state) << "\"]; " << states.find(state)->second << ";\n"; - } - - //Print nonfinal states - for (const auto& state : states) { - if (!a.getFinalStates().count(state.first)) { - out << "node [shape = circle, label=\"" << alib::StringDataFactory::toString(state.first) << "\" ]; " << state.second << ";\n"; - } - } - - //Mark initial states - out << "node [shape = plaintext, label=\"start\"]; 0; \n"; - out << "0 -> " << states.find(a.getInitialState())->second << ";\n"; - - transitions(a, states, out); - out << "}"; -} - -auto DotConverterOneTapeDTM = DotConverter::RegistratorWrapper<void, automaton::OneTapeDTM<>>(DotConverter::convert); - -void DotConverter::transitions(const automaton::EpsilonNFA < > & fsm, const std::map<label::Label, int>& states, std::ostream& out) { - std::map<std::pair<int, int>, std::string> transitions; - - //put transitions from automaton to "transitions" - for (const auto& transition : fsm.getTransitions()) { - std::string symbol; - if (transition.first.second.is<string::Epsilon < >>()) { - symbol = "ε"; - } else { - symbol = alib::StringDataFactory::toString(std::get<1>(transition.first).get<alphabet::Symbol>()); - } - - for(const label::Label& to : transition.second) { - std::pair<int, int> key(states.find(transition.first.first)->second, states.find(to)->second); - std::map<std::pair<int, int>, std::string>::iterator mapit = transitions.find(key); - - if (mapit == transitions.end()) { - transitions.insert(std::make_pair(key, symbol)); - } else { - mapit->second += ","; - - size_t pos = mapit->second.find_last_of("\n"); - if(pos == std::string::npos) pos = 0; - if(mapit->second.size() - pos > 100) mapit->second += "\n"; - else mapit->second += " "; - - mapit->second += symbol; - } - } - } - - //print the map - for (std::pair<const std::pair<int, int>, std::string>& transition : transitions) { - out << transition.first.first << " -> " << transition.first.second; - replace(transition.second, "\n", "\\n"); - out << "[label=\"" << transition.second << "\"]\n"; - } -} - -void DotConverter::transitions(const automaton::MultiInitialStateNFA < >& fsm, const std::map<label::Label, int>& states, std::ostream& out) { - std::map<std::pair<int, int>, std::string> transitions; - - //put transitions from automaton to "transitions" - for (const auto& transition : fsm.getTransitions()) { - std::string symbol = alib::StringDataFactory::toString(transition.first.second); - - for(const label::Label& to : transition.second) { - std::pair<int, int> key(states.find(transition.first.first)->second, states.find(to)->second); - std::map<std::pair<int, int>, std::string>::iterator mapit = transitions.find(key); - - if (mapit == transitions.end()) { - transitions.insert(std::make_pair(key, symbol)); - } else { - mapit->second += ","; - - size_t pos = mapit->second.find_last_of("\n"); - if(pos == std::string::npos) pos = 0; - if(mapit->second.size() - pos > 100) mapit->second += "\n"; - else mapit->second += " "; - - mapit->second += symbol; - } - } - } - - //print the map - for (std::pair< const std::pair<int, int>, std::string>& transition : transitions) { - out << transition.first.first << " -> " << transition.first.second; - replace(transition.second, "\n", "\\n"); - out << "[label=\"" << transition.second << "\"]\n"; - } -} - -void DotConverter::transitions(const automaton::NFA < > & fsm, const std::map<label::Label, int>& states, std::ostream& out) { - std::map<std::pair<int, int>, std::string> transitions; - - //put transitions from automaton to "transitions" - for (const auto& transition : fsm.getTransitions()) { - std::string symbol = alib::StringDataFactory::toString(transition.first.second); - - for(const label::Label& to : transition.second) { - std::pair<int, int> key(states.find(transition.first.first)->second, states.find(to)->second); - std::map<std::pair<int, int>, std::string>::iterator mapit = transitions.find(key); - - if (mapit == transitions.end()) { - transitions.insert(std::make_pair(key, symbol)); - } else { - mapit->second += ","; - - size_t pos = mapit->second.find_last_of("\n"); - if(pos == std::string::npos) pos = 0; - if(mapit->second.size() - pos > 100) mapit->second += "\n"; - else mapit->second += " "; - - mapit->second += symbol; - } - } - } - - //print the map - for (std::pair<const std::pair<int, int>, std::string>& transition : transitions) { - out << transition.first.first << " -> " << transition.first.second; - replace(transition.second, "\n", "\\n"); - out << "[label=\"" << transition.second << "\"]\n"; - } -} - -void DotConverter::transitions(const automaton::DFA<>& fsm, const std::map<label::Label, int>& states, std::ostream& out) { - std::map<std::pair<int, int>, std::string> transitions; - - //put transitions from automaton to "transitions" - for (const auto& transition : fsm.getTransitions()) { - std::string symbol = alib::StringDataFactory::toString(transition.first.second); - - std::pair<int, int> key(states.find(transition.first.first)->second, states.find(transition.second)->second); - std::map<std::pair<int, int>, std::string>::iterator mapit = transitions.find(key); - - if (mapit == transitions.end()) { - transitions.insert(std::make_pair(key, symbol)); - } else { - mapit->second += ","; - - size_t pos = mapit->second.find_last_of("\n"); - if(pos == std::string::npos) pos = 0; - if(mapit->second.size() - pos > 100) mapit->second += "\n"; - else mapit->second += " "; - - mapit->second += symbol; - } - } - - //print the map - for (std::pair<const std::pair<int, int>, std::string>& transition : transitions) { - out << transition.first.first << " -> " << transition.first.second; - replace(transition.second, "\n", "\\n"); - out << "[label=\"" << transition.second << "\"]\n"; - } -} - -void DotConverter::transitions(const automaton::ExtendedNFA < > & fsm, const std::map<label::Label, int>& states, std::ostream& out) { - std::map<std::pair<int, int>, std::string> transitions; - - //put transitions from automaton to "transitions" - for (const auto& transition : fsm.getTransitions()) { - std::string symbol = alib::StringDataFactory::toString(transition.first.second); - - for(const label::Label& to : transition.second) { - std::pair<int, int> key(states.find(transition.first.first)->second, states.find(to)->second); - std::map<std::pair<int, int>, std::string>::iterator mapit = transitions.find(key); - - if (mapit == transitions.end()) { - transitions.insert(std::make_pair(key, symbol)); - } else { - mapit->second += ","; - - size_t pos = mapit->second.find_last_of("\n"); - if(pos == std::string::npos) pos = 0; - if(mapit->second.size() - pos > 100) mapit->second += "\n"; - else mapit->second += " "; - - mapit->second += symbol; - } - } - } - - //print the map - for (std::pair<const std::pair<int, int>, std::string>& transition : transitions) { - out << transition.first.first << " -> " << transition.first.second; - replace(transition.second, "\n", "\\n"); - out << "[label=\"" << transition.second << "\"]\n"; - } -} - -void DotConverter::transitions(const automaton::CompactNFA < > & fsm, const std::map<label::Label, int>& states, std::ostream& out) { - std::map<std::pair<int, int>, std::string> transitions; - - //put transitions from automaton to "transitions" - for (const auto& transition : fsm.getTransitions()) { - std::string symbol = alib::StringDataFactory::toString(string::stringFrom ( transition.first.second ) ); - - for(const label::Label& to : transition.second) { - std::pair<int, int> key(states.find(transition.first.first)->second, states.find(to)->second); - std::map<std::pair<int, int>, std::string>::iterator mapit = transitions.find(key); - - if (mapit == transitions.end()) { - transitions.insert(std::make_pair(key, symbol)); - } else { - mapit->second += ","; - - size_t pos = mapit->second.find_last_of("\n"); - if(pos == std::string::npos) pos = 0; - if(mapit->second.size() - pos > 100) mapit->second += "\n"; - else mapit->second += " "; - - mapit->second += symbol; - } - } - } - - //print the map - for (std::pair<const std::pair<int, int>, std::string>& transition : transitions) { - out << transition.first.first << " -> " << transition.first.second; - replace(transition.second, "\n", "\\n"); - out << "[label=\"" << transition.second << "\"]\n"; - } -} - -void DotConverter::transitions(const automaton::NFTA < > & fta, const std::map<label::Label, int>& states, std::ostream& out) { - std::map<std::pair<int, std::vector<int>>, std::string> transitions; - - //put transitions from automaton to "transitions" - for (const auto& transition : fta.getTransitions()) { - std::string symbol = alib::StringDataFactory::toString(transition.first.first.getSymbol()); - symbol += std::to_string(transition.first.first.getRank().getData()); - - for(const label::Label& to : transition.second) { - std::pair<int, std::vector<int>> key(states.find(to)->second, {}); - for(const label::Label& state : transition.first.second) { - key.second.push_back(states.find(state)->second); - } - std::map<std::pair<int, std::vector<int>>, std::string>::iterator mapit = transitions.find(key); - - if (mapit == transitions.end()) { - transitions.insert(std::make_pair(key, symbol)); - } else { - mapit->second += ","; - - size_t pos = mapit->second.find_last_of("\n"); - if(pos == std::string::npos) pos = 0; - if(mapit->second.size() - pos > 100) mapit->second += "\n"; - else mapit->second += " "; - - mapit->second += symbol; - } - } - } - - //Print auxilary dots - for (unsigned i = 1; i < transitions.size(); i++) { - out << "node [shape = point, label=\"\"]; " << states.size() + i << ";\n"; - } - - //print the map - unsigned i = states.size() + 1; - for (std::pair<const std::pair<int, std::vector<int>>, std::string>& transition : transitions) { - out << i << " -> " << transition.first.first; - replace(transition.second, "\n", "\\n"); - out << "[label=\"" << transition.second << "\"]\n"; - unsigned j = 0; - for(int from : transition.first.second) { - out << from << " -> " << i; - out << "[label=\"" << j << "\"]\n"; - j++; - } - i++; - } -} - -void DotConverter::transitions(const automaton::DFTA < > & fta, const std::map<label::Label, int>& states, std::ostream& out) { - std::map<std::pair<int, std::vector<int>>, std::string> transitions; - - //put transitions from automaton to "transitions" - for (const auto& transition : fta.getTransitions()) { - std::string symbol = alib::StringDataFactory::toString(transition.first.first.getSymbol()); - symbol += std::to_string(transition.first.first.getRank().getData()); - - std::pair<int, std::vector<int>> key(states.find(transition.second)->second, {}); - for(const label::Label& state : transition.first.second) { - key.second.push_back(states.find(state)->second); - } - std::map<std::pair<int, std::vector<int>>, std::string>::iterator mapit = transitions.find(key); - - if (mapit == transitions.end()) { - transitions.insert(std::make_pair(key, symbol)); - } else { - mapit->second += ","; - - size_t pos = mapit->second.find_last_of("\n"); - if(pos == std::string::npos) pos = 0; - if(mapit->second.size() - pos > 100) mapit->second += "\n"; - else mapit->second += " "; - - mapit->second += symbol; - } - } - - //Print auxilary dots - for (unsigned i = 1; i < transitions.size(); i++) { - out << "node [shape = point, label=\"\"]; " << states.size() + i << ";\n"; - } - - //print the map - unsigned i = states.size() + 1; - for (std::pair<const std::pair<int, std::vector<int>>, std::string>& transition : transitions) { - out << i << " -> " << transition.first.first; - replace(transition.second, "\n", "\\n"); - out << "[label=\"" << transition.second << "\"]\n"; - unsigned j = 0; - for(int from : transition.first.second) { - out << from << " -> " << i; - out << "[label=\"" << j << "\"]\n"; - j++; - } - i++; - } -} - -void DotConverter::transitions(const automaton::DPDA < > & pda, const std::map<label::Label, int>& states, std::ostream& out) { - std::map<std::pair<int, int>, std::string> transitions; - - for (const auto& transition : pda.getTransitions()) { - std::string symbol; - - //input symbol - if (std::get<1>(transition.first).is<string::Epsilon < >>()) { - symbol = "ε"; - } else { - symbol = alib::StringDataFactory::toString(std::get<1>(transition.first).get<alphabet::Symbol>()); - } - - symbol += " |"; - - //Pop part - if (std::get<2>(transition.first).size() == 0) { - symbol += " ε"; - } else { - for (alphabet::Symbol symb : std::get<2>(transition.first)) { - symbol += " " + alib::StringDataFactory::toString(symb); - } - - } - - symbol += " ->"; - - //Push part - if (transition.second.second.size() == 0) { - symbol += " ε"; - } else { - for (alphabet::Symbol symb : transition.second.second) { - symbol += " " + alib::StringDataFactory::toString(symb); - } - - } - - //Insert into map - std::pair<int, int> key(states.find(std::get<0>(transition.first))->second, states.find(transition.second.first)->second); - std::map<std::pair<int, int>, std::string>::iterator mapit = transitions.find(key); - - if (mapit == transitions.end()) { - transitions.insert(std::make_pair(key, symbol)); - } else { - mapit->second += ","; - - size_t pos = mapit->second.find_last_of("\n"); - if(pos == std::string::npos) pos = 0; - if(mapit->second.size() - pos > 100) mapit->second += "\n"; - else mapit->second += " "; - - mapit->second += symbol; - } - } - - //print the map - for (std::pair<const std::pair<int, int>, std::string>& transition : transitions) { - out << transition.first.first << " -> " << transition.first.second; - replace(transition.second, "\n", "\\n"); - out << "[label=\"" << transition.second << "\"]\n"; - } -} - -void DotConverter::transitions(const automaton::SinglePopDPDA < > & pda, const std::map<label::Label, int>& states, std::ostream& out) { - std::map<std::pair<int, int>, std::string> transitions; - - for (const auto& transition : pda.getTransitions()) { - std::string symbol; - - //input symbol - if (std::get<1>(transition.first).is<string::Epsilon < >>()) { - symbol = "ε"; - } else { - symbol = alib::StringDataFactory::toString(std::get<1>(transition.first).get<alphabet::Symbol>()); - } - - symbol += " |"; - - //Pop part - symbol += " " + alib::StringDataFactory::toString(std::get<2>(transition.first)); - - symbol += " ->"; - - //Push part - if (transition.second.second.size() == 0) { - symbol += " ε"; - } else { - for (alphabet::Symbol symb : transition.second.second) { - symbol += " " + alib::StringDataFactory::toString(symb); - } - - } - - //Insert into map - std::pair<int, int> key(states.find(std::get<0>(transition.first))->second, states.find(transition.second.first)->second); - std::map<std::pair<int, int>, std::string>::iterator mapit = transitions.find(key); - - if (mapit == transitions.end()) { - transitions.insert(std::make_pair(key, symbol)); - } else { - mapit->second += ","; - - size_t pos = mapit->second.find_last_of("\n"); - if(pos == std::string::npos) pos = 0; - if(mapit->second.size() - pos > 100) mapit->second += "\n"; - else mapit->second += " "; - - mapit->second += symbol; - } - } - - //print the map - for (std::pair<const std::pair<int, int>, std::string>& transition : transitions) { - out << transition.first.first << " -> " << transition.first.second; - replace(transition.second, "\n", "\\n"); - out << "[label=\"" << transition.second << "\"]\n"; - } -} - -void DotConverter::transitions(const automaton::InputDrivenDPDA < > & pda, const std::map<label::Label, int>& states, std::ostream& out) { - std::map<std::pair<int, int>, std::string> transitions; - - const auto& symbolToPDSOperation = pda.getPushdownStoreOperations(); - for (const auto& transition : pda.getTransitions()) { - const auto& pop = symbolToPDSOperation.find(transition.first.second)->second.first; - const auto& push = symbolToPDSOperation.find(transition.first.second)->second.second; - - std::string symbol; - - //input symbol - symbol = alib::StringDataFactory::toString(transition.first.second); - - symbol += " |"; - - //Pop part - if (pop.size() == 0) { - symbol += " ε"; - } else { - for (alphabet::Symbol symb : pop) { - symbol += " " + alib::StringDataFactory::toString(symb); - } - - } - - symbol += " ->"; - - const auto& to = transition.second; - //Push part - if (push.size() == 0) { - symbol += " ε"; - } else { - for (alphabet::Symbol symb : push) { - symbol += " " + alib::StringDataFactory::toString(symb); - } - - } - - //Insert into map - std::pair<int, int> key(states.find(transition.first.first)->second, states.find(to)->second); - std::map<std::pair<int, int>, std::string>::iterator mapit = transitions.find(key); - - if (mapit == transitions.end()) { - transitions.insert(std::make_pair(key, symbol)); - } else { - mapit->second += ","; - - size_t pos = mapit->second.find_last_of("\n"); - if(pos == std::string::npos) pos = 0; - if(mapit->second.size() - pos > 100) mapit->second += "\n"; - else mapit->second += " "; - - mapit->second += symbol; - } - } - - //print the map - for (std::pair<const std::pair<int, int>, std::string>& transition : transitions) { - out << transition.first.first << " -> " << transition.first.second; - replace(transition.second, "\n", "\\n"); - out << "[label=\"" << transition.second << "\"]\n"; - } -} - -void DotConverter::transitions(const automaton::InputDrivenNPDA < > & pda, const std::map<label::Label, int>& states, std::ostream& out) { - std::map<std::pair<int, int>, std::string> transitions; - - const auto& symbolToPDSOperation = pda.getPushdownStoreOperations(); - for (const auto& transition : pda.getTransitions()) { - const auto& pop = symbolToPDSOperation.find(transition.first.second)->second.first; - const auto& push = symbolToPDSOperation.find(transition.first.second)->second.second; - - std::string symbol; - - //input symbol - symbol = alib::StringDataFactory::toString(transition.first.second); - - symbol += " |"; - - //Pop part - if (pop.size() == 0) { - symbol += " ε"; - } else { - for (alphabet::Symbol symb : pop) { - symbol += " " + alib::StringDataFactory::toString(symb); - } - - } - - symbol += " ->"; - - std::string symbol2; - for(const auto& to : transition.second) { - symbol2 = symbol; - //Push part - if (push.size() == 0) { - symbol2 += " ε"; - } else { - for (alphabet::Symbol symb : push) { - symbol2 += " " + alib::StringDataFactory::toString(symb); - } - - } - - //Insert into map - std::pair<int, int> key(states.find(transition.first.first)->second, states.find(to)->second); - std::map<std::pair<int, int>, std::string>::iterator mapit = transitions.find(key); - - if (mapit == transitions.end()) { - transitions.insert(std::make_pair(key, symbol2)); - } else { - mapit->second += ","; - - size_t pos = mapit->second.find_last_of("\n"); - if(pos == std::string::npos) pos = 0; - if(mapit->second.size() - pos > 100) mapit->second += "\n"; - else mapit->second += " "; - - mapit->second += symbol2; - } - } - } - - //print the map - for (std::pair<const std::pair<int, int>, std::string>& transition : transitions) { - out << transition.first.first << " -> " << transition.first.second; - replace(transition.second, "\n", "\\n"); - out << "[label=\"" << transition.second << "\"]\n"; - } -} - -void DotConverter::transitions(const automaton::VisiblyPushdownDPDA < > & pda, const std::map<label::Label, int>& states, std::ostream& out) { - std::map<std::pair<int, int>, std::string> transitions; - - for (const auto& transition : pda.getCallTransitions()) { - std::string symbol; - - //input symbol - symbol = alib::StringDataFactory::toString(transition.first.second); - - symbol += " |"; - - //Pop part - symbol += " ε"; - symbol += " ->"; - - symbol += " " + alib::StringDataFactory::toString(transition.second.second); - - //Insert into map - std::pair<int, int> key(states.find(transition.first.first)->second, states.find(transition.second.first)->second); - std::map<std::pair<int, int>, std::string>::iterator mapit = transitions.find(key); - - if (mapit == transitions.end()) { - transitions.insert(std::make_pair(key, symbol)); - } else { - mapit->second += ","; - - size_t pos = mapit->second.find_last_of("\n"); - if(pos == std::string::npos) pos = 0; - if(mapit->second.size() - pos > 100) mapit->second += "\n"; - else mapit->second += " "; - - mapit->second += symbol; - } - } - - for (const auto& transition : pda.getReturnTransitions()) { - std::string symbol; - - //input symbol - symbol = alib::StringDataFactory::toString(std::get<1>(transition.first)); - - symbol += " |"; - - //Pop part - symbol += " " + alib::StringDataFactory::toString(std::get<2>(transition.first)); - symbol += " ->"; - - symbol += " ε"; - - //Insert into map - std::pair<int, int> key(states.find(std::get<0>(transition.first))->second, states.find(transition.second)->second); - std::map<std::pair<int, int>, std::string>::iterator mapit = transitions.find(key); - - if (mapit == transitions.end()) { - transitions.insert(std::make_pair(key, symbol)); - } else { - mapit->second += ","; - - size_t pos = mapit->second.find_last_of("\n"); - if(pos == std::string::npos) pos = 0; - if(mapit->second.size() - pos > 100) mapit->second += "\n"; - else mapit->second += " "; - - mapit->second += symbol; - } - } - - for (const auto& transition : pda.getLocalTransitions()) { - std::string symbol; - - //input symbol - symbol = alib::StringDataFactory::toString(transition.first.second); - - symbol += " |"; - - //Pop part - symbol += " ε"; - symbol += " ->"; - - symbol += " ε"; - - //Insert into map - std::pair<int, int> key(states.find(transition.first.first)->second, states.find(transition.second)->second); - std::map<std::pair<int, int>, std::string>::iterator mapit = transitions.find(key); - - if (mapit == transitions.end()) { - transitions.insert(std::make_pair(key, symbol)); - } else { - mapit->second += ","; - - size_t pos = mapit->second.find_last_of("\n"); - if(pos == std::string::npos) pos = 0; - if(mapit->second.size() - pos > 100) mapit->second += "\n"; - else mapit->second += " "; - - mapit->second += symbol; - } - } - - //print the map - for (std::pair<const std::pair<int, int>, std::string>& transition : transitions) { - out << transition.first.first << " -> " << transition.first.second; - replace(transition.second, "\n", "\\n"); - out << "[label=\"" << transition.second << "\"]\n"; - } -} - -void DotConverter::transitions(const automaton::VisiblyPushdownNPDA < > & pda, const std::map<label::Label, int>& states, std::ostream& out) { - std::map<std::pair<int, int>, std::string> transitions; - - for (const auto& transition : pda.getCallTransitions()) { - std::string symbol; - - //input symbol - symbol = alib::StringDataFactory::toString(transition.first.second); - - symbol += " |"; - - //Pop part - symbol += " ε"; - symbol += " ->"; - - std::string symbol2; - for(const auto& to : transition.second) { - symbol2 = symbol; - symbol2 += " " + alib::StringDataFactory::toString(to.second); - - //Insert into map - std::pair<int, int> key(states.find(transition.first.first)->second, states.find(to.first)->second); - std::map<std::pair<int, int>, std::string>::iterator mapit = transitions.find(key); - - if (mapit == transitions.end()) { - transitions.insert(std::make_pair(key, symbol2)); - } else { - mapit->second += ","; - - size_t pos = mapit->second.find_last_of("\n"); - if(pos == std::string::npos) pos = 0; - if(mapit->second.size() - pos > 100) mapit->second += "\n"; - else mapit->second += " "; - - mapit->second += symbol2; - } - } - } - - for (const auto& transition : pda.getReturnTransitions()) { - std::string symbol; - - //input symbol - symbol = alib::StringDataFactory::toString(std::get<1>(transition.first)); - - symbol += " |"; - - //Pop part - symbol += " " + alib::StringDataFactory::toString(std::get<2>(transition.first)); - symbol += " ->"; - - std::string symbol2; - for(const auto& to : transition.second) { - symbol2 = symbol; - symbol2 += " ε"; - - //Insert into map - std::pair<int, int> key(states.find(std::get<0>(transition.first))->second, states.find(to)->second); - std::map<std::pair<int, int>, std::string>::iterator mapit = transitions.find(key); - - if (mapit == transitions.end()) { - transitions.insert(std::make_pair(key, symbol2)); - } else { - mapit->second += ","; - - size_t pos = mapit->second.find_last_of("\n"); - if(pos == std::string::npos) pos = 0; - if(mapit->second.size() - pos > 100) mapit->second += "\n"; - else mapit->second += " "; - - mapit->second += symbol2; - } - } - } - - for (const auto& transition : pda.getLocalTransitions()) { - std::string symbol; - - //input symbol - symbol = alib::StringDataFactory::toString(transition.first.second); - - symbol += " |"; - - //Pop part - symbol += " ε"; - symbol += " ->"; - - std::string symbol2; - for(const auto& to : transition.second) { - symbol2 = symbol; - symbol2 += " ε"; - - //Insert into map - std::pair<int, int> key(states.find(transition.first.first)->second, states.find(to)->second); - std::map<std::pair<int, int>, std::string>::iterator mapit = transitions.find(key); - - if (mapit == transitions.end()) { - transitions.insert(std::make_pair(key, symbol2)); - } else { - mapit->second += ","; - - size_t pos = mapit->second.find_last_of("\n"); - if(pos == std::string::npos) pos = 0; - if(mapit->second.size() - pos > 100) mapit->second += "\n"; - else mapit->second += " "; - - mapit->second += symbol2; - } - } - } - - //print the map - for (std::pair<const std::pair<int, int>, std::string>& transition : transitions) { - out << transition.first.first << " -> " << transition.first.second; - replace(transition.second, "\n", "\\n"); - out << "[label=\"" << transition.second << "\"]\n"; - } -} - -void DotConverter::transitions(const automaton::RealTimeHeightDeterministicDPDA < > & pda, const std::map<label::Label, int>& states, std::ostream& out) { - std::map<std::pair<int, int>, std::string> transitions; - - for (const auto& transition : pda.getCallTransitions()) { - std::string symbol; - - //input symbol - if(transition.first.second.is<string::Epsilon < >>()) - symbol = "&epsilon"; - else - symbol = alib::StringDataFactory::toString(transition.first.second.get<alphabet::Symbol>()); - - symbol += " |"; - - //Pop part - symbol += " ε"; - symbol += " ->"; - - symbol += " " + alib::StringDataFactory::toString(transition.second.second); - - //Insert into map - std::pair<int, int> key(states.find(transition.first.first)->second, states.find(transition.second.first)->second); - std::map<std::pair<int, int>, std::string>::iterator mapit = transitions.find(key); - - if (mapit == transitions.end()) { - transitions.insert(std::make_pair(key, symbol)); - } else { - mapit->second += ","; - - size_t pos = mapit->second.find_last_of("\n"); - if(pos == std::string::npos) pos = 0; - if(mapit->second.size() - pos > 100) mapit->second += "\n"; - else mapit->second += " "; - - mapit->second += symbol; - } - } - - for (const auto& transition : pda.getReturnTransitions()) { - std::string symbol; - - //input symbol - if(std::get<1>(transition.first).is<string::Epsilon < >>()) - symbol = "&epsilon"; - else - symbol = alib::StringDataFactory::toString(std::get<1>(transition.first).get<alphabet::Symbol>()); - - symbol += " |"; - - //Pop part - symbol += " " + alib::StringDataFactory::toString(std::get<2>(transition.first)); - symbol += " ->"; - - symbol += " ε"; - - //Insert into map - std::pair<int, int> key(states.find(std::get<0>(transition.first))->second, states.find(transition.second)->second); - std::map<std::pair<int, int>, std::string>::iterator mapit = transitions.find(key); - - if (mapit == transitions.end()) { - transitions.insert(std::make_pair(key, symbol)); - } else { - mapit->second += ","; - - size_t pos = mapit->second.find_last_of("\n"); - if(pos == std::string::npos) pos = 0; - if(mapit->second.size() - pos > 100) mapit->second += "\n"; - else mapit->second += " "; - - mapit->second += symbol; - } - } - - for (const auto& transition : pda.getLocalTransitions()) { - std::string symbol; - - //input symbol - if(transition.first.second.is<string::Epsilon < >>()) - symbol = "&epsilon"; - else - symbol = alib::StringDataFactory::toString(transition.first.second.get<alphabet::Symbol>()); - - symbol += " |"; - - //Pop part - symbol += " ε"; - symbol += " ->"; - - symbol += " ε"; - - //Insert into map - std::pair<int, int> key(states.find(transition.first.first)->second, states.find(transition.second)->second); - std::map<std::pair<int, int>, std::string>::iterator mapit = transitions.find(key); - - if (mapit == transitions.end()) { - transitions.insert(std::make_pair(key, symbol)); - } else { - mapit->second += ","; - - size_t pos = mapit->second.find_last_of("\n"); - if(pos == std::string::npos) pos = 0; - if(mapit->second.size() - pos > 100) mapit->second += "\n"; - else mapit->second += " "; - - mapit->second += symbol; - } - } - - //print the map - for (std::pair<const std::pair<int, int>, std::string>& transition : transitions) { - out << transition.first.first << " -> " << transition.first.second; - replace(transition.second, "\n", "\\n"); - out << "[label=\"" << transition.second << "\"]\n"; - } -} - -void DotConverter::transitions(const automaton::RealTimeHeightDeterministicNPDA < > & pda, const std::map<label::Label, int>& states, std::ostream& out) { - std::map<std::pair<int, int>, std::string> transitions; - - for (const auto& transition : pda.getCallTransitions()) { - std::string symbol; - - //input symbol - if(transition.first.second.is<string::Epsilon < >>()) - symbol = "&epsilon"; - else - symbol = alib::StringDataFactory::toString(transition.first.second.get<alphabet::Symbol>()); - - symbol += " |"; - - //Pop part - symbol += " ε"; - symbol += " ->"; - - std::string symbol2; - for(const auto& to : transition.second) { - symbol2 = symbol; - symbol2 += " " + alib::StringDataFactory::toString(to.second); - - //Insert into map - std::pair<int, int> key(states.find(transition.first.first)->second, states.find(to.first)->second); - std::map<std::pair<int, int>, std::string>::iterator mapit = transitions.find(key); - - if (mapit == transitions.end()) { - transitions.insert(std::make_pair(key, symbol2)); - } else { - mapit->second += ","; - - size_t pos = mapit->second.find_last_of("\n"); - if(pos == std::string::npos) pos = 0; - if(mapit->second.size() - pos > 100) mapit->second += "\n"; - else mapit->second += " "; - - mapit->second += symbol2; - } - } - } - - for (const auto& transition : pda.getReturnTransitions()) { - std::string symbol; - - //input symbol - if(std::get<1>(transition.first).is<string::Epsilon < >>()) - symbol = "ε"; - else - symbol = alib::StringDataFactory::toString(std::get<1>(transition.first).get<alphabet::Symbol>()); - - symbol += " |"; - - //Pop part - symbol += " " + alib::StringDataFactory::toString(std::get<2>(transition.first)); - symbol += " ->"; - - std::string symbol2; - for(const auto& to : transition.second) { - symbol2 = symbol; - symbol2 += " ε"; - - //Insert into map - std::pair<int, int> key(states.find(std::get<0>(transition.first))->second, states.find(to)->second); - std::map<std::pair<int, int>, std::string>::iterator mapit = transitions.find(key); - - if (mapit == transitions.end()) { - transitions.insert(std::make_pair(key, symbol2)); - } else { - mapit->second += ","; - - size_t pos = mapit->second.find_last_of("\n"); - if(pos == std::string::npos) pos = 0; - if(mapit->second.size() - pos > 100) mapit->second += "\n"; - else mapit->second += " "; - - mapit->second += symbol2; - } - } - } - - for (const auto& transition : pda.getLocalTransitions()) { - std::string symbol; - - //input symbol - if(transition.first.second.is<string::Epsilon < >>()) - symbol = "ε"; - else - symbol = alib::StringDataFactory::toString(transition.first.second.get<alphabet::Symbol>()); - - symbol += " |"; - - //Pop part - symbol += " ε"; - symbol += " ->"; - - std::string symbol2; - for(const auto& to : transition.second) { - symbol2 = symbol; - symbol2 += " ε"; - - //Insert into map - std::pair<int, int> key(states.find(transition.first.first)->second, states.find(to)->second); - std::map<std::pair<int, int>, std::string>::iterator mapit = transitions.find(key); - - if (mapit == transitions.end()) { - transitions.insert(std::make_pair(key, symbol2)); - } else { - mapit->second += ","; - - size_t pos = mapit->second.find_last_of("\n"); - if(pos == std::string::npos) pos = 0; - if(mapit->second.size() - pos > 100) mapit->second += "\n"; - else mapit->second += " "; - - mapit->second += symbol2; - } - } - } - - //print the map - for (std::pair<const std::pair<int, int>, std::string>& transition : transitions) { - out << transition.first.first << " -> " << transition.first.second; - replace(transition.second, "\n", "\\n"); - out << "[label=\"" << transition.second << "\"]\n"; - } -} - -void DotConverter::transitions(const automaton::NPDA < > & pda, const std::map<label::Label, int>& states, std::ostream& out) { - std::map<std::pair<int, int>, std::string> transitions; - - for (const auto& transition : pda.getTransitions()) { - std::string symbol; - - //input symbol - if (std::get<1>(transition.first).is<string::Epsilon < >>()) { - symbol = "ε"; - } else { - symbol = alib::StringDataFactory::toString(std::get<1>(transition.first).get<alphabet::Symbol>()); - } - - symbol += " |"; - - //Pop part - if (std::get<2>(transition.first).size() == 0) { - symbol += " ε"; - } else { - for (alphabet::Symbol symb : std::get<2>(transition.first)) { - symbol += " " + alib::StringDataFactory::toString(symb); - } - - } - - symbol += " ->"; - - std::string symbol2; - for(const auto& to : transition.second) { - symbol2 = symbol; - //Push part - if (to.second.size() == 0) { - symbol2 += " ε"; - } else { - for (alphabet::Symbol symb : to.second) { - symbol2 += " " + alib::StringDataFactory::toString(symb); - } - - } - - //Insert into map - std::pair<int, int> key(states.find(std::get<0>(transition.first))->second, states.find(to.first)->second); - std::map<std::pair<int, int>, std::string>::iterator mapit = transitions.find(key); - - if (mapit == transitions.end()) { - transitions.insert(std::make_pair(key, symbol2)); - } else { - mapit->second += ","; - - size_t pos = mapit->second.find_last_of("\n"); - if(pos == std::string::npos) pos = 0; - if(mapit->second.size() - pos > 100) mapit->second += "\n"; - else mapit->second += " "; - - mapit->second += symbol2; - } - } - } - - //print the map - for (std::pair<const std::pair<int, int>, std::string>& transition : transitions) { - out << transition.first.first << " -> " << transition.first.second; - replace(transition.second, "\n", "\\n"); - out << "[label=\"" << transition.second << "\"]\n"; - } -} - -void DotConverter::transitions(const automaton::SinglePopNPDA < > & pda, const std::map<label::Label, int>& states, std::ostream& out) { - std::map<std::pair<int, int>, std::string> transitions; - - for (const auto& transition : pda.getTransitions()) { - std::string symbol; - - //input symbol - if (std::get<1>(transition.first).is<string::Epsilon < >>()) { - symbol = "ε"; - } else { - symbol = alib::StringDataFactory::toString(std::get<1>(transition.first).get<alphabet::Symbol>()); - } - - symbol += " |"; - - //Pop part - symbol += " " + alib::StringDataFactory::toString(std::get<2>(transition.first)); - - symbol += " ->"; - - std::string symbol2; - for(const auto& to : transition.second) { - symbol2 = symbol; - //Push part - if (to.second.size() == 0) { - symbol2 += " ε"; - } else { - for (alphabet::Symbol symb : to.second) { - symbol2 += " " + alib::StringDataFactory::toString(symb); - } - - } - - //Insert into map - std::pair<int, int> key(states.find(std::get<0>(transition.first))->second, states.find(to.first)->second); - std::map<std::pair<int, int>, std::string>::iterator mapit = transitions.find(key); - - if (mapit == transitions.end()) { - transitions.insert(std::make_pair(key, symbol2)); - } else { - mapit->second += ","; - - size_t pos = mapit->second.find_last_of("\n"); - if(pos == std::string::npos) pos = 0; - if(mapit->second.size() - pos > 100) mapit->second += "\n"; - else mapit->second += " "; - - mapit->second += symbol2; - } - } - } - - //print the map - for (std::pair<const std::pair<int, int>, std::string>& transition : transitions) { - out << transition.first.first << " -> " << transition.first.second; - replace(transition.second, "\n", "\\n"); - out << "[label=\"" << transition.second << "\"]\n"; - } -} - -void DotConverter::transitions(const automaton::OneTapeDTM<>& tm, const std::map<label::Label, int>& states, std::ostream& out) { - std::map<std::pair<int, int>, std::string> transitions; - for (const auto& transition : tm.getTransitions()) { - std::string symbol; - - //input symbol - symbol = "("; - symbol += alib::StringDataFactory::toString(transition.first.second); - symbol += ", "; - symbol += alib::StringDataFactory::toString(std::get<1>(transition.second)); - symbol += " "; - switch(std::get<2>(transition.second)) { - case automaton::Shift::LEFT: - symbol += "←"; - break; - case automaton::Shift::RIGHT: - symbol += "→"; - break; - case automaton::Shift::NONE: - symbol += "×"; - break; - default: - throw exception::CommonException("Unexpected shift direction"); - } - - //Insert into map - std::pair<int, int> key(states.find(transition.first.first)->second, states.find(std::get<0>(transition.second))->second); - std::map<std::pair<int, int>, std::string>::iterator mapit = transitions.find(key); - - if (mapit == transitions.end()) { - transitions.insert(std::make_pair(key, symbol)); - } else { - mapit->second += ","; - - size_t pos = mapit->second.find_last_of("\n"); - if(pos == std::string::npos) pos = 0; - if(mapit->second.size() - pos > 100) mapit->second += "\n"; - else mapit->second += " "; - - mapit->second += symbol; - } - } - - //print the map - for (std::pair<const std::pair<int, int>, std::string>& transition : transitions) { - out << transition.first.first << " -> " << transition.first.second; - replace(transition.second, "\n", "\\n"); - out << "[label=\"" << transition.second << "\"]\n"; - } -} +auto DotConverterOneTapeDTM = DotConverter::RegistratorWrapper<void, automaton::OneTapeDTM < > >(DotConverter::convert); diff --git a/aconvert2/src/DotConverter.h b/aconvert2/src/DotConverter.h index feeef85866..2bcb88ecef 100644 --- a/aconvert2/src/DotConverter.h +++ b/aconvert2/src/DotConverter.h @@ -9,58 +9,1991 @@ #define DOT_CONVERTER_H_ #include <ostream> +#include <set> +#include <map> +#include <list> +#include <utility> +#include <vector> +#include <typeinfo> + #include <core/multipleDispatch.hpp> +#include <exception/CommonException.h> + +#include <string/String.h> #include <automaton/Automaton.h> #include <automaton/AutomatonFeatures.h> -#include <label/Label.h> +#include <automaton/FSM/NFA.h> +#include <automaton/FSM/EpsilonNFA.h> +#include <automaton/FSM/MultiInitialStateNFA.h> +#include <automaton/FSM/DFA.h> +#include <automaton/FSM/ExtendedNFA.h> +#include <automaton/FSM/CompactNFA.h> +#include <automaton/TA/NFTA.h> +#include <automaton/TA/DFTA.h> +#include <automaton/PDA/NPDA.h> +#include <automaton/PDA/SinglePopNPDA.h> +#include <automaton/PDA/InputDrivenDPDA.h> +#include <automaton/PDA/InputDrivenNPDA.h> +#include <automaton/PDA/VisiblyPushdownDPDA.h> +#include <automaton/PDA/VisiblyPushdownNPDA.h> +#include <automaton/PDA/RealTimeHeightDeterministicDPDA.h> +#include <automaton/PDA/RealTimeHeightDeterministicNPDA.h> +#include <automaton/PDA/DPDA.h> +#include <automaton/PDA/SinglePopDPDA.h> +#include <automaton/TM/OneTapeDTM.h> -#include <map> -#include <utility> +#include <factory/StringDataFactory.hpp> + +#include "common/converterCommon.hpp" class DotConverter : public std::SingleDispatchFirstStaticParam<DotConverter, void, std::ostream&, const automaton::AutomatonBase &> { - static void transitions(const automaton::EpsilonNFA < > & fsm, const std::map<label::Label, int>& states, std::ostream& out); - static void transitions(const automaton::MultiInitialStateNFA < >& fsm, const std::map<label::Label, int>& states, std::ostream& out); - static void transitions(const automaton::NFA < > & fsm, const std::map<label::Label, int>& states, std::ostream& out); - static void transitions(const automaton::DFA<>& fsm, const std::map<label::Label, int>& states, std::ostream& out); - static void transitions(const automaton::ExtendedNFA < > & fsm, const std::map<label::Label, int>& states, std::ostream& out); - static void transitions(const automaton::CompactNFA < > & fsm, const std::map<label::Label, int>& states, std::ostream& out); - static void transitions(const automaton::NFTA < > & fsm, const std::map<label::Label, int>& states, std::ostream& out); - static void transitions(const automaton::DFTA < > & fsm, const std::map<label::Label, int>& states, std::ostream& out); - static void transitions(const automaton::DPDA < > & pda, const std::map<label::Label, int>& states, std::ostream& out); - static void transitions(const automaton::SinglePopDPDA < > & tm, const std::map<label::Label, int>& states, std::ostream& out); - static void transitions(const automaton::InputDrivenDPDA < > & pda, const std::map<label::Label, int>& states, std::ostream& out); - static void transitions(const automaton::InputDrivenNPDA < > & pda, const std::map<label::Label, int>& states, std::ostream& out); - static void transitions(const automaton::VisiblyPushdownDPDA < > & tm, const std::map<label::Label, int>& states, std::ostream& out); - static void transitions(const automaton::VisiblyPushdownNPDA < > & tm, const std::map<label::Label, int>& states, std::ostream& out); - static void transitions(const automaton::RealTimeHeightDeterministicDPDA < > & tm, const std::map<label::Label, int>& states, std::ostream& out); - static void transitions(const automaton::RealTimeHeightDeterministicNPDA < > & tm, const std::map<label::Label, int>& states, std::ostream& out); - static void transitions(const automaton::NPDA < > & pda, const std::map<label::Label, int>& states, std::ostream& out); - static void transitions(const automaton::SinglePopNPDA < > & tm, const std::map<label::Label, int>& states, std::ostream& out); - static void transitions(const automaton::OneTapeDTM<>& tm, const std::map<label::Label, int>& states, std::ostream& out); + template < class SymbolType, class StateType > + static void transitions(const automaton::DFA < SymbolType, StateType > & fsm, const std::map < StateType, int > & states, std::ostream & out); + + template < class SymbolType, class StateType > + static void transitions(const automaton::NFA < SymbolType, StateType > & fsm, const std::map < StateType, int > & states, std::ostream & out); + + template < class SymbolType, class StateType > + static void transitions(const automaton::MultiInitialStateNFA < SymbolType, StateType > & fsm, const std::map < StateType, int > & states, std::ostream & out); + + template < class SymbolType, class EpsilonType, class StateType > + static void transitions(const automaton::EpsilonNFA < SymbolType, EpsilonType, StateType > & fsm, const std::map < StateType, int > & states, std::ostream & out); + + template < class SymbolType, class StateType > + static void transitions(const automaton::ExtendedNFA < SymbolType, StateType > & fsm, const std::map < StateType, int > & states, std::ostream & out); + + template < class SymbolType, class StateType > + static void transitions(const automaton::CompactNFA < SymbolType, StateType > & fsm, const std::map < StateType, int > & states, std::ostream & out); + + template < class SymbolType, class RankType, class StateType > + static void transitions(const automaton::NFTA < SymbolType, RankType, StateType > & fsm, const std::map < StateType, int > & states, std::ostream & out); + + template < class SymbolType, class RankType, class StateType > + static void transitions(const automaton::DFTA < SymbolType, RankType, StateType > & fsm, const std::map < StateType, int > & states, std::ostream & out); + + template < class SymbolType, class EpsilonType, class StateType > + static void transitions(const automaton::DPDA < SymbolType, EpsilonType, StateType > & pda, const std::map < StateType, int > & states, std::ostream & out); + + template < class SymbolType, class EpsilonType, class StateType > + static void transitions(const automaton::NPDA < SymbolType, EpsilonType, StateType > & pda, const std::map < StateType, int > & states, std::ostream & out); + + template < class SymbolType, class EpsilonType, class StateType > + static void transitions(const automaton::SinglePopDPDA < SymbolType, EpsilonType, StateType > & tm, const std::map < StateType, int > & states, std::ostream & out); + + template < class SymbolType, class EpsilonType, class StateType > + static void transitions(const automaton::SinglePopNPDA < SymbolType, EpsilonType, StateType > & tm, const std::map < StateType, int > & states, std::ostream & out); + + template < class SymbolType, class StateType > + static void transitions(const automaton::InputDrivenDPDA < SymbolType, StateType > & pda, const std::map < StateType, int > & states, std::ostream & out); + + template < class SymbolType, class StateType > + static void transitions(const automaton::InputDrivenNPDA < SymbolType, StateType > & pda, const std::map < StateType, int > & states, std::ostream & out); + + template < class SymbolType, class StateType > + static void transitions(const automaton::VisiblyPushdownDPDA < SymbolType, StateType > & tm, const std::map < StateType, int > & states, std::ostream & out); + + template < class SymbolType, class StateType > + static void transitions(const automaton::VisiblyPushdownNPDA < SymbolType, StateType > & tm, const std::map < StateType, int > & states, std::ostream & out); + + template < class SymbolType, class EpsilonType, class StateType > + static void transitions(const automaton::RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType > & tm, const std::map < StateType, int > & states, std::ostream & out); + + template < class SymbolType, class EpsilonType, class StateType > + static void transitions(const automaton::RealTimeHeightDeterministicNPDA < SymbolType, EpsilonType, StateType > & tm, const std::map < StateType, int > & states, std::ostream & out); + + template < class SymbolType, class StateType > + static void transitions(const automaton::OneTapeDTM < SymbolType, StateType > & tm, const std::map < StateType, int > & states, std::ostream & out); public: static void convert(std::ostream& out, const automaton::Automaton& a); - static void convert(std::ostream& out, const automaton::EpsilonNFA < > & a); - static void convert(std::ostream& out, const automaton::MultiInitialStateNFA < >& a); - static void convert(std::ostream& out, const automaton::NFA < > & a); - static void convert(std::ostream& out, const automaton::DFA<>& a); - static void convert(std::ostream& out, const automaton::ExtendedNFA < > & a); - static void convert(std::ostream& out, const automaton::CompactNFA < > & a); - static void convert(std::ostream& out, const automaton::NFTA < > & a); - static void convert(std::ostream& out, const automaton::DFTA < > & a); - static void convert(std::ostream& out, const automaton::DPDA < > & a); - static void convert(std::ostream& out, const automaton::SinglePopDPDA < > & a); - static void convert(std::ostream& out, const automaton::InputDrivenDPDA < > & a); - static void convert(std::ostream& out, const automaton::InputDrivenNPDA < > & a); - static void convert(std::ostream& out, const automaton::VisiblyPushdownDPDA < > & a); - static void convert(std::ostream& out, const automaton::VisiblyPushdownNPDA < > & a); - static void convert(std::ostream& out, const automaton::RealTimeHeightDeterministicDPDA < > & a); - static void convert(std::ostream& out, const automaton::RealTimeHeightDeterministicNPDA < > & a); - static void convert(std::ostream& out, const automaton::NPDA < > & a); - static void convert(std::ostream& out, const automaton::SinglePopNPDA < > & a); - static void convert(std::ostream& out, const automaton::OneTapeDTM<>& a); + template < class SymbolType, class StateType > + static void convert(std::ostream& out, const automaton::DFA < SymbolType, StateType > & a); + + template < class SymbolType, class StateType > + static void convert(std::ostream& out, const automaton::NFA < SymbolType, StateType > & a); + + template < class SymbolType, class StateType > + static void convert(std::ostream& out, const automaton::MultiInitialStateNFA < SymbolType, StateType >& a); + + template < class SymbolType, class EpsilonType, class StateType > + static void convert(std::ostream& out, const automaton::EpsilonNFA < SymbolType, EpsilonType, StateType > & a); + + template < class SymbolType, class StateType > + static void convert(std::ostream& out, const automaton::ExtendedNFA < SymbolType, StateType > & a); + + template < class SymbolType, class StateType > + static void convert(std::ostream& out, const automaton::CompactNFA < SymbolType, StateType > & a); + + template < class SymbolType, class RankType, class StateType > + static void convert(std::ostream& out, const automaton::NFTA < SymbolType, RankType, StateType > & a); + + template < class SymbolType, class RankType, class StateType > + static void convert(std::ostream& out, const automaton::DFTA < SymbolType, RankType, StateType > & a); + + template < class SymbolType, class EpsilonType, class StateType > + static void convert(std::ostream& out, const automaton::DPDA < SymbolType, EpsilonType, StateType > & a); + + template < class SymbolType, class EpsilonType, class StateType > + static void convert(std::ostream& out, const automaton::NPDA < SymbolType, EpsilonType, StateType > & a); + + template < class SymbolType, class EpsilonType, class StateType > + static void convert(std::ostream& out, const automaton::SinglePopDPDA < SymbolType, EpsilonType, StateType > & a); + + template < class SymbolType, class EpsilonType, class StateType > + static void convert(std::ostream& out, const automaton::SinglePopNPDA < SymbolType, EpsilonType, StateType > & a); + + template < class SymbolType, class StateType > + static void convert(std::ostream& out, const automaton::InputDrivenDPDA < SymbolType, StateType > & a); + + template < class SymbolType, class StateType > + static void convert(std::ostream& out, const automaton::InputDrivenNPDA < SymbolType, StateType > & a); + + template < class SymbolType, class StateType > + static void convert(std::ostream& out, const automaton::VisiblyPushdownDPDA < SymbolType, StateType > & a); + + template < class SymbolType, class StateType > + static void convert(std::ostream& out, const automaton::VisiblyPushdownNPDA < SymbolType, StateType > & a); + + template < class SymbolType, class EpsilonType, class StateType > + static void convert(std::ostream& out, const automaton::RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType > & a); + + template < class SymbolType, class EpsilonType, class StateType > + static void convert(std::ostream& out, const automaton::RealTimeHeightDeterministicNPDA < SymbolType, EpsilonType, StateType > & a); + + template < class SymbolType, class StateType > + static void convert(std::ostream& out, const automaton::OneTapeDTM < SymbolType, StateType > & a); }; +template < class SymbolType, class EpsilonType, class StateType > +void DotConverter::convert(std::ostream& out, const automaton::EpsilonNFA < SymbolType, EpsilonType, StateType > & a) { + out << "digraph automaton {\n"; + out << "rankdir=LR;\n"; + int cnt = 1; + + //Map states to indices + std::map<StateType, int> states; + for (const StateType& state : a.getStates()) { + states.insert(std::make_pair(state, cnt++)); + } + + //Print final states + for (const StateType& state : a.getFinalStates()) { + out << "node [shape = doublecircle, label=\"" << alib::StringDataFactory::toString(state) << "\"]; " << states.find(state)->second << ";\n"; + } + + //Print nonfinal states + for (const auto& state : states) { + if (!a.getFinalStates().count(state.first)) { + out << "node [shape = circle, label=\"" << alib::StringDataFactory::toString(state.first) << "\" ]; " << state.second << ";\n"; + } + } + + //Mark initial states + out << "node [shape = plaintext, label=\"start\"]; 0; \n"; + out << "0 -> " << states.find(a.getInitialState())->second << ";\n"; + + transitions(a, states, out); + out << "}"; +} + +template < class SymbolType, class StateType > +void DotConverter::convert(std::ostream& out, const automaton::MultiInitialStateNFA < SymbolType, StateType >& a) { + out << "digraph automaton {\n"; + out << "rankdir=LR;\n"; + int cnt = 1; + + //Map states to indices + std::map<StateType, int> states; + for (const StateType& state : a.getStates()) { + states.insert(std::make_pair(state, cnt++)); + } + + //Print final states + for (const StateType& state : a.getFinalStates()) { + out << "node [shape = doublecircle, label=\"" << alib::StringDataFactory::toString(state) << "\"]; " << states.find(state)->second << ";\n"; + } + + //Print nonfinal states + for (const auto& state : states) { + if (!a.getFinalStates().count(state.first)) { + out << "node [shape = circle, label=\"" << alib::StringDataFactory::toString(state.first) << "\" ]; " << state.second << ";\n"; + } + } + + //Mark initial states + out << "node [shape = plaintext, label=\"start\"]; 0; \n"; + for (const StateType& state : a.getInitialStates()) { + out << "0 -> " << states.find(state)->second << ";\n"; + } + + transitions(a, states, out); + out << "}"; +} + +template < class SymbolType, class StateType > +void DotConverter::convert(std::ostream& out, const automaton::NFA < SymbolType, StateType > & a) { + out << "digraph automaton {\n"; + out << "rankdir=LR;\n"; + int cnt = 1; + + //Map states to indices + std::map<StateType, int> states; + for (const StateType& state : a.getStates()) { + states.insert(std::make_pair(state, cnt++)); + } + + //Print final states + for (const StateType& state : a.getFinalStates()) { + out << "node [shape = doublecircle, label=\"" << alib::StringDataFactory::toString(state) << "\"]; " << states.find(state)->second << ";\n"; + } + + //Print nonfinal states + for (const auto& state : states) { + if (!a.getFinalStates().count(state.first)) { + out << "node [shape = circle, label=\"" << alib::StringDataFactory::toString(state.first) << "\" ]; " << state.second << ";\n"; + } + } + + //Mark initial states + out << "node [shape = plaintext, label=\"start\"]; 0; \n"; + out << "0 -> " << states.find(a.getInitialState())->second << ";\n"; + + transitions(a, states, out); + out << "}"; +} + +template < class SymbolType, class StateType > +void DotConverter::convert(std::ostream& out, const automaton::DFA < SymbolType, StateType > & a) { + out << "digraph automaton {\n"; + out << "rankdir=LR;\n"; + int cnt = 1; + + //Map states to indices + std::map<StateType, int> states; + for (const StateType& state : a.getStates()) { + states.insert(std::make_pair(state, cnt++)); + } + + //Print final states + for (const StateType& state : a.getFinalStates()) { + out << "node [shape = doublecircle, label=\"" << alib::StringDataFactory::toString(state) << "\"]; " << states.find(state)->second << ";\n"; + } + + //Print nonfinal states + for (const auto& state : states) { + if (!a.getFinalStates().count(state.first)) { + out << "node [shape = circle, label=\"" << alib::StringDataFactory::toString(state.first) << "\" ]; " << state.second << ";\n"; + } + } + + //Mark initial states + out << "node [shape = plaintext, label=\"start\"]; 0; \n"; + out << "0 -> " << states.find(a.getInitialState())->second << ";\n"; + + transitions(a, states, out); + out << "}"; +} + +template < class SymbolType, class StateType > +void DotConverter::convert(std::ostream& out, const automaton::ExtendedNFA < SymbolType, StateType > & a) { + out << "digraph automaton {\n"; + out << "rankdir=LR;\n"; + int cnt = 1; + + //Map states to indices + std::map<StateType, int> states; + for (const StateType& state : a.getStates()) { + states.insert(std::make_pair(state, cnt++)); + } + + //Print final states + for (const StateType& state : a.getFinalStates()) { + out << "node [shape = doublecircle, label=\"" << alib::StringDataFactory::toString(state) << "\"]; " << states.find(state)->second << ";\n"; + } + + //Print nonfinal states + for (const auto& state : states) { + if (!a.getFinalStates().count(state.first)) { + out << "node [shape = circle, label=\"" << alib::StringDataFactory::toString(state.first) << "\" ]; " << state.second << ";\n"; + } + } + + //Mark initial states + out << "node [shape = plaintext, label=\"start\"]; 0; \n"; + out << "0 -> " << states.find(a.getInitialState())->second << ";\n"; + + transitions(a, states, out); + out << "}"; +} + +template < class SymbolType, class StateType > +void DotConverter::convert(std::ostream& out, const automaton::CompactNFA < SymbolType, StateType > & a) { + out << "digraph automaton {\n"; + out << "rankdir=LR;\n"; + int cnt = 1; + + //Map states to indices + std::map<StateType, int> states; + for (const StateType& state : a.getStates()) { + states.insert(std::make_pair(state, cnt++)); + } + + //Print final states + for (const StateType& state : a.getFinalStates()) { + out << "node [shape = doublecircle, label=\"" << alib::StringDataFactory::toString(state) << "\"]; " << states.find(state)->second << ";\n"; + } + + //Print nonfinal states + for (const auto& state : states) { + if (!a.getFinalStates().count(state.first)) { + out << "node [shape = circle, label=\"" << alib::StringDataFactory::toString(state.first) << "\" ]; " << state.second << ";\n"; + } + } + + //Mark initial states + out << "node [shape = plaintext, label=\"start\"]; 0; \n"; + out << "0 -> " << states.find(a.getInitialState())->second << ";\n"; + + transitions(a, states, out); + out << "}"; +} + +template < class SymbolType, class RankType, class StateType > +void DotConverter::convert(std::ostream& out, const automaton::NFTA < SymbolType, RankType, StateType > & a) { + out << "digraph automaton {\n"; + out << "rankdir=LR;\n"; + int cnt = 1; + + //Map states to indices + std::map<StateType, int> states; + for (const StateType& state : a.getStates()) { + states.insert(std::make_pair(state, cnt++)); + } + + //Print final states + for (const StateType& state : a.getFinalStates()) { + out << "node [shape = doublecircle, label=\"" << alib::StringDataFactory::toString(state) << "\"]; " << states.find(state)->second << ";\n"; + } + + //Print nonfinal states + for (const auto& state : states) { + if (!a.getFinalStates().count(state.first)) { + out << "node [shape = circle, label=\"" << alib::StringDataFactory::toString(state.first) << "\" ]; " << state.second << ";\n"; + } + } + + transitions(a, states, out); + out << "}"; +} + +template < class SymbolType, class RankType, class StateType > +void DotConverter::convert(std::ostream& out, const automaton::DFTA < SymbolType, RankType, StateType > & a) { + out << "digraph automaton {\n"; + out << "rankdir=LR;\n"; + int cnt = 1; + + //Map states to indices + std::map<StateType, int> states; + for (const StateType& state : a.getStates()) { + states.insert(std::make_pair(state, cnt++)); + } + + //Print final states + for (const StateType& state : a.getFinalStates()) { + out << "node [shape = doublecircle, label=\"" << alib::StringDataFactory::toString(state) << "\"]; " << states.find(state)->second << ";\n"; + } + + //Print nonfinal states + for (const auto& state : states) { + if (!a.getFinalStates().count(state.first)) { + out << "node [shape = circle, label=\"" << alib::StringDataFactory::toString(state.first) << "\" ]; " << state.second << ";\n"; + } + } + + transitions(a, states, out); + out << "}"; +} + +template < class SymbolType, class EpsilonType, class StateType > +void DotConverter::convert(std::ostream& out, const automaton::DPDA < SymbolType, EpsilonType, StateType > & a) { + out << "digraph automaton {\n"; + out << "rankdir=LR;\n"; + int cnt = 1; + + //Map states to indices + std::map<StateType, int> states; + for (const StateType& state : a.getStates()) { + states.insert(std::make_pair(state, cnt++)); + } + + //Print final states + for (const StateType& state : a.getFinalStates()) { + out << "node [shape = doublecircle, label=\"" << alib::StringDataFactory::toString(state) << "\"]; " << states.find(state)->second << ";\n"; + } + + //Print nonfinal states + for (const auto& state : states) { + if (!a.getFinalStates().count(state.first)) { + out << "node [shape = circle, label=\"" << alib::StringDataFactory::toString(state.first) << "\" ]; " << state.second << ";\n"; + } + } + + //Mark initial states + out << "node [shape = plaintext, label=\"start\"]; 0; \n"; + out << "0 -> " << states.find(a.getInitialState())->second << ";\n"; + + transitions(a, states, out); + out << "}"; +} + +template < class SymbolType, class EpsilonType, class StateType > +void DotConverter::convert(std::ostream& out, const automaton::SinglePopDPDA < SymbolType, EpsilonType, StateType > & a) { + out << "digraph automaton {\n"; + out << "rankdir=LR;\n"; + int cnt = 1; + + //Map states to indices + std::map<StateType, int> states; + for (const StateType& state : a.getStates()) { + states.insert(std::make_pair(state, cnt++)); + } + + //Print final states + for (const StateType& state : a.getFinalStates()) { + out << "node [shape = doublecircle, label=\"" << alib::StringDataFactory::toString(state) << "\"]; " << states.find(state)->second << ";\n"; + } + + //Print nonfinal states + for (const auto& state : states) { + if (!a.getFinalStates().count(state.first)) { + out << "node [shape = circle, label=\"" << alib::StringDataFactory::toString(state.first) << "\" ]; " << state.second << ";\n"; + } + } + + //Mark initial states + out << "node [shape = plaintext, label=\"start\"]; 0; \n"; + out << "0 -> " << states.find(a.getInitialState())->second << ";\n"; + + transitions(a, states, out); + out << "}"; +} + +template < class SymbolType, class StateType > +void DotConverter::convert(std::ostream& out, const automaton::InputDrivenDPDA < SymbolType, StateType > & a) { + out << "digraph automaton {\n"; + out << "rankdir=LR;\n"; + int cnt = 1; + + //Map states to indices + std::map<StateType, int> states; + for (const StateType& state : a.getStates()) { + states.insert(std::make_pair(state, cnt++)); + } + + //Print final states + for (const StateType& state : a.getFinalStates()) { + out << "node [shape = doublecircle, label=\"" << alib::StringDataFactory::toString(state) << "\"]; " << states.find(state)->second << ";\n"; + } + + //Print nonfinal states + for (const auto& state : states) { + if (!a.getFinalStates().count(state.first)) { + out << "node [shape = circle, label=\"" << alib::StringDataFactory::toString(state.first) << "\" ]; " << state.second << ";\n"; + } + } + + //Mark initial states + out << "node [shape = plaintext, label=\"start\"]; 0; \n"; + out << "0 -> " << states.find(a.getInitialState())->second << ";\n"; + + transitions(a, states, out); + out << "}"; +} + +template < class SymbolType, class StateType > +void DotConverter::convert(std::ostream& out, const automaton::InputDrivenNPDA < SymbolType, StateType > & a) { + out << "digraph automaton {\n"; + out << "rankdir=LR;\n"; + int cnt = 1; + + //Map states to indices + std::map<StateType, int> states; + for (const StateType& state : a.getStates()) { + states.insert(std::make_pair(state, cnt++)); + } + + //Print final states + for (const StateType& state : a.getFinalStates()) { + out << "node [shape = doublecircle, label=\"" << alib::StringDataFactory::toString(state) << "\"]; " << states.find(state)->second << ";\n"; + } + + //Print nonfinal states + for (const auto& state : states) { + if (!a.getFinalStates().count(state.first)) { + out << "node [shape = circle, label=\"" << alib::StringDataFactory::toString(state.first) << "\" ]; " << state.second << ";\n"; + } + } + + //Mark initial states + out << "node [shape = plaintext, label=\"start\"]; 0; \n"; + out << "0 -> " << states.find(a.getInitialState())->second << ";\n"; + + transitions(a, states, out); + out << "}"; +} + +template < class SymbolType, class StateType > +void DotConverter::convert(std::ostream& out, const automaton::VisiblyPushdownDPDA < SymbolType, StateType > & a) { + out << "digraph automaton {\n"; + out << "rankdir=LR;\n"; + int cnt = 1; + + //Map states to indices + std::map<StateType, int> states; + for (const StateType& state : a.getStates()) { + states.insert(std::make_pair(state, cnt++)); + } + + //Print final states + for (const StateType& state : a.getFinalStates()) { + out << "node [shape = doublecircle, label=\"" << alib::StringDataFactory::toString(state) << "\"]; " << states.find(state)->second << ";\n"; + } + + //Print nonfinal states + for (const auto& state : states) { + if (!a.getFinalStates().count(state.first)) { + out << "node [shape = circle, label=\"" << alib::StringDataFactory::toString(state.first) << "\" ]; " << state.second << ";\n"; + } + } + + //Mark initial states + out << "node [shape = plaintext, label=\"start\"]; 0; \n"; + out << "0 -> " << states.find(a.getInitialState())->second << ";\n"; + + transitions(a, states, out); + out << "}"; +} + +template < class SymbolType, class StateType > +void DotConverter::convert(std::ostream& out, const automaton::VisiblyPushdownNPDA < SymbolType, StateType > & a) { + out << "digraph automaton {\n"; + out << "rankdir=LR;\n"; + int cnt = 1; + + //Map states to indices + std::map<StateType, int> states; + for (const StateType& state : a.getStates()) { + states.insert(std::make_pair(state, cnt++)); + } + + //Print final states + for (const StateType& state : a.getFinalStates()) { + out << "node [shape = doublecircle, label=\"" << alib::StringDataFactory::toString(state) << "\"]; " << states.find(state)->second << ";\n"; + } + + //Print nonfinal states + for (const auto& state : states) { + if (!a.getFinalStates().count(state.first)) { + out << "node [shape = circle, label=\"" << alib::StringDataFactory::toString(state.first) << "\" ]; " << state.second << ";\n"; + } + } + + //Mark initial states + out << "node [shape = plaintext, label=\"start\"]; 0; \n"; + for (const StateType& state : a.getInitialStates()) { + out << "0 -> " << states.find(state)->second << ";\n"; + } + + transitions(a, states, out); + out << "}"; +} + +template < class SymbolType, class EpsilonType, class StateType > +void DotConverter::convert(std::ostream& out, const automaton::RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType > & a) { + out << "digraph automaton {\n"; + out << "rankdir=LR;\n"; + int cnt = 1; + + //Map states to indices + std::map<StateType, int> states; + for (const StateType& state : a.getStates()) { + states.insert(std::make_pair(state, cnt++)); + } + + //Print final states + for (const StateType& state : a.getFinalStates()) { + out << "node [shape = doublecircle, label=\"" << alib::StringDataFactory::toString(state) << "\"]; " << states.find(state)->second << ";\n"; + } + + //Print nonfinal states + for (const auto& state : states) { + if (!a.getFinalStates().count(state.first)) { + out << "node [shape = circle, label=\"" << alib::StringDataFactory::toString(state.first) << "\" ]; " << state.second << ";\n"; + } + } + + //Mark initial states + out << "node [shape = plaintext, label=\"start\"]; 0; \n"; + out << "0 -> " << states.find(a.getInitialState())->second << ";\n"; + + transitions(a, states, out); + out << "}"; +} + +template < class SymbolType, class EpsilonType, class StateType > +void DotConverter::convert(std::ostream& out, const automaton::RealTimeHeightDeterministicNPDA < SymbolType, EpsilonType, StateType > & a) { + out << "digraph automaton {\n"; + out << "rankdir=LR;\n"; + int cnt = 1; + + //Map states to indices + std::map<StateType, int> states; + for (const StateType& state : a.getStates()) { + states.insert(std::make_pair(state, cnt++)); + } + + //Print final states + for (const StateType& state : a.getFinalStates()) { + out << "node [shape = doublecircle, label=\"" << alib::StringDataFactory::toString(state) << "\"]; " << states.find(state)->second << ";\n"; + } + + //Print nonfinal states + for (const auto& state : states) { + if (!a.getFinalStates().count(state.first)) { + out << "node [shape = circle, label=\"" << alib::StringDataFactory::toString(state.first) << "\" ]; " << state.second << ";\n"; + } + } + + //Mark initial states + out << "node [shape = plaintext, label=\"start\"]; 0; \n"; + for (const StateType& state : a.getInitialStates()) { + out << "0 -> " << states.find(state)->second << ";\n"; + } + + transitions(a, states, out); + out << "}"; +} + +template < class SymbolType, class EpsilonType, class StateType > +void DotConverter::convert(std::ostream& out, const automaton::NPDA < SymbolType, EpsilonType, StateType > & a) { + out << "digraph automaton {\n"; + out << "rankdir=LR;\n"; + int cnt = 1; + + //Map states to indices + std::map<StateType, int> states; + for (const StateType& state : a.getStates()) { + states.insert(std::make_pair(state, cnt++)); + } + + //Print final states + for (const StateType& state : a.getFinalStates()) { + out << "node [shape = doublecircle, label=\"" << alib::StringDataFactory::toString(state) << "\"]; " << states.find(state)->second << ";\n"; + } + + //Print nonfinal states + for (const auto& state : states) { + if (!a.getFinalStates().count(state.first)) { + out << "node [shape = circle, label=\"" << alib::StringDataFactory::toString(state.first) << "\" ]; " << state.second << ";\n"; + } + } + + //Mark initial states + out << "node [shape = plaintext, label=\"start\"]; 0; \n"; + out << "0 -> " << states.find(a.getInitialState())->second << ";\n"; + + transitions(a, states, out); + out << "}"; +} + +template < class SymbolType, class EpsilonType, class StateType > +void DotConverter::convert(std::ostream& out, const automaton::SinglePopNPDA < SymbolType, EpsilonType, StateType > & a) { + out << "digraph automaton {\n"; + out << "rankdir=LR;\n"; + int cnt = 1; + + //Map states to indices + std::map<StateType, int> states; + for (const StateType& state : a.getStates()) { + states.insert(std::make_pair(state, cnt++)); + } + + //Print final states + for (const StateType& state : a.getFinalStates()) { + out << "node [shape = doublecircle, label=\"" << alib::StringDataFactory::toString(state) << "\"]; " << states.find(state)->second << ";\n"; + } + + //Print nonfinal states + for (const auto& state : states) { + if (!a.getFinalStates().count(state.first)) { + out << "node [shape = circle, label=\"" << alib::StringDataFactory::toString(state.first) << "\" ]; " << state.second << ";\n"; + } + } + + //Mark initial states + out << "node [shape = plaintext, label=\"start\"]; 0; \n"; + out << "0 -> " << states.find(a.getInitialState())->second << ";\n"; + + transitions(a, states, out); + out << "}"; +} + +template < class SymbolType, class StateType > +void DotConverter::convert(std::ostream& out, const automaton::OneTapeDTM < SymbolType, StateType > & a) { + out << "digraph automaton {\n"; + out << "rankdir=LR;\n"; + int cnt = 1; + + //Map states to indices + std::map<StateType, int> states; + for (const StateType& state : a.getStates()) { + states.insert(std::make_pair(state, cnt++)); + } + + //Print final states + for (const StateType& state : a.getFinalStates()) { + out << "node [shape = doublecircle, label=\"" << alib::StringDataFactory::toString(state) << "\"]; " << states.find(state)->second << ";\n"; + } + + //Print nonfinal states + for (const auto& state : states) { + if (!a.getFinalStates().count(state.first)) { + out << "node [shape = circle, label=\"" << alib::StringDataFactory::toString(state.first) << "\" ]; " << state.second << ";\n"; + } + } + + //Mark initial states + out << "node [shape = plaintext, label=\"start\"]; 0; \n"; + out << "0 -> " << states.find(a.getInitialState())->second << ";\n"; + + transitions(a, states, out); + out << "}"; +} + +template < class SymbolType, class EpsilonType, class StateType > +void DotConverter::transitions(const automaton::EpsilonNFA < SymbolType, EpsilonType, StateType > & fsm, const std::map<StateType, int>& states, std::ostream& out) { + std::map<std::pair<int, int>, std::string> transitions; + + //put transitions from automaton to "transitions" + for (const auto& transition : fsm.getTransitions()) { + std::string symbol; + if (transition.first.second.template is< EpsilonType >()) { + symbol = "ε"; + } else { + symbol = alib::StringDataFactory::toString(std::get<1>(transition.first).template get<SymbolType>()); + } + + for(const StateType& to : transition.second) { + std::pair<int, int> key(states.find(transition.first.first)->second, states.find(to)->second); + std::map<std::pair<int, int>, std::string>::iterator mapit = transitions.find(key); + + if (mapit == transitions.end()) { + transitions.insert(std::make_pair(key, symbol)); + } else { + mapit->second += ","; + + size_t pos = mapit->second.find_last_of("\n"); + if(pos == std::string::npos) pos = 0; + if(mapit->second.size() - pos > 100) mapit->second += "\n"; + else mapit->second += " "; + + mapit->second += symbol; + } + } + } + + //print the map + for (std::pair<const std::pair<int, int>, std::string>& transition : transitions) { + out << transition.first.first << " -> " << transition.first.second; + replace(transition.second, "\n", "\\n"); + out << "[label=\"" << transition.second << "\"]\n"; + } +} + +template < class SymbolType, class StateType > +void DotConverter::transitions(const automaton::MultiInitialStateNFA < SymbolType, StateType >& fsm, const std::map<StateType, int>& states, std::ostream& out) { + std::map<std::pair<int, int>, std::string> transitions; + + //put transitions from automaton to "transitions" + for (const auto& transition : fsm.getTransitions()) { + std::string symbol = alib::StringDataFactory::toString(transition.first.second); + + for(const StateType& to : transition.second) { + std::pair<int, int> key(states.find(transition.first.first)->second, states.find(to)->second); + std::map<std::pair<int, int>, std::string>::iterator mapit = transitions.find(key); + + if (mapit == transitions.end()) { + transitions.insert(std::make_pair(key, symbol)); + } else { + mapit->second += ","; + + size_t pos = mapit->second.find_last_of("\n"); + if(pos == std::string::npos) pos = 0; + if(mapit->second.size() - pos > 100) mapit->second += "\n"; + else mapit->second += " "; + + mapit->second += symbol; + } + } + } + + //print the map + for (std::pair< const std::pair<int, int>, std::string>& transition : transitions) { + out << transition.first.first << " -> " << transition.first.second; + replace(transition.second, "\n", "\\n"); + out << "[label=\"" << transition.second << "\"]\n"; + } +} + +template < class SymbolType, class StateType > +void DotConverter::transitions(const automaton::NFA < SymbolType, StateType > & fsm, const std::map<StateType, int>& states, std::ostream& out) { + std::map<std::pair<int, int>, std::string> transitions; + + //put transitions from automaton to "transitions" + for (const auto& transition : fsm.getTransitions()) { + std::string symbol = alib::StringDataFactory::toString(transition.first.second); + + for(const StateType& to : transition.second) { + std::pair<int, int> key(states.find(transition.first.first)->second, states.find(to)->second); + std::map<std::pair<int, int>, std::string>::iterator mapit = transitions.find(key); + + if (mapit == transitions.end()) { + transitions.insert(std::make_pair(key, symbol)); + } else { + mapit->second += ","; + + size_t pos = mapit->second.find_last_of("\n"); + if(pos == std::string::npos) pos = 0; + if(mapit->second.size() - pos > 100) mapit->second += "\n"; + else mapit->second += " "; + + mapit->second += symbol; + } + } + } + + //print the map + for (std::pair<const std::pair<int, int>, std::string>& transition : transitions) { + out << transition.first.first << " -> " << transition.first.second; + replace(transition.second, "\n", "\\n"); + out << "[label=\"" << transition.second << "\"]\n"; + } +} + +template < class SymbolType, class StateType > +void DotConverter::transitions(const automaton::DFA < SymbolType, StateType > & fsm, const std::map<StateType, int>& states, std::ostream& out) { + std::map<std::pair<int, int>, std::string> transitions; + + //put transitions from automaton to "transitions" + for (const auto& transition : fsm.getTransitions()) { + std::string symbol = alib::StringDataFactory::toString(transition.first.second); + + std::pair<int, int> key(states.find(transition.first.first)->second, states.find(transition.second)->second); + std::map<std::pair<int, int>, std::string>::iterator mapit = transitions.find(key); + + if (mapit == transitions.end()) { + transitions.insert(std::make_pair(key, symbol)); + } else { + mapit->second += ","; + + size_t pos = mapit->second.find_last_of("\n"); + if(pos == std::string::npos) pos = 0; + if(mapit->second.size() - pos > 100) mapit->second += "\n"; + else mapit->second += " "; + + mapit->second += symbol; + } + } + + //print the map + for (std::pair<const std::pair<int, int>, std::string>& transition : transitions) { + out << transition.first.first << " -> " << transition.first.second; + replace(transition.second, "\n", "\\n"); + out << "[label=\"" << transition.second << "\"]\n"; + } +} + +template < class SymbolType, class StateType > +void DotConverter::transitions(const automaton::ExtendedNFA < SymbolType, StateType > & fsm, const std::map<StateType, int>& states, std::ostream& out) { + std::map<std::pair<int, int>, std::string> transitions; + + //put transitions from automaton to "transitions" + for (const auto& transition : fsm.getTransitions()) { + std::string symbol = alib::StringDataFactory::toString(transition.first.second); + + for(const StateType& to : transition.second) { + std::pair<int, int> key(states.find(transition.first.first)->second, states.find(to)->second); + std::map<std::pair<int, int>, std::string>::iterator mapit = transitions.find(key); + + if (mapit == transitions.end()) { + transitions.insert(std::make_pair(key, symbol)); + } else { + mapit->second += ","; + + size_t pos = mapit->second.find_last_of("\n"); + if(pos == std::string::npos) pos = 0; + if(mapit->second.size() - pos > 100) mapit->second += "\n"; + else mapit->second += " "; + + mapit->second += symbol; + } + } + } + + //print the map + for (std::pair<const std::pair<int, int>, std::string>& transition : transitions) { + out << transition.first.first << " -> " << transition.first.second; + replace(transition.second, "\n", "\\n"); + out << "[label=\"" << transition.second << "\"]\n"; + } +} + +template < class SymbolType, class StateType > +void DotConverter::transitions(const automaton::CompactNFA < SymbolType, StateType > & fsm, const std::map<StateType, int>& states, std::ostream& out) { + std::map<std::pair<int, int>, std::string> transitions; + + //put transitions from automaton to "transitions" + for (const auto& transition : fsm.getTransitions()) { + std::string symbol = alib::StringDataFactory::toString(string::stringFrom ( transition.first.second ) ); + + for(const StateType& to : transition.second) { + std::pair<int, int> key(states.find(transition.first.first)->second, states.find(to)->second); + std::map<std::pair<int, int>, std::string>::iterator mapit = transitions.find(key); + + if (mapit == transitions.end()) { + transitions.insert(std::make_pair(key, symbol)); + } else { + mapit->second += ","; + + size_t pos = mapit->second.find_last_of("\n"); + if(pos == std::string::npos) pos = 0; + if(mapit->second.size() - pos > 100) mapit->second += "\n"; + else mapit->second += " "; + + mapit->second += symbol; + } + } + } + + //print the map + for (std::pair<const std::pair<int, int>, std::string>& transition : transitions) { + out << transition.first.first << " -> " << transition.first.second; + replace(transition.second, "\n", "\\n"); + out << "[label=\"" << transition.second << "\"]\n"; + } +} + +template < class SymbolType, class RankType, class StateType > +void DotConverter::transitions(const automaton::NFTA < SymbolType, RankType, StateType > & fta, const std::map<StateType, int>& states, std::ostream& out) { + std::map<std::pair<int, std::vector<int>>, std::string> transitions; + + //put transitions from automaton to "transitions" + for (const auto& transition : fta.getTransitions()) { + std::string symbol = alib::StringDataFactory::toString(transition.first.first.getSymbol()); + symbol += std::to_string(transition.first.first.getRank().getData()); + + for(const StateType& to : transition.second) { + std::pair<int, std::vector<int>> key(states.find(to)->second, {}); + for(const StateType& state : transition.first.second) { + key.second.push_back(states.find(state)->second); + } + std::map<std::pair<int, std::vector<int>>, std::string>::iterator mapit = transitions.find(key); + + if (mapit == transitions.end()) { + transitions.insert(std::make_pair(key, symbol)); + } else { + mapit->second += ","; + + size_t pos = mapit->second.find_last_of("\n"); + if(pos == std::string::npos) pos = 0; + if(mapit->second.size() - pos > 100) mapit->second += "\n"; + else mapit->second += " "; + + mapit->second += symbol; + } + } + } + + //Print auxilary dots + for (unsigned i = 1; i < transitions.size(); i++) { + out << "node [shape = point, label=\"\"]; " << states.size() + i << ";\n"; + } + + //print the map + unsigned i = states.size() + 1; + for (std::pair<const std::pair<int, std::vector<int>>, std::string>& transition : transitions) { + out << i << " -> " << transition.first.first; + replace(transition.second, "\n", "\\n"); + out << "[label=\"" << transition.second << "\"]\n"; + unsigned j = 0; + for(int from : transition.first.second) { + out << from << " -> " << i; + out << "[label=\"" << j << "\"]\n"; + j++; + } + i++; + } +} + +template < class SymbolType, class RankType, class StateType > +void DotConverter::transitions(const automaton::DFTA < SymbolType, RankType, StateType > & fta, const std::map<StateType, int>& states, std::ostream& out) { + std::map<std::pair<int, std::vector<int>>, std::string> transitions; + + //put transitions from automaton to "transitions" + for (const auto& transition : fta.getTransitions()) { + std::string symbol = alib::StringDataFactory::toString(transition.first.first.getSymbol()); + symbol += std::to_string(transition.first.first.getRank().getData()); + + std::pair<int, std::vector<int>> key(states.find(transition.second)->second, {}); + for(const StateType& state : transition.first.second) { + key.second.push_back(states.find(state)->second); + } + std::map<std::pair<int, std::vector<int>>, std::string>::iterator mapit = transitions.find(key); + + if (mapit == transitions.end()) { + transitions.insert(std::make_pair(key, symbol)); + } else { + mapit->second += ","; + + size_t pos = mapit->second.find_last_of("\n"); + if(pos == std::string::npos) pos = 0; + if(mapit->second.size() - pos > 100) mapit->second += "\n"; + else mapit->second += " "; + + mapit->second += symbol; + } + } + + //Print auxilary dots + for (unsigned i = 1; i < transitions.size(); i++) { + out << "node [shape = point, label=\"\"]; " << states.size() + i << ";\n"; + } + + //print the map + unsigned i = states.size() + 1; + for (std::pair<const std::pair<int, std::vector<int>>, std::string>& transition : transitions) { + out << i << " -> " << transition.first.first; + replace(transition.second, "\n", "\\n"); + out << "[label=\"" << transition.second << "\"]\n"; + unsigned j = 0; + for(int from : transition.first.second) { + out << from << " -> " << i; + out << "[label=\"" << j << "\"]\n"; + j++; + } + i++; + } +} + +template < class SymbolType, class EpsilonType, class StateType > +void DotConverter::transitions(const automaton::DPDA < SymbolType, EpsilonType, StateType > & pda, const std::map<StateType, int>& states, std::ostream& out) { + std::map<std::pair<int, int>, std::string> transitions; + + for (const auto& transition : pda.getTransitions()) { + std::string symbol; + + //input symbol + if (std::get<1>(transition.first).template is< EpsilonType >()) { + symbol = "ε"; + } else { + symbol = alib::StringDataFactory::toString(std::get<1>(transition.first).template get<SymbolType>()); + } + + symbol += " |"; + + //Pop part + if (std::get<2>(transition.first).size() == 0) { + symbol += " ε"; + } else { + for (SymbolType symb : std::get<2>(transition.first)) { + symbol += " " + alib::StringDataFactory::toString(symb); + } + + } + + symbol += " ->"; + + //Push part + if (transition.second.second.size() == 0) { + symbol += " ε"; + } else { + for (SymbolType symb : transition.second.second) { + symbol += " " + alib::StringDataFactory::toString(symb); + } + + } + + //Insert into map + std::pair<int, int> key(states.find(std::get<0>(transition.first))->second, states.find(transition.second.first)->second); + std::map<std::pair<int, int>, std::string>::iterator mapit = transitions.find(key); + + if (mapit == transitions.end()) { + transitions.insert(std::make_pair(key, symbol)); + } else { + mapit->second += ","; + + size_t pos = mapit->second.find_last_of("\n"); + if(pos == std::string::npos) pos = 0; + if(mapit->second.size() - pos > 100) mapit->second += "\n"; + else mapit->second += " "; + + mapit->second += symbol; + } + } + + //print the map + for (std::pair<const std::pair<int, int>, std::string>& transition : transitions) { + out << transition.first.first << " -> " << transition.first.second; + replace(transition.second, "\n", "\\n"); + out << "[label=\"" << transition.second << "\"]\n"; + } +} + +template < class SymbolType, class EpsilonType, class StateType > +void DotConverter::transitions(const automaton::SinglePopDPDA < SymbolType, EpsilonType, StateType > & pda, const std::map<StateType, int>& states, std::ostream& out) { + std::map<std::pair<int, int>, std::string> transitions; + + for (const auto& transition : pda.getTransitions()) { + std::string symbol; + + //input symbol + if (std::get<1>(transition.first).template is< EpsilonType >()) { + symbol = "ε"; + } else { + symbol = alib::StringDataFactory::toString(std::get<1>(transition.first).template get<SymbolType>()); + } + + symbol += " |"; + + //Pop part + symbol += " " + alib::StringDataFactory::toString(std::get<2>(transition.first)); + + symbol += " ->"; + + //Push part + if (transition.second.second.size() == 0) { + symbol += " ε"; + } else { + for (SymbolType symb : transition.second.second) { + symbol += " " + alib::StringDataFactory::toString(symb); + } + + } + + //Insert into map + std::pair<int, int> key(states.find(std::get<0>(transition.first))->second, states.find(transition.second.first)->second); + std::map<std::pair<int, int>, std::string>::iterator mapit = transitions.find(key); + + if (mapit == transitions.end()) { + transitions.insert(std::make_pair(key, symbol)); + } else { + mapit->second += ","; + + size_t pos = mapit->second.find_last_of("\n"); + if(pos == std::string::npos) pos = 0; + if(mapit->second.size() - pos > 100) mapit->second += "\n"; + else mapit->second += " "; + + mapit->second += symbol; + } + } + + //print the map + for (std::pair<const std::pair<int, int>, std::string>& transition : transitions) { + out << transition.first.first << " -> " << transition.first.second; + replace(transition.second, "\n", "\\n"); + out << "[label=\"" << transition.second << "\"]\n"; + } +} + +template < class SymbolType, class StateType > +void DotConverter::transitions(const automaton::InputDrivenDPDA < SymbolType, StateType > & pda, const std::map<StateType, int>& states, std::ostream& out) { + std::map<std::pair<int, int>, std::string> transitions; + + const auto& symbolToPDSOperation = pda.getPushdownStoreOperations(); + for (const auto& transition : pda.getTransitions()) { + const auto& pop = symbolToPDSOperation.find(transition.first.second)->second.first; + const auto& push = symbolToPDSOperation.find(transition.first.second)->second.second; + + std::string symbol; + + //input symbol + symbol = alib::StringDataFactory::toString(transition.first.second); + + symbol += " |"; + + //Pop part + if (pop.size() == 0) { + symbol += " ε"; + } else { + for (SymbolType symb : pop) { + symbol += " " + alib::StringDataFactory::toString(symb); + } + + } + + symbol += " ->"; + + const auto& to = transition.second; + //Push part + if (push.size() == 0) { + symbol += " ε"; + } else { + for (SymbolType symb : push) { + symbol += " " + alib::StringDataFactory::toString(symb); + } + + } + + //Insert into map + std::pair<int, int> key(states.find(transition.first.first)->second, states.find(to)->second); + std::map<std::pair<int, int>, std::string>::iterator mapit = transitions.find(key); + + if (mapit == transitions.end()) { + transitions.insert(std::make_pair(key, symbol)); + } else { + mapit->second += ","; + + size_t pos = mapit->second.find_last_of("\n"); + if(pos == std::string::npos) pos = 0; + if(mapit->second.size() - pos > 100) mapit->second += "\n"; + else mapit->second += " "; + + mapit->second += symbol; + } + } + + //print the map + for (std::pair<const std::pair<int, int>, std::string>& transition : transitions) { + out << transition.first.first << " -> " << transition.first.second; + replace(transition.second, "\n", "\\n"); + out << "[label=\"" << transition.second << "\"]\n"; + } +} + +template < class SymbolType, class StateType > +void DotConverter::transitions(const automaton::InputDrivenNPDA < SymbolType, StateType > & pda, const std::map<StateType, int>& states, std::ostream& out) { + std::map<std::pair<int, int>, std::string> transitions; + + const auto& symbolToPDSOperation = pda.getPushdownStoreOperations(); + for (const auto& transition : pda.getTransitions()) { + const auto& pop = symbolToPDSOperation.find(transition.first.second)->second.first; + const auto& push = symbolToPDSOperation.find(transition.first.second)->second.second; + + std::string symbol; + + //input symbol + symbol = alib::StringDataFactory::toString(transition.first.second); + + symbol += " |"; + + //Pop part + if (pop.size() == 0) { + symbol += " ε"; + } else { + for (SymbolType symb : pop) { + symbol += " " + alib::StringDataFactory::toString(symb); + } + + } + + symbol += " ->"; + + std::string symbol2; + for(const auto& to : transition.second) { + symbol2 = symbol; + //Push part + if (push.size() == 0) { + symbol2 += " ε"; + } else { + for (SymbolType symb : push) { + symbol2 += " " + alib::StringDataFactory::toString(symb); + } + + } + + //Insert into map + std::pair<int, int> key(states.find(transition.first.first)->second, states.find(to)->second); + std::map<std::pair<int, int>, std::string>::iterator mapit = transitions.find(key); + + if (mapit == transitions.end()) { + transitions.insert(std::make_pair(key, symbol2)); + } else { + mapit->second += ","; + + size_t pos = mapit->second.find_last_of("\n"); + if(pos == std::string::npos) pos = 0; + if(mapit->second.size() - pos > 100) mapit->second += "\n"; + else mapit->second += " "; + + mapit->second += symbol2; + } + } + } + + //print the map + for (std::pair<const std::pair<int, int>, std::string>& transition : transitions) { + out << transition.first.first << " -> " << transition.first.second; + replace(transition.second, "\n", "\\n"); + out << "[label=\"" << transition.second << "\"]\n"; + } +} + +template < class SymbolType, class StateType > +void DotConverter::transitions(const automaton::VisiblyPushdownDPDA < SymbolType, StateType > & pda, const std::map<StateType, int>& states, std::ostream& out) { + std::map<std::pair<int, int>, std::string> transitions; + + for (const auto& transition : pda.getCallTransitions()) { + std::string symbol; + + //input symbol + symbol = alib::StringDataFactory::toString(transition.first.second); + + symbol += " |"; + + //Pop part + symbol += " ε"; + symbol += " ->"; + + symbol += " " + alib::StringDataFactory::toString(transition.second.second); + + //Insert into map + std::pair<int, int> key(states.find(transition.first.first)->second, states.find(transition.second.first)->second); + std::map<std::pair<int, int>, std::string>::iterator mapit = transitions.find(key); + + if (mapit == transitions.end()) { + transitions.insert(std::make_pair(key, symbol)); + } else { + mapit->second += ","; + + size_t pos = mapit->second.find_last_of("\n"); + if(pos == std::string::npos) pos = 0; + if(mapit->second.size() - pos > 100) mapit->second += "\n"; + else mapit->second += " "; + + mapit->second += symbol; + } + } + + for (const auto& transition : pda.getReturnTransitions()) { + std::string symbol; + + //input symbol + symbol = alib::StringDataFactory::toString(std::get<1>(transition.first)); + + symbol += " |"; + + //Pop part + symbol += " " + alib::StringDataFactory::toString(std::get<2>(transition.first)); + symbol += " ->"; + + symbol += " ε"; + + //Insert into map + std::pair<int, int> key(states.find(std::get<0>(transition.first))->second, states.find(transition.second)->second); + std::map<std::pair<int, int>, std::string>::iterator mapit = transitions.find(key); + + if (mapit == transitions.end()) { + transitions.insert(std::make_pair(key, symbol)); + } else { + mapit->second += ","; + + size_t pos = mapit->second.find_last_of("\n"); + if(pos == std::string::npos) pos = 0; + if(mapit->second.size() - pos > 100) mapit->second += "\n"; + else mapit->second += " "; + + mapit->second += symbol; + } + } + + for (const auto& transition : pda.getLocalTransitions()) { + std::string symbol; + + //input symbol + symbol = alib::StringDataFactory::toString(transition.first.second); + + symbol += " |"; + + //Pop part + symbol += " ε"; + symbol += " ->"; + + symbol += " ε"; + + //Insert into map + std::pair<int, int> key(states.find(transition.first.first)->second, states.find(transition.second)->second); + std::map<std::pair<int, int>, std::string>::iterator mapit = transitions.find(key); + + if (mapit == transitions.end()) { + transitions.insert(std::make_pair(key, symbol)); + } else { + mapit->second += ","; + + size_t pos = mapit->second.find_last_of("\n"); + if(pos == std::string::npos) pos = 0; + if(mapit->second.size() - pos > 100) mapit->second += "\n"; + else mapit->second += " "; + + mapit->second += symbol; + } + } + + //print the map + for (std::pair<const std::pair<int, int>, std::string>& transition : transitions) { + out << transition.first.first << " -> " << transition.first.second; + replace(transition.second, "\n", "\\n"); + out << "[label=\"" << transition.second << "\"]\n"; + } +} + +template < class SymbolType, class StateType > +void DotConverter::transitions(const automaton::VisiblyPushdownNPDA < SymbolType, StateType > & pda, const std::map<StateType, int>& states, std::ostream& out) { + std::map<std::pair<int, int>, std::string> transitions; + + for (const auto& transition : pda.getCallTransitions()) { + std::string symbol; + + //input symbol + symbol = alib::StringDataFactory::toString(transition.first.second); + + symbol += " |"; + + //Pop part + symbol += " ε"; + symbol += " ->"; + + std::string symbol2; + for(const auto& to : transition.second) { + symbol2 = symbol; + symbol2 += " " + alib::StringDataFactory::toString(to.second); + + //Insert into map + std::pair<int, int> key(states.find(transition.first.first)->second, states.find(to.first)->second); + std::map<std::pair<int, int>, std::string>::iterator mapit = transitions.find(key); + + if (mapit == transitions.end()) { + transitions.insert(std::make_pair(key, symbol2)); + } else { + mapit->second += ","; + + size_t pos = mapit->second.find_last_of("\n"); + if(pos == std::string::npos) pos = 0; + if(mapit->second.size() - pos > 100) mapit->second += "\n"; + else mapit->second += " "; + + mapit->second += symbol2; + } + } + } + + for (const auto& transition : pda.getReturnTransitions()) { + std::string symbol; + + //input symbol + symbol = alib::StringDataFactory::toString(std::get<1>(transition.first)); + + symbol += " |"; + + //Pop part + symbol += " " + alib::StringDataFactory::toString(std::get<2>(transition.first)); + symbol += " ->"; + + std::string symbol2; + for(const auto& to : transition.second) { + symbol2 = symbol; + symbol2 += " ε"; + + //Insert into map + std::pair<int, int> key(states.find(std::get<0>(transition.first))->second, states.find(to)->second); + std::map<std::pair<int, int>, std::string>::iterator mapit = transitions.find(key); + + if (mapit == transitions.end()) { + transitions.insert(std::make_pair(key, symbol2)); + } else { + mapit->second += ","; + + size_t pos = mapit->second.find_last_of("\n"); + if(pos == std::string::npos) pos = 0; + if(mapit->second.size() - pos > 100) mapit->second += "\n"; + else mapit->second += " "; + + mapit->second += symbol2; + } + } + } + + for (const auto& transition : pda.getLocalTransitions()) { + std::string symbol; + + //input symbol + symbol = alib::StringDataFactory::toString(transition.first.second); + + symbol += " |"; + + //Pop part + symbol += " ε"; + symbol += " ->"; + + std::string symbol2; + for(const auto& to : transition.second) { + symbol2 = symbol; + symbol2 += " ε"; + + //Insert into map + std::pair<int, int> key(states.find(transition.first.first)->second, states.find(to)->second); + std::map<std::pair<int, int>, std::string>::iterator mapit = transitions.find(key); + + if (mapit == transitions.end()) { + transitions.insert(std::make_pair(key, symbol2)); + } else { + mapit->second += ","; + + size_t pos = mapit->second.find_last_of("\n"); + if(pos == std::string::npos) pos = 0; + if(mapit->second.size() - pos > 100) mapit->second += "\n"; + else mapit->second += " "; + + mapit->second += symbol2; + } + } + } + + //print the map + for (std::pair<const std::pair<int, int>, std::string>& transition : transitions) { + out << transition.first.first << " -> " << transition.first.second; + replace(transition.second, "\n", "\\n"); + out << "[label=\"" << transition.second << "\"]\n"; + } +} + +template < class SymbolType, class EpsilonType, class StateType > +void DotConverter::transitions(const automaton::RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType > & pda, const std::map<StateType, int>& states, std::ostream& out) { + std::map<std::pair<int, int>, std::string> transitions; + + for (const auto& transition : pda.getCallTransitions()) { + std::string symbol; + + //input symbol + if(transition.first.second.template is< EpsilonType >()) + symbol = "&epsilon"; + else + symbol = alib::StringDataFactory::toString(transition.first.second.template get<SymbolType>()); + + symbol += " |"; + + //Pop part + symbol += " ε"; + symbol += " ->"; + + symbol += " " + alib::StringDataFactory::toString(transition.second.second); + + //Insert into map + std::pair<int, int> key(states.find(transition.first.first)->second, states.find(transition.second.first)->second); + std::map<std::pair<int, int>, std::string>::iterator mapit = transitions.find(key); + + if (mapit == transitions.end()) { + transitions.insert(std::make_pair(key, symbol)); + } else { + mapit->second += ","; + + size_t pos = mapit->second.find_last_of("\n"); + if(pos == std::string::npos) pos = 0; + if(mapit->second.size() - pos > 100) mapit->second += "\n"; + else mapit->second += " "; + + mapit->second += symbol; + } + } + + for (const auto& transition : pda.getReturnTransitions()) { + std::string symbol; + + //input symbol + if(std::get<1>(transition.first).template is< EpsilonType >()) + symbol = "&epsilon"; + else + symbol = alib::StringDataFactory::toString(std::get<1>(transition.first).template get<SymbolType>()); + + symbol += " |"; + + //Pop part + symbol += " " + alib::StringDataFactory::toString(std::get<2>(transition.first)); + symbol += " ->"; + + symbol += " ε"; + + //Insert into map + std::pair<int, int> key(states.find(std::get<0>(transition.first))->second, states.find(transition.second)->second); + std::map<std::pair<int, int>, std::string>::iterator mapit = transitions.find(key); + + if (mapit == transitions.end()) { + transitions.insert(std::make_pair(key, symbol)); + } else { + mapit->second += ","; + + size_t pos = mapit->second.find_last_of("\n"); + if(pos == std::string::npos) pos = 0; + if(mapit->second.size() - pos > 100) mapit->second += "\n"; + else mapit->second += " "; + + mapit->second += symbol; + } + } + + for (const auto& transition : pda.getLocalTransitions()) { + std::string symbol; + + //input symbol + if(transition.first.second.template is< EpsilonType >()) + symbol = "&epsilon"; + else + symbol = alib::StringDataFactory::toString(transition.first.second.template get<SymbolType>()); + + symbol += " |"; + + //Pop part + symbol += " ε"; + symbol += " ->"; + + symbol += " ε"; + + //Insert into map + std::pair<int, int> key(states.find(transition.first.first)->second, states.find(transition.second)->second); + std::map<std::pair<int, int>, std::string>::iterator mapit = transitions.find(key); + + if (mapit == transitions.end()) { + transitions.insert(std::make_pair(key, symbol)); + } else { + mapit->second += ","; + + size_t pos = mapit->second.find_last_of("\n"); + if(pos == std::string::npos) pos = 0; + if(mapit->second.size() - pos > 100) mapit->second += "\n"; + else mapit->second += " "; + + mapit->second += symbol; + } + } + + //print the map + for (std::pair<const std::pair<int, int>, std::string>& transition : transitions) { + out << transition.first.first << " -> " << transition.first.second; + replace(transition.second, "\n", "\\n"); + out << "[label=\"" << transition.second << "\"]\n"; + } +} + +template < class SymbolType, class EpsilonType, class StateType > +void DotConverter::transitions(const automaton::RealTimeHeightDeterministicNPDA < SymbolType, EpsilonType, StateType > & pda, const std::map<StateType, int>& states, std::ostream& out) { + std::map<std::pair<int, int>, std::string> transitions; + + for (const auto& transition : pda.getCallTransitions()) { + std::string symbol; + + //input symbol + if(transition.first.second.template is< EpsilonType >()) + symbol = "&epsilon"; + else + symbol = alib::StringDataFactory::toString(transition.first.second.template get<SymbolType>()); + + symbol += " |"; + + //Pop part + symbol += " ε"; + symbol += " ->"; + + std::string symbol2; + for(const auto& to : transition.second) { + symbol2 = symbol; + symbol2 += " " + alib::StringDataFactory::toString(to.second); + + //Insert into map + std::pair<int, int> key(states.find(transition.first.first)->second, states.find(to.first)->second); + std::map<std::pair<int, int>, std::string>::iterator mapit = transitions.find(key); + + if (mapit == transitions.end()) { + transitions.insert(std::make_pair(key, symbol2)); + } else { + mapit->second += ","; + + size_t pos = mapit->second.find_last_of("\n"); + if(pos == std::string::npos) pos = 0; + if(mapit->second.size() - pos > 100) mapit->second += "\n"; + else mapit->second += " "; + + mapit->second += symbol2; + } + } + } + + for (const auto& transition : pda.getReturnTransitions()) { + std::string symbol; + + //input symbol + if(std::get<1>(transition.first).template is< EpsilonType >()) + symbol = "ε"; + else + symbol = alib::StringDataFactory::toString(std::get<1>(transition.first).template get<SymbolType>()); + + symbol += " |"; + + //Pop part + symbol += " " + alib::StringDataFactory::toString(std::get<2>(transition.first)); + symbol += " ->"; + + std::string symbol2; + for(const auto& to : transition.second) { + symbol2 = symbol; + symbol2 += " ε"; + + //Insert into map + std::pair<int, int> key(states.find(std::get<0>(transition.first))->second, states.find(to)->second); + std::map<std::pair<int, int>, std::string>::iterator mapit = transitions.find(key); + + if (mapit == transitions.end()) { + transitions.insert(std::make_pair(key, symbol2)); + } else { + mapit->second += ","; + + size_t pos = mapit->second.find_last_of("\n"); + if(pos == std::string::npos) pos = 0; + if(mapit->second.size() - pos > 100) mapit->second += "\n"; + else mapit->second += " "; + + mapit->second += symbol2; + } + } + } + + for (const auto& transition : pda.getLocalTransitions()) { + std::string symbol; + + //input symbol + if(transition.first.second.template is< EpsilonType >()) + symbol = "ε"; + else + symbol = alib::StringDataFactory::toString(transition.first.second.template get<SymbolType>()); + + symbol += " |"; + + //Pop part + symbol += " ε"; + symbol += " ->"; + + std::string symbol2; + for(const auto& to : transition.second) { + symbol2 = symbol; + symbol2 += " ε"; + + //Insert into map + std::pair<int, int> key(states.find(transition.first.first)->second, states.find(to)->second); + std::map<std::pair<int, int>, std::string>::iterator mapit = transitions.find(key); + + if (mapit == transitions.end()) { + transitions.insert(std::make_pair(key, symbol2)); + } else { + mapit->second += ","; + + size_t pos = mapit->second.find_last_of("\n"); + if(pos == std::string::npos) pos = 0; + if(mapit->second.size() - pos > 100) mapit->second += "\n"; + else mapit->second += " "; + + mapit->second += symbol2; + } + } + } + + //print the map + for (std::pair<const std::pair<int, int>, std::string>& transition : transitions) { + out << transition.first.first << " -> " << transition.first.second; + replace(transition.second, "\n", "\\n"); + out << "[label=\"" << transition.second << "\"]\n"; + } +} + +template < class SymbolType, class EpsilonType, class StateType > +void DotConverter::transitions(const automaton::NPDA < SymbolType, EpsilonType, StateType > & pda, const std::map<StateType, int>& states, std::ostream& out) { + std::map<std::pair<int, int>, std::string> transitions; + + for (const auto& transition : pda.getTransitions()) { + std::string symbol; + + //input symbol + if (std::get<1>(transition.first).template is< EpsilonType >()) { + symbol = "ε"; + } else { + symbol = alib::StringDataFactory::toString(std::get<1>(transition.first).template get<SymbolType>()); + } + + symbol += " |"; + + //Pop part + if (std::get<2>(transition.first).size() == 0) { + symbol += " ε"; + } else { + for (SymbolType symb : std::get<2>(transition.first)) { + symbol += " " + alib::StringDataFactory::toString(symb); + } + + } + + symbol += " ->"; + + std::string symbol2; + for(const auto& to : transition.second) { + symbol2 = symbol; + //Push part + if (to.second.size() == 0) { + symbol2 += " ε"; + } else { + for (SymbolType symb : to.second) { + symbol2 += " " + alib::StringDataFactory::toString(symb); + } + + } + + //Insert into map + std::pair<int, int> key(states.find(std::get<0>(transition.first))->second, states.find(to.first)->second); + std::map<std::pair<int, int>, std::string>::iterator mapit = transitions.find(key); + + if (mapit == transitions.end()) { + transitions.insert(std::make_pair(key, symbol2)); + } else { + mapit->second += ","; + + size_t pos = mapit->second.find_last_of("\n"); + if(pos == std::string::npos) pos = 0; + if(mapit->second.size() - pos > 100) mapit->second += "\n"; + else mapit->second += " "; + + mapit->second += symbol2; + } + } + } + + //print the map + for (std::pair<const std::pair<int, int>, std::string>& transition : transitions) { + out << transition.first.first << " -> " << transition.first.second; + replace(transition.second, "\n", "\\n"); + out << "[label=\"" << transition.second << "\"]\n"; + } +} + +template < class SymbolType, class EpsilonType, class StateType > +void DotConverter::transitions(const automaton::SinglePopNPDA < SymbolType, EpsilonType, StateType > & pda, const std::map<StateType, int>& states, std::ostream& out) { + std::map<std::pair<int, int>, std::string> transitions; + + for (const auto& transition : pda.getTransitions()) { + std::string symbol; + + //input symbol + if (std::get<1>(transition.first).template is< EpsilonType >()) { + symbol = "ε"; + } else { + symbol = alib::StringDataFactory::toString(std::get<1>(transition.first).template get<SymbolType>()); + } + + symbol += " |"; + + //Pop part + symbol += " " + alib::StringDataFactory::toString(std::get<2>(transition.first)); + + symbol += " ->"; + + std::string symbol2; + for(const auto& to : transition.second) { + symbol2 = symbol; + //Push part + if (to.second.size() == 0) { + symbol2 += " ε"; + } else { + for (SymbolType symb : to.second) { + symbol2 += " " + alib::StringDataFactory::toString(symb); + } + + } + + //Insert into map + std::pair<int, int> key(states.find(std::get<0>(transition.first))->second, states.find(to.first)->second); + std::map<std::pair<int, int>, std::string>::iterator mapit = transitions.find(key); + + if (mapit == transitions.end()) { + transitions.insert(std::make_pair(key, symbol2)); + } else { + mapit->second += ","; + + size_t pos = mapit->second.find_last_of("\n"); + if(pos == std::string::npos) pos = 0; + if(mapit->second.size() - pos > 100) mapit->second += "\n"; + else mapit->second += " "; + + mapit->second += symbol2; + } + } + } + + //print the map + for (std::pair<const std::pair<int, int>, std::string>& transition : transitions) { + out << transition.first.first << " -> " << transition.first.second; + replace(transition.second, "\n", "\\n"); + out << "[label=\"" << transition.second << "\"]\n"; + } +} + +template < class SymbolType, class StateType > +void DotConverter::transitions(const automaton::OneTapeDTM < SymbolType, StateType > & tm, const std::map < StateType, int > & states, std::ostream& out) { + std::map<std::pair<int, int>, std::string> transitions; + for (const auto& transition : tm.getTransitions()) { + std::string symbol; + + //input symbol + symbol = "("; + symbol += alib::StringDataFactory::toString(transition.first.second); + symbol += ", "; + symbol += alib::StringDataFactory::toString(std::get<1>(transition.second)); + symbol += " "; + switch(std::get<2>(transition.second)) { + case automaton::Shift::LEFT: + symbol += "←"; + break; + case automaton::Shift::RIGHT: + symbol += "→"; + break; + case automaton::Shift::NONE: + symbol += "×"; + break; + default: + throw exception::CommonException("Unexpected shift direction"); + } + + //Insert into map + std::pair<int, int> key(states.find(transition.first.first)->second, states.find(std::get<0>(transition.second))->second); + std::map<std::pair<int, int>, std::string>::iterator mapit = transitions.find(key); + + if (mapit == transitions.end()) { + transitions.insert(std::make_pair(key, symbol)); + } else { + mapit->second += ","; + + size_t pos = mapit->second.find_last_of("\n"); + if(pos == std::string::npos) pos = 0; + if(mapit->second.size() - pos > 100) mapit->second += "\n"; + else mapit->second += " "; + + mapit->second += symbol; + } + } + + //print the map + for (std::pair<const std::pair<int, int>, std::string>& transition : transitions) { + out << transition.first.first << " -> " << transition.first.second; + replace(transition.second, "\n", "\\n"); + out << "[label=\"" << transition.second << "\"]\n"; + } +} + #endif /* DOT_CONVERTER_H_ */ diff --git a/aconvert2/src/GasTexConverter.cpp b/aconvert2/src/GasTexConverter.cpp index b8bf6ef0e6..e9845d297b 100644 --- a/aconvert2/src/GasTexConverter.cpp +++ b/aconvert2/src/GasTexConverter.cpp @@ -7,765 +7,6 @@ #include "GasTexConverter.h" -#include <automaton/FSM/NFA.h> -#include <automaton/FSM/MultiInitialStateNFA.h> -#include <automaton/FSM/EpsilonNFA.h> -#include <automaton/FSM/DFA.h> -#include <automaton/FSM/ExtendedNFA.h> -#include <automaton/FSM/CompactNFA.h> -#include <automaton/TA/NFTA.h> -#include <automaton/TA/DFTA.h> -#include <automaton/PDA/DPDA.h> -#include <automaton/PDA/SinglePopDPDA.h> -#include <automaton/PDA/InputDrivenDPDA.h> -#include <automaton/PDA/InputDrivenNPDA.h> -#include <automaton/PDA/VisiblyPushdownDPDA.h> -#include <automaton/PDA/VisiblyPushdownNPDA.h> -#include <automaton/PDA/RealTimeHeightDeterministicDPDA.h> -#include <automaton/PDA/RealTimeHeightDeterministicNPDA.h> -#include <automaton/PDA/NPDA.h> -#include <automaton/PDA/SinglePopNPDA.h> -#include <automaton/TM/OneTapeDTM.h> - -#include <factory/StringDataFactory.hpp> - -#include <exception/CommonException.h> - -#include <string/String.h> - -#include <set> -#include <map> -#include <typeinfo> - -void GasTexConverter::convert(std::ostream& out, const automaton::Automaton& a) { - dispatch(out, a.getData()); -} - -void GasTexConverter::convert(std::ostream& out, const automaton::EpsilonNFA < > & a) { - out << "\\begin{center}\n"; - out << "\\begin{picture}(,)(,)\n"; - - for (auto& state : a.getStates()) { - bool initial = false; - bool final = false; - - if(a.getInitialState() == state){ - initial = true; - } - if(a.getFinalStates().count(state)){ - final = true; - } - - if(initial || final) { - out << "\\node[Nmarks="; - if(initial){ - out << "i"; - } - if(final){ - out << "r"; - } - out<<"]("; - } else { - out <<"\\node("; - } - - out << state; - out << ")(,){"; - out << state; - out << "}\n"; - } - - transitions(a, out); - out << "\\end{center}\n"; - out << "\\end{picture}\n"; -} - -auto GasTexConverterEpsilonNFA = GasTexConverter::RegistratorWrapper<void, automaton::EpsilonNFA < > >(GasTexConverter::convert); - -void GasTexConverter::convert(std::ostream& out, const automaton::MultiInitialStateNFA < >& a) { - out << "\\begin{center}\n"; - out << "\\begin{picture}(,)(,)\n"; - - for (auto& state : a.getStates()) { - bool initial = false; - bool final = false; - - if(a.getInitialStates().count(state)){ - initial = true; - } - if(a.getFinalStates().count(state)){ - final = true; - } - - if(initial || final) { - out << "\\node[Nmarks="; - if(initial){ - out << "i"; - } - if(final){ - out << "r"; - } - out<<"]("; - } else { - out <<"\\node("; - } - - out << state; - out << ")(,){"; - out << state; - out << "}\n"; - } - - transitions(a, out); - out << "\\end{center}\n"; - out << "\\end{picture}\n"; -} - -auto GasTexConverterMultiInitialStateNFA = GasTexConverter::RegistratorWrapper<void, automaton::MultiInitialStateNFA < >>(GasTexConverter::convert); - -void GasTexConverter::convert(std::ostream& out, const automaton::NFA < > & a) { - out << "\\begin{center}\n"; - out << "\\begin{picture}(,)(,)\n"; - - for (auto& state : a.getStates()) { - bool initial = false; - bool final = false; - - if(a.getInitialState() == state){ - initial = true; - } - if(a.getFinalStates().count(state)){ - final = true; - } - - if(initial || final) { - out << "\\node[Nmarks="; - if(initial){ - out << "i"; - } - if(final){ - out << "r"; - } - out<<"]("; - } else { - out <<"\\node("; - } - - out << state; - out << ")(,){"; - out << state; - out << "}\n"; - } - - transitions(a, out); - out << "\\end{center}\n"; - out << "\\end{picture}\n"; -} - -auto GasTexConverterNFA = GasTexConverter::RegistratorWrapper<void, automaton::NFA < > >(GasTexConverter::convert); - -void GasTexConverter::convert(std::ostream& out, const automaton::DFA<>& a) { - out << "\\begin{center}\n"; - out << "\\begin{picture}(,)(,)\n"; - - for (auto& state : a.getStates()) { - bool initial = false; - bool final = false; - - if(a.getInitialState() == state){ - initial = true; - } - if(a.getFinalStates().count(state)){ - final = true; - } - - if(initial || final) { - out << "\\node[Nmarks="; - if(initial){ - out << "i"; - } - if(final){ - out << "r"; - } - out<<"]("; - } else { - out <<"\\node("; - } - - out << state; - out << ")(,){"; - out << state; - out << "}\n"; - } - - transitions(a, out); - out << "\\end{center}\n"; - out << "\\end{picture}\n"; -} - -auto GasTexConverterDFA = GasTexConverter::RegistratorWrapper<void, automaton::DFA<>>(GasTexConverter::convert); - -void GasTexConverter::convert(std::ostream& out, const automaton::ExtendedNFA < > & a) { - out << "\\begin{center}\n"; - out << "\\begin{picture}(,)(,)\n"; - - for (auto& state : a.getStates()) { - bool initial = false; - bool final = false; - - if(a.getInitialState() == state){ - initial = true; - } - if(a.getFinalStates().count(state)){ - final = true; - } - - if(initial || final) { - out << "\\node[Nmarks="; - if(initial){ - out << "i"; - } - if(final){ - out << "r"; - } - out<<"]("; - } else { - out <<"\\node("; - } - - out << state; - out << ")(,){"; - out << state; - out << "}\n"; - } - - transitions(a, out); - out << "\\end{center}\n"; - out << "\\end{picture}\n"; -} - -auto GasTexConverterExtendedNFA = GasTexConverter::RegistratorWrapper<void, automaton::ExtendedNFA < > >(GasTexConverter::convert); - -void GasTexConverter::convert(std::ostream& out, const automaton::CompactNFA < > & a) { - out << "\\begin{center}\n"; - out << "\\begin{picture}(,)(,)\n"; - - for (auto& state : a.getStates()) { - bool initial = false; - bool final = false; - - if(a.getInitialState() == state){ - initial = true; - } - if(a.getFinalStates().count(state)){ - final = true; - } - - if(initial || final) { - out << "\\node[Nmarks="; - if(initial){ - out << "i"; - } - if(final){ - out << "r"; - } - out<<"]("; - } else { - out <<"\\node("; - } - - out << state; - out << ")(,){"; - out << state; - out << "}\n"; - } - - transitions(a, out); - out << "\\end{center}\n"; - out << "\\end{picture}\n"; -} - -auto GasTexConverterCompactNFA = GasTexConverter::RegistratorWrapper<void, automaton::CompactNFA < > >(GasTexConverter::convert); - -void GasTexConverter::convert(std::ostream&, const automaton::NFTA < > &) { - //TODO -} - -auto GasTexConverterNFTA = GasTexConverter::RegistratorWrapper<void, automaton::NFTA < > >(GasTexConverter::convert); - -void GasTexConverter::convert(std::ostream&, const automaton::DFTA < > &) { - //TODO -} - -auto GasTexConverterDFTA = GasTexConverter::RegistratorWrapper<void, automaton::DFTA < > >(GasTexConverter::convert); - -void GasTexConverter::convert(std::ostream& out, const automaton::DPDA < > & a) { - out << "\\begin{center}\n"; - out << "\\begin{picture}(,)(,)\n"; - - for (auto& state : a.getStates()) { - bool initial = false; - bool final = false; - - if(a.getInitialState() == state) { - initial = true; - } - if(a.getFinalStates().count(state)) { - final = true; - } - - if(initial || final) { - out << "\\node[Nmarks="; - if(initial){ - out << "i"; - } - if(final){ - out << "r"; - } - out<<"]("; - } else { - out <<"\\node("; - } - - out << state; - out << ")(,){"; - out << state; - out << "}\n"; - } - - transitions(a, out); - out << "\\end{center}\n"; - out << "\\end{picture}\n"; -} - -auto GasTexConverterDPDA = GasTexConverter::RegistratorWrapper<void, automaton::DPDA < > >(GasTexConverter::convert); - -void GasTexConverter::convert(std::ostream& out, const automaton::SinglePopDPDA < > & a) { - out << "\\begin{center}\n"; - out << "\\begin{picture}(,)(,)\n"; - - for (auto& state : a.getStates()) { - bool initial = false; - bool final = false; - - if(a.getInitialState() == state) { - initial = true; - } - if(a.getFinalStates().count(state)){ - final = true; - } - - if(initial || final) { - out << "\\node[Nmarks="; - if(initial){ - out << "i"; - } - if(final){ - out << "r"; - } - out<<"]("; - } else { - out <<"\\node("; - } - - out << state; - out << ")(,){"; - out << state; - out << "}\n"; - } - - transitions(a, out); - out << "\\end{center}\n"; - out << "\\end{picture}\n"; -} - -auto GasTexConverterSinglePopDPDA = GasTexConverter::RegistratorWrapper<void, automaton::SinglePopDPDA < > >(GasTexConverter::convert); - -void GasTexConverter::convert(std::ostream& out, const automaton::InputDrivenDPDA < > & a) { - out << "\\begin{center}\n"; - out << "\\begin{picture}(,)(,)\n"; - - for (auto& state : a.getStates()) { - bool initial = false; - bool final = false; - - if(a.getInitialState() == state){ - initial = true; - } - if(a.getFinalStates().count(state)){ - final = true; - } - - if(initial || final) { - out << "\\node[Nmarks="; - if(initial){ - out << "i"; - } - if(final){ - out << "r"; - } - out<<"]("; - } else { - out <<"\\node("; - } - - out << state; - out << ")(,){"; - out << state; - out << "}\n"; - } - - transitions(a, out); - out << "\\end{center}\n"; - out << "\\end{picture}\n"; -} - -auto GasTexConverterInputDrivenDPDA = GasTexConverter::RegistratorWrapper<void, automaton::InputDrivenDPDA < > >(GasTexConverter::convert); - -void GasTexConverter::convert(std::ostream& out, const automaton::InputDrivenNPDA < > & a) { - out << "\\begin{center}\n"; - out << "\\begin{picture}(,)(,)\n"; - - for (auto& state : a.getStates()) { - bool initial = false; - bool final = false; - - if(a.getInitialState() == state){ - initial = true; - } - if(a.getFinalStates().count(state)){ - final = true; - } - - if(initial || final) { - out << "\\node[Nmarks="; - if(initial){ - out << "i"; - } - if(final){ - out << "r"; - } - out<<"]("; - } else { - out <<"\\node("; - } - - out << state; - out << ")(,){"; - out << state; - out << "}\n"; - } - - transitions(a, out); - out << "\\end{center}\n"; - out << "\\end{picture}\n"; -} - -auto GasTexConverterInputDrivenNPDA = GasTexConverter::RegistratorWrapper<void, automaton::InputDrivenNPDA < > >(GasTexConverter::convert); - -void GasTexConverter::convert(std::ostream& out, const automaton::VisiblyPushdownDPDA < > & a) { - out << "\\begin{center}\n"; - out << "\\begin{picture}(,)(,)\n"; - - for (auto& state : a.getStates()) { - bool initial = false; - bool final = false; - - if(a.getInitialState() == state){ - initial = true; - } - if(a.getFinalStates().count(state)){ - final = true; - } - - if(initial || final) { - out << "\\node[Nmarks="; - if(initial){ - out << "i"; - } - if(final){ - out << "r"; - } - out<<"]("; - } else { - out <<"\\node("; - } - - out << state; - out << ")(,){"; - out << state; - out << "}\n"; - } - - transitions(a, out); - out << "\\end{center}\n"; - out << "\\end{picture}\n"; -} - -auto GasTexConverterVisiblyPushdownDPDA = GasTexConverter::RegistratorWrapper<void, automaton::VisiblyPushdownDPDA < > >(GasTexConverter::convert); - -void GasTexConverter::convert(std::ostream& out, const automaton::VisiblyPushdownNPDA < > & a) { - out << "\\begin{center}\n"; - out << "\\begin{picture}(,)(,)\n"; - - for (auto& state : a.getStates()) { - bool initial = false; - bool final = false; - - if(a.getInitialStates().count(state)){ - initial = true; - } - if(a.getFinalStates().count(state)){ - final = true; - } - - if(initial || final) { - out << "\\node[Nmarks="; - if(initial){ - out << "i"; - } - if(final){ - out << "r"; - } - out<<"]("; - } else { - out <<"\\node("; - } - - out << state; - out << ")(,){"; - out << state; - out << "}\n"; - } - - transitions(a, out); - out << "\\end{center}\n"; - out << "\\end{picture}\n"; -} - -auto GasTexConverterVisiblyPushdownNPDA = GasTexConverter::RegistratorWrapper<void, automaton::VisiblyPushdownNPDA < > >(GasTexConverter::convert); - -void GasTexConverter::convert(std::ostream& out, const automaton::RealTimeHeightDeterministicDPDA < > & a) { - out << "\\begin{center}\n"; - out << "\\begin{picture}(,)(,)\n"; - - for (auto& state : a.getStates()) { - bool initial = false; - bool final = false; - - if(a.getInitialState() == state){ - initial = true; - } - if(a.getFinalStates().count(state)){ - final = true; - } - - if(initial || final) { - out << "\\node[Nmarks="; - if(initial){ - out << "i"; - } - if(final){ - out << "r"; - } - out<<"]("; - } else { - out <<"\\node("; - } - - out << state; - out << ")(,){"; - out << state; - out << "}\n"; - } - - transitions(a, out); - out << "\\end{center}\n"; - out << "\\end{picture}\n"; -} - -auto GasTexConverterRealTimeHeightDeterministicDPDA = GasTexConverter::RegistratorWrapper<void, automaton::RealTimeHeightDeterministicDPDA < > >(GasTexConverter::convert); - -void GasTexConverter::convert(std::ostream& out, const automaton::RealTimeHeightDeterministicNPDA < > & a) { - out << "\\begin{center}\n"; - out << "\\begin{picture}(,)(,)\n"; - - for (auto& state : a.getStates()) { - bool initial = false; - bool final = false; - - if(a.getInitialStates().count(state)){ - initial = true; - } - if(a.getFinalStates().count(state)){ - final = true; - } - - if(initial || final) { - out << "\\node[Nmarks="; - if(initial){ - out << "i"; - } - if(final){ - out << "r"; - } - out<<"]("; - } else { - out <<"\\node("; - } - - out << state; - out << ")(,){"; - out << state; - out << "}\n"; - } - - transitions(a, out); - out << "\\end{center}\n"; - out << "\\end{picture}\n"; -} - -auto GasTexConverterRealTimeHeightDeterministicNPDA = GasTexConverter::RegistratorWrapper<void, automaton::RealTimeHeightDeterministicNPDA < > >(GasTexConverter::convert); - -void GasTexConverter::convert(std::ostream& out, const automaton::NPDA < > & a) { - out << "\\begin{center}\n"; - out << "\\begin{picture}(,)(,)\n"; - - for (auto& state : a.getStates()) { - bool initial = false; - bool final = false; - - if(a.getInitialState() == state){ - initial = true; - } - if(a.getFinalStates().count(state)){ - final = true; - } - - if(initial || final) { - out << "\\node[Nmarks="; - if(initial){ - out << "i"; - } - if(final){ - out << "r"; - } - out<<"]("; - } else { - out <<"\\node("; - } - - out << state; - out << ")(,){"; - out << state; - out << "}\n"; - } - - transitions(a, out); - out << "\\end{center}\n"; - out << "\\end{picture}\n"; -} - -auto GasTexConverterNPDA = GasTexConverter::RegistratorWrapper<void, automaton::NPDA < > >(GasTexConverter::convert); - -void GasTexConverter::convert(std::ostream& out, const automaton::SinglePopNPDA < > & a) { - out << "\\begin{center}\n"; - out << "\\begin{picture}(,)(,)\n"; - - for (auto& state : a.getStates()) { - bool initial = false; - bool final = false; - - if(a.getInitialState() == state){ - initial = true; - } - if(a.getFinalStates().count(state)){ - final = true; - } - - if(initial || final) { - out << "\\node[Nmarks="; - if(initial){ - out << "i"; - } - if(final){ - out << "r"; - } - out<<"]("; - } else { - out <<"\\node("; - } - - out << state; - out << ")(,){"; - out << state; - out << "}\n"; - } - - transitions(a, out); - out << "\\end{center}\n"; - out << "\\end{picture}\n"; -} - -auto GasTexConverterSinglePopNPDA = GasTexConverter::RegistratorWrapper<void, automaton::SinglePopNPDA < > >(GasTexConverter::convert); - -void GasTexConverter::convert(std::ostream& out, const automaton::OneTapeDTM<>& a) { - out << "\\begin{center}\n"; - out << "\\begin{picture}(,)(,)\n"; - - for (auto& state : a.getStates()) { - bool initial = false; - bool final = false; - - if(a.getInitialState() == state){ - initial = true; - } - if(a.getFinalStates().count(state)){ - final = true; - } - - if(initial || final) { - out << "\\node[Nmarks="; - if(initial){ - out << "i"; - } - if(final){ - out << "r"; - } - out<<"]("; - } else { - out <<"\\node("; - } - - out << state; - out << ")(,){"; - out << state; - out << "}\n"; - } - - transitions(a, out); - out << "\\end{center}\n"; - out << "\\end{picture}\n"; -} - -auto GasTexConverterOneTapeDTM = GasTexConverter::RegistratorWrapper<void, automaton::OneTapeDTM<>>(GasTexConverter::convert); - -std::string GasTexConverter::getStackSymbols(const std::vector<alphabet::Symbol>& stackSymbols) { - if (stackSymbols.size() == 0) { - return "$\\varepsilon$"; - } - - std::string symbols = ""; - int i=0; - for (const auto& symbol : stackSymbols) { - if(i++ !=0) { - symbols +=" "; - } - symbols += (std::string) symbol.getData(); - } - return symbols; -} - void GasTexConverter::printTransitionMap(const std::map<std::pair<std::string, std::string>, std::string> transitionMap, std::ostream& out) { for (const auto& transition : transitionMap) { std::string from = transition.first.first; @@ -791,644 +32,27 @@ void GasTexConverter::printTransitionMap(const std::map<std::pair<std::string, s } } -void GasTexConverter::transitions(const automaton::EpsilonNFA < > & fsm, std::ostream& out) { - std::map<std::pair<std::string, std::string>, std::string> transitionMap; - for (const auto& transition : fsm.getTransitions()) { - for(const auto& to : transition.second) { - std::pair<std::string, std::string> key((std::string) transition.first.first, (std::string) to); - - std::string symbol; - if (transition.first.second.is<string::Epsilon < >>()) { - symbol = "$\\varepsilon$"; - } else { - symbol = (std::string) transition.first.second.get<alphabet::Symbol>(); - } - - auto mapIterator = transitionMap.find(key); - if (mapIterator == transitionMap.end()) { - transitionMap.insert(make_pair(key, symbol)); - } else { - mapIterator->second += ", " + symbol; - } - } - } - printTransitionMap(transitionMap, out); -} - -void GasTexConverter::transitions(const automaton::MultiInitialStateNFA < >& fsm, std::ostream& out) { - std::map<std::pair<std::string, std::string>, std::string> transitionMap; - for (const auto& transition : fsm.getTransitions()) { - for(const auto& to : transition.second) { - std::pair<std::string, std::string> key((std::string) transition.first.first, (std::string) to); - - std::string symbol = (std::string) transition.first.second; - - auto mapIterator = transitionMap.find(key); - if (mapIterator == transitionMap.end()) { - transitionMap.insert(make_pair(key, symbol)); - } else { - mapIterator->second += ", " + symbol; - } - } - } - printTransitionMap(transitionMap, out); -} - -void GasTexConverter::transitions(const automaton::NFA < > & fsm, std::ostream& out) { - std::map<std::pair<std::string, std::string>, std::string> transitionMap; - for (const auto& transition : fsm.getTransitions()) { - for(const auto& to : transition.second) { - std::pair<std::string, std::string> key((std::string) transition.first.first, (std::string) to); - - std::string symbol = (std::string) transition.first.second; - - auto mapIterator = transitionMap.find(key); - if (mapIterator == transitionMap.end()) { - transitionMap.insert(make_pair(key, symbol)); - } else { - mapIterator->second += ", " + symbol; - } - } - } - printTransitionMap(transitionMap, out); -} - -void GasTexConverter::transitions(const automaton::DFA<>& fsm, std::ostream& out) { - std::map<std::pair<std::string, std::string>, std::string> transitionMap; - for (const auto& transition : fsm.getTransitions()) { - std::pair<std::string, std::string> key((std::string) transition.first.first, (std::string) transition.second); - - std::string symbol = (std::string) transition.first.second; - - auto mapIterator = transitionMap.find(key); - if (mapIterator == transitionMap.end()) { - transitionMap.insert(make_pair(key, symbol)); - } else { - mapIterator->second += ", " + symbol; - } - } - printTransitionMap(transitionMap, out); -} - -void GasTexConverter::transitions(const automaton::ExtendedNFA < > & fsm, std::ostream& out) { - std::map<std::pair<std::string, std::string>, std::string> transitionMap; - - for (const auto& transition : fsm.getTransitions()) { - for(const auto& to : transition.second) { - std::pair<std::string, std::string> key((std::string) transition.first.first, (std::string) to); - - std::string symbol = alib::StringDataFactory::toString(transition.first.second); - - auto mapIterator = transitionMap.find(key); - if (mapIterator == transitionMap.end()) { - transitionMap.insert(make_pair(key, symbol)); - } else { - mapIterator->second += ", " + symbol; - } - } - } - printTransitionMap(transitionMap, out); -} - -void GasTexConverter::transitions(const automaton::CompactNFA < > & fsm, std::ostream& out) { - std::map<std::pair<std::string, std::string>, std::string> transitionMap; - - for (const auto& transition : fsm.getTransitions()) { - for(const auto& to : transition.second) { - std::pair<std::string, std::string> key((std::string) transition.first.first, (std::string) to); - - std::string symbol = alib::StringDataFactory::toString(string::stringFrom(transition.first.second)); - - auto mapIterator = transitionMap.find(key); - if (mapIterator == transitionMap.end()) { - transitionMap.insert(make_pair(key, symbol)); - } else { - mapIterator->second += ", " + symbol; - } - } - } - printTransitionMap(transitionMap, out); -} - -void GasTexConverter::transitions(const automaton::NFTA < > &, std::ostream&) { - //TODO -} - -void GasTexConverter::transitions(const automaton::DFTA < > &, std::ostream&) { - //TODO -} - -void GasTexConverter::transitions(const automaton::DPDA < > & pda, std::ostream& out) { - std::map<std::pair<std::string, std::string>, std::string> transitionMap; - - for (const auto& transition : pda.getTransitions()) { - std::pair<std::string, std::string> key((std::string) std::get<0>(transition.first), (std::string) transition.second.first); - auto mapIterator = transitionMap.find(key); - - std::string symbol; - if (std::get<1>(transition.first).is<string::Epsilon < >>()) { - symbol = "$\\varepsilon;$"; - } else { - symbol = alib::StringDataFactory::toString(std::get<1>(transition.first).get<alphabet::Symbol>()); - } - - symbol += "|"; - - symbol += getStackSymbols(std::get<2>(transition.first)); - symbol += "\\rarrow"; - symbol += getStackSymbols(transition.second.second); - - if (mapIterator == transitionMap.end()) { - transitionMap.insert(std::make_pair(key, symbol)); - } else { - mapIterator->second += "; " + symbol; - } - } - - printTransitionMap(transitionMap, out); -} - -void GasTexConverter::transitions(const automaton::SinglePopDPDA < > & pda, std::ostream& out) { - std::map<std::pair<std::string, std::string>, std::string> transitionMap; - - for (const auto& transition : pda.getTransitions()) { - std::pair<std::string, std::string> key((std::string) std::get<0>(transition.first), (std::string) transition.second.first); - auto mapIterator = transitionMap.find(key); - - std::string symbol; - if (std::get<1>(transition.first).is<string::Epsilon < >>()) { - symbol = "$\\varepsilon;$"; - } else { - symbol = alib::StringDataFactory::toString(std::get<1>(transition.first).get<alphabet::Symbol>()); - } - - symbol += "|"; - - symbol += alib::StringDataFactory::toString(std::get<2>(transition.first)); - symbol += "\\rarrow"; - symbol += getStackSymbols(transition.second.second); - - if (mapIterator == transitionMap.end()) { - transitionMap.insert(std::make_pair(key, symbol)); - } else { - mapIterator->second += "; " + symbol; - } - } - - printTransitionMap(transitionMap, out); -} - -void GasTexConverter::transitions(const automaton::InputDrivenDPDA < > & pda, std::ostream& out) { - std::map<std::pair<std::string, std::string>, std::string> transitionMap; - - const auto& symbolToPDSOperation = pda.getPushdownStoreOperations(); - for (const auto& transition : pda.getTransitions()) { - const auto& pop = symbolToPDSOperation.find(std::get<1>(transition.first))->second.first; - const auto& push = symbolToPDSOperation.find(std::get<1>(transition.first))->second.second; - - const auto& to = transition.second; - std::pair<std::string, std::string> key((std::string) transition.first.first, (std::string) to); - auto mapIterator = transitionMap.find(key); - - std::string symbol = alib::StringDataFactory::toString(transition.first.second); - - symbol += "|"; - - symbol += getStackSymbols(pop); - symbol += "\\rarrow"; - symbol += getStackSymbols(push); - - if (mapIterator == transitionMap.end()) { - transitionMap.insert(std::make_pair(key, symbol)); - } else { - mapIterator->second += "; " + symbol; - } - } - - printTransitionMap(transitionMap, out); -} - -void GasTexConverter::transitions(const automaton::InputDrivenNPDA < > & pda, std::ostream& out) { - std::map<std::pair<std::string, std::string>, std::string> transitionMap; - - const auto& symbolToPDSOperation = pda.getPushdownStoreOperations(); - for (const auto& transition : pda.getTransitions()) { - const auto& pop = symbolToPDSOperation.find(std::get<1>(transition.first))->second.first; - const auto& push = symbolToPDSOperation.find(std::get<1>(transition.first))->second.second; - - for(const auto& to : transition.second) { - std::pair<std::string, std::string> key((std::string) transition.first.first, (std::string) to); - auto mapIterator = transitionMap.find(key); - - std::string symbol = alib::StringDataFactory::toString(transition.first.second); - - symbol += "|"; - - symbol += getStackSymbols(pop); - symbol += "\\rarrow"; - symbol += getStackSymbols(push); - - if (mapIterator == transitionMap.end()) { - transitionMap.insert(std::make_pair(key, symbol)); - } else { - mapIterator->second += "; " + symbol; - } - } - } - - printTransitionMap(transitionMap, out); -} - -void GasTexConverter::transitions(const automaton::VisiblyPushdownDPDA < > & pda, std::ostream& out) { - std::map<std::pair<std::string, std::string>, std::string> transitionMap; - - for (const auto& transition : pda.getCallTransitions()) { - std::pair<std::string, std::string> key((std::string) transition.first.first, (std::string) transition.second.first); - auto mapIterator = transitionMap.find(key); - - std::string symbol; - symbol = alib::StringDataFactory::toString(transition.first.second); - - symbol += "|"; - - symbol += "$\\varepsilon;$"; - symbol += "\\rarrow"; - symbol += alib::StringDataFactory::toString(transition.second.second); - - if (mapIterator == transitionMap.end()) { - transitionMap.insert(std::make_pair(key, symbol)); - } else { - mapIterator->second += "; " + symbol; - } - } - - for (const auto& transition : pda.getReturnTransitions()) { - std::pair<std::string, std::string> key((std::string) std::get<0>(transition.first), (std::string) transition.second); - auto mapIterator = transitionMap.find(key); - - std::string symbol; - symbol = alib::StringDataFactory::toString(std::get<1>(transition.first)); - - symbol += "|"; - - symbol += alib::StringDataFactory::toString(std::get<2>(transition.first)); - symbol += "\\rarrow"; - symbol += "$\\varepsilon;$"; - - if (mapIterator == transitionMap.end()) { - transitionMap.insert(std::make_pair(key, symbol)); - } else { - mapIterator->second += "; " + symbol; - } - } - - for (const auto& transition : pda.getLocalTransitions()) { - std::pair<std::string, std::string> key((std::string) transition.first.first, (std::string) transition.second); - auto mapIterator = transitionMap.find(key); - - std::string symbol; - symbol = alib::StringDataFactory::toString(transition.first.second); - - symbol += "|"; - - symbol += "$\\varepsilon;$"; - symbol += "\\rarrow"; - symbol += "$\\varepsilon;$"; - - if (mapIterator == transitionMap.end()) { - transitionMap.insert(std::make_pair(key, symbol)); - } else { - mapIterator->second += "; " + symbol; - } - } - - printTransitionMap(transitionMap, out); -} - -void GasTexConverter::transitions(const automaton::VisiblyPushdownNPDA < > & pda, std::ostream& out) { - std::map<std::pair<std::string, std::string>, std::string> transitionMap; - - for (const auto& transition : pda.getCallTransitions()) { - for(const auto& to : transition.second) { - std::pair<std::string, std::string> key((std::string) transition.first.first, (std::string) to.first); - auto mapIterator = transitionMap.find(key); - - std::string symbol; - symbol = alib::StringDataFactory::toString(transition.first.second); - - symbol += "|"; - - symbol += "$\\varepsilon;$"; - symbol += "\\rarrow"; - symbol += alib::StringDataFactory::toString(to.second); - - if (mapIterator == transitionMap.end()) { - transitionMap.insert(std::make_pair(key, symbol)); - } else { - mapIterator->second += "; " + symbol; - } - } - } - - for (const auto& transition : pda.getReturnTransitions()) { - for(const auto& to : transition.second) { - std::pair<std::string, std::string> key((std::string) std::get<0>(transition.first), (std::string) to); - auto mapIterator = transitionMap.find(key); - - std::string symbol; - symbol = alib::StringDataFactory::toString(std::get<1>(transition.first)); - - symbol += "|"; - - symbol += alib::StringDataFactory::toString(std::get<2>(transition.first)); - symbol += "\\rarrow"; - symbol += "$\\varepsilon;$"; - - if (mapIterator == transitionMap.end()) { - transitionMap.insert(std::make_pair(key, symbol)); - } else { - mapIterator->second += "; " + symbol; - } - } - } - - for (const auto& transition : pda.getLocalTransitions()) { - for(const auto& to : transition.second) { - std::pair<std::string, std::string> key((std::string) transition.first.first, (std::string) to); - auto mapIterator = transitionMap.find(key); - - std::string symbol; - symbol = alib::StringDataFactory::toString(transition.first.second); - - symbol += "|"; - - symbol += "$\\varepsilon;$"; - symbol += "\\rarrow"; - symbol += "$\\varepsilon;$"; - - if (mapIterator == transitionMap.end()) { - transitionMap.insert(std::make_pair(key, symbol)); - } else { - mapIterator->second += "; " + symbol; - } - } - } - - printTransitionMap(transitionMap, out); -} - -void GasTexConverter::transitions(const automaton::RealTimeHeightDeterministicDPDA < > & pda, std::ostream& out) { - std::map<std::pair<std::string, std::string>, std::string> transitionMap; - - for (const auto& transition : pda.getCallTransitions()) { - std::pair<std::string, std::string> key((std::string) transition.first.first, (std::string) transition.second.first); - auto mapIterator = transitionMap.find(key); - - std::string symbol; - if(transition.first.second.is<string::Epsilon < >>()) - symbol = "$\\varepsilon;$"; - else - symbol = alib::StringDataFactory::toString(transition.first.second.get<alphabet::Symbol>()); - - symbol += "|"; - - symbol += "$\\varepsilon;$"; - symbol += "\\rarrow"; - symbol += alib::StringDataFactory::toString(transition.second.second); - - if (mapIterator == transitionMap.end()) { - transitionMap.insert(std::make_pair(key, symbol)); - } else { - mapIterator->second += "; " + symbol; - } - } - - for (const auto& transition : pda.getReturnTransitions()) { - std::pair<std::string, std::string> key((std::string) std::get<0>(transition.first), (std::string) transition.second); - auto mapIterator = transitionMap.find(key); - - std::string symbol; - if(std::get<1>(transition.first).is<string::Epsilon < >>()) - symbol = "$\\varepsilon;$"; - else - symbol = alib::StringDataFactory::toString(std::get<1>(transition.first).get<alphabet::Symbol>()); - - symbol += "|"; - - symbol += alib::StringDataFactory::toString(std::get<2>(transition.first)); - symbol += "\\rarrow"; - symbol += "$\\varepsilon;$"; - - if (mapIterator == transitionMap.end()) { - transitionMap.insert(std::make_pair(key, symbol)); - } else { - mapIterator->second += "; " + symbol; - } - } - - for (const auto& transition : pda.getLocalTransitions()) { - std::pair<std::string, std::string> key((std::string) transition.first.first, (std::string) transition.second); - auto mapIterator = transitionMap.find(key); - - std::string symbol; - if(transition.first.second.is<string::Epsilon < >>()) - symbol = "$\\varepsilon;$"; - else - symbol = alib::StringDataFactory::toString(transition.first.second.get<alphabet::Symbol>()); - - symbol += "|"; - - symbol += "$\\varepsilon;$"; - symbol += "\\rarrow"; - symbol += "$\\varepsilon;$"; - - if (mapIterator == transitionMap.end()) { - transitionMap.insert(std::make_pair(key, symbol)); - } else { - mapIterator->second += "; " + symbol; - } - } - - printTransitionMap(transitionMap, out); -} - -void GasTexConverter::transitions(const automaton::RealTimeHeightDeterministicNPDA < > & pda, std::ostream& out) { - std::map<std::pair<std::string, std::string>, std::string> transitionMap; - - for (const auto& transition : pda.getCallTransitions()) { - for(const auto& to : transition.second) { - std::pair<std::string, std::string> key((std::string) transition.first.first, (std::string) to.first); - auto mapIterator = transitionMap.find(key); - - std::string symbol; - if(transition.first.second.is<string::Epsilon < >>()) - symbol = "$\\varepsilon;$"; - else - symbol = alib::StringDataFactory::toString(transition.first.second.get<alphabet::Symbol>()); - - symbol += "|"; - - symbol += "$\\varepsilon;$"; - symbol += "\\rarrow"; - symbol += alib::StringDataFactory::toString(to.second); - - if (mapIterator == transitionMap.end()) { - transitionMap.insert(std::make_pair(key, symbol)); - } else { - mapIterator->second += "; " + symbol; - } - } - } - - for (const auto& transition : pda.getReturnTransitions()) { - for(const auto& to : transition.second) { - std::pair<std::string, std::string> key((std::string) std::get<0>(transition.first), (std::string) to); - auto mapIterator = transitionMap.find(key); - - std::string symbol; - if(std::get<1>(transition.first).is<string::Epsilon < >>()) - symbol = "$\\varepsilon;$"; - else - symbol = alib::StringDataFactory::toString(std::get<1>(transition.first).get<alphabet::Symbol>()); - - symbol += "|"; - - symbol += alib::StringDataFactory::toString(std::get<2>(transition.first)); - symbol += "\\rarrow"; - symbol += "$\\varepsilon;$"; - - if (mapIterator == transitionMap.end()) { - transitionMap.insert(std::make_pair(key, symbol)); - } else { - mapIterator->second += "; " + symbol; - } - } - } - - for (const auto& transition : pda.getLocalTransitions()) { - for(const auto& to : transition.second) { - std::pair<std::string, std::string> key((std::string) transition.first.first, (std::string) to); - auto mapIterator = transitionMap.find(key); - - std::string symbol; - if(transition.first.second.is<string::Epsilon < >>()) - symbol = "$\\varepsilon;$"; - else - symbol = alib::StringDataFactory::toString(transition.first.second.get<alphabet::Symbol>()); - - symbol += "|"; - - symbol += "$\\varepsilon;$"; - symbol += "\\rarrow"; - symbol += "$\\varepsilon;$"; - - if (mapIterator == transitionMap.end()) { - transitionMap.insert(std::make_pair(key, symbol)); - } else { - mapIterator->second += "; " + symbol; - } - } - } - - printTransitionMap(transitionMap, out); -} - -void GasTexConverter::transitions(const automaton::NPDA < > & pda, std::ostream& out) { - std::map<std::pair<std::string, std::string>, std::string> transitionMap; - - for (const auto& transition : pda.getTransitions()) { - for(const auto& to : transition.second) { - std::pair<std::string, std::string> key((std::string) std::get<0>(transition.first), (std::string) to.first); - auto mapIterator = transitionMap.find(key); - - std::string symbol; - if (std::get<1>(transition.first).is<string::Epsilon < >>()) { - symbol = "$\\varepsilon;$"; - } else { - symbol = alib::StringDataFactory::toString(std::get<1>(transition.first).get<alphabet::Symbol>()); - } - - symbol += "|"; - - symbol += getStackSymbols(std::get<2>(transition.first)); - symbol += "\\rarrow"; - symbol += getStackSymbols(to.second); - - if (mapIterator == transitionMap.end()) { - transitionMap.insert(std::make_pair(key, symbol)); - } else { - mapIterator->second += "; " + symbol; - } - } - } - - printTransitionMap(transitionMap, out); -} - -void GasTexConverter::transitions(const automaton::SinglePopNPDA < > & pda, std::ostream& out) { - std::map<std::pair<std::string, std::string>, std::string> transitionMap; - - for (const auto& transition : pda.getTransitions()) { - for(const auto& to : transition.second) { - std::pair<std::string, std::string> key((std::string) std::get<0>(transition.first), (std::string) to.first); - auto mapIterator = transitionMap.find(key); - - std::string symbol; - if (std::get<1>(transition.first).is<string::Epsilon < >>()) { - symbol = "$\\varepsilon;$"; - } else { - symbol = alib::StringDataFactory::toString(std::get<1>(transition.first).get<alphabet::Symbol>()); - } - - symbol += "|"; - - symbol += alib::StringDataFactory::toString(std::get<2>(transition.first)); - symbol += "\\rarrow"; - symbol += getStackSymbols(to.second); - - if (mapIterator == transitionMap.end()) { - transitionMap.insert(std::make_pair(key, symbol)); - } else { - mapIterator->second += "; " + symbol; - } - } - } - - printTransitionMap(transitionMap, out); +void GasTexConverter::convert(std::ostream& out, const automaton::Automaton& a) { + dispatch(out, a.getData()); } -void GasTexConverter::transitions(const automaton::OneTapeDTM<>& tm, std::ostream& out) { - std::map<std::pair<std::string, std::string>, std::string> transitionMap; - - for (auto& transition : tm.getTransitions()) { - std::pair<std::string, std::string> key((std::string) transition.first.first, (std::string) std::get<0>(transition.second)); - auto mapIterator = transitionMap.find(key); - - std::string symbol = alib::StringDataFactory::toString(transition.first.second); - symbol += "/"; - symbol += alib::StringDataFactory::toString(std::get<1>(transition.second)); - symbol += ","; - switch(std::get<2>(transition.second)) { - case automaton::Shift::LEFT: - symbol += "$\\leftarrow$"; - break; - case automaton::Shift::RIGHT: - symbol += "$\\rightarrow$"; - break; - case automaton::Shift::NONE: - symbol += "$\\times$"; - break; - default: - throw exception::CommonException("Unexpected shift direction"); - } - - if (mapIterator == transitionMap.end()) { - transitionMap.insert(std::make_pair(key, symbol)); - } else { - mapIterator->second += "; " + symbol; - } - } - - printTransitionMap(transitionMap, out); -} +auto GasTexConverterEpsilonNFA = GasTexConverter::RegistratorWrapper<void, automaton::EpsilonNFA < > >(GasTexConverter::convert); +auto GasTexConverterMultiInitialStateNFA = GasTexConverter::RegistratorWrapper<void, automaton::MultiInitialStateNFA < > >(GasTexConverter::convert); +auto GasTexConverterNFA = GasTexConverter::RegistratorWrapper<void, automaton::NFA < > >(GasTexConverter::convert); +auto GasTexConverterDFA = GasTexConverter::RegistratorWrapper<void, automaton::DFA < > >(GasTexConverter::convert); +auto GasTexConverterExtendedNFA = GasTexConverter::RegistratorWrapper<void, automaton::ExtendedNFA < > >(GasTexConverter::convert); +auto GasTexConverterCompactNFA = GasTexConverter::RegistratorWrapper<void, automaton::CompactNFA < > >(GasTexConverter::convert); +auto GasTexConverterNFTA = GasTexConverter::RegistratorWrapper<void, automaton::NFTA < > >(GasTexConverter::convert); +auto GasTexConverterDFTA = GasTexConverter::RegistratorWrapper<void, automaton::DFTA < > >(GasTexConverter::convert); +auto GasTexConverterDPDA = GasTexConverter::RegistratorWrapper<void, automaton::DPDA < > >(GasTexConverter::convert); +auto GasTexConverterSinglePopDPDA = GasTexConverter::RegistratorWrapper<void, automaton::SinglePopDPDA < > >(GasTexConverter::convert); +auto GasTexConverterInputDrivenDPDA = GasTexConverter::RegistratorWrapper<void, automaton::InputDrivenDPDA < > >(GasTexConverter::convert); +auto GasTexConverterInputDrivenNPDA = GasTexConverter::RegistratorWrapper<void, automaton::InputDrivenNPDA < > >(GasTexConverter::convert); +auto GasTexConverterVisiblyPushdownDPDA = GasTexConverter::RegistratorWrapper<void, automaton::VisiblyPushdownDPDA < > >(GasTexConverter::convert); +auto GasTexConverterVisiblyPushdownNPDA = GasTexConverter::RegistratorWrapper<void, automaton::VisiblyPushdownNPDA < > >(GasTexConverter::convert); +auto GasTexConverterRealTimeHeightDeterministicDPDA = GasTexConverter::RegistratorWrapper<void, automaton::RealTimeHeightDeterministicDPDA < > >(GasTexConverter::convert); +auto GasTexConverterRealTimeHeightDeterministicNPDA = GasTexConverter::RegistratorWrapper<void, automaton::RealTimeHeightDeterministicNPDA < > >(GasTexConverter::convert); +auto GasTexConverterNPDA = GasTexConverter::RegistratorWrapper<void, automaton::NPDA < > >(GasTexConverter::convert); +auto GasTexConverterSinglePopNPDA = GasTexConverter::RegistratorWrapper<void, automaton::SinglePopNPDA < > >(GasTexConverter::convert); +auto GasTexConverterOneTapeDTM = GasTexConverter::RegistratorWrapper<void, automaton::OneTapeDTM < > >(GasTexConverter::convert); diff --git a/aconvert2/src/GasTexConverter.h b/aconvert2/src/GasTexConverter.h index baacda7c34..dae47f3421 100644 --- a/aconvert2/src/GasTexConverter.h +++ b/aconvert2/src/GasTexConverter.h @@ -9,59 +9,1526 @@ #define GAS_TEX_CONVERTER_H_ #include <ostream> -#include <core/multipleDispatch.hpp> #include <map> #include <utility> #include <vector> -#include "automaton/Automaton.h" +#include <set> +#include <typeinfo> + +#include <core/multipleDispatch.hpp> +#include <exception/CommonException.h> + +#include <automaton/Automaton.h> #include <automaton/AutomatonFeatures.h> -#include "alphabet/Symbol.h" + +#include <string/String.h> + +#include <automaton/FSM/NFA.h> +#include <automaton/FSM/MultiInitialStateNFA.h> +#include <automaton/FSM/EpsilonNFA.h> +#include <automaton/FSM/DFA.h> +#include <automaton/FSM/ExtendedNFA.h> +#include <automaton/FSM/CompactNFA.h> +#include <automaton/TA/NFTA.h> +#include <automaton/TA/DFTA.h> +#include <automaton/PDA/DPDA.h> +#include <automaton/PDA/SinglePopDPDA.h> +#include <automaton/PDA/InputDrivenDPDA.h> +#include <automaton/PDA/InputDrivenNPDA.h> +#include <automaton/PDA/VisiblyPushdownDPDA.h> +#include <automaton/PDA/VisiblyPushdownNPDA.h> +#include <automaton/PDA/RealTimeHeightDeterministicDPDA.h> +#include <automaton/PDA/RealTimeHeightDeterministicNPDA.h> +#include <automaton/PDA/NPDA.h> +#include <automaton/PDA/SinglePopNPDA.h> +#include <automaton/TM/OneTapeDTM.h> + +#include <factory/StringDataFactory.hpp> + +#include "common/converterCommon.hpp" class GasTexConverter : public std::SingleDispatchFirstStaticParam<GasTexConverter, void, std::ostream&, const automaton::AutomatonBase &> { static void printTransitionMap( const std::map<std::pair<std::string, std::string>, std::string> transitionMap, std::ostream& out); - static std::string getStackSymbols(const std::vector<alphabet::Symbol>& stackSymbols); - - static void transitions(const automaton::EpsilonNFA < > & fsm, std::ostream& out); - static void transitions(const automaton::MultiInitialStateNFA < >& fsm, std::ostream& out); - static void transitions(const automaton::NFA < > & fsm, std::ostream& out); - static void transitions(const automaton::DFA<>& fsm, std::ostream& out); - static void transitions(const automaton::ExtendedNFA < > & fsm, std::ostream& out); - static void transitions(const automaton::CompactNFA < > & fsm, std::ostream& out); - static void transitions(const automaton::NFTA < > & fsm, std::ostream& out); - static void transitions(const automaton::DFTA < > & fsm, std::ostream& out); - static void transitions(const automaton::DPDA < > & pda, std::ostream& out); - static void transitions(const automaton::SinglePopDPDA < > & tm, std::ostream& out); - static void transitions(const automaton::InputDrivenDPDA < > & pda, std::ostream& out); - static void transitions(const automaton::InputDrivenNPDA < > & pda, std::ostream& out); - static void transitions(const automaton::VisiblyPushdownDPDA < > & tm, std::ostream& out); - static void transitions(const automaton::VisiblyPushdownNPDA < > & tm, std::ostream& out); - static void transitions(const automaton::RealTimeHeightDeterministicDPDA < > & tm, std::ostream& out); - static void transitions(const automaton::RealTimeHeightDeterministicNPDA < > & tm, std::ostream& out); - static void transitions(const automaton::NPDA < > & pda, std::ostream& out); - static void transitions(const automaton::SinglePopNPDA < > & tm, std::ostream& out); - static void transitions(const automaton::OneTapeDTM<>& tm, std::ostream& out); + + template < class SymbolType > + static std::string getStackSymbols(const std::vector<SymbolType>& stackSymbols); + + template < class SymbolType, class StateType > + static void transitions(const automaton::DFA < SymbolType, StateType > & fsm, std::ostream & out); + + template < class SymbolType, class StateType > + static void transitions(const automaton::NFA < SymbolType, StateType > & fsm, std::ostream & out); + + template < class SymbolType, class StateType > + static void transitions(const automaton::MultiInitialStateNFA < SymbolType, StateType > & fsm, std::ostream & out); + + template < class SymbolType, class EpsilonType, class StateType > + static void transitions(const automaton::EpsilonNFA < SymbolType, EpsilonType, StateType > & fsm, std::ostream & out); + + template < class SymbolType, class StateType > + static void transitions(const automaton::ExtendedNFA < SymbolType, StateType > & fsm, std::ostream & out); + + template < class SymbolType, class StateType > + static void transitions(const automaton::CompactNFA < SymbolType, StateType > & fsm, std::ostream & out); + + template < class SymbolType, class RankType, class StateType > + static void transitions(const automaton::NFTA < SymbolType, RankType, StateType > & fsm, std::ostream & out); + + template < class SymbolType, class RankType, class StateType > + static void transitions(const automaton::DFTA < SymbolType, RankType, StateType > & fsm, std::ostream & out); + + template < class SymbolType, class EpsilonType, class StateType > + static void transitions(const automaton::DPDA < SymbolType, EpsilonType, StateType > & pda, std::ostream & out); + + template < class SymbolType, class EpsilonType, class StateType > + static void transitions(const automaton::NPDA < SymbolType, EpsilonType, StateType > & pda, std::ostream & out); + + template < class SymbolType, class EpsilonType, class StateType > + static void transitions(const automaton::SinglePopDPDA < SymbolType, EpsilonType, StateType > & tm, std::ostream & out); + + template < class SymbolType, class EpsilonType, class StateType > + static void transitions(const automaton::SinglePopNPDA < SymbolType, EpsilonType, StateType > & tm, std::ostream & out); + + template < class SymbolType, class StateType > + static void transitions(const automaton::InputDrivenDPDA < SymbolType, StateType > & pda, std::ostream & out); + + template < class SymbolType, class StateType > + static void transitions(const automaton::InputDrivenNPDA < SymbolType, StateType > & pda, std::ostream & out); + + template < class SymbolType, class StateType > + static void transitions(const automaton::VisiblyPushdownDPDA < SymbolType, StateType > & tm, std::ostream & out); + + template < class SymbolType, class StateType > + static void transitions(const automaton::VisiblyPushdownNPDA < SymbolType, StateType > & tm, std::ostream & out); + + template < class SymbolType, class EpsilonType, class StateType > + static void transitions(const automaton::RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType > & tm, std::ostream & out); + + template < class SymbolType, class EpsilonType, class StateType > + static void transitions(const automaton::RealTimeHeightDeterministicNPDA < SymbolType, EpsilonType, StateType > & tm, std::ostream & out); + + template < class SymbolType, class StateType > + static void transitions(const automaton::OneTapeDTM < SymbolType, StateType > & tm, std::ostream & out); public: static void convert(std::ostream& out, const automaton::Automaton& a); - static void convert(std::ostream& out, const automaton::EpsilonNFA < > & a); - static void convert(std::ostream& out, const automaton::MultiInitialStateNFA < >& a); - static void convert(std::ostream& out, const automaton::NFA < > & a); - static void convert(std::ostream& out, const automaton::DFA<>& a); - static void convert(std::ostream& out, const automaton::ExtendedNFA < > & a); - static void convert(std::ostream& out, const automaton::CompactNFA < > & a); - static void convert(std::ostream& out, const automaton::NFTA < > & a); - static void convert(std::ostream& out, const automaton::DFTA < > & a); - static void convert(std::ostream& out, const automaton::DPDA < > & a); - static void convert(std::ostream& out, const automaton::SinglePopDPDA < > & a); - static void convert(std::ostream& out, const automaton::InputDrivenDPDA < > & a); - static void convert(std::ostream& out, const automaton::InputDrivenNPDA < > & a); - static void convert(std::ostream& out, const automaton::VisiblyPushdownDPDA < > & a); - static void convert(std::ostream& out, const automaton::VisiblyPushdownNPDA < > & a); - static void convert(std::ostream& out, const automaton::RealTimeHeightDeterministicDPDA < > & a); - static void convert(std::ostream& out, const automaton::RealTimeHeightDeterministicNPDA < > & a); - static void convert(std::ostream& out, const automaton::NPDA < > & a); - static void convert(std::ostream& out, const automaton::SinglePopNPDA < > & a); - static void convert(std::ostream& out, const automaton::OneTapeDTM<>& a); + template < class SymbolType, class StateType > + static void convert(std::ostream& out, const automaton::DFA < SymbolType, StateType > & a); + + template < class SymbolType, class StateType > + static void convert(std::ostream& out, const automaton::NFA < SymbolType, StateType > & a); + + template < class SymbolType, class StateType > + static void convert(std::ostream& out, const automaton::MultiInitialStateNFA < SymbolType, StateType >& a); + + template < class SymbolType, class EpsilonType, class StateType > + static void convert(std::ostream& out, const automaton::EpsilonNFA < SymbolType, EpsilonType, StateType > & a); + + template < class SymbolType, class StateType > + static void convert(std::ostream& out, const automaton::ExtendedNFA < SymbolType, StateType > & a); + + template < class SymbolType, class StateType > + static void convert(std::ostream& out, const automaton::CompactNFA < SymbolType, StateType > & a); + + template < class SymbolType, class RankType, class StateType > + static void convert(std::ostream& out, const automaton::NFTA < SymbolType, RankType, StateType > & a); + + template < class SymbolType, class RankType, class StateType > + static void convert(std::ostream& out, const automaton::DFTA < SymbolType, RankType, StateType > & a); + + template < class SymbolType, class EpsilonType, class StateType > + static void convert(std::ostream& out, const automaton::DPDA < SymbolType, EpsilonType, StateType > & a); + + template < class SymbolType, class EpsilonType, class StateType > + static void convert(std::ostream& out, const automaton::NPDA < SymbolType, EpsilonType, StateType > & a); + + template < class SymbolType, class EpsilonType, class StateType > + static void convert(std::ostream& out, const automaton::SinglePopDPDA < SymbolType, EpsilonType, StateType > & a); + + template < class SymbolType, class EpsilonType, class StateType > + static void convert(std::ostream& out, const automaton::SinglePopNPDA < SymbolType, EpsilonType, StateType > & a); + + template < class SymbolType, class StateType > + static void convert(std::ostream& out, const automaton::InputDrivenDPDA < SymbolType, StateType > & a); + + template < class SymbolType, class StateType > + static void convert(std::ostream& out, const automaton::InputDrivenNPDA < SymbolType, StateType > & a); + + template < class SymbolType, class StateType > + static void convert(std::ostream& out, const automaton::VisiblyPushdownDPDA < SymbolType, StateType > & a); + + template < class SymbolType, class StateType > + static void convert(std::ostream& out, const automaton::VisiblyPushdownNPDA < SymbolType, StateType > & a); + + template < class SymbolType, class EpsilonType, class StateType > + static void convert(std::ostream& out, const automaton::RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType > & a); + + template < class SymbolType, class EpsilonType, class StateType > + static void convert(std::ostream& out, const automaton::RealTimeHeightDeterministicNPDA < SymbolType, EpsilonType, StateType > & a); + + template < class SymbolType, class StateType > + static void convert(std::ostream& out, const automaton::OneTapeDTM < SymbolType, StateType > & a); }; +template < class SymbolType, class EpsilonType, class StateType > +void GasTexConverter::convert(std::ostream& out, const automaton::EpsilonNFA < SymbolType, EpsilonType, StateType > & a) { + out << "\\begin{center}\n"; + out << "\\begin{picture}(,)(,)\n"; + + for (auto& state : a.getStates()) { + bool initial = false; + bool final = false; + + if(a.getInitialState() == state){ + initial = true; + } + if(a.getFinalStates().count(state)){ + final = true; + } + + if(initial || final) { + out << "\\node[Nmarks="; + if(initial){ + out << "i"; + } + if(final){ + out << "r"; + } + out<<"]("; + } else { + out <<"\\node("; + } + + out << state; + out << ")(,){"; + out << state; + out << "}\n"; + } + + transitions(a, out); + out << "\\end{center}\n"; + out << "\\end{picture}\n"; +} + +template < class SymbolType, class StateType > +void GasTexConverter::convert(std::ostream& out, const automaton::MultiInitialStateNFA < SymbolType, StateType >& a) { + out << "\\begin{center}\n"; + out << "\\begin{picture}(,)(,)\n"; + + for (auto& state : a.getStates()) { + bool initial = false; + bool final = false; + + if(a.getInitialStates().count(state)){ + initial = true; + } + if(a.getFinalStates().count(state)){ + final = true; + } + + if(initial || final) { + out << "\\node[Nmarks="; + if(initial){ + out << "i"; + } + if(final){ + out << "r"; + } + out<<"]("; + } else { + out <<"\\node("; + } + + out << state; + out << ")(,){"; + out << state; + out << "}\n"; + } + + transitions(a, out); + out << "\\end{center}\n"; + out << "\\end{picture}\n"; +} + +template < class SymbolType, class StateType > +void GasTexConverter::convert(std::ostream& out, const automaton::NFA < SymbolType, StateType > & a) { + out << "\\begin{center}\n"; + out << "\\begin{picture}(,)(,)\n"; + + for (auto& state : a.getStates()) { + bool initial = false; + bool final = false; + + if(a.getInitialState() == state){ + initial = true; + } + if(a.getFinalStates().count(state)){ + final = true; + } + + if(initial || final) { + out << "\\node[Nmarks="; + if(initial){ + out << "i"; + } + if(final){ + out << "r"; + } + out<<"]("; + } else { + out <<"\\node("; + } + + out << state; + out << ")(,){"; + out << state; + out << "}\n"; + } + + transitions(a, out); + out << "\\end{center}\n"; + out << "\\end{picture}\n"; +} + +template < class SymbolType, class StateType > +void GasTexConverter::convert(std::ostream& out, const automaton::DFA < SymbolType, StateType > & a) { + out << "\\begin{center}\n"; + out << "\\begin{picture}(,)(,)\n"; + + for (auto& state : a.getStates()) { + bool initial = false; + bool final = false; + + if(a.getInitialState() == state){ + initial = true; + } + if(a.getFinalStates().count(state)){ + final = true; + } + + if(initial || final) { + out << "\\node[Nmarks="; + if(initial){ + out << "i"; + } + if(final){ + out << "r"; + } + out<<"]("; + } else { + out <<"\\node("; + } + + out << state; + out << ")(,){"; + out << state; + out << "}\n"; + } + + transitions(a, out); + out << "\\end{center}\n"; + out << "\\end{picture}\n"; +} + +template < class SymbolType, class StateType > +void GasTexConverter::convert(std::ostream& out, const automaton::ExtendedNFA < SymbolType, StateType > & a) { + out << "\\begin{center}\n"; + out << "\\begin{picture}(,)(,)\n"; + + for (auto& state : a.getStates()) { + bool initial = false; + bool final = false; + + if(a.getInitialState() == state){ + initial = true; + } + if(a.getFinalStates().count(state)){ + final = true; + } + + if(initial || final) { + out << "\\node[Nmarks="; + if(initial){ + out << "i"; + } + if(final){ + out << "r"; + } + out<<"]("; + } else { + out <<"\\node("; + } + + out << state; + out << ")(,){"; + out << state; + out << "}\n"; + } + + transitions(a, out); + out << "\\end{center}\n"; + out << "\\end{picture}\n"; +} + +template < class SymbolType, class StateType > +void GasTexConverter::convert(std::ostream& out, const automaton::CompactNFA < SymbolType, StateType > & a) { + out << "\\begin{center}\n"; + out << "\\begin{picture}(,)(,)\n"; + + for (auto& state : a.getStates()) { + bool initial = false; + bool final = false; + + if(a.getInitialState() == state){ + initial = true; + } + if(a.getFinalStates().count(state)){ + final = true; + } + + if(initial || final) { + out << "\\node[Nmarks="; + if(initial){ + out << "i"; + } + if(final){ + out << "r"; + } + out<<"]("; + } else { + out <<"\\node("; + } + + out << state; + out << ")(,){"; + out << state; + out << "}\n"; + } + + transitions(a, out); + out << "\\end{center}\n"; + out << "\\end{picture}\n"; +} + +template < class SymbolType, class RankType, class StateType > +void GasTexConverter::convert(std::ostream&, const automaton::NFTA < SymbolType, RankType, StateType > &) { + //TODO +} + +template < class SymbolType, class RankType, class StateType > +void GasTexConverter::convert(std::ostream&, const automaton::DFTA < SymbolType, RankType, StateType > &) { + //TODO +} + +template < class SymbolType, class EpsilonType, class StateType > +void GasTexConverter::convert(std::ostream& out, const automaton::DPDA < SymbolType, EpsilonType, StateType > & a) { + out << "\\begin{center}\n"; + out << "\\begin{picture}(,)(,)\n"; + + for (auto& state : a.getStates()) { + bool initial = false; + bool final = false; + + if(a.getInitialState() == state) { + initial = true; + } + if(a.getFinalStates().count(state)) { + final = true; + } + + if(initial || final) { + out << "\\node[Nmarks="; + if(initial){ + out << "i"; + } + if(final){ + out << "r"; + } + out<<"]("; + } else { + out <<"\\node("; + } + + out << state; + out << ")(,){"; + out << state; + out << "}\n"; + } + + transitions(a, out); + out << "\\end{center}\n"; + out << "\\end{picture}\n"; +} + +template < class SymbolType, class EpsilonType, class StateType > +void GasTexConverter::convert(std::ostream& out, const automaton::SinglePopDPDA < SymbolType, EpsilonType, StateType > & a) { + out << "\\begin{center}\n"; + out << "\\begin{picture}(,)(,)\n"; + + for (auto& state : a.getStates()) { + bool initial = false; + bool final = false; + + if(a.getInitialState() == state) { + initial = true; + } + if(a.getFinalStates().count(state)){ + final = true; + } + + if(initial || final) { + out << "\\node[Nmarks="; + if(initial){ + out << "i"; + } + if(final){ + out << "r"; + } + out<<"]("; + } else { + out <<"\\node("; + } + + out << state; + out << ")(,){"; + out << state; + out << "}\n"; + } + + transitions(a, out); + out << "\\end{center}\n"; + out << "\\end{picture}\n"; +} + +template < class SymbolType, class StateType > +void GasTexConverter::convert(std::ostream& out, const automaton::InputDrivenDPDA < SymbolType, StateType > & a) { + out << "\\begin{center}\n"; + out << "\\begin{picture}(,)(,)\n"; + + for (auto& state : a.getStates()) { + bool initial = false; + bool final = false; + + if(a.getInitialState() == state){ + initial = true; + } + if(a.getFinalStates().count(state)){ + final = true; + } + + if(initial || final) { + out << "\\node[Nmarks="; + if(initial){ + out << "i"; + } + if(final){ + out << "r"; + } + out<<"]("; + } else { + out <<"\\node("; + } + + out << state; + out << ")(,){"; + out << state; + out << "}\n"; + } + + transitions(a, out); + out << "\\end{center}\n"; + out << "\\end{picture}\n"; +} + +template < class SymbolType, class StateType > +void GasTexConverter::convert(std::ostream& out, const automaton::InputDrivenNPDA < SymbolType, StateType > & a) { + out << "\\begin{center}\n"; + out << "\\begin{picture}(,)(,)\n"; + + for (auto& state : a.getStates()) { + bool initial = false; + bool final = false; + + if(a.getInitialState() == state){ + initial = true; + } + if(a.getFinalStates().count(state)){ + final = true; + } + + if(initial || final) { + out << "\\node[Nmarks="; + if(initial){ + out << "i"; + } + if(final){ + out << "r"; + } + out<<"]("; + } else { + out <<"\\node("; + } + + out << state; + out << ")(,){"; + out << state; + out << "}\n"; + } + + transitions(a, out); + out << "\\end{center}\n"; + out << "\\end{picture}\n"; +} + +template < class SymbolType, class StateType > +void GasTexConverter::convert(std::ostream& out, const automaton::VisiblyPushdownDPDA < SymbolType, StateType > & a) { + out << "\\begin{center}\n"; + out << "\\begin{picture}(,)(,)\n"; + + for (auto& state : a.getStates()) { + bool initial = false; + bool final = false; + + if(a.getInitialState() == state){ + initial = true; + } + if(a.getFinalStates().count(state)){ + final = true; + } + + if(initial || final) { + out << "\\node[Nmarks="; + if(initial){ + out << "i"; + } + if(final){ + out << "r"; + } + out<<"]("; + } else { + out <<"\\node("; + } + + out << state; + out << ")(,){"; + out << state; + out << "}\n"; + } + + transitions(a, out); + out << "\\end{center}\n"; + out << "\\end{picture}\n"; +} + +template < class SymbolType, class StateType > +void GasTexConverter::convert(std::ostream& out, const automaton::VisiblyPushdownNPDA < SymbolType, StateType > & a) { + out << "\\begin{center}\n"; + out << "\\begin{picture}(,)(,)\n"; + + for (auto& state : a.getStates()) { + bool initial = false; + bool final = false; + + if(a.getInitialStates().count(state)){ + initial = true; + } + if(a.getFinalStates().count(state)){ + final = true; + } + + if(initial || final) { + out << "\\node[Nmarks="; + if(initial){ + out << "i"; + } + if(final){ + out << "r"; + } + out<<"]("; + } else { + out <<"\\node("; + } + + out << state; + out << ")(,){"; + out << state; + out << "}\n"; + } + + transitions(a, out); + out << "\\end{center}\n"; + out << "\\end{picture}\n"; +} + +template < class SymbolType, class EpsilonType, class StateType > +void GasTexConverter::convert(std::ostream& out, const automaton::RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType > & a) { + out << "\\begin{center}\n"; + out << "\\begin{picture}(,)(,)\n"; + + for (auto& state : a.getStates()) { + bool initial = false; + bool final = false; + + if(a.getInitialState() == state){ + initial = true; + } + if(a.getFinalStates().count(state)){ + final = true; + } + + if(initial || final) { + out << "\\node[Nmarks="; + if(initial){ + out << "i"; + } + if(final){ + out << "r"; + } + out<<"]("; + } else { + out <<"\\node("; + } + + out << state; + out << ")(,){"; + out << state; + out << "}\n"; + } + + transitions(a, out); + out << "\\end{center}\n"; + out << "\\end{picture}\n"; +} + +template < class SymbolType, class EpsilonType, class StateType > +void GasTexConverter::convert(std::ostream& out, const automaton::RealTimeHeightDeterministicNPDA < SymbolType, EpsilonType, StateType > & a) { + out << "\\begin{center}\n"; + out << "\\begin{picture}(,)(,)\n"; + + for (auto& state : a.getStates()) { + bool initial = false; + bool final = false; + + if(a.getInitialStates().count(state)){ + initial = true; + } + if(a.getFinalStates().count(state)){ + final = true; + } + + if(initial || final) { + out << "\\node[Nmarks="; + if(initial){ + out << "i"; + } + if(final){ + out << "r"; + } + out<<"]("; + } else { + out <<"\\node("; + } + + out << state; + out << ")(,){"; + out << state; + out << "}\n"; + } + + transitions(a, out); + out << "\\end{center}\n"; + out << "\\end{picture}\n"; +} + +template < class SymbolType, class EpsilonType, class StateType > +void GasTexConverter::convert(std::ostream& out, const automaton::NPDA < SymbolType, EpsilonType, StateType > & a) { + out << "\\begin{center}\n"; + out << "\\begin{picture}(,)(,)\n"; + + for (auto& state : a.getStates()) { + bool initial = false; + bool final = false; + + if(a.getInitialState() == state){ + initial = true; + } + if(a.getFinalStates().count(state)){ + final = true; + } + + if(initial || final) { + out << "\\node[Nmarks="; + if(initial){ + out << "i"; + } + if(final){ + out << "r"; + } + out<<"]("; + } else { + out <<"\\node("; + } + + out << state; + out << ")(,){"; + out << state; + out << "}\n"; + } + + transitions(a, out); + out << "\\end{center}\n"; + out << "\\end{picture}\n"; +} + +template < class SymbolType, class EpsilonType, class StateType > +void GasTexConverter::convert(std::ostream& out, const automaton::SinglePopNPDA < SymbolType, EpsilonType, StateType > & a) { + out << "\\begin{center}\n"; + out << "\\begin{picture}(,)(,)\n"; + + for (auto& state : a.getStates()) { + bool initial = false; + bool final = false; + + if(a.getInitialState() == state){ + initial = true; + } + if(a.getFinalStates().count(state)){ + final = true; + } + + if(initial || final) { + out << "\\node[Nmarks="; + if(initial){ + out << "i"; + } + if(final){ + out << "r"; + } + out<<"]("; + } else { + out <<"\\node("; + } + + out << state; + out << ")(,){"; + out << state; + out << "}\n"; + } + + transitions(a, out); + out << "\\end{center}\n"; + out << "\\end{picture}\n"; +} + +template < class SymbolType, class StateType > +void GasTexConverter::convert(std::ostream& out, const automaton::OneTapeDTM < SymbolType, StateType > & a) { + out << "\\begin{center}\n"; + out << "\\begin{picture}(,)(,)\n"; + + for (auto& state : a.getStates()) { + bool initial = false; + bool final = false; + + if(a.getInitialState() == state){ + initial = true; + } + if(a.getFinalStates().count(state)){ + final = true; + } + + if(initial || final) { + out << "\\node[Nmarks="; + if(initial){ + out << "i"; + } + if(final){ + out << "r"; + } + out<<"]("; + } else { + out <<"\\node("; + } + + out << state; + out << ")(,){"; + out << state; + out << "}\n"; + } + + transitions(a, out); + out << "\\end{center}\n"; + out << "\\end{picture}\n"; +} + +template< class SymbolType > +std::string GasTexConverter::getStackSymbols(const std::vector<SymbolType>& stackSymbols) { + if (stackSymbols.size() == 0) { + return "$\\varepsilon$"; + } + + std::string symbols = ""; + int i=0; + for (const SymbolType & symbol : stackSymbols) { + if(i++ !=0) { + symbols +=" "; + } + symbols += std::to_string ( symbol.getData() ); + } + return symbols; +} + +template<class SymbolType, class EpsilonType, class StateType> +void GasTexConverter::transitions(const automaton::EpsilonNFA < SymbolType, EpsilonType, StateType > & fsm, std::ostream& out) { + std::map<std::pair<std::string, std::string>, std::string> transitionMap; + for (const auto& transition : fsm.getTransitions()) { + for(const auto& to : transition.second) { + std::pair<std::string, std::string> key(std::to_string ( transition.first.first ), std::to_string ( to ) ); + + std::string symbol; + if (transition.first.second.template is<EpsilonType>()) { + symbol = "$\\varepsilon$"; + } else { + symbol = std::to_string ( transition.first.second.template get<SymbolType>() ); + } + + auto mapIterator = transitionMap.find(key); + if (mapIterator == transitionMap.end()) { + transitionMap.insert(make_pair(key, symbol)); + } else { + mapIterator->second += ", " + symbol; + } + } + } + printTransitionMap(transitionMap, out); +} + +template<class SymbolType, class StateType> +void GasTexConverter::transitions(const automaton::MultiInitialStateNFA < SymbolType, StateType >& fsm, std::ostream& out) { + std::map<std::pair<std::string, std::string>, std::string> transitionMap; + for (const auto& transition : fsm.getTransitions()) { + for(const auto& to : transition.second) { + std::pair<std::string, std::string> key(std::to_string ( transition.first.first ), std::to_string ( to ) ); + + std::string symbol = std::to_string ( transition.first.second ); + + auto mapIterator = transitionMap.find(key); + if (mapIterator == transitionMap.end()) { + transitionMap.insert(make_pair(key, symbol)); + } else { + mapIterator->second += ", " + symbol; + } + } + } + printTransitionMap(transitionMap, out); +} + +template<class SymbolType, class StateType> +void GasTexConverter::transitions(const automaton::NFA < SymbolType, StateType > & fsm, std::ostream& out) { + std::map<std::pair<std::string, std::string>, std::string> transitionMap; + for (const auto& transition : fsm.getTransitions()) { + for(const auto& to : transition.second) { + std::pair<std::string, std::string> key( std::to_string ( transition.first.first ), std::to_string ( to ) ); + + std::string symbol = std::to_string ( transition.first.second ); + + auto mapIterator = transitionMap.find(key); + if (mapIterator == transitionMap.end()) { + transitionMap.insert(make_pair(key, symbol)); + } else { + mapIterator->second += ", " + symbol; + } + } + } + printTransitionMap(transitionMap, out); +} + +template<class SymbolType, class StateType> +void GasTexConverter::transitions(const automaton::DFA < SymbolType, StateType > & fsm, std::ostream& out) { + std::map<std::pair<std::string, std::string>, std::string> transitionMap; + for (const auto& transition : fsm.getTransitions()) { + std::pair<std::string, std::string> key( std::to_string ( transition.first.first ), std::to_string ( transition.second ) ); + + std::string symbol = std::to_string ( transition.first.second ); + + auto mapIterator = transitionMap.find(key); + if (mapIterator == transitionMap.end()) { + transitionMap.insert(make_pair(key, symbol)); + } else { + mapIterator->second += ", " + symbol; + } + } + printTransitionMap(transitionMap, out); +} + +template<class SymbolType, class StateType> +void GasTexConverter::transitions(const automaton::ExtendedNFA < SymbolType, StateType > & fsm, std::ostream& out) { + std::map<std::pair<std::string, std::string>, std::string> transitionMap; + + for (const auto& transition : fsm.getTransitions()) { + for(const auto& to : transition.second) { + std::pair<std::string, std::string> key( std::to_string ( transition.first.first ), std::to_string ( to ) ); + + std::string symbol = alib::StringDataFactory::toString(transition.first.second); + + auto mapIterator = transitionMap.find(key); + if (mapIterator == transitionMap.end()) { + transitionMap.insert(make_pair(key, symbol)); + } else { + mapIterator->second += ", " + symbol; + } + } + } + printTransitionMap(transitionMap, out); +} + +template<class SymbolType, class StateType> +void GasTexConverter::transitions(const automaton::CompactNFA < SymbolType, StateType > & fsm, std::ostream& out) { + std::map<std::pair<std::string, std::string>, std::string> transitionMap; + + for (const auto& transition : fsm.getTransitions()) { + for(const auto& to : transition.second) { + std::pair<std::string, std::string> key(std::to_string ( transition.first.first ), std::to_string ( to ) ); + + std::string symbol = alib::StringDataFactory::toString(string::stringFrom(transition.first.second)); + + auto mapIterator = transitionMap.find(key); + if (mapIterator == transitionMap.end()) { + transitionMap.insert(make_pair(key, symbol)); + } else { + mapIterator->second += ", " + symbol; + } + } + } + printTransitionMap(transitionMap, out); +} + +template<class SymbolType, class RankType, class StateType> +void GasTexConverter::transitions(const automaton::NFTA < SymbolType, RankType, StateType > &, std::ostream&) { + //TODO +} + +template<class SymbolType, class RankType, class StateType> +void GasTexConverter::transitions(const automaton::DFTA < SymbolType, RankType, StateType > &, std::ostream&) { + //TODO +} + +template<class SymbolType, class EpsilonType, class StateType> +void GasTexConverter::transitions(const automaton::DPDA < SymbolType, EpsilonType, StateType > & pda, std::ostream& out) { + std::map<std::pair<std::string, std::string>, std::string> transitionMap; + + for (const auto& transition : pda.getTransitions()) { + std::pair<std::string, std::string> key(std::to_string ( std::get<0>(transition.first) ), std::to_string ( transition.second.first ) ); + auto mapIterator = transitionMap.find(key); + + std::string symbol; + if (std::get<1>(transition.first).template is<EpsilonType>()) { + symbol = "$\\varepsilon;$"; + } else { + symbol = alib::StringDataFactory::toString(std::get<1>(transition.first).template get<SymbolType>()); + } + + symbol += "|"; + + symbol += getStackSymbols(std::get<2>(transition.first)); + symbol += "\\rarrow"; + symbol += getStackSymbols(transition.second.second); + + if (mapIterator == transitionMap.end()) { + transitionMap.insert(std::make_pair(key, symbol)); + } else { + mapIterator->second += "; " + symbol; + } + } + + printTransitionMap(transitionMap, out); +} + +template<class SymbolType, class EpsilonType, class StateType> +void GasTexConverter::transitions(const automaton::SinglePopDPDA < SymbolType, EpsilonType, StateType > & pda, std::ostream& out) { + std::map<std::pair<std::string, std::string>, std::string> transitionMap; + + for (const auto& transition : pda.getTransitions()) { + std::pair<std::string, std::string> key(std::to_string ( std::get<0>(transition.first) ), std::to_string ( transition.second.first ) ); + auto mapIterator = transitionMap.find(key); + + std::string symbol; + if (std::get<1>(transition.first).template is<EpsilonType>()) { + symbol = "$\\varepsilon;$"; + } else { + symbol = alib::StringDataFactory::toString(std::get<1>(transition.first).template get<SymbolType>()); + } + + symbol += "|"; + + symbol += alib::StringDataFactory::toString(std::get<2>(transition.first)); + symbol += "\\rarrow"; + symbol += getStackSymbols(transition.second.second); + + if (mapIterator == transitionMap.end()) { + transitionMap.insert(std::make_pair(key, symbol)); + } else { + mapIterator->second += "; " + symbol; + } + } + + printTransitionMap(transitionMap, out); +} + +template<class SymbolType, class StateType> +void GasTexConverter::transitions(const automaton::InputDrivenDPDA < SymbolType, StateType > & pda, std::ostream& out) { + std::map<std::pair<std::string, std::string>, std::string> transitionMap; + + const auto& symbolToPDSOperation = pda.getPushdownStoreOperations(); + for (const auto& transition : pda.getTransitions()) { + const auto& pop = symbolToPDSOperation.find(std::get<1>(transition.first))->second.first; + const auto& push = symbolToPDSOperation.find(std::get<1>(transition.first))->second.second; + + const auto& to = transition.second; + std::pair<std::string, std::string> key(std::to_string ( transition.first.first ), std::to_string ( to ) ); + auto mapIterator = transitionMap.find(key); + + std::string symbol = alib::StringDataFactory::toString(transition.first.second); + + symbol += "|"; + + symbol += getStackSymbols(pop); + symbol += "\\rarrow"; + symbol += getStackSymbols(push); + + if (mapIterator == transitionMap.end()) { + transitionMap.insert(std::make_pair(key, symbol)); + } else { + mapIterator->second += "; " + symbol; + } + } + + printTransitionMap(transitionMap, out); +} + +template<class SymbolType, class StateType> +void GasTexConverter::transitions(const automaton::InputDrivenNPDA < SymbolType, StateType > & pda, std::ostream& out) { + std::map<std::pair<std::string, std::string>, std::string> transitionMap; + + const auto& symbolToPDSOperation = pda.getPushdownStoreOperations(); + for (const auto& transition : pda.getTransitions()) { + const auto& pop = symbolToPDSOperation.find(std::get<1>(transition.first))->second.first; + const auto& push = symbolToPDSOperation.find(std::get<1>(transition.first))->second.second; + + for(const auto& to : transition.second) { + std::pair<std::string, std::string> key( std::to_string ( transition.first.first ), std::to_string ( to ) ); + auto mapIterator = transitionMap.find(key); + + std::string symbol = alib::StringDataFactory::toString(transition.first.second); + + symbol += "|"; + + symbol += getStackSymbols(pop); + symbol += "\\rarrow"; + symbol += getStackSymbols(push); + + if (mapIterator == transitionMap.end()) { + transitionMap.insert(std::make_pair(key, symbol)); + } else { + mapIterator->second += "; " + symbol; + } + } + } + + printTransitionMap(transitionMap, out); +} + +template<class SymbolType, class StateType> +void GasTexConverter::transitions(const automaton::VisiblyPushdownDPDA < SymbolType, StateType > & pda, std::ostream& out) { + std::map<std::pair<std::string, std::string>, std::string> transitionMap; + + for (const auto& transition : pda.getCallTransitions()) { + std::pair<std::string, std::string> key( std::to_string ( transition.first.first ), std::to_string ( transition.second.first ) ); + auto mapIterator = transitionMap.find(key); + + std::string symbol = alib::StringDataFactory::toString(transition.first.second); + + symbol += "|"; + + symbol += "$\\varepsilon;$"; + symbol += "\\rarrow"; + symbol += alib::StringDataFactory::toString(transition.second.second); + + if (mapIterator == transitionMap.end()) { + transitionMap.insert(std::make_pair(key, symbol)); + } else { + mapIterator->second += "; " + symbol; + } + } + + for (const auto& transition : pda.getReturnTransitions()) { + std::pair<std::string, std::string> key( std::to_string ( std::get<0>(transition.first) ), std::to_string ( transition.second ) ); + auto mapIterator = transitionMap.find(key); + + std::string symbol = alib::StringDataFactory::toString(std::get<1>(transition.first)); + + symbol += "|"; + + symbol += alib::StringDataFactory::toString(std::get<2>(transition.first)); + symbol += "\\rarrow"; + symbol += "$\\varepsilon;$"; + + if (mapIterator == transitionMap.end()) { + transitionMap.insert(std::make_pair(key, symbol)); + } else { + mapIterator->second += "; " + symbol; + } + } + + for (const auto& transition : pda.getLocalTransitions()) { + std::pair<std::string, std::string> key( std::to_string ( transition.first.first ), std::to_string ( transition.second ) ); + auto mapIterator = transitionMap.find(key); + + std::string symbol = alib::StringDataFactory::toString(transition.first.second); + + symbol += "|"; + + symbol += "$\\varepsilon;$"; + symbol += "\\rarrow"; + symbol += "$\\varepsilon;$"; + + if (mapIterator == transitionMap.end()) { + transitionMap.insert(std::make_pair(key, symbol)); + } else { + mapIterator->second += "; " + symbol; + } + } + + printTransitionMap(transitionMap, out); +} + +template<class SymbolType, class StateType> +void GasTexConverter::transitions(const automaton::VisiblyPushdownNPDA < SymbolType, StateType > & pda, std::ostream& out) { + std::map<std::pair<std::string, std::string>, std::string> transitionMap; + + for (const auto& transition : pda.getCallTransitions()) { + for(const auto& to : transition.second) { + std::pair<std::string, std::string> key( std::to_string ( transition.first.first ), std::to_string ( to.first ) ); + auto mapIterator = transitionMap.find(key); + + std::string symbol = alib::StringDataFactory::toString(transition.first.second); + + symbol += "|"; + + symbol += "$\\varepsilon;$"; + symbol += "\\rarrow"; + symbol += alib::StringDataFactory::toString(to.second); + + if (mapIterator == transitionMap.end()) { + transitionMap.insert(std::make_pair(key, symbol)); + } else { + mapIterator->second += "; " + symbol; + } + } + } + + for (const auto& transition : pda.getReturnTransitions()) { + for(const auto& to : transition.second) { + std::pair<std::string, std::string> key( std::to_string ( std::get<0>(transition.first) ), std::to_string ( to ) ); + auto mapIterator = transitionMap.find(key); + + std::string symbol = alib::StringDataFactory::toString(std::get<1>(transition.first)); + + symbol += "|"; + + symbol += alib::StringDataFactory::toString(std::get<2>(transition.first)); + symbol += "\\rarrow"; + symbol += "$\\varepsilon;$"; + + if (mapIterator == transitionMap.end()) { + transitionMap.insert(std::make_pair(key, symbol)); + } else { + mapIterator->second += "; " + symbol; + } + } + } + + for (const auto& transition : pda.getLocalTransitions()) { + for(const auto& to : transition.second) { + std::pair<std::string, std::string> key( std::to_string ( transition.first.first ), std::to_string ( to ) ); + auto mapIterator = transitionMap.find(key); + + std::string symbol = alib::StringDataFactory::toString(transition.first.second); + + symbol += "|"; + + symbol += "$\\varepsilon;$"; + symbol += "\\rarrow"; + symbol += "$\\varepsilon;$"; + + if (mapIterator == transitionMap.end()) { + transitionMap.insert(std::make_pair(key, symbol)); + } else { + mapIterator->second += "; " + symbol; + } + } + } + + printTransitionMap(transitionMap, out); +} + +template<class SymbolType, class EpsilonType, class StateType> +void GasTexConverter::transitions(const automaton::RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType > & pda, std::ostream& out) { + std::map<std::pair<std::string, std::string>, std::string> transitionMap; + + for (const auto& transition : pda.getCallTransitions()) { + std::pair<std::string, std::string> key( std::to_string ( transition.first.first ), std::to_string ( transition.second.first ) ); + auto mapIterator = transitionMap.find(key); + + std::string symbol; + if(transition.first.second.template is<EpsilonType>()) + symbol = "$\\varepsilon;$"; + else + symbol = alib::StringDataFactory::toString(transition.first.second.template get<SymbolType>()); + + symbol += "|"; + + symbol += "$\\varepsilon;$"; + symbol += "\\rarrow"; + symbol += alib::StringDataFactory::toString(transition.second.second); + + if (mapIterator == transitionMap.end()) { + transitionMap.insert(std::make_pair(key, symbol)); + } else { + mapIterator->second += "; " + symbol; + } + } + + for (const auto& transition : pda.getReturnTransitions()) { + std::pair<std::string, std::string> key( std::to_string ( std::get<0>(transition.first) ), std::to_string ( transition.second ) ); + auto mapIterator = transitionMap.find(key); + + std::string symbol; + if(std::get<1>(transition.first).template is<EpsilonType>()) + symbol = "$\\varepsilon;$"; + else + symbol = alib::StringDataFactory::toString(std::get<1>(transition.first).template get<SymbolType>()); + + symbol += "|"; + + symbol += alib::StringDataFactory::toString(std::get<2>(transition.first)); + symbol += "\\rarrow"; + symbol += "$\\varepsilon;$"; + + if (mapIterator == transitionMap.end()) { + transitionMap.insert(std::make_pair(key, symbol)); + } else { + mapIterator->second += "; " + symbol; + } + } + + for (const auto& transition : pda.getLocalTransitions()) { + std::pair<std::string, std::string> key( std::to_string ( transition.first.first ), std::to_string ( transition.second ) ); + auto mapIterator = transitionMap.find(key); + + std::string symbol; + if(transition.first.second.template is<EpsilonType>()) + symbol = "$\\varepsilon;$"; + else + symbol = alib::StringDataFactory::toString(transition.first.second.template get<SymbolType>()); + + symbol += "|"; + + symbol += "$\\varepsilon;$"; + symbol += "\\rarrow"; + symbol += "$\\varepsilon;$"; + + if (mapIterator == transitionMap.end()) { + transitionMap.insert(std::make_pair(key, symbol)); + } else { + mapIterator->second += "; " + symbol; + } + } + + printTransitionMap(transitionMap, out); +} + +template<class SymbolType, class EpsilonType, class StateType> +void GasTexConverter::transitions(const automaton::RealTimeHeightDeterministicNPDA < SymbolType, EpsilonType, StateType > & pda, std::ostream& out) { + std::map<std::pair<std::string, std::string>, std::string> transitionMap; + + for (const auto& transition : pda.getCallTransitions()) { + for(const auto& to : transition.second) { + std::pair<std::string, std::string> key( std::to_string ( transition.first.first ), std::to_string ( to.first ) ); + auto mapIterator = transitionMap.find(key); + + std::string symbol; + if(transition.first.second.template is<EpsilonType>()) + symbol = "$\\varepsilon;$"; + else + symbol = alib::StringDataFactory::toString(transition.first.second.template get<SymbolType>()); + + symbol += "|"; + + symbol += "$\\varepsilon;$"; + symbol += "\\rarrow"; + symbol += alib::StringDataFactory::toString(to.second); + + if (mapIterator == transitionMap.end()) { + transitionMap.insert(std::make_pair(key, symbol)); + } else { + mapIterator->second += "; " + symbol; + } + } + } + + for (const auto& transition : pda.getReturnTransitions()) { + for(const auto& to : transition.second) { + std::pair<std::string, std::string> key( std::to_string ( std::get<0>(transition.first) ), std::to_string ( to ) ); + auto mapIterator = transitionMap.find(key); + + std::string symbol; + if(std::get<1>(transition.first).template is<EpsilonType>()) + symbol = "$\\varepsilon;$"; + else + symbol = alib::StringDataFactory::toString(std::get<1>(transition.first).template get<SymbolType>()); + + symbol += "|"; + + symbol += alib::StringDataFactory::toString(std::get<2>(transition.first)); + symbol += "\\rarrow"; + symbol += "$\\varepsilon;$"; + + if (mapIterator == transitionMap.end()) { + transitionMap.insert(std::make_pair(key, symbol)); + } else { + mapIterator->second += "; " + symbol; + } + } + } + + for (const auto& transition : pda.getLocalTransitions()) { + for(const auto& to : transition.second) { + std::pair<std::string, std::string> key( std::to_string ( transition.first.first ), std::to_string ( to ) ); + auto mapIterator = transitionMap.find(key); + + std::string symbol; + if(transition.first.second.template is<EpsilonType>()) + symbol = "$\\varepsilon;$"; + else + symbol = alib::StringDataFactory::toString(transition.first.second.template get<SymbolType>()); + + symbol += "|"; + + symbol += "$\\varepsilon;$"; + symbol += "\\rarrow"; + symbol += "$\\varepsilon;$"; + + if (mapIterator == transitionMap.end()) { + transitionMap.insert(std::make_pair(key, symbol)); + } else { + mapIterator->second += "; " + symbol; + } + } + } + + printTransitionMap(transitionMap, out); +} + +template<class SymbolType, class EpsilonType, class StateType> +void GasTexConverter::transitions(const automaton::NPDA < SymbolType, EpsilonType, StateType > & pda, std::ostream& out) { + std::map<std::pair<std::string, std::string>, std::string> transitionMap; + + for (const auto& transition : pda.getTransitions()) { + for(const auto& to : transition.second) { + std::pair<std::string, std::string> key( std::to_string ( std::get<0>(transition.first) ), std::to_string ( to.first ) ); + auto mapIterator = transitionMap.find(key); + + std::string symbol; + if (std::get<1>(transition.first).template is<EpsilonType>()) { + symbol = "$\\varepsilon;$"; + } else { + symbol = alib::StringDataFactory::toString(std::get<1>(transition.first).template get<SymbolType>()); + } + + symbol += "|"; + + symbol += getStackSymbols(std::get<2>(transition.first)); + symbol += "\\rarrow"; + symbol += getStackSymbols(to.second); + + if (mapIterator == transitionMap.end()) { + transitionMap.insert(std::make_pair(key, symbol)); + } else { + mapIterator->second += "; " + symbol; + } + } + } + + printTransitionMap(transitionMap, out); +} + +template<class SymbolType, class EpsilonType, class StateType> +void GasTexConverter::transitions(const automaton::SinglePopNPDA < SymbolType, EpsilonType, StateType > & pda, std::ostream& out) { + std::map<std::pair<std::string, std::string>, std::string> transitionMap; + + for (const auto& transition : pda.getTransitions()) { + for(const auto& to : transition.second) { + std::pair<std::string, std::string> key( std::to_string ( std::get<0>(transition.first) ), std::to_string ( to.first ) ); + auto mapIterator = transitionMap.find(key); + + std::string symbol; + if (std::get<1>(transition.first).template is<EpsilonType>()) { + symbol = "$\\varepsilon;$"; + } else { + symbol = alib::StringDataFactory::toString(std::get<1>(transition.first).template get<SymbolType>()); + } + + symbol += "|"; + + symbol += alib::StringDataFactory::toString(std::get<2>(transition.first)); + symbol += "\\rarrow"; + symbol += getStackSymbols(to.second); + + if (mapIterator == transitionMap.end()) { + transitionMap.insert(std::make_pair(key, symbol)); + } else { + mapIterator->second += "; " + symbol; + } + } + } + + printTransitionMap(transitionMap, out); +} + +template<class SymbolType, class StateType> +void GasTexConverter::transitions(const automaton::OneTapeDTM < SymbolType, StateType > & tm, std::ostream& out) { + std::map<std::pair<std::string, std::string>, std::string> transitionMap; + + for (auto& transition : tm.getTransitions()) { + std::pair<std::string, std::string> key( std::to_string ( transition.first.first ), std::to_string ( std::get<0>(transition.second))); + auto mapIterator = transitionMap.find(key); + + std::string symbol = alib::StringDataFactory::toString(transition.first.second); + symbol += "/"; + symbol += alib::StringDataFactory::toString(std::get<1>(transition.second)); + symbol += ","; + switch(std::get<2>(transition.second)) { + case automaton::Shift::LEFT: + symbol += "$\\leftarrow$"; + break; + case automaton::Shift::RIGHT: + symbol += "$\\rightarrow$"; + break; + case automaton::Shift::NONE: + symbol += "$\\times$"; + break; + default: + throw exception::CommonException("Unexpected shift direction"); + } + + if (mapIterator == transitionMap.end()) { + transitionMap.insert(std::make_pair(key, symbol)); + } else { + mapIterator->second += "; " + symbol; + } + } + + printTransitionMap(transitionMap, out); +} + #endif /* GAS_TEX_CONVERTER_H_ */ diff --git a/aconvert2/src/TikZConverter.cpp b/aconvert2/src/TikZConverter.cpp index 1df53520ec..b283e06dff 100644 --- a/aconvert2/src/TikZConverter.cpp +++ b/aconvert2/src/TikZConverter.cpp @@ -7,1980 +7,27 @@ #include "TikZConverter.h" -#include <automaton/FSM/NFA.h> -#include <automaton/FSM/EpsilonNFA.h> -#include <automaton/FSM/MultiInitialStateNFA.h> -#include <automaton/FSM/DFA.h> -#include <automaton/FSM/ExtendedNFA.h> -#include <automaton/FSM/CompactNFA.h> -#include <automaton/TA/NFTA.h> -#include <automaton/TA/DFTA.h> -#include <automaton/PDA/NPDA.h> -#include <automaton/PDA/SinglePopNPDA.h> -#include <automaton/PDA/InputDrivenDPDA.h> -#include <automaton/PDA/InputDrivenNPDA.h> -#include <automaton/PDA/VisiblyPushdownDPDA.h> -#include <automaton/PDA/VisiblyPushdownNPDA.h> -#include <automaton/PDA/RealTimeHeightDeterministicDPDA.h> -#include <automaton/PDA/RealTimeHeightDeterministicNPDA.h> -#include <automaton/PDA/DPDA.h> -#include <automaton/PDA/SinglePopDPDA.h> -#include <automaton/TM/OneTapeDTM.h> - -#include <factory/StringDataFactory.hpp> - -#include <exception/CommonException.h> - -#include <string/String.h> - -#include <set> -#include <map> -#include <list> -#include <utility> -#include <vector> -#include <typeinfo> - -auto replace = [] ( std::string & str, const std::string & what, const std::string & with ) { - size_t index = 0; - - while ( ( index = str.find ( what, index ) ) != std::string::npos ) { - str.replace ( index, what.length ( ), with ); - index += with.length ( ); - } -}; - void TikZConverter::convert ( std::ostream & out, const automaton::Automaton & a ) { dispatch ( out, a.getData ( ) ); } -void TikZConverter::convert ( std::ostream & out, const automaton::EpsilonNFA < > & a ) { - out << "\\begin{tikzpicture}\n"; - int cnt = 1; - - // Map states to indices - std::map < label::Label, int > states; - - for ( const label::Label & state : a.getStates ( ) ) - states.insert ( std::make_pair ( state, cnt++ ) ); - - // Print states - for ( const auto & state : states ) { - std::string mods; - - if ( a.getFinalStates ( ).count ( state.first ) ) - mods += ",accepting"; - - if ( a.getInitialState ( ) == state.first ) - mods += ",initial"; - - out << "\\node[state" + mods + "] (" << state.second << ") {" << alib::StringDataFactory::toString ( state.first ) << "}\n"; - } - - transitions ( a, states, out ); - out << "\\end{tikzpicture}"; -} - auto TikZConverterEpsilonNFA = TikZConverter::RegistratorWrapper < void, automaton::EpsilonNFA < > > ( TikZConverter::convert ); - -void TikZConverter::convert ( std::ostream & out, const automaton::MultiInitialStateNFA < > & a ) { - out << "\\begin{tikzpicture}\n"; - int cnt = 1; - - // Map states to indices - std::map < label::Label, int > states; - - for ( const label::Label & state : a.getStates ( ) ) - states.insert ( std::make_pair ( state, cnt++ ) ); - - // Print states - for ( const auto & state : states ) { - std::string mods; - - if ( a.getFinalStates ( ).count ( state.first ) ) - mods += ",accepting"; - - if ( a.getInitialStates ( ).count ( state.first ) ) - mods += ",initial"; - - out << "\\node[state" + mods + "] (" << state.second << ") {" << alib::StringDataFactory::toString ( state.first ) << "}\n"; - } - - transitions ( a, states, out ); - out << "\\end{tikzpicture}"; -} - auto TikZConverterMultiInitialStateNFA = TikZConverter::RegistratorWrapper < void, automaton::MultiInitialStateNFA < > > ( TikZConverter::convert ); - -void TikZConverter::convert ( std::ostream & out, const automaton::NFA < > & a ) { - out << "\\begin{tikzpicture}\n"; - int cnt = 1; - - // Map states to indices - std::map < label::Label, int > states; - - for ( const label::Label & state : a.getStates ( ) ) - states.insert ( std::make_pair ( state, cnt++ ) ); - - // Print states - for ( const auto & state : states ) { - std::string mods; - - if ( a.getFinalStates ( ).count ( state.first ) ) - mods += ",accepting"; - - if ( a.getInitialState ( ) == state.first ) - mods += ",initial"; - - out << "\\node[state" + mods + "] (" << state.second << ") {" << alib::StringDataFactory::toString ( state.first ) << "}\n"; - } - - transitions ( a, states, out ); - out << "\\end{tikzpicture}"; -} - auto TikZConverterNFA = TikZConverter::RegistratorWrapper < void, automaton::NFA < > > ( TikZConverter::convert ); - -void TikZConverter::convert ( std::ostream & out, const automaton::DFA<> & a ) { - out << "\\begin{tikzpicture}\n"; - int cnt = 1; - - // Map states to indices - std::map < label::Label, int > states; - - for ( const label::Label & state : a.getStates ( ) ) - states.insert ( std::make_pair ( state, cnt++ ) ); - - // Print states - for ( const auto & state : states ) { - std::string mods; - - if ( a.getFinalStates ( ).count ( state.first ) ) - mods += ",accepting"; - - if ( a.getInitialState ( ) == state.first ) - mods += ",initial"; - - out << "\\node[state" + mods + "] (" << state.second << ") {" << alib::StringDataFactory::toString ( state.first ) << "}\n"; - } - - transitions ( a, states, out ); - out << "\\end{tikzpicture}"; -} - -auto TikZConverterDFA = TikZConverter::RegistratorWrapper < void, automaton::DFA<> > ( TikZConverter::convert ); - -void TikZConverter::convert ( std::ostream & out, const automaton::ExtendedNFA < > & a ) { - out << "\\begin{tikzpicture}\n"; - int cnt = 1; - - // Map states to indices - std::map < label::Label, int > states; - - for ( const label::Label & state : a.getStates ( ) ) - states.insert ( std::make_pair ( state, cnt++ ) ); - - // Print states - for ( const auto & state : states ) { - std::string mods; - - if ( a.getFinalStates ( ).count ( state.first ) ) - mods += ",accepting"; - - if ( a.getInitialState ( ) == state.first ) - mods += ",initial"; - - out << "\\node[state" + mods + "] (" << state.second << ") {" << alib::StringDataFactory::toString ( state.first ) << "}\n"; - } - - transitions ( a, states, out ); - out << "\\end{tikzpicture}"; -} - +auto TikZConverterDFA = TikZConverter::RegistratorWrapper < void, automaton::DFA < > > ( TikZConverter::convert ); auto TikZConverterExtendedNFA = TikZConverter::RegistratorWrapper < void, automaton::ExtendedNFA < > > ( TikZConverter::convert ); - -void TikZConverter::convert ( std::ostream & out, const automaton::CompactNFA < > & a ) { - out << "\\begin{tikzpicture}\n"; - int cnt = 1; - - // Map states to indices - std::map < label::Label, int > states; - - for ( const label::Label & state : a.getStates ( ) ) - states.insert ( std::make_pair ( state, cnt++ ) ); - - // Print states - for ( const auto & state : states ) { - std::string mods; - - if ( a.getFinalStates ( ).count ( state.first ) ) - mods += ",accepting"; - - if ( a.getInitialState ( ) == state.first ) - mods += ",initial"; - - out << "\\node[state" + mods + "] (" << state.second << ") {" << alib::StringDataFactory::toString ( state.first ) << "}\n"; - } - - transitions ( a, states, out ); - out << "\\end{tikzpicture}"; -} - auto TikZConverterCompactNFA = TikZConverter::RegistratorWrapper < void, automaton::CompactNFA < > > ( TikZConverter::convert ); - -void TikZConverter::convert ( std::ostream & out, const automaton::NFTA < > & a ) { - out << "\\begin{tikzpicture}\n"; - int cnt = 1; - - // Map states to indices - std::map < label::Label, int > states; - - for ( const label::Label & state : a.getStates ( ) ) - states.insert ( std::make_pair ( state, cnt++ ) ); - - // Print states - for ( const auto & state : states ) { - std::string mods; - - if ( a.getFinalStates ( ).count ( state.first ) ) - mods += ",accepting"; - - out << "\\node[state" + mods + "] (" << state.second << ") {" << alib::StringDataFactory::toString ( state.first ) << "}\n"; - } - - transitions ( a, states, out ); - out << "\\end{tikzpicture}"; -} - auto TikZConverterNFTA = TikZConverter::RegistratorWrapper < void, automaton::NFTA < > > ( TikZConverter::convert ); - -void TikZConverter::convert ( std::ostream & out, const automaton::DFTA < > & a ) { - out << "\\begin{tikzpicture}\n"; - int cnt = 1; - - // Map states to indices - std::map < label::Label, int > states; - - for ( const label::Label & state : a.getStates ( ) ) - states.insert ( std::make_pair ( state, cnt++ ) ); - - // Print states - for ( const auto & state : states ) { - std::string mods; - - if ( a.getFinalStates ( ).count ( state.first ) ) - mods += ",accepting"; - - out << "\\node[state" + mods + "] (" << state.second << ") {" << alib::StringDataFactory::toString ( state.first ) << "}\n"; - } - - transitions ( a, states, out ); - out << "\\end{tikzpicture}"; -} - auto TikZConverterDFTA = TikZConverter::RegistratorWrapper < void, automaton::DFTA < > > ( TikZConverter::convert ); - -void TikZConverter::convert ( std::ostream & out, const automaton::DPDA < > & a ) { - out << "\\begin{tikzpicture}\n"; - int cnt = 1; - - // Map states to indices - std::map < label::Label, int > states; - - for ( const label::Label & state : a.getStates ( ) ) - states.insert ( std::make_pair ( state, cnt++ ) ); - - // Print states - for ( const auto & state : states ) { - std::string mods; - - if ( a.getFinalStates ( ).count ( state.first ) ) - mods += ",accepting"; - - if ( a.getInitialState ( ) == state.first ) - mods += ",initial"; - - out << "\\node[state" + mods + "] (" << state.second << ") {" << alib::StringDataFactory::toString ( state.first ) << "}\n"; - } - - transitions ( a, states, out ); - out << "\\end{tikzpicture}"; -} - auto TikZConverterDPDA = TikZConverter::RegistratorWrapper < void, automaton::DPDA < > > ( TikZConverter::convert ); - -void TikZConverter::convert ( std::ostream & out, const automaton::SinglePopDPDA < > & a ) { - out << "\\begin{tikzpicture}\n"; - int cnt = 1; - - // Map states to indices - std::map < label::Label, int > states; - - for ( const label::Label & state : a.getStates ( ) ) - states.insert ( std::make_pair ( state, cnt++ ) ); - - // Print states - for ( const auto & state : states ) { - std::string mods; - - if ( a.getFinalStates ( ).count ( state.first ) ) - mods += ",accepting"; - - if ( a.getInitialState ( ) == state.first ) - mods += ",initial"; - - out << "\\node[state" + mods + "] (" << state.second << ") {" << alib::StringDataFactory::toString ( state.first ) << "}\n"; - } - - transitions ( a, states, out ); - out << "\\end{tikzpicture}"; -} - auto TikZConverterSinglePopDPDA = TikZConverter::RegistratorWrapper < void, automaton::SinglePopDPDA < > > ( TikZConverter::convert ); - -void TikZConverter::convert ( std::ostream & out, const automaton::InputDrivenDPDA < > & a ) { - out << "\\begin{tikzpicture}\n"; - int cnt = 1; - - // Map states to indices - std::map < label::Label, int > states; - - for ( const label::Label & state : a.getStates ( ) ) - states.insert ( std::make_pair ( state, cnt++ ) ); - - // Print states - for ( const auto & state : states ) { - std::string mods; - - if ( a.getFinalStates ( ).count ( state.first ) ) - mods += ",accepting"; - - if ( a.getInitialState ( ) == state.first ) - mods += ",initial"; - - out << "\\node[state" + mods + "] (" << state.second << ") {" << alib::StringDataFactory::toString ( state.first ) << "}\n"; - } - - transitions ( a, states, out ); - out << "\\end{tikzpicture}"; -} - auto TikZConverterInputDrivenDPDA = TikZConverter::RegistratorWrapper < void, automaton::InputDrivenDPDA < > > ( TikZConverter::convert ); - -void TikZConverter::convert ( std::ostream & out, const automaton::InputDrivenNPDA < > & a ) { - out << "\\begin{tikzpicture}\n"; - int cnt = 1; - - // Map states to indices - std::map < label::Label, int > states; - - for ( const label::Label & state : a.getStates ( ) ) - states.insert ( std::make_pair ( state, cnt++ ) ); - - // Print states - for ( const auto & state : states ) { - std::string mods; - - if ( a.getFinalStates ( ).count ( state.first ) ) - mods += ",accepting"; - - if ( a.getInitialState ( ) == state.first ) - mods += ",initial"; - - out << "\\node[state" + mods + "] (" << state.second << ") {" << alib::StringDataFactory::toString ( state.first ) << "}\n"; - } - - transitions ( a, states, out ); - out << "\\end{tikzpicture}"; -} - auto TikZConverterInputDrivenNPDA = TikZConverter::RegistratorWrapper < void, automaton::InputDrivenNPDA < > > ( TikZConverter::convert ); - -void TikZConverter::convert ( std::ostream & out, const automaton::VisiblyPushdownDPDA < > & a ) { - out << "\\begin{tikzpicture}\n"; - int cnt = 1; - - // Map states to indices - std::map < label::Label, int > states; - - for ( const label::Label & state : a.getStates ( ) ) - states.insert ( std::make_pair ( state, cnt++ ) ); - - // Print states - for ( const auto & state : states ) { - std::string mods; - - if ( a.getFinalStates ( ).count ( state.first ) ) - mods += ",accepting"; - - if ( a.getInitialState ( ) == state.first ) - mods += ",initial"; - - out << "\\node[state" + mods + "] (" << state.second << ") {" << alib::StringDataFactory::toString ( state.first ) << "}\n"; - } - - transitions ( a, states, out ); - out << "\\end{tikzpicture}"; -} - auto TikZConverterVisiblyPushdownDPDA = TikZConverter::RegistratorWrapper < void, automaton::VisiblyPushdownDPDA < > > ( TikZConverter::convert ); - -void TikZConverter::convert ( std::ostream & out, const automaton::VisiblyPushdownNPDA < > & a ) { - out << "\\begin{tikzpicture}\n"; - int cnt = 1; - - // Map states to indices - std::map < label::Label, int > states; - - for ( const label::Label & state : a.getStates ( ) ) - states.insert ( std::make_pair ( state, cnt++ ) ); - - // Print states - for ( const auto & state : states ) { - std::string mods; - - if ( a.getFinalStates ( ).count ( state.first ) ) - mods += ",accepting"; - - if ( a.getInitialStates ( ).count ( state.first ) ) - mods += ",initial"; - - out << "\\node[state" + mods + "] (" << state.second << ") {" << alib::StringDataFactory::toString ( state.first ) << "}\n"; - } - - transitions ( a, states, out ); - out << "\\end{tikzpicture}"; -} - auto TikZConverterVisiblyPushdownNPDA = TikZConverter::RegistratorWrapper < void, automaton::VisiblyPushdownNPDA < > > ( TikZConverter::convert ); - -void TikZConverter::convert ( std::ostream & out, const automaton::RealTimeHeightDeterministicDPDA < > & a ) { - out << "\\begin{tikzpicture}\n"; - int cnt = 1; - - // Map states to indices - std::map < label::Label, int > states; - - for ( const label::Label & state : a.getStates ( ) ) - states.insert ( std::make_pair ( state, cnt++ ) ); - - // Print states - for ( const auto & state : states ) { - std::string mods; - - if ( a.getFinalStates ( ).count ( state.first ) ) - mods += ",accepting"; - - if ( a.getInitialState ( ) == state.first ) - mods += ",initial"; - - out << "\\node[state" + mods + "] (" << state.second << ") {" << alib::StringDataFactory::toString ( state.first ) << "}\n"; - } - - transitions ( a, states, out ); - out << "\\end{tikzpicture}"; -} - auto TikZConverterRealTimeHeightDeterministicDPDA = TikZConverter::RegistratorWrapper < void, automaton::RealTimeHeightDeterministicDPDA < > > ( TikZConverter::convert ); - -void TikZConverter::convert ( std::ostream & out, const automaton::RealTimeHeightDeterministicNPDA < > & a ) { - out << "\\begin{tikzpicture}\n"; - int cnt = 1; - - // Map states to indices - std::map < label::Label, int > states; - - for ( const label::Label & state : a.getStates ( ) ) - states.insert ( std::make_pair ( state, cnt++ ) ); - - // Print states - for ( const auto & state : states ) { - std::string mods; - - if ( a.getFinalStates ( ).count ( state.first ) ) - mods += ",accepting"; - - if ( a.getInitialStates ( ).count ( state.first ) ) - mods += ",initial"; - - out << "\\node[state" + mods + "] (" << state.second << ") {" << alib::StringDataFactory::toString ( state.first ) << "}\n"; - } - - transitions ( a, states, out ); - out << "\\end{tikzpicture}"; -} - auto TikZConverterRealTimeHeightDeterministicNPDA = TikZConverter::RegistratorWrapper < void, automaton::RealTimeHeightDeterministicNPDA < > > ( TikZConverter::convert ); - -void TikZConverter::convert ( std::ostream & out, const automaton::NPDA < > & a ) { - out << "\\begin{tikzpicture}\n"; - int cnt = 1; - - // Map states to indices - std::map < label::Label, int > states; - - for ( const label::Label & state : a.getStates ( ) ) - states.insert ( std::make_pair ( state, cnt++ ) ); - - // Print states - for ( const auto & state : states ) { - std::string mods; - - if ( a.getFinalStates ( ).count ( state.first ) ) - mods += ",accepting"; - - if ( a.getInitialState ( ) == state.first ) - mods += ",initial"; - - out << "\\node[state" + mods + "] (" << state.second << ") {" << alib::StringDataFactory::toString ( state.first ) << "}\n"; - } - - transitions ( a, states, out ); - out << "\\end{tikzpicture}"; -} - auto TikZConverterNPDA = TikZConverter::RegistratorWrapper < void, automaton::NPDA < > > ( TikZConverter::convert ); - -void TikZConverter::convert ( std::ostream & out, const automaton::SinglePopNPDA < > & a ) { - out << "\\begin{tikzpicture}\n"; - int cnt = 1; - - // Map states to indices - std::map < label::Label, int > states; - - for ( const label::Label & state : a.getStates ( ) ) - states.insert ( std::make_pair ( state, cnt++ ) ); - - // Print states - for ( const auto & state : states ) { - std::string mods; - - if ( a.getFinalStates ( ).count ( state.first ) ) - mods += ",accepting"; - - if ( a.getInitialState ( ) == state.first ) - mods += ",initial"; - - out << "\\node[state" + mods + "] (" << state.second << ") {" << alib::StringDataFactory::toString ( state.first ) << "}\n"; - } - - transitions ( a, states, out ); - out << "\\end{tikzpicture}"; -} - auto TikZConverterSinglePopNPDA = TikZConverter::RegistratorWrapper < void, automaton::SinglePopNPDA < > > ( TikZConverter::convert ); - -void TikZConverter::convert ( std::ostream & out, const automaton::OneTapeDTM < > & a ) { - out << "\\begin{tikzpicture}\n"; - int cnt = 1; - - // Map states to indices - std::map < label::Label, int > states; - - for ( const label::Label & state : a.getStates ( ) ) - states.insert ( std::make_pair ( state, cnt++ ) ); - - // Print states - for ( const auto & state : states ) { - std::string mods; - - if ( a.getFinalStates ( ).count ( state.first ) ) - mods += ",accepting"; - - if ( a.getInitialState ( ) == state.first ) - mods += ",initial"; - - out << "\\node[state" + mods + "] (" << state.second << ") {" << alib::StringDataFactory::toString ( state.first ) << "}\n"; - } - - transitions ( a, states, out ); - out << "\\end{tikzpicture}"; -} - auto TikZConverterOneTapeDTM = TikZConverter::RegistratorWrapper < void, automaton::OneTapeDTM < > > ( TikZConverter::convert ); -void TikZConverter::transitions ( const automaton::EpsilonNFA < > & fsm, const std::map < label::Label, int > & states, std::ostream & out ) { - std::map < std::pair < int, int >, std::string > transitions; - - // put transitions from automaton to "transitions" - for ( const auto & transition : fsm.getTransitions ( ) ) { - std::string symbol; - - if ( transition.first.second.is < string::Epsilon < > > ( ) ) - symbol = "ε"; - else - symbol = alib::StringDataFactory::toString ( std::get < 1 > ( transition.first ).get < alphabet::Symbol > ( ) ); - - for ( const label::Label & to : transition.second ) { - std::pair < int, int > key ( states.find ( transition.first.first )->second, states.find ( to )->second ); - std::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key ); - - if ( mapit == transitions.end ( ) ) { - transitions.insert ( std::make_pair ( key, symbol ) ); - } else { - mapit->second += ","; - - size_t pos = mapit->second.find_last_of ( "\n" ); - - if ( pos == std::string::npos ) pos = 0; - - if ( mapit->second.size ( ) - pos > 100 ) - mapit->second += "\n"; - else - mapit->second += " "; - - mapit->second += symbol; - } - } - } - - out << "\\path[->]"; - - // print the map - for ( std::pair < const std::pair < int, int >, std::string > & transition : transitions ) { - replace ( transition.second, "\n", "\\n" ); - - out << "(" << transition.first.first << ") edge [left] node [align=center] "; - out << "{$" << transition.second << "$}"; - out << "(" << transition.first.second << ")\n"; - } -} - -void TikZConverter::transitions ( const automaton::MultiInitialStateNFA < > & fsm, const std::map < label::Label, int > & states, std::ostream & out ) { - std::map < std::pair < int, int >, std::string > transitions; - - // put transitions from automaton to "transitions" - for ( const auto & transition : fsm.getTransitions ( ) ) { - std::string symbol = alib::StringDataFactory::toString ( transition.first.second ); - - for ( const label::Label & to : transition.second ) { - std::pair < int, int > key ( states.find ( transition.first.first )->second, states.find ( to )->second ); - std::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key ); - - if ( mapit == transitions.end ( ) ) { - transitions.insert ( std::make_pair ( key, symbol ) ); - } else { - mapit->second += ","; - - size_t pos = mapit->second.find_last_of ( "\n" ); - - if ( pos == std::string::npos ) pos = 0; - - if ( mapit->second.size ( ) - pos > 100 ) - mapit->second += "\n"; - else - mapit->second += " "; - - mapit->second += symbol; - } - } - } - - out << "\\path[->]"; - - // print the map - for ( std::pair < const std::pair < int, int >, std::string > & transition : transitions ) { - replace ( transition.second, "\n", "\\n" ); - - out << "(" << transition.first.first << ") edge [left] node [align=center] "; - out << "{$" << transition.second << "$}"; - out << "(" << transition.first.second << ")\n"; - } -} - -void TikZConverter::transitions ( const automaton::NFA < > & fsm, const std::map < label::Label, int > & states, std::ostream & out ) { - std::map < std::pair < int, int >, std::string > transitions; - - // put transitions from automaton to "transitions" - for ( const auto & transition : fsm.getTransitions ( ) ) { - std::string symbol = alib::StringDataFactory::toString ( transition.first.second ); - - for ( const label::Label & to : transition.second ) { - std::pair < int, int > key ( states.find ( transition.first.first )->second, states.find ( to )->second ); - std::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key ); - - if ( mapit == transitions.end ( ) ) { - transitions.insert ( std::make_pair ( key, symbol ) ); - } else { - mapit->second += ","; - - size_t pos = mapit->second.find_last_of ( "\n" ); - - if ( pos == std::string::npos ) pos = 0; - - if ( mapit->second.size ( ) - pos > 100 ) - mapit->second += "\n"; - else - mapit->second += " "; - - mapit->second += symbol; - } - } - } - - out << "\\path[->]"; - - // print the map - for ( std::pair < const std::pair < int, int >, std::string > & transition : transitions ) { - replace ( transition.second, "\n", "\\n" ); - - out << "(" << transition.first.first << ") edge [left] node [align=center] "; - out << "{$" << transition.second << "$}"; - out << "(" << transition.first.second << ")\n"; - } -} - -void TikZConverter::transitions ( const automaton::DFA<> & fsm, const std::map < label::Label, int > & states, std::ostream & out ) { - std::map < std::pair < int, int >, std::string > transitions; - - // put transitions from automaton to "transitions" - for ( const auto & transition : fsm.getTransitions ( ) ) { - std::string symbol = alib::StringDataFactory::toString ( transition.first.second ); - - std::pair < int, int > key ( states.find ( transition.first.first )->second, states.find ( transition.second )->second ); - std::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key ); - - if ( mapit == transitions.end ( ) ) { - transitions.insert ( std::make_pair ( key, symbol ) ); - } else { - mapit->second += ","; - - size_t pos = mapit->second.find_last_of ( "\n" ); - - if ( pos == std::string::npos ) pos = 0; - - if ( mapit->second.size ( ) - pos > 100 ) - mapit->second += "\n"; - else - mapit->second += " "; - - mapit->second += symbol; - } - } - - out << "\\path[->]"; - - // print the map - for ( std::pair < const std::pair < int, int >, std::string > & transition : transitions ) { - replace ( transition.second, "\n", "\\n" ); - - out << "(" << transition.first.first << ") edge [left] node [align=center] "; - out << "{$" << transition.second << "$}"; - out << "(" << transition.first.second << ")\n"; - } -} - -void TikZConverter::transitions ( const automaton::ExtendedNFA < > & fsm, const std::map < label::Label, int > & states, std::ostream & out ) { - std::map < std::pair < int, int >, std::string > transitions; - - // put transitions from automaton to "transitions" - for ( const auto & transition : fsm.getTransitions ( ) ) { - std::string symbol = alib::StringDataFactory::toString ( transition.first.second ); - - for ( const label::Label & to : transition.second ) { - std::pair < int, int > key ( states.find ( transition.first.first )->second, states.find ( to )->second ); - std::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key ); - - if ( mapit == transitions.end ( ) ) { - transitions.insert ( std::make_pair ( key, symbol ) ); - } else { - mapit->second += ","; - - size_t pos = mapit->second.find_last_of ( "\n" ); - - if ( pos == std::string::npos ) pos = 0; - - if ( mapit->second.size ( ) - pos > 100 ) - mapit->second += "\n"; - else - mapit->second += " "; - - mapit->second += symbol; - } - } - } - - out << "\\path[->]"; - - // print the map - for ( std::pair < const std::pair < int, int >, std::string > & transition : transitions ) { - replace ( transition.second, "\n", "\\n" ); - - out << "(" << transition.first.first << ") edge [left] node [align=center] "; - out << "{$" << transition.second << "$}"; - out << "(" << transition.first.second << ")\n"; - } -} - -void TikZConverter::transitions ( const automaton::CompactNFA < > & fsm, const std::map < label::Label, int > & states, std::ostream & out ) { - std::map < std::pair < int, int >, std::string > transitions; - - // put transitions from automaton to "transitions" - for ( const auto & transition : fsm.getTransitions ( ) ) { - std::string symbol = alib::StringDataFactory::toString ( string::stringFrom ( transition.first.second ) ); - - for ( const label::Label & to : transition.second ) { - std::pair < int, int > key ( states.find ( transition.first.first )->second, states.find ( to )->second ); - std::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key ); - - if ( mapit == transitions.end ( ) ) { - transitions.insert ( std::make_pair ( key, symbol ) ); - } else { - mapit->second += ","; - - size_t pos = mapit->second.find_last_of ( "\n" ); - - if ( pos == std::string::npos ) pos = 0; - - if ( mapit->second.size ( ) - pos > 100 ) - mapit->second += "\n"; - else - mapit->second += " "; - - mapit->second += symbol; - } - } - } - - out << "\\path[->]"; - - // print the map - for ( std::pair < const std::pair < int, int >, std::string > & transition : transitions ) { - replace ( transition.second, "\n", "\\n" ); - - out << "(" << transition.first.first << ") edge [left] node [align=center] "; - out << "{$" << transition.second << "$}"; - out << "(" << transition.first.second << ")\n"; - } -} - -void TikZConverter::transitions ( const automaton::NFTA < > & fta, const std::map < label::Label, int > & states, std::ostream & out ) { - std::map < std::pair < int, std::vector < int > >, std::string > transitions; - - // put transitions from automaton to "transitions" - for ( const auto & transition : fta.getTransitions ( ) ) { - std::string symbol = alib::StringDataFactory::toString ( transition.first.first.getSymbol ( ) ); - symbol += std::to_string ( transition.first.first.getRank ( ).getData ( ) ); - - for ( const label::Label & to : transition.second ) { - std::pair < int, std::vector < int > > key ( states.find ( to )->second, { } ); - - for ( const label::Label & state : transition.first.second ) - key.second.push_back ( states.find ( state )->second ); - - std::map < std::pair < int, std::vector < int > >, std::string >::iterator mapit = transitions.find ( key ); - - if ( mapit == transitions.end ( ) ) { - transitions.insert ( std::make_pair ( key, symbol ) ); - } else { - mapit->second += ","; - - size_t pos = mapit->second.find_last_of ( "\n" ); - - if ( pos == std::string::npos ) pos = 0; - - if ( mapit->second.size ( ) - pos > 100 ) - mapit->second += "\n"; - else - mapit->second += " "; - - mapit->second += symbol; - } - } - } - - // Print auxilary dots - for ( unsigned i = 1; i < transitions.size ( ); i++ ) - out << "\\node[draw=none,fill=none] (" << states.size ( ) + i << ") {}\n"; - - out << "\\path[->]"; - - // print the map - unsigned i = states.size ( ) + 1; - - for ( std::pair < const std::pair < int, std::vector < int > >, std::string > & transition : transitions ) { - replace ( transition.second, "\n", "\\n" ); - - out << "(" << i << ") edge [left] node [align=center] "; - out << "{$" << transition.second << "$}"; - out << "(" << transition.first.first << ")\n"; - - unsigned j = 0; - - for ( int from : transition.first.second ) { - out << "(" << from << ") edge [left] node [align=center] "; - out << "{$" << j << "$}"; - out << "(" << i << ")\n"; - - j++; - } - - i++; - } -} - -void TikZConverter::transitions ( const automaton::DFTA < > & fta, const std::map < label::Label, int > & states, std::ostream & out ) { - std::map < std::pair < int, std::vector < int > >, std::string > transitions; - - // put transitions from automaton to "transitions" - for ( const auto & transition : fta.getTransitions ( ) ) { - std::string symbol = alib::StringDataFactory::toString ( transition.first.first.getSymbol ( ) ); - symbol += std::to_string ( transition.first.first.getRank ( ).getData ( ) ); - - std::pair < int, std::vector < int > > key ( states.find ( transition.second )->second, { } ); - - for ( const label::Label & state : transition.first.second ) - key.second.push_back ( states.find ( state )->second ); - - std::map < std::pair < int, std::vector < int > >, std::string >::iterator mapit = transitions.find ( key ); - - if ( mapit == transitions.end ( ) ) { - transitions.insert ( std::make_pair ( key, symbol ) ); - } else { - mapit->second += ","; - - size_t pos = mapit->second.find_last_of ( "\n" ); - - if ( pos == std::string::npos ) pos = 0; - - if ( mapit->second.size ( ) - pos > 100 ) - mapit->second += "\n"; - else - mapit->second += " "; - - mapit->second += symbol; - } - } - - // Print auxilary dots - for ( unsigned i = 1; i < transitions.size ( ); i++ ) - out << "\\node[draw=none,fill=none] (" << states.size ( ) + i << ") {}\n"; - - out << "\\path[->]"; - - // print the map - unsigned i = states.size ( ) + 1; - - for ( std::pair < const std::pair < int, std::vector < int > >, std::string > & transition : transitions ) { - replace ( transition.second, "\n", "\\n" ); - - out << "(" << i << ") edge [left] node [align=center] "; - out << "{$" << transition.second << "$}"; - out << "(" << transition.first.first << ")\n"; - - unsigned j = 0; - - for ( int from : transition.first.second ) { - out << "(" << from << ") edge [left] node [align=center] "; - out << "{$" << j << "$}"; - out << "(" << i << ")\n"; - - j++; - } - - i++; - } -} - -void TikZConverter::transitions ( const automaton::DPDA < > & pda, const std::map < label::Label, int > & states, std::ostream & out ) { - std::map < std::pair < int, int >, std::string > transitions; - - for ( const auto & transition : pda.getTransitions ( ) ) { - std::string symbol; - - // input symbol - if ( std::get < 1 > ( transition.first ).is < string::Epsilon < > > ( ) ) - symbol = "ε"; - else - symbol = alib::StringDataFactory::toString ( std::get < 1 > ( transition.first ).get < alphabet::Symbol > ( ) ); - - symbol += " |"; - - // Pop part - if ( std::get < 2 > ( transition.first ).size ( ) == 0 ) - symbol += " ε"; - else - for ( alphabet::Symbol symb : std::get < 2 > ( transition.first ) ) - symbol += " " + alib::StringDataFactory::toString ( symb ); - - symbol += " ->"; - - // Push part - if ( transition.second.second.size ( ) == 0 ) - symbol += " ε"; - else - for ( alphabet::Symbol symb : transition.second.second ) - symbol += " " + alib::StringDataFactory::toString ( symb ); - - // Insert into map - std::pair < int, int > key ( states.find ( std::get < 0 > ( transition.first ) )->second, states.find ( transition.second.first )->second ); - std::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key ); - - if ( mapit == transitions.end ( ) ) { - transitions.insert ( std::make_pair ( key, symbol ) ); - } else { - mapit->second += ","; - - size_t pos = mapit->second.find_last_of ( "\n" ); - - if ( pos == std::string::npos ) pos = 0; - - if ( mapit->second.size ( ) - pos > 100 ) - mapit->second += "\n"; - else - mapit->second += " "; - - mapit->second += symbol; - } - } - - out << "\\path[->]"; - - // print the map - for ( std::pair < const std::pair < int, int >, std::string > & transition : transitions ) { - replace ( transition.second, "\n", "\\n" ); - - out << "(" << transition.first.first << ") edge [left] node [align=center] "; - out << "{$" << transition.second << "$}"; - out << "(" << transition.first.second << ")\n"; - } -} - -void TikZConverter::transitions ( const automaton::SinglePopDPDA < > & pda, const std::map < label::Label, int > & states, std::ostream & out ) { - std::map < std::pair < int, int >, std::string > transitions; - - for ( const auto & transition : pda.getTransitions ( ) ) { - std::string symbol; - - // input symbol - if ( std::get < 1 > ( transition.first ).is < string::Epsilon < > > ( ) ) - symbol = "ε"; - else - symbol = alib::StringDataFactory::toString ( std::get < 1 > ( transition.first ).get < alphabet::Symbol > ( ) ); - - symbol += " |"; - - // Pop part - symbol += " " + alib::StringDataFactory::toString ( std::get < 2 > ( transition.first ) ); - - symbol += " ->"; - - // Push part - if ( transition.second.second.size ( ) == 0 ) - symbol += " ε"; - else - for ( alphabet::Symbol symb : transition.second.second ) - symbol += " " + alib::StringDataFactory::toString ( symb ); - - // Insert into map - std::pair < int, int > key ( states.find ( std::get < 0 > ( transition.first ) )->second, states.find ( transition.second.first )->second ); - std::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key ); - - if ( mapit == transitions.end ( ) ) { - transitions.insert ( std::make_pair ( key, symbol ) ); - } else { - mapit->second += ","; - - size_t pos = mapit->second.find_last_of ( "\n" ); - - if ( pos == std::string::npos ) pos = 0; - - if ( mapit->second.size ( ) - pos > 100 ) - mapit->second += "\n"; - else - mapit->second += " "; - - mapit->second += symbol; - } - } - - out << "\\path[->]"; - - // print the map - for ( std::pair < const std::pair < int, int >, std::string > & transition : transitions ) { - replace ( transition.second, "\n", "\\n" ); - - out << "(" << transition.first.first << ") edge [left] node [align=center] "; - out << "{$" << transition.second << "$}"; - out << "(" << transition.first.second << ")\n"; - } -} - -void TikZConverter::transitions ( const automaton::InputDrivenDPDA < > & pda, const std::map < label::Label, int > & states, std::ostream & out ) { - std::map < std::pair < int, int >, std::string > transitions; - - const auto & symbolToPDSOperation = pda.getPushdownStoreOperations ( ); - - for ( const auto & transition : pda.getTransitions ( ) ) { - const auto & pop = symbolToPDSOperation.find ( transition.first.second )->second.first; - const auto & push = symbolToPDSOperation.find ( transition.first.second )->second.second; - - std::string symbol; - - // input symbol - symbol = alib::StringDataFactory::toString ( transition.first.second ); - - symbol += " |"; - - // Pop part - if ( pop.size ( ) == 0 ) - symbol += " ε"; - else - for ( alphabet::Symbol symb : pop ) - symbol += " " + alib::StringDataFactory::toString ( symb ); - - symbol += " ->"; - - const auto & to = transition.second; - - // Push part - if ( push.size ( ) == 0 ) - symbol += " ε"; - else - for ( alphabet::Symbol symb : push ) - symbol += " " + alib::StringDataFactory::toString ( symb ); - - // Insert into map - std::pair < int, int > key ( states.find ( transition.first.first )->second, states.find ( to )->second ); - std::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key ); - - if ( mapit == transitions.end ( ) ) { - transitions.insert ( std::make_pair ( key, symbol ) ); - } else { - mapit->second += ","; - - size_t pos = mapit->second.find_last_of ( "\n" ); - - if ( pos == std::string::npos ) pos = 0; - - if ( mapit->second.size ( ) - pos > 100 ) - mapit->second += "\n"; - else - mapit->second += " "; - - mapit->second += symbol; - } - } - - out << "\\path[->]"; - - // print the map - for ( std::pair < const std::pair < int, int >, std::string > & transition : transitions ) { - replace ( transition.second, "\n", "\\n" ); - - out << "(" << transition.first.first << ") edge [left] node [align=center] "; - out << "{$" << transition.second << "$}"; - out << "(" << transition.first.second << ")\n"; - } -} - -void TikZConverter::transitions ( const automaton::InputDrivenNPDA < > & pda, const std::map < label::Label, int > & states, std::ostream & out ) { - std::map < std::pair < int, int >, std::string > transitions; - - const auto & symbolToPDSOperation = pda.getPushdownStoreOperations ( ); - - for ( const auto & transition : pda.getTransitions ( ) ) { - const auto & pop = symbolToPDSOperation.find ( transition.first.second )->second.first; - const auto & push = symbolToPDSOperation.find ( transition.first.second )->second.second; - - std::string symbol; - - // input symbol - symbol = alib::StringDataFactory::toString ( transition.first.second ); - - symbol += " |"; - - // Pop part - if ( pop.size ( ) == 0 ) - symbol += " ε"; - else - for ( alphabet::Symbol symb : pop ) - symbol += " " + alib::StringDataFactory::toString ( symb ); - - symbol += " ->"; - - std::string symbol2; - - for ( const auto & to : transition.second ) { - symbol2 = symbol; - - // Push part - if ( push.size ( ) == 0 ) - symbol2 += " ε"; - else - for ( alphabet::Symbol symb : push ) - symbol2 += " " + alib::StringDataFactory::toString ( symb ); - - // Insert into map - std::pair < int, int > key ( states.find ( transition.first.first )->second, states.find ( to )->second ); - std::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key ); - - if ( mapit == transitions.end ( ) ) { - transitions.insert ( std::make_pair ( key, symbol2 ) ); - } else { - mapit->second += ","; - - size_t pos = mapit->second.find_last_of ( "\n" ); - - if ( pos == std::string::npos ) pos = 0; - - if ( mapit->second.size ( ) - pos > 100 ) - mapit->second += "\n"; - else - mapit->second += " "; - - mapit->second += symbol2; - } - } - } - - out << "\\path[->]"; - - // print the map - for ( std::pair < const std::pair < int, int >, std::string > & transition : transitions ) { - replace ( transition.second, "\n", "\\n" ); - - out << "(" << transition.first.first << ") edge [left] node [align=center] "; - out << "{$" << transition.second << "$}"; - out << "(" << transition.first.second << ")\n"; - } -} - -void TikZConverter::transitions ( const automaton::VisiblyPushdownDPDA < > & pda, const std::map < label::Label, int > & states, std::ostream & out ) { - std::map < std::pair < int, int >, std::string > transitions; - - for ( const auto & transition : pda.getCallTransitions ( ) ) { - std::string symbol; - - // input symbol - symbol = alib::StringDataFactory::toString ( transition.first.second ); - - symbol += " |"; - - // Pop part - symbol += " ε"; - symbol += " ->"; - - symbol += " " + alib::StringDataFactory::toString ( transition.second.second ); - - // Insert into map - std::pair < int, int > key ( states.find ( transition.first.first )->second, states.find ( transition.second.first )->second ); - std::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key ); - - if ( mapit == transitions.end ( ) ) { - transitions.insert ( std::make_pair ( key, symbol ) ); - } else { - mapit->second += ","; - - size_t pos = mapit->second.find_last_of ( "\n" ); - - if ( pos == std::string::npos ) pos = 0; - - if ( mapit->second.size ( ) - pos > 100 ) - mapit->second += "\n"; - else - mapit->second += " "; - - mapit->second += symbol; - } - } - - for ( const auto & transition : pda.getReturnTransitions ( ) ) { - std::string symbol; - - // input symbol - symbol = alib::StringDataFactory::toString ( std::get < 1 > ( transition.first ) ); - - symbol += " |"; - - // Pop part - symbol += " " + alib::StringDataFactory::toString ( std::get < 2 > ( transition.first ) ); - symbol += " ->"; - - symbol += " ε"; - - // Insert into map - std::pair < int, int > key ( states.find ( std::get < 0 > ( transition.first ) )->second, states.find ( transition.second )->second ); - std::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key ); - - if ( mapit == transitions.end ( ) ) { - transitions.insert ( std::make_pair ( key, symbol ) ); - } else { - mapit->second += ","; - - size_t pos = mapit->second.find_last_of ( "\n" ); - - if ( pos == std::string::npos ) pos = 0; - - if ( mapit->second.size ( ) - pos > 100 ) - mapit->second += "\n"; - else - mapit->second += " "; - - mapit->second += symbol; - } - } - - for ( const auto & transition : pda.getLocalTransitions ( ) ) { - std::string symbol; - - // input symbol - symbol = alib::StringDataFactory::toString ( transition.first.second ); - - symbol += " |"; - - // Pop part - symbol += " ε"; - symbol += " ->"; - - symbol += " ε"; - - // Insert into map - std::pair < int, int > key ( states.find ( transition.first.first )->second, states.find ( transition.second )->second ); - std::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key ); - - if ( mapit == transitions.end ( ) ) { - transitions.insert ( std::make_pair ( key, symbol ) ); - } else { - mapit->second += ","; - - size_t pos = mapit->second.find_last_of ( "\n" ); - - if ( pos == std::string::npos ) pos = 0; - - if ( mapit->second.size ( ) - pos > 100 ) - mapit->second += "\n"; - else - mapit->second += " "; - - mapit->second += symbol; - } - } - - out << "\\path[->]"; - - // print the map - for ( std::pair < const std::pair < int, int >, std::string > & transition : transitions ) { - replace ( transition.second, "\n", "\\n" ); - - out << "(" << transition.first.first << ") edge [left] node [align=center] "; - out << "{$" << transition.second << "$}"; - out << "(" << transition.first.second << ")\n"; - } -} - -void TikZConverter::transitions ( const automaton::VisiblyPushdownNPDA < > & pda, const std::map < label::Label, int > & states, std::ostream & out ) { - std::map < std::pair < int, int >, std::string > transitions; - - for ( const auto & transition : pda.getCallTransitions ( ) ) { - std::string symbol; - - // input symbol - symbol = alib::StringDataFactory::toString ( transition.first.second ); - - symbol += " |"; - - // Pop part - symbol += " ε"; - symbol += " ->"; - - std::string symbol2; - - for ( const auto & to : transition.second ) { - symbol2 = symbol; - symbol2 += " " + alib::StringDataFactory::toString ( to.second ); - - // Insert into map - std::pair < int, int > key ( states.find ( transition.first.first )->second, states.find ( to.first )->second ); - std::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key ); - - if ( mapit == transitions.end ( ) ) { - transitions.insert ( std::make_pair ( key, symbol2 ) ); - } else { - mapit->second += ","; - - size_t pos = mapit->second.find_last_of ( "\n" ); - - if ( pos == std::string::npos ) pos = 0; - - if ( mapit->second.size ( ) - pos > 100 ) - mapit->second += "\n"; - else - mapit->second += " "; - - mapit->second += symbol2; - } - } - } - - for ( const auto & transition : pda.getReturnTransitions ( ) ) { - std::string symbol; - - // input symbol - symbol = alib::StringDataFactory::toString ( std::get < 1 > ( transition.first ) ); - - symbol += " |"; - - // Pop part - symbol += " " + alib::StringDataFactory::toString ( std::get < 2 > ( transition.first ) ); - symbol += " ->"; - - std::string symbol2; - - for ( const auto & to : transition.second ) { - symbol2 = symbol; - symbol2 += " ε"; - - // Insert into map - std::pair < int, int > key ( states.find ( std::get < 0 > ( transition.first ) )->second, states.find ( to )->second ); - std::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key ); - - if ( mapit == transitions.end ( ) ) { - transitions.insert ( std::make_pair ( key, symbol2 ) ); - } else { - mapit->second += ","; - - size_t pos = mapit->second.find_last_of ( "\n" ); - - if ( pos == std::string::npos ) pos = 0; - - if ( mapit->second.size ( ) - pos > 100 ) - mapit->second += "\n"; - else - mapit->second += " "; - - mapit->second += symbol2; - } - } - } - - for ( const auto & transition : pda.getLocalTransitions ( ) ) { - std::string symbol; - - // input symbol - symbol = alib::StringDataFactory::toString ( transition.first.second ); - - symbol += " |"; - - // Pop part - symbol += " ε"; - symbol += " ->"; - - std::string symbol2; - - for ( const auto & to : transition.second ) { - symbol2 = symbol; - symbol2 += " ε"; - - // Insert into map - std::pair < int, int > key ( states.find ( transition.first.first )->second, states.find ( to )->second ); - std::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key ); - - if ( mapit == transitions.end ( ) ) { - transitions.insert ( std::make_pair ( key, symbol2 ) ); - } else { - mapit->second += ","; - - size_t pos = mapit->second.find_last_of ( "\n" ); - - if ( pos == std::string::npos ) pos = 0; - - if ( mapit->second.size ( ) - pos > 100 ) - mapit->second += "\n"; - else - mapit->second += " "; - - mapit->second += symbol2; - } - } - } - - out << "\\path[->]"; - - // print the map - for ( std::pair < const std::pair < int, int >, std::string > & transition : transitions ) { - replace ( transition.second, "\n", "\\n" ); - - out << "(" << transition.first.first << ") edge [left] node [align=center] "; - out << "{$" << transition.second << "$}"; - out << "(" << transition.first.second << ")\n"; - } -} - -void TikZConverter::transitions ( const automaton::RealTimeHeightDeterministicDPDA < > & pda, const std::map < label::Label, int > & states, std::ostream & out ) { - std::map < std::pair < int, int >, std::string > transitions; - - for ( const auto & transition : pda.getCallTransitions ( ) ) { - std::string symbol; - - // input symbol - if ( transition.first.second.is < string::Epsilon < > > ( ) ) - symbol = "&epsilon"; - else - symbol = alib::StringDataFactory::toString ( transition.first.second.get < alphabet::Symbol > ( ) ); - - symbol += " |"; - - // Pop part - symbol += " ε"; - symbol += " ->"; - - symbol += " " + alib::StringDataFactory::toString ( transition.second.second ); - - // Insert into map - std::pair < int, int > key ( states.find ( transition.first.first )->second, states.find ( transition.second.first )->second ); - std::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key ); - - if ( mapit == transitions.end ( ) ) { - transitions.insert ( std::make_pair ( key, symbol ) ); - } else { - mapit->second += ","; - - size_t pos = mapit->second.find_last_of ( "\n" ); - - if ( pos == std::string::npos ) pos = 0; - - if ( mapit->second.size ( ) - pos > 100 ) - mapit->second += "\n"; - else - mapit->second += " "; - - mapit->second += symbol; - } - } - - for ( const auto & transition : pda.getReturnTransitions ( ) ) { - std::string symbol; - - // input symbol - if ( std::get < 1 > ( transition.first ).is < string::Epsilon < > > ( ) ) - symbol = "&epsilon"; - else - symbol = alib::StringDataFactory::toString ( std::get < 1 > ( transition.first ).get < alphabet::Symbol > ( ) ); - - symbol += " |"; - - // Pop part - symbol += " " + alib::StringDataFactory::toString ( std::get < 2 > ( transition.first ) ); - symbol += " ->"; - - symbol += " ε"; - - // Insert into map - std::pair < int, int > key ( states.find ( std::get < 0 > ( transition.first ) )->second, states.find ( transition.second )->second ); - std::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key ); - - if ( mapit == transitions.end ( ) ) { - transitions.insert ( std::make_pair ( key, symbol ) ); - } else { - mapit->second += ","; - - size_t pos = mapit->second.find_last_of ( "\n" ); - - if ( pos == std::string::npos ) pos = 0; - - if ( mapit->second.size ( ) - pos > 100 ) - mapit->second += "\n"; - else - mapit->second += " "; - - mapit->second += symbol; - } - } - - for ( const auto & transition : pda.getLocalTransitions ( ) ) { - std::string symbol; - - // input symbol - if ( transition.first.second.is < string::Epsilon < > > ( ) ) - symbol = "&epsilon"; - else - symbol = alib::StringDataFactory::toString ( transition.first.second.get < alphabet::Symbol > ( ) ); - - symbol += " |"; - - // Pop part - symbol += " ε"; - symbol += " ->"; - - symbol += " ε"; - - // Insert into map - std::pair < int, int > key ( states.find ( transition.first.first )->second, states.find ( transition.second )->second ); - std::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key ); - - if ( mapit == transitions.end ( ) ) { - transitions.insert ( std::make_pair ( key, symbol ) ); - } else { - mapit->second += ","; - - size_t pos = mapit->second.find_last_of ( "\n" ); - - if ( pos == std::string::npos ) pos = 0; - - if ( mapit->second.size ( ) - pos > 100 ) - mapit->second += "\n"; - else - mapit->second += " "; - - mapit->second += symbol; - } - } - - out << "\\path[->]"; - - // print the map - for ( std::pair < const std::pair < int, int >, std::string > & transition : transitions ) { - replace ( transition.second, "\n", "\\n" ); - - out << "(" << transition.first.first << ") edge [left] node [align=center] "; - out << "{$" << transition.second << "$}"; - out << "(" << transition.first.second << ")\n"; - } -} - -void TikZConverter::transitions ( const automaton::RealTimeHeightDeterministicNPDA < > & pda, const std::map < label::Label, int > & states, std::ostream & out ) { - std::map < std::pair < int, int >, std::string > transitions; - - for ( const auto & transition : pda.getCallTransitions ( ) ) { - std::string symbol; - - // input symbol - if ( transition.first.second.is < string::Epsilon < > > ( ) ) - symbol = "&epsilon"; - else - symbol = alib::StringDataFactory::toString ( transition.first.second.get < alphabet::Symbol > ( ) ); - - symbol += " |"; - - // Pop part - symbol += " ε"; - symbol += " ->"; - - std::string symbol2; - - for ( const auto & to : transition.second ) { - symbol2 = symbol; - symbol2 += " " + alib::StringDataFactory::toString ( to.second ); - - // Insert into map - std::pair < int, int > key ( states.find ( transition.first.first )->second, states.find ( to.first )->second ); - std::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key ); - - if ( mapit == transitions.end ( ) ) { - transitions.insert ( std::make_pair ( key, symbol2 ) ); - } else { - mapit->second += ","; - - size_t pos = mapit->second.find_last_of ( "\n" ); - - if ( pos == std::string::npos ) pos = 0; - - if ( mapit->second.size ( ) - pos > 100 ) - mapit->second += "\n"; - else - mapit->second += " "; - - mapit->second += symbol2; - } - } - } - - for ( const auto & transition : pda.getReturnTransitions ( ) ) { - std::string symbol; - - // input symbol - if ( std::get < 1 > ( transition.first ).is < string::Epsilon < > > ( ) ) - symbol = "ε"; - else - symbol = alib::StringDataFactory::toString ( std::get < 1 > ( transition.first ).get < alphabet::Symbol > ( ) ); - - symbol += " |"; - - // Pop part - symbol += " " + alib::StringDataFactory::toString ( std::get < 2 > ( transition.first ) ); - symbol += " ->"; - - std::string symbol2; - - for ( const auto & to : transition.second ) { - symbol2 = symbol; - symbol2 += " ε"; - - // Insert into map - std::pair < int, int > key ( states.find ( std::get < 0 > ( transition.first ) )->second, states.find ( to )->second ); - std::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key ); - - if ( mapit == transitions.end ( ) ) { - transitions.insert ( std::make_pair ( key, symbol2 ) ); - } else { - mapit->second += ","; - - size_t pos = mapit->second.find_last_of ( "\n" ); - - if ( pos == std::string::npos ) pos = 0; - - if ( mapit->second.size ( ) - pos > 100 ) - mapit->second += "\n"; - else - mapit->second += " "; - - mapit->second += symbol2; - } - } - } - - for ( const auto & transition : pda.getLocalTransitions ( ) ) { - std::string symbol; - - // input symbol - if ( transition.first.second.is < string::Epsilon < > > ( ) ) - symbol = "ε"; - else - symbol = alib::StringDataFactory::toString ( transition.first.second.get < alphabet::Symbol > ( ) ); - - symbol += " |"; - - // Pop part - symbol += " ε"; - symbol += " ->"; - - std::string symbol2; - - for ( const auto & to : transition.second ) { - symbol2 = symbol; - symbol2 += " ε"; - - // Insert into map - std::pair < int, int > key ( states.find ( transition.first.first )->second, states.find ( to )->second ); - std::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key ); - - if ( mapit == transitions.end ( ) ) { - transitions.insert ( std::make_pair ( key, symbol2 ) ); - } else { - mapit->second += ","; - - size_t pos = mapit->second.find_last_of ( "\n" ); - - if ( pos == std::string::npos ) pos = 0; - - if ( mapit->second.size ( ) - pos > 100 ) - mapit->second += "\n"; - else - mapit->second += " "; - - mapit->second += symbol2; - } - } - } - - out << "\\path[->]"; - - // print the map - for ( std::pair < const std::pair < int, int >, std::string > & transition : transitions ) { - replace ( transition.second, "\n", "\\n" ); - - out << "(" << transition.first.first << ") edge [left] node [align=center] "; - out << "{$" << transition.second << "$}"; - out << "(" << transition.first.second << ")\n"; - } -} - -void TikZConverter::transitions ( const automaton::NPDA < > & pda, const std::map < label::Label, int > & states, std::ostream & out ) { - std::map < std::pair < int, int >, std::string > transitions; - - for ( const auto & transition : pda.getTransitions ( ) ) { - std::string symbol; - - // input symbol - if ( std::get < 1 > ( transition.first ).is < string::Epsilon < > > ( ) ) - symbol = "ε"; - else - symbol = alib::StringDataFactory::toString ( std::get < 1 > ( transition.first ).get < alphabet::Symbol > ( ) ); - - symbol += " |"; - - // Pop part - if ( std::get < 2 > ( transition.first ).size ( ) == 0 ) - symbol += " ε"; - else - for ( alphabet::Symbol symb : std::get < 2 > ( transition.first ) ) - symbol += " " + alib::StringDataFactory::toString ( symb ); - - symbol += " ->"; - - std::string symbol2; - - for ( const auto & to : transition.second ) { - symbol2 = symbol; - - // Push part - if ( to.second.size ( ) == 0 ) - symbol2 += " ε"; - else - for ( alphabet::Symbol symb : to.second ) - symbol2 += " " + alib::StringDataFactory::toString ( symb ); - - // Insert into map - std::pair < int, int > key ( states.find ( std::get < 0 > ( transition.first ) )->second, states.find ( to.first )->second ); - std::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key ); - - if ( mapit == transitions.end ( ) ) { - transitions.insert ( std::make_pair ( key, symbol2 ) ); - } else { - mapit->second += ","; - - size_t pos = mapit->second.find_last_of ( "\n" ); - - if ( pos == std::string::npos ) pos = 0; - - if ( mapit->second.size ( ) - pos > 100 ) - mapit->second += "\n"; - else - mapit->second += " "; - - mapit->second += symbol2; - } - } - } - - out << "\\path[->]"; - - // print the map - for ( std::pair < const std::pair < int, int >, std::string > & transition : transitions ) { - replace ( transition.second, "\n", "\\n" ); - - out << "(" << transition.first.first << ") edge [left] node [align=center] "; - out << "{$" << transition.second << "$}"; - out << "(" << transition.first.second << ")\n"; - } -} - -void TikZConverter::transitions ( const automaton::SinglePopNPDA < > & pda, const std::map < label::Label, int > & states, std::ostream & out ) { - std::map < std::pair < int, int >, std::string > transitions; - - for ( const auto & transition : pda.getTransitions ( ) ) { - std::string symbol; - - // input symbol - if ( std::get < 1 > ( transition.first ).is < string::Epsilon < > > ( ) ) - symbol = "ε"; - else - symbol = alib::StringDataFactory::toString ( std::get < 1 > ( transition.first ).get < alphabet::Symbol > ( ) ); - - symbol += " |"; - - // Pop part - symbol += " " + alib::StringDataFactory::toString ( std::get < 2 > ( transition.first ) ); - - symbol += " ->"; - - std::string symbol2; - - for ( const auto & to : transition.second ) { - symbol2 = symbol; - - // Push part - if ( to.second.size ( ) == 0 ) - symbol2 += " ε"; - else - for ( alphabet::Symbol symb : to.second ) - symbol2 += " " + alib::StringDataFactory::toString ( symb ); - - // Insert into map - std::pair < int, int > key ( states.find ( std::get < 0 > ( transition.first ) )->second, states.find ( to.first )->second ); - std::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key ); - - if ( mapit == transitions.end ( ) ) { - transitions.insert ( std::make_pair ( key, symbol2 ) ); - } else { - mapit->second += ","; - - size_t pos = mapit->second.find_last_of ( "\n" ); - - if ( pos == std::string::npos ) pos = 0; - - if ( mapit->second.size ( ) - pos > 100 ) - mapit->second += "\n"; - else - mapit->second += " "; - - mapit->second += symbol2; - } - } - } - - out << "\\path[->]"; - - // print the map - for ( std::pair < const std::pair < int, int >, std::string > & transition : transitions ) { - replace ( transition.second, "\n", "\\n" ); - - out << "(" << transition.first.first << ") edge [left] node [align=center] "; - out << "{$" << transition.second << "$}"; - out << "(" << transition.first.second << ")\n"; - } -} - -void TikZConverter::transitions ( const automaton::OneTapeDTM < > & tm, const std::map < label::Label, int > & states, std::ostream & out ) { - std::map < std::pair < int, int >, std::string > transitions; - - for ( const auto & transition : tm.getTransitions ( ) ) { - std::string symbol; - - // input symbol - symbol = "("; - symbol += alib::StringDataFactory::toString ( transition.first.second ); - symbol += ", "; - symbol += alib::StringDataFactory::toString ( std::get < 1 > ( transition.second ) ); - symbol += " "; - - switch ( std::get < 2 > ( transition.second ) ) { - case automaton::Shift::LEFT: - symbol += "←"; - break; - - case automaton::Shift::RIGHT: - symbol += "→"; - break; - - case automaton::Shift::NONE: - symbol += "×"; - break; - - default: - throw exception::CommonException ( "Unexpected shift direction" ); - } - - // Insert into map - std::pair < int, int > key ( states.find ( transition.first.first )->second, states.find ( std::get < 0 > ( transition.second ) )->second ); - std::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key ); - - if ( mapit == transitions.end ( ) ) { - transitions.insert ( std::make_pair ( key, symbol ) ); - } else { - mapit->second += ","; - - size_t pos = mapit->second.find_last_of ( "\n" ); - - if ( pos == std::string::npos ) pos = 0; - - if ( mapit->second.size ( ) - pos > 100 ) - mapit->second += "\n"; - else - mapit->second += " "; - - mapit->second += symbol; - } - } - - out << "\\path[->]"; - - // print the map - for ( std::pair < const std::pair < int, int >, std::string > & transition : transitions ) { - replace ( transition.second, "\n", "\\n" ); - - out << "(" << transition.first.first << ") edge [left] node [align=center] "; - out << "{$" << transition.second << "$}"; - out << "(" << transition.first.second << ")\n"; - } -} diff --git a/aconvert2/src/TikZConverter.h b/aconvert2/src/TikZConverter.h index f63decadb2..3dfe411827 100644 --- a/aconvert2/src/TikZConverter.h +++ b/aconvert2/src/TikZConverter.h @@ -9,60 +9,2079 @@ #define TIKZ_CONVERTER_H_ #include <ostream> +#include <set> +#include <list> +#include <vector> +#include <typeinfo> +#include <map> +#include <utility> + #include <core/multipleDispatch.hpp> +#include <exception/CommonException.h> #include <automaton/Automaton.h> #include <automaton/AutomatonFeatures.h> -#include <label/Label.h> +#include <string/String.h> -#include <map> -#include <utility> +#include <automaton/FSM/NFA.h> +#include <automaton/FSM/EpsilonNFA.h> +#include <automaton/FSM/MultiInitialStateNFA.h> +#include <automaton/FSM/DFA.h> +#include <automaton/FSM/ExtendedNFA.h> +#include <automaton/FSM/CompactNFA.h> +#include <automaton/TA/NFTA.h> +#include <automaton/TA/DFTA.h> +#include <automaton/PDA/NPDA.h> +#include <automaton/PDA/SinglePopNPDA.h> +#include <automaton/PDA/InputDrivenDPDA.h> +#include <automaton/PDA/InputDrivenNPDA.h> +#include <automaton/PDA/VisiblyPushdownDPDA.h> +#include <automaton/PDA/VisiblyPushdownNPDA.h> +#include <automaton/PDA/RealTimeHeightDeterministicDPDA.h> +#include <automaton/PDA/RealTimeHeightDeterministicNPDA.h> +#include <automaton/PDA/DPDA.h> +#include <automaton/PDA/SinglePopDPDA.h> +#include <automaton/TM/OneTapeDTM.h> + +#include <factory/StringDataFactory.hpp> + +#include "common/converterCommon.hpp" class TikZConverter : public std::SingleDispatchFirstStaticParam < TikZConverter, void, std::ostream &, const automaton::AutomatonBase & > { - static void transitions ( const automaton::EpsilonNFA < > & fsm, const std::map < label::Label, int > & states, std::ostream & out ); - static void transitions ( const automaton::MultiInitialStateNFA < > & fsm, const std::map < label::Label, int > & states, std::ostream & out ); - static void transitions ( const automaton::NFA < > & fsm, const std::map < label::Label, int > & states, std::ostream & out ); - static void transitions ( const automaton::DFA<> & fsm, const std::map < label::Label, int > & states, std::ostream & out ); - static void transitions ( const automaton::ExtendedNFA < > & fsm, const std::map < label::Label, int > & states, std::ostream & out ); - static void transitions ( const automaton::CompactNFA < > & fsm, const std::map < label::Label, int > & states, std::ostream & out ); - static void transitions ( const automaton::NFTA < > & fsm, const std::map < label::Label, int > & states, std::ostream & out ); - static void transitions ( const automaton::DFTA < > & fsm, const std::map < label::Label, int > & states, std::ostream & out ); - static void transitions ( const automaton::DPDA < > & pda, const std::map < label::Label, int > & states, std::ostream & out ); - static void transitions ( const automaton::SinglePopDPDA < > & tm, const std::map < label::Label, int > & states, std::ostream & out ); - static void transitions ( const automaton::InputDrivenDPDA < > & pda, const std::map < label::Label, int > & states, std::ostream & out ); - static void transitions ( const automaton::InputDrivenNPDA < > & pda, const std::map < label::Label, int > & states, std::ostream & out ); - static void transitions ( const automaton::VisiblyPushdownDPDA < > & tm, const std::map < label::Label, int > & states, std::ostream & out ); - static void transitions ( const automaton::VisiblyPushdownNPDA < > & tm, const std::map < label::Label, int > & states, std::ostream & out ); - static void transitions ( const automaton::RealTimeHeightDeterministicDPDA < > & tm, const std::map < label::Label, int > & states, std::ostream & out ); - static void transitions ( const automaton::RealTimeHeightDeterministicNPDA < > & tm, const std::map < label::Label, int > & states, std::ostream & out ); - static void transitions ( const automaton::NPDA < > & pda, const std::map < label::Label, int > & states, std::ostream & out ); - static void transitions ( const automaton::SinglePopNPDA < > & tm, const std::map < label::Label, int > & states, std::ostream & out ); - static void transitions ( const automaton::OneTapeDTM < > & tm, const std::map < label::Label, int > & states, std::ostream & out ); + template < class SymbolType, class StateType > + static void transitions(const automaton::DFA < SymbolType, StateType > & fsm, const std::map < StateType, int > & states, std::ostream & out); + + template < class SymbolType, class StateType > + static void transitions(const automaton::NFA < SymbolType, StateType > & fsm, const std::map < StateType, int > & states, std::ostream & out); + + template < class SymbolType, class StateType > + static void transitions(const automaton::MultiInitialStateNFA < SymbolType, StateType > & fsm, const std::map < StateType, int > & states, std::ostream & out); + + template < class SymbolType, class EpsilonType, class StateType > + static void transitions(const automaton::EpsilonNFA < SymbolType, EpsilonType, StateType > & fsm, const std::map < StateType, int > & states, std::ostream & out); + + template < class SymbolType, class StateType > + static void transitions(const automaton::ExtendedNFA < SymbolType, StateType > & fsm, const std::map < StateType, int > & states, std::ostream & out); + + template < class SymbolType, class StateType > + static void transitions(const automaton::CompactNFA < SymbolType, StateType > & fsm, const std::map < StateType, int > & states, std::ostream & out); + + template < class SymbolType, class RankType, class StateType > + static void transitions(const automaton::NFTA < SymbolType, RankType, StateType > & fsm, const std::map < StateType, int > & states, std::ostream & out); + + template < class SymbolType, class RankType, class StateType > + static void transitions(const automaton::DFTA < SymbolType, RankType, StateType > & fsm, const std::map < StateType, int > & states, std::ostream & out); + + template < class SymbolType, class EpsilonType, class StateType > + static void transitions(const automaton::DPDA < SymbolType, EpsilonType, StateType > & pda, const std::map < StateType, int > & states, std::ostream & out); + + template < class SymbolType, class EpsilonType, class StateType > + static void transitions(const automaton::NPDA < SymbolType, EpsilonType, StateType > & pda, const std::map < StateType, int > & states, std::ostream & out); + template < class SymbolType, class EpsilonType, class StateType > + static void transitions(const automaton::SinglePopDPDA < SymbolType, EpsilonType, StateType > & tm, const std::map < StateType, int > & states, std::ostream & out); + + template < class SymbolType, class EpsilonType, class StateType > + static void transitions(const automaton::SinglePopNPDA < SymbolType, EpsilonType, StateType > & tm, const std::map < StateType, int > & states, std::ostream & out); + + template < class SymbolType, class StateType > + static void transitions(const automaton::InputDrivenDPDA < SymbolType, StateType > & pda, const std::map < StateType, int > & states, std::ostream & out); + + template < class SymbolType, class StateType > + static void transitions(const automaton::InputDrivenNPDA < SymbolType, StateType > & pda, const std::map < StateType, int > & states, std::ostream & out); + + template < class SymbolType, class StateType > + static void transitions(const automaton::VisiblyPushdownDPDA < SymbolType, StateType > & tm, const std::map < StateType, int > & states, std::ostream & out); + + template < class SymbolType, class StateType > + static void transitions(const automaton::VisiblyPushdownNPDA < SymbolType, StateType > & tm, const std::map < StateType, int > & states, std::ostream & out); + + template < class SymbolType, class EpsilonType, class StateType > + static void transitions(const automaton::RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType > & tm, const std::map < StateType, int > & states, std::ostream & out); + + template < class SymbolType, class EpsilonType, class StateType > + static void transitions(const automaton::RealTimeHeightDeterministicNPDA < SymbolType, EpsilonType, StateType > & tm, const std::map < StateType, int > & states, std::ostream & out); + + template < class SymbolType, class StateType > + static void transitions(const automaton::OneTapeDTM < SymbolType, StateType > & tm, const std::map < StateType, int > & states, std::ostream & out); public: static void convert ( std::ostream & out, const automaton::Automaton & a ); - static void convert ( std::ostream & out, const automaton::EpsilonNFA < > & a ); - static void convert ( std::ostream & out, const automaton::MultiInitialStateNFA < > & a ); - static void convert ( std::ostream & out, const automaton::NFA < > & a ); - static void convert ( std::ostream & out, const automaton::DFA<> & a ); - static void convert ( std::ostream & out, const automaton::ExtendedNFA < > & a ); - static void convert ( std::ostream & out, const automaton::CompactNFA < > & a ); - static void convert ( std::ostream & out, const automaton::NFTA < > & a ); - static void convert ( std::ostream & out, const automaton::DFTA < > & a ); - static void convert ( std::ostream & out, const automaton::DPDA < > & a ); - static void convert ( std::ostream & out, const automaton::SinglePopDPDA < > & a ); - static void convert ( std::ostream & out, const automaton::InputDrivenDPDA < > & a ); - static void convert ( std::ostream & out, const automaton::InputDrivenNPDA < > & a ); - static void convert ( std::ostream & out, const automaton::VisiblyPushdownDPDA < > & a ); - static void convert ( std::ostream & out, const automaton::VisiblyPushdownNPDA < > & a ); - static void convert ( std::ostream & out, const automaton::RealTimeHeightDeterministicDPDA < > & a ); - static void convert ( std::ostream & out, const automaton::RealTimeHeightDeterministicNPDA < > & a ); - static void convert ( std::ostream & out, const automaton::NPDA < > & a ); - static void convert ( std::ostream & out, const automaton::SinglePopNPDA < > & a ); - static void convert ( std::ostream & out, const automaton::OneTapeDTM < > & a ); + template < class SymbolType, class StateType > + static void convert(std::ostream& out, const automaton::DFA < SymbolType, StateType > & a); + + template < class SymbolType, class StateType > + static void convert(std::ostream& out, const automaton::NFA < SymbolType, StateType > & a); + + template < class SymbolType, class StateType > + static void convert(std::ostream& out, const automaton::MultiInitialStateNFA < SymbolType, StateType >& a); + + template < class SymbolType, class EpsilonType, class StateType > + static void convert(std::ostream& out, const automaton::EpsilonNFA < SymbolType, EpsilonType, StateType > & a); + + template < class SymbolType, class StateType > + static void convert(std::ostream& out, const automaton::ExtendedNFA < SymbolType, StateType > & a); + + template < class SymbolType, class StateType > + static void convert(std::ostream& out, const automaton::CompactNFA < SymbolType, StateType > & a); + + template < class SymbolType, class RankType, class StateType > + static void convert(std::ostream& out, const automaton::NFTA < SymbolType, RankType, StateType > & a); + + template < class SymbolType, class RankType, class StateType > + static void convert(std::ostream& out, const automaton::DFTA < SymbolType, RankType, StateType > & a); + + template < class SymbolType, class EpsilonType, class StateType > + static void convert(std::ostream& out, const automaton::DPDA < SymbolType, EpsilonType, StateType > & a); + template < class SymbolType, class EpsilonType, class StateType > + static void convert(std::ostream& out, const automaton::NPDA < SymbolType, EpsilonType, StateType > & a); + + template < class SymbolType, class EpsilonType, class StateType > + static void convert(std::ostream& out, const automaton::SinglePopDPDA < SymbolType, EpsilonType, StateType > & a); + + template < class SymbolType, class EpsilonType, class StateType > + static void convert(std::ostream& out, const automaton::SinglePopNPDA < SymbolType, EpsilonType, StateType > & a); + + template < class SymbolType, class StateType > + static void convert(std::ostream& out, const automaton::InputDrivenDPDA < SymbolType, StateType > & a); + + template < class SymbolType, class StateType > + static void convert(std::ostream& out, const automaton::InputDrivenNPDA < SymbolType, StateType > & a); + + template < class SymbolType, class StateType > + static void convert(std::ostream& out, const automaton::VisiblyPushdownDPDA < SymbolType, StateType > & a); + + template < class SymbolType, class StateType > + static void convert(std::ostream& out, const automaton::VisiblyPushdownNPDA < SymbolType, StateType > & a); + + template < class SymbolType, class EpsilonType, class StateType > + static void convert(std::ostream& out, const automaton::RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType > & a); + + template < class SymbolType, class EpsilonType, class StateType > + static void convert(std::ostream& out, const automaton::RealTimeHeightDeterministicNPDA < SymbolType, EpsilonType, StateType > & a); + + template < class SymbolType, class StateType > + static void convert(std::ostream& out, const automaton::OneTapeDTM < SymbolType, StateType > & a); }; +template<class SymbolType, class EpsilonType, class StateType> +void TikZConverter::convert ( std::ostream & out, const automaton::EpsilonNFA < SymbolType, EpsilonType, StateType > & a ) { + out << "\\begin{tikzpicture}\n"; + int cnt = 1; + + // Map states to indices + std::map < StateType, int > states; + + for ( const StateType & state : a.getStates ( ) ) + states.insert ( std::make_pair ( state, cnt++ ) ); + + // Print states + for ( const auto & state : states ) { + std::string mods; + + if ( a.getFinalStates ( ).count ( state.first ) ) + mods += ",accepting"; + + if ( a.getInitialState ( ) == state.first ) + mods += ",initial"; + + out << "\\node[state" + mods + "] (" << state.second << ") {" << alib::StringDataFactory::toString ( state.first ) << "}\n"; + } + + transitions ( a, states, out ); + out << "\\end{tikzpicture}"; +} + +template<class SymbolType, class StateType> +void TikZConverter::convert ( std::ostream & out, const automaton::MultiInitialStateNFA < SymbolType, StateType > & a ) { + out << "\\begin{tikzpicture}\n"; + int cnt = 1; + + // Map states to indices + std::map < StateType, int > states; + + for ( const StateType & state : a.getStates ( ) ) + states.insert ( std::make_pair ( state, cnt++ ) ); + + // Print states + for ( const auto & state : states ) { + std::string mods; + + if ( a.getFinalStates ( ).count ( state.first ) ) + mods += ",accepting"; + + if ( a.getInitialStates ( ).count ( state.first ) ) + mods += ",initial"; + + out << "\\node[state" + mods + "] (" << state.second << ") {" << alib::StringDataFactory::toString ( state.first ) << "}\n"; + } + + transitions ( a, states, out ); + out << "\\end{tikzpicture}"; +} + +template<class SymbolType, class StateType> +void TikZConverter::convert ( std::ostream & out, const automaton::NFA < SymbolType, StateType > & a ) { + out << "\\begin{tikzpicture}\n"; + int cnt = 1; + + // Map states to indices + std::map < StateType, int > states; + + for ( const StateType & state : a.getStates ( ) ) + states.insert ( std::make_pair ( state, cnt++ ) ); + + // Print states + for ( const auto & state : states ) { + std::string mods; + + if ( a.getFinalStates ( ).count ( state.first ) ) + mods += ",accepting"; + + if ( a.getInitialState ( ) == state.first ) + mods += ",initial"; + + out << "\\node[state" + mods + "] (" << state.second << ") {" << alib::StringDataFactory::toString ( state.first ) << "}\n"; + } + + transitions ( a, states, out ); + out << "\\end{tikzpicture}"; +} + +template<class SymbolType, class StateType> +void TikZConverter::convert ( std::ostream & out, const automaton::DFA < SymbolType, StateType > & a ) { + out << "\\begin{tikzpicture}\n"; + int cnt = 1; + + // Map states to indices + std::map < StateType, int > states; + + for ( const StateType & state : a.getStates ( ) ) + states.insert ( std::make_pair ( state, cnt++ ) ); + + // Print states + for ( const auto & state : states ) { + std::string mods; + + if ( a.getFinalStates ( ).count ( state.first ) ) + mods += ",accepting"; + + if ( a.getInitialState ( ) == state.first ) + mods += ",initial"; + + out << "\\node[state" + mods + "] (" << state.second << ") {" << alib::StringDataFactory::toString ( state.first ) << "}\n"; + } + + transitions ( a, states, out ); + out << "\\end{tikzpicture}"; +} + +template<class SymbolType, class StateType> +void TikZConverter::convert ( std::ostream & out, const automaton::ExtendedNFA < SymbolType, StateType > & a ) { + out << "\\begin{tikzpicture}\n"; + int cnt = 1; + + // Map states to indices + std::map < StateType, int > states; + + for ( const StateType & state : a.getStates ( ) ) + states.insert ( std::make_pair ( state, cnt++ ) ); + + // Print states + for ( const auto & state : states ) { + std::string mods; + + if ( a.getFinalStates ( ).count ( state.first ) ) + mods += ",accepting"; + + if ( a.getInitialState ( ) == state.first ) + mods += ",initial"; + + out << "\\node[state" + mods + "] (" << state.second << ") {" << alib::StringDataFactory::toString ( state.first ) << "}\n"; + } + + transitions ( a, states, out ); + out << "\\end{tikzpicture}"; +} + +template<class SymbolType, class StateType> +void TikZConverter::convert ( std::ostream & out, const automaton::CompactNFA < SymbolType, StateType > & a ) { + out << "\\begin{tikzpicture}\n"; + int cnt = 1; + + // Map states to indices + std::map < StateType, int > states; + + for ( const StateType & state : a.getStates ( ) ) + states.insert ( std::make_pair ( state, cnt++ ) ); + + // Print states + for ( const auto & state : states ) { + std::string mods; + + if ( a.getFinalStates ( ).count ( state.first ) ) + mods += ",accepting"; + + if ( a.getInitialState ( ) == state.first ) + mods += ",initial"; + + out << "\\node[state" + mods + "] (" << state.second << ") {" << alib::StringDataFactory::toString ( state.first ) << "}\n"; + } + + transitions ( a, states, out ); + out << "\\end{tikzpicture}"; +} + +template<class SymbolType, class RankType, class StateType> +void TikZConverter::convert ( std::ostream & out, const automaton::NFTA < SymbolType, RankType, StateType > & a ) { + out << "\\begin{tikzpicture}\n"; + int cnt = 1; + + // Map states to indices + std::map < StateType, int > states; + + for ( const StateType & state : a.getStates ( ) ) + states.insert ( std::make_pair ( state, cnt++ ) ); + + // Print states + for ( const auto & state : states ) { + std::string mods; + + if ( a.getFinalStates ( ).count ( state.first ) ) + mods += ",accepting"; + + out << "\\node[state" + mods + "] (" << state.second << ") {" << alib::StringDataFactory::toString ( state.first ) << "}\n"; + } + + transitions ( a, states, out ); + out << "\\end{tikzpicture}"; +} + +template<class SymbolType, class RankType, class StateType> +void TikZConverter::convert ( std::ostream & out, const automaton::DFTA < SymbolType, RankType, StateType > & a ) { + out << "\\begin{tikzpicture}\n"; + int cnt = 1; + + // Map states to indices + std::map < StateType, int > states; + + for ( const StateType & state : a.getStates ( ) ) + states.insert ( std::make_pair ( state, cnt++ ) ); + + // Print states + for ( const auto & state : states ) { + std::string mods; + + if ( a.getFinalStates ( ).count ( state.first ) ) + mods += ",accepting"; + + out << "\\node[state" + mods + "] (" << state.second << ") {" << alib::StringDataFactory::toString ( state.first ) << "}\n"; + } + + transitions ( a, states, out ); + out << "\\end{tikzpicture}"; +} + +template<class SymbolType, class EpsilonType, class StateType> +void TikZConverter::convert ( std::ostream & out, const automaton::DPDA < SymbolType, EpsilonType, StateType > & a ) { + out << "\\begin{tikzpicture}\n"; + int cnt = 1; + + // Map states to indices + std::map < StateType, int > states; + + for ( const StateType & state : a.getStates ( ) ) + states.insert ( std::make_pair ( state, cnt++ ) ); + + // Print states + for ( const auto & state : states ) { + std::string mods; + + if ( a.getFinalStates ( ).count ( state.first ) ) + mods += ",accepting"; + + if ( a.getInitialState ( ) == state.first ) + mods += ",initial"; + + out << "\\node[state" + mods + "] (" << state.second << ") {" << alib::StringDataFactory::toString ( state.first ) << "}\n"; + } + + transitions ( a, states, out ); + out << "\\end{tikzpicture}"; +} + +template<class SymbolType, class EpsilonType, class StateType> +void TikZConverter::convert ( std::ostream & out, const automaton::SinglePopDPDA < SymbolType, EpsilonType, StateType > & a ) { + out << "\\begin{tikzpicture}\n"; + int cnt = 1; + + // Map states to indices + std::map < StateType, int > states; + + for ( const StateType & state : a.getStates ( ) ) + states.insert ( std::make_pair ( state, cnt++ ) ); + + // Print states + for ( const auto & state : states ) { + std::string mods; + + if ( a.getFinalStates ( ).count ( state.first ) ) + mods += ",accepting"; + + if ( a.getInitialState ( ) == state.first ) + mods += ",initial"; + + out << "\\node[state" + mods + "] (" << state.second << ") {" << alib::StringDataFactory::toString ( state.first ) << "}\n"; + } + + transitions ( a, states, out ); + out << "\\end{tikzpicture}"; +} + +template<class SymbolType, class StateType> +void TikZConverter::convert ( std::ostream & out, const automaton::InputDrivenDPDA < SymbolType, StateType > & a ) { + out << "\\begin{tikzpicture}\n"; + int cnt = 1; + + // Map states to indices + std::map < StateType, int > states; + + for ( const StateType & state : a.getStates ( ) ) + states.insert ( std::make_pair ( state, cnt++ ) ); + + // Print states + for ( const auto & state : states ) { + std::string mods; + + if ( a.getFinalStates ( ).count ( state.first ) ) + mods += ",accepting"; + + if ( a.getInitialState ( ) == state.first ) + mods += ",initial"; + + out << "\\node[state" + mods + "] (" << state.second << ") {" << alib::StringDataFactory::toString ( state.first ) << "}\n"; + } + + transitions ( a, states, out ); + out << "\\end{tikzpicture}"; +} + +template<class SymbolType, class StateType> +void TikZConverter::convert ( std::ostream & out, const automaton::InputDrivenNPDA < SymbolType, StateType > & a ) { + out << "\\begin{tikzpicture}\n"; + int cnt = 1; + + // Map states to indices + std::map < StateType, int > states; + + for ( const StateType & state : a.getStates ( ) ) + states.insert ( std::make_pair ( state, cnt++ ) ); + + // Print states + for ( const auto & state : states ) { + std::string mods; + + if ( a.getFinalStates ( ).count ( state.first ) ) + mods += ",accepting"; + + if ( a.getInitialState ( ) == state.first ) + mods += ",initial"; + + out << "\\node[state" + mods + "] (" << state.second << ") {" << alib::StringDataFactory::toString ( state.first ) << "}\n"; + } + + transitions ( a, states, out ); + out << "\\end{tikzpicture}"; +} + +template<class SymbolType, class StateType> +void TikZConverter::convert ( std::ostream & out, const automaton::VisiblyPushdownDPDA < SymbolType, StateType > & a ) { + out << "\\begin{tikzpicture}\n"; + int cnt = 1; + + // Map states to indices + std::map < StateType, int > states; + + for ( const StateType & state : a.getStates ( ) ) + states.insert ( std::make_pair ( state, cnt++ ) ); + + // Print states + for ( const auto & state : states ) { + std::string mods; + + if ( a.getFinalStates ( ).count ( state.first ) ) + mods += ",accepting"; + + if ( a.getInitialState ( ) == state.first ) + mods += ",initial"; + + out << "\\node[state" + mods + "] (" << state.second << ") {" << alib::StringDataFactory::toString ( state.first ) << "}\n"; + } + + transitions ( a, states, out ); + out << "\\end{tikzpicture}"; +} + +template<class SymbolType, class StateType> +void TikZConverter::convert ( std::ostream & out, const automaton::VisiblyPushdownNPDA < SymbolType, StateType > & a ) { + out << "\\begin{tikzpicture}\n"; + int cnt = 1; + + // Map states to indices + std::map < StateType, int > states; + + for ( const StateType & state : a.getStates ( ) ) + states.insert ( std::make_pair ( state, cnt++ ) ); + + // Print states + for ( const auto & state : states ) { + std::string mods; + + if ( a.getFinalStates ( ).count ( state.first ) ) + mods += ",accepting"; + + if ( a.getInitialStates ( ).count ( state.first ) ) + mods += ",initial"; + + out << "\\node[state" + mods + "] (" << state.second << ") {" << alib::StringDataFactory::toString ( state.first ) << "}\n"; + } + + transitions ( a, states, out ); + out << "\\end{tikzpicture}"; +} + +template<class SymbolType, class EpsilonType, class StateType> +void TikZConverter::convert ( std::ostream & out, const automaton::RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType > & a ) { + out << "\\begin{tikzpicture}\n"; + int cnt = 1; + + // Map states to indices + std::map < StateType, int > states; + + for ( const StateType & state : a.getStates ( ) ) + states.insert ( std::make_pair ( state, cnt++ ) ); + + // Print states + for ( const auto & state : states ) { + std::string mods; + + if ( a.getFinalStates ( ).count ( state.first ) ) + mods += ",accepting"; + + if ( a.getInitialState ( ) == state.first ) + mods += ",initial"; + + out << "\\node[state" + mods + "] (" << state.second << ") {" << alib::StringDataFactory::toString ( state.first ) << "}\n"; + } + + transitions ( a, states, out ); + out << "\\end{tikzpicture}"; +} + +template<class SymbolType, class EpsilonType, class StateType> +void TikZConverter::convert ( std::ostream & out, const automaton::RealTimeHeightDeterministicNPDA < SymbolType, EpsilonType, StateType > & a ) { + out << "\\begin{tikzpicture}\n"; + int cnt = 1; + + // Map states to indices + std::map < StateType, int > states; + + for ( const StateType & state : a.getStates ( ) ) + states.insert ( std::make_pair ( state, cnt++ ) ); + + // Print states + for ( const auto & state : states ) { + std::string mods; + + if ( a.getFinalStates ( ).count ( state.first ) ) + mods += ",accepting"; + + if ( a.getInitialStates ( ).count ( state.first ) ) + mods += ",initial"; + + out << "\\node[state" + mods + "] (" << state.second << ") {" << alib::StringDataFactory::toString ( state.first ) << "}\n"; + } + + transitions ( a, states, out ); + out << "\\end{tikzpicture}"; +} + +template<class SymbolType, class EpsilonType, class StateType> +void TikZConverter::convert ( std::ostream & out, const automaton::NPDA < SymbolType, EpsilonType, StateType > & a ) { + out << "\\begin{tikzpicture}\n"; + int cnt = 1; + + // Map states to indices + std::map < StateType, int > states; + + for ( const StateType & state : a.getStates ( ) ) + states.insert ( std::make_pair ( state, cnt++ ) ); + + // Print states + for ( const auto & state : states ) { + std::string mods; + + if ( a.getFinalStates ( ).count ( state.first ) ) + mods += ",accepting"; + + if ( a.getInitialState ( ) == state.first ) + mods += ",initial"; + + out << "\\node[state" + mods + "] (" << state.second << ") {" << alib::StringDataFactory::toString ( state.first ) << "}\n"; + } + + transitions ( a, states, out ); + out << "\\end{tikzpicture}"; +} + +template<class SymbolType, class EpsilonType, class StateType> +void TikZConverter::convert ( std::ostream & out, const automaton::SinglePopNPDA < SymbolType, EpsilonType, StateType > & a ) { + out << "\\begin{tikzpicture}\n"; + int cnt = 1; + + // Map states to indices + std::map < StateType, int > states; + + for ( const StateType & state : a.getStates ( ) ) + states.insert ( std::make_pair ( state, cnt++ ) ); + + // Print states + for ( const auto & state : states ) { + std::string mods; + + if ( a.getFinalStates ( ).count ( state.first ) ) + mods += ",accepting"; + + if ( a.getInitialState ( ) == state.first ) + mods += ",initial"; + + out << "\\node[state" + mods + "] (" << state.second << ") {" << alib::StringDataFactory::toString ( state.first ) << "}\n"; + } + + transitions ( a, states, out ); + out << "\\end{tikzpicture}"; +} + +template<class SymbolType, class StateType> +void TikZConverter::convert ( std::ostream & out, const automaton::OneTapeDTM < SymbolType, StateType > & a ) { + out << "\\begin{tikzpicture}\n"; + int cnt = 1; + + // Map states to indices + std::map < StateType, int > states; + + for ( const StateType & state : a.getStates ( ) ) + states.insert ( std::make_pair ( state, cnt++ ) ); + + // Print states + for ( const auto & state : states ) { + std::string mods; + + if ( a.getFinalStates ( ).count ( state.first ) ) + mods += ",accepting"; + + if ( a.getInitialState ( ) == state.first ) + mods += ",initial"; + + out << "\\node[state" + mods + "] (" << state.second << ") {" << alib::StringDataFactory::toString ( state.first ) << "}\n"; + } + + transitions ( a, states, out ); + out << "\\end{tikzpicture}"; +} + +template<class SymbolType, class EpsilonType, class StateType> +void TikZConverter::transitions ( const automaton::EpsilonNFA < SymbolType, EpsilonType, StateType > & fsm, const std::map < StateType, int > & states, std::ostream & out ) { + std::map < std::pair < int, int >, std::string > transitions; + + // put transitions from automaton to "transitions" + for ( const auto & transition : fsm.getTransitions ( ) ) { + std::string symbol; + + if ( transition.first.second.template is < EpsilonType > ( ) ) + symbol = "ε"; + else + symbol = alib::StringDataFactory::toString ( std::get < 1 > ( transition.first ).template get < SymbolType > ( ) ); + + for ( const StateType & to : transition.second ) { + std::pair < int, int > key ( states.find ( transition.first.first )->second, states.find ( to )->second ); + std::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key ); + + if ( mapit == transitions.end ( ) ) { + transitions.insert ( std::make_pair ( key, symbol ) ); + } else { + mapit->second += ","; + + size_t pos = mapit->second.find_last_of ( "\n" ); + + if ( pos == std::string::npos ) pos = 0; + + if ( mapit->second.size ( ) - pos > 100 ) + mapit->second += "\n"; + else + mapit->second += " "; + + mapit->second += symbol; + } + } + } + + out << "\\path[->]"; + + // print the map + for ( std::pair < const std::pair < int, int >, std::string > & transition : transitions ) { + replace ( transition.second, "\n", "\\n" ); + + out << "(" << transition.first.first << ") edge [left] node [align=center] "; + out << "{$" << transition.second << "$}"; + out << "(" << transition.first.second << ")\n"; + } +} + +template<class SymbolType, class StateType> +void TikZConverter::transitions ( const automaton::MultiInitialStateNFA < SymbolType, StateType > & fsm, const std::map < StateType, int > & states, std::ostream & out ) { + std::map < std::pair < int, int >, std::string > transitions; + + // put transitions from automaton to "transitions" + for ( const auto & transition : fsm.getTransitions ( ) ) { + std::string symbol = alib::StringDataFactory::toString ( transition.first.second ); + + for ( const StateType & to : transition.second ) { + std::pair < int, int > key ( states.find ( transition.first.first )->second, states.find ( to )->second ); + std::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key ); + + if ( mapit == transitions.end ( ) ) { + transitions.insert ( std::make_pair ( key, symbol ) ); + } else { + mapit->second += ","; + + size_t pos = mapit->second.find_last_of ( "\n" ); + + if ( pos == std::string::npos ) pos = 0; + + if ( mapit->second.size ( ) - pos > 100 ) + mapit->second += "\n"; + else + mapit->second += " "; + + mapit->second += symbol; + } + } + } + + out << "\\path[->]"; + + // print the map + for ( std::pair < const std::pair < int, int >, std::string > & transition : transitions ) { + replace ( transition.second, "\n", "\\n" ); + + out << "(" << transition.first.first << ") edge [left] node [align=center] "; + out << "{$" << transition.second << "$}"; + out << "(" << transition.first.second << ")\n"; + } +} + +template<class SymbolType, class StateType> +void TikZConverter::transitions ( const automaton::NFA < SymbolType, StateType > & fsm, const std::map < StateType, int > & states, std::ostream & out ) { + std::map < std::pair < int, int >, std::string > transitions; + + // put transitions from automaton to "transitions" + for ( const auto & transition : fsm.getTransitions ( ) ) { + std::string symbol = alib::StringDataFactory::toString ( transition.first.second ); + + for ( const StateType & to : transition.second ) { + std::pair < int, int > key ( states.find ( transition.first.first )->second, states.find ( to )->second ); + std::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key ); + + if ( mapit == transitions.end ( ) ) { + transitions.insert ( std::make_pair ( key, symbol ) ); + } else { + mapit->second += ","; + + size_t pos = mapit->second.find_last_of ( "\n" ); + + if ( pos == std::string::npos ) pos = 0; + + if ( mapit->second.size ( ) - pos > 100 ) + mapit->second += "\n"; + else + mapit->second += " "; + + mapit->second += symbol; + } + } + } + + out << "\\path[->]"; + + // print the map + for ( std::pair < const std::pair < int, int >, std::string > & transition : transitions ) { + replace ( transition.second, "\n", "\\n" ); + + out << "(" << transition.first.first << ") edge [left] node [align=center] "; + out << "{$" << transition.second << "$}"; + out << "(" << transition.first.second << ")\n"; + } +} + +template<class SymbolType, class StateType> +void TikZConverter::transitions ( const automaton::DFA < SymbolType, StateType > & fsm, const std::map < StateType, int > & states, std::ostream & out ) { + std::map < std::pair < int, int >, std::string > transitions; + + // put transitions from automaton to "transitions" + for ( const auto & transition : fsm.getTransitions ( ) ) { + std::string symbol = alib::StringDataFactory::toString ( transition.first.second ); + + std::pair < int, int > key ( states.find ( transition.first.first )->second, states.find ( transition.second )->second ); + std::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key ); + + if ( mapit == transitions.end ( ) ) { + transitions.insert ( std::make_pair ( key, symbol ) ); + } else { + mapit->second += ","; + + size_t pos = mapit->second.find_last_of ( "\n" ); + + if ( pos == std::string::npos ) pos = 0; + + if ( mapit->second.size ( ) - pos > 100 ) + mapit->second += "\n"; + else + mapit->second += " "; + + mapit->second += symbol; + } + } + + out << "\\path[->]"; + + // print the map + for ( std::pair < const std::pair < int, int >, std::string > & transition : transitions ) { + replace ( transition.second, "\n", "\\n" ); + + out << "(" << transition.first.first << ") edge [left] node [align=center] "; + out << "{$" << transition.second << "$}"; + out << "(" << transition.first.second << ")\n"; + } +} + +template<class SymbolType, class StateType> +void TikZConverter::transitions ( const automaton::ExtendedNFA < SymbolType, StateType > & fsm, const std::map < StateType, int > & states, std::ostream & out ) { + std::map < std::pair < int, int >, std::string > transitions; + + // put transitions from automaton to "transitions" + for ( const auto & transition : fsm.getTransitions ( ) ) { + std::string symbol = alib::StringDataFactory::toString ( transition.first.second ); + + for ( const StateType & to : transition.second ) { + std::pair < int, int > key ( states.find ( transition.first.first )->second, states.find ( to )->second ); + std::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key ); + + if ( mapit == transitions.end ( ) ) { + transitions.insert ( std::make_pair ( key, symbol ) ); + } else { + mapit->second += ","; + + size_t pos = mapit->second.find_last_of ( "\n" ); + + if ( pos == std::string::npos ) pos = 0; + + if ( mapit->second.size ( ) - pos > 100 ) + mapit->second += "\n"; + else + mapit->second += " "; + + mapit->second += symbol; + } + } + } + + out << "\\path[->]"; + + // print the map + for ( std::pair < const std::pair < int, int >, std::string > & transition : transitions ) { + replace ( transition.second, "\n", "\\n" ); + + out << "(" << transition.first.first << ") edge [left] node [align=center] "; + out << "{$" << transition.second << "$}"; + out << "(" << transition.first.second << ")\n"; + } +} + +template<class SymbolType, class StateType> +void TikZConverter::transitions ( const automaton::CompactNFA < SymbolType, StateType > & fsm, const std::map < StateType, int > & states, std::ostream & out ) { + std::map < std::pair < int, int >, std::string > transitions; + + // put transitions from automaton to "transitions" + for ( const auto & transition : fsm.getTransitions ( ) ) { + std::string symbol = alib::StringDataFactory::toString ( string::stringFrom ( transition.first.second ) ); + + for ( const StateType & to : transition.second ) { + std::pair < int, int > key ( states.find ( transition.first.first )->second, states.find ( to )->second ); + std::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key ); + + if ( mapit == transitions.end ( ) ) { + transitions.insert ( std::make_pair ( key, symbol ) ); + } else { + mapit->second += ","; + + size_t pos = mapit->second.find_last_of ( "\n" ); + + if ( pos == std::string::npos ) pos = 0; + + if ( mapit->second.size ( ) - pos > 100 ) + mapit->second += "\n"; + else + mapit->second += " "; + + mapit->second += symbol; + } + } + } + + out << "\\path[->]"; + + // print the map + for ( std::pair < const std::pair < int, int >, std::string > & transition : transitions ) { + replace ( transition.second, "\n", "\\n" ); + + out << "(" << transition.first.first << ") edge [left] node [align=center] "; + out << "{$" << transition.second << "$}"; + out << "(" << transition.first.second << ")\n"; + } +} + +template<class SymbolType, class RankType, class StateType> +void TikZConverter::transitions ( const automaton::NFTA < SymbolType, RankType, StateType > & fta, const std::map < StateType, int > & states, std::ostream & out ) { + std::map < std::pair < int, std::vector < int > >, std::string > transitions; + + // put transitions from automaton to "transitions" + for ( const auto & transition : fta.getTransitions ( ) ) { + std::string symbol = alib::StringDataFactory::toString ( transition.first.first.getSymbol ( ) ); + symbol += std::to_string ( transition.first.first.getRank ( ).getData ( ) ); + + for ( const StateType & to : transition.second ) { + std::pair < int, std::vector < int > > key ( states.find ( to )->second, { } ); + + for ( const StateType & state : transition.first.second ) + key.second.push_back ( states.find ( state )->second ); + + std::map < std::pair < int, std::vector < int > >, std::string >::iterator mapit = transitions.find ( key ); + + if ( mapit == transitions.end ( ) ) { + transitions.insert ( std::make_pair ( key, symbol ) ); + } else { + mapit->second += ","; + + size_t pos = mapit->second.find_last_of ( "\n" ); + + if ( pos == std::string::npos ) pos = 0; + + if ( mapit->second.size ( ) - pos > 100 ) + mapit->second += "\n"; + else + mapit->second += " "; + + mapit->second += symbol; + } + } + } + + // Print auxilary dots + for ( unsigned i = 1; i < transitions.size ( ); i++ ) + out << "\\node[draw=none,fill=none] (" << states.size ( ) + i << ") {}\n"; + + out << "\\path[->]"; + + // print the map + unsigned i = states.size ( ) + 1; + + for ( std::pair < const std::pair < int, std::vector < int > >, std::string > & transition : transitions ) { + replace ( transition.second, "\n", "\\n" ); + + out << "(" << i << ") edge [left] node [align=center] "; + out << "{$" << transition.second << "$}"; + out << "(" << transition.first.first << ")\n"; + + unsigned j = 0; + + for ( int from : transition.first.second ) { + out << "(" << from << ") edge [left] node [align=center] "; + out << "{$" << j << "$}"; + out << "(" << i << ")\n"; + + j++; + } + + i++; + } +} + +template<class SymbolType, class RankType, class StateType> +void TikZConverter::transitions ( const automaton::DFTA < SymbolType, RankType, StateType > & fta, const std::map < StateType, int > & states, std::ostream & out ) { + std::map < std::pair < int, std::vector < int > >, std::string > transitions; + + // put transitions from automaton to "transitions" + for ( const auto & transition : fta.getTransitions ( ) ) { + std::string symbol = alib::StringDataFactory::toString ( transition.first.first.getSymbol ( ) ); + symbol += std::to_string ( transition.first.first.getRank ( ).getData ( ) ); + + std::pair < int, std::vector < int > > key ( states.find ( transition.second )->second, { } ); + + for ( const StateType & state : transition.first.second ) + key.second.push_back ( states.find ( state )->second ); + + std::map < std::pair < int, std::vector < int > >, std::string >::iterator mapit = transitions.find ( key ); + + if ( mapit == transitions.end ( ) ) { + transitions.insert ( std::make_pair ( key, symbol ) ); + } else { + mapit->second += ","; + + size_t pos = mapit->second.find_last_of ( "\n" ); + + if ( pos == std::string::npos ) pos = 0; + + if ( mapit->second.size ( ) - pos > 100 ) + mapit->second += "\n"; + else + mapit->second += " "; + + mapit->second += symbol; + } + } + + // Print auxilary dots + for ( unsigned i = 1; i < transitions.size ( ); i++ ) + out << "\\node[draw=none,fill=none] (" << states.size ( ) + i << ") {}\n"; + + out << "\\path[->]"; + + // print the map + unsigned i = states.size ( ) + 1; + + for ( std::pair < const std::pair < int, std::vector < int > >, std::string > & transition : transitions ) { + replace ( transition.second, "\n", "\\n" ); + + out << "(" << i << ") edge [left] node [align=center] "; + out << "{$" << transition.second << "$}"; + out << "(" << transition.first.first << ")\n"; + + unsigned j = 0; + + for ( int from : transition.first.second ) { + out << "(" << from << ") edge [left] node [align=center] "; + out << "{$" << j << "$}"; + out << "(" << i << ")\n"; + + j++; + } + + i++; + } +} + +template<class SymbolType, class EpsilonType, class StateType> +void TikZConverter::transitions ( const automaton::DPDA < SymbolType, EpsilonType, StateType > & pda, const std::map < StateType, int > & states, std::ostream & out ) { + std::map < std::pair < int, int >, std::string > transitions; + + for ( const auto & transition : pda.getTransitions ( ) ) { + std::string symbol; + + // input symbol + if ( std::get < 1 > ( transition.first ).template is < EpsilonType > ( ) ) + symbol = "ε"; + else + symbol = alib::StringDataFactory::toString ( std::get < 1 > ( transition.first ).template get < SymbolType > ( ) ); + + symbol += " |"; + + // Pop part + if ( std::get < 2 > ( transition.first ).size ( ) == 0 ) + symbol += " ε"; + else + for ( SymbolType symb : std::get < 2 > ( transition.first ) ) + symbol += " " + alib::StringDataFactory::toString ( symb ); + + symbol += " ->"; + + // Push part + if ( transition.second.second.size ( ) == 0 ) + symbol += " ε"; + else + for ( SymbolType symb : transition.second.second ) + symbol += " " + alib::StringDataFactory::toString ( symb ); + + // Insert into map + std::pair < int, int > key ( states.find ( std::get < 0 > ( transition.first ) )->second, states.find ( transition.second.first )->second ); + std::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key ); + + if ( mapit == transitions.end ( ) ) { + transitions.insert ( std::make_pair ( key, symbol ) ); + } else { + mapit->second += ","; + + size_t pos = mapit->second.find_last_of ( "\n" ); + + if ( pos == std::string::npos ) pos = 0; + + if ( mapit->second.size ( ) - pos > 100 ) + mapit->second += "\n"; + else + mapit->second += " "; + + mapit->second += symbol; + } + } + + out << "\\path[->]"; + + // print the map + for ( std::pair < const std::pair < int, int >, std::string > & transition : transitions ) { + replace ( transition.second, "\n", "\\n" ); + + out << "(" << transition.first.first << ") edge [left] node [align=center] "; + out << "{$" << transition.second << "$}"; + out << "(" << transition.first.second << ")\n"; + } +} + +template<class SymbolType, class EpsilonType, class StateType> +void TikZConverter::transitions ( const automaton::SinglePopDPDA < SymbolType, EpsilonType, StateType > & pda, const std::map < StateType, int > & states, std::ostream & out ) { + std::map < std::pair < int, int >, std::string > transitions; + + for ( const auto & transition : pda.getTransitions ( ) ) { + std::string symbol; + + // input symbol + if ( std::get < 1 > ( transition.first ).template is < EpsilonType > ( ) ) + symbol = "ε"; + else + symbol = alib::StringDataFactory::toString ( std::get < 1 > ( transition.first ).template get < SymbolType > ( ) ); + + symbol += " |"; + + // Pop part + symbol += " " + alib::StringDataFactory::toString ( std::get < 2 > ( transition.first ) ); + + symbol += " ->"; + + // Push part + if ( transition.second.second.size ( ) == 0 ) + symbol += " ε"; + else + for ( SymbolType symb : transition.second.second ) + symbol += " " + alib::StringDataFactory::toString ( symb ); + + // Insert into map + std::pair < int, int > key ( states.find ( std::get < 0 > ( transition.first ) )->second, states.find ( transition.second.first )->second ); + std::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key ); + + if ( mapit == transitions.end ( ) ) { + transitions.insert ( std::make_pair ( key, symbol ) ); + } else { + mapit->second += ","; + + size_t pos = mapit->second.find_last_of ( "\n" ); + + if ( pos == std::string::npos ) pos = 0; + + if ( mapit->second.size ( ) - pos > 100 ) + mapit->second += "\n"; + else + mapit->second += " "; + + mapit->second += symbol; + } + } + + out << "\\path[->]"; + + // print the map + for ( std::pair < const std::pair < int, int >, std::string > & transition : transitions ) { + replace ( transition.second, "\n", "\\n" ); + + out << "(" << transition.first.first << ") edge [left] node [align=center] "; + out << "{$" << transition.second << "$}"; + out << "(" << transition.first.second << ")\n"; + } +} + +template<class SymbolType, class StateType> +void TikZConverter::transitions ( const automaton::InputDrivenDPDA < SymbolType, StateType > & pda, const std::map < StateType, int > & states, std::ostream & out ) { + std::map < std::pair < int, int >, std::string > transitions; + + const auto & symbolToPDSOperation = pda.getPushdownStoreOperations ( ); + + for ( const auto & transition : pda.getTransitions ( ) ) { + const auto & pop = symbolToPDSOperation.find ( transition.first.second )->second.first; + const auto & push = symbolToPDSOperation.find ( transition.first.second )->second.second; + + // input symbol + std::string symbol = alib::StringDataFactory::toString ( transition.first.second ); + + symbol += " |"; + + // Pop part + if ( pop.size ( ) == 0 ) + symbol += " ε"; + else + for ( SymbolType symb : pop ) + symbol += " " + alib::StringDataFactory::toString ( symb ); + + symbol += " ->"; + + const auto & to = transition.second; + + // Push part + if ( push.size ( ) == 0 ) + symbol += " ε"; + else + for ( SymbolType symb : push ) + symbol += " " + alib::StringDataFactory::toString ( symb ); + + // Insert into map + std::pair < int, int > key ( states.find ( transition.first.first )->second, states.find ( to )->second ); + std::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key ); + + if ( mapit == transitions.end ( ) ) { + transitions.insert ( std::make_pair ( key, symbol ) ); + } else { + mapit->second += ","; + + size_t pos = mapit->second.find_last_of ( "\n" ); + + if ( pos == std::string::npos ) pos = 0; + + if ( mapit->second.size ( ) - pos > 100 ) + mapit->second += "\n"; + else + mapit->second += " "; + + mapit->second += symbol; + } + } + + out << "\\path[->]"; + + // print the map + for ( std::pair < const std::pair < int, int >, std::string > & transition : transitions ) { + replace ( transition.second, "\n", "\\n" ); + + out << "(" << transition.first.first << ") edge [left] node [align=center] "; + out << "{$" << transition.second << "$}"; + out << "(" << transition.first.second << ")\n"; + } +} + +template<class SymbolType, class StateType> +void TikZConverter::transitions ( const automaton::InputDrivenNPDA < SymbolType, StateType > & pda, const std::map < StateType, int > & states, std::ostream & out ) { + std::map < std::pair < int, int >, std::string > transitions; + + const auto & symbolToPDSOperation = pda.getPushdownStoreOperations ( ); + + for ( const auto & transition : pda.getTransitions ( ) ) { + const auto & pop = symbolToPDSOperation.find ( transition.first.second )->second.first; + const auto & push = symbolToPDSOperation.find ( transition.first.second )->second.second; + + // input symbol + std::string symbol = alib::StringDataFactory::toString ( transition.first.second ); + + symbol += " |"; + + // Pop part + if ( pop.size ( ) == 0 ) + symbol += " ε"; + else + for ( SymbolType symb : pop ) + symbol += " " + alib::StringDataFactory::toString ( symb ); + + symbol += " ->"; + + std::string symbol2; + + for ( const auto & to : transition.second ) { + symbol2 = symbol; + + // Push part + if ( push.size ( ) == 0 ) + symbol2 += " ε"; + else + for ( SymbolType symb : push ) + symbol2 += " " + alib::StringDataFactory::toString ( symb ); + + // Insert into map + std::pair < int, int > key ( states.find ( transition.first.first )->second, states.find ( to )->second ); + std::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key ); + + if ( mapit == transitions.end ( ) ) { + transitions.insert ( std::make_pair ( key, symbol2 ) ); + } else { + mapit->second += ","; + + size_t pos = mapit->second.find_last_of ( "\n" ); + + if ( pos == std::string::npos ) pos = 0; + + if ( mapit->second.size ( ) - pos > 100 ) + mapit->second += "\n"; + else + mapit->second += " "; + + mapit->second += symbol2; + } + } + } + + out << "\\path[->]"; + + // print the map + for ( std::pair < const std::pair < int, int >, std::string > & transition : transitions ) { + replace ( transition.second, "\n", "\\n" ); + + out << "(" << transition.first.first << ") edge [left] node [align=center] "; + out << "{$" << transition.second << "$}"; + out << "(" << transition.first.second << ")\n"; + } +} + +template<class SymbolType, class StateType> +void TikZConverter::transitions ( const automaton::VisiblyPushdownDPDA < SymbolType, StateType > & pda, const std::map < StateType, int > & states, std::ostream & out ) { + std::map < std::pair < int, int >, std::string > transitions; + + for ( const auto & transition : pda.getCallTransitions ( ) ) { + // input symbol + std::string symbol = alib::StringDataFactory::toString ( transition.first.second ); + + symbol += " |"; + + // Pop part + symbol += " ε"; + symbol += " ->"; + + symbol += " " + alib::StringDataFactory::toString ( transition.second.second ); + + // Insert into map + std::pair < int, int > key ( states.find ( transition.first.first )->second, states.find ( transition.second.first )->second ); + std::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key ); + + if ( mapit == transitions.end ( ) ) { + transitions.insert ( std::make_pair ( key, symbol ) ); + } else { + mapit->second += ","; + + size_t pos = mapit->second.find_last_of ( "\n" ); + + if ( pos == std::string::npos ) pos = 0; + + if ( mapit->second.size ( ) - pos > 100 ) + mapit->second += "\n"; + else + mapit->second += " "; + + mapit->second += symbol; + } + } + + for ( const auto & transition : pda.getReturnTransitions ( ) ) { + // input symbol + std::string symbol = alib::StringDataFactory::toString ( std::get < 1 > ( transition.first ) ); + + symbol += " |"; + + // Pop part + symbol += " " + alib::StringDataFactory::toString ( std::get < 2 > ( transition.first ) ); + symbol += " ->"; + + symbol += " ε"; + + // Insert into map + std::pair < int, int > key ( states.find ( std::get < 0 > ( transition.first ) )->second, states.find ( transition.second )->second ); + std::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key ); + + if ( mapit == transitions.end ( ) ) { + transitions.insert ( std::make_pair ( key, symbol ) ); + } else { + mapit->second += ","; + + size_t pos = mapit->second.find_last_of ( "\n" ); + + if ( pos == std::string::npos ) pos = 0; + + if ( mapit->second.size ( ) - pos > 100 ) + mapit->second += "\n"; + else + mapit->second += " "; + + mapit->second += symbol; + } + } + + for ( const auto & transition : pda.getLocalTransitions ( ) ) { + // input symbol + std::string symbol = alib::StringDataFactory::toString ( transition.first.second ); + + symbol += " |"; + + // Pop part + symbol += " ε"; + symbol += " ->"; + + symbol += " ε"; + + // Insert into map + std::pair < int, int > key ( states.find ( transition.first.first )->second, states.find ( transition.second )->second ); + std::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key ); + + if ( mapit == transitions.end ( ) ) { + transitions.insert ( std::make_pair ( key, symbol ) ); + } else { + mapit->second += ","; + + size_t pos = mapit->second.find_last_of ( "\n" ); + + if ( pos == std::string::npos ) pos = 0; + + if ( mapit->second.size ( ) - pos > 100 ) + mapit->second += "\n"; + else + mapit->second += " "; + + mapit->second += symbol; + } + } + + out << "\\path[->]"; + + // print the map + for ( std::pair < const std::pair < int, int >, std::string > & transition : transitions ) { + replace ( transition.second, "\n", "\\n" ); + + out << "(" << transition.first.first << ") edge [left] node [align=center] "; + out << "{$" << transition.second << "$}"; + out << "(" << transition.first.second << ")\n"; + } +} + +template<class SymbolType, class StateType> +void TikZConverter::transitions ( const automaton::VisiblyPushdownNPDA < SymbolType, StateType > & pda, const std::map < StateType, int > & states, std::ostream & out ) { + std::map < std::pair < int, int >, std::string > transitions; + + for ( const auto & transition : pda.getCallTransitions ( ) ) { + // input symbol + std::string symbol = alib::StringDataFactory::toString ( transition.first.second ); + + symbol += " |"; + + // Pop part + symbol += " ε"; + symbol += " ->"; + + std::string symbol2; + + for ( const auto & to : transition.second ) { + symbol2 = symbol; + symbol2 += " " + alib::StringDataFactory::toString ( to.second ); + + // Insert into map + std::pair < int, int > key ( states.find ( transition.first.first )->second, states.find ( to.first )->second ); + std::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key ); + + if ( mapit == transitions.end ( ) ) { + transitions.insert ( std::make_pair ( key, symbol2 ) ); + } else { + mapit->second += ","; + + size_t pos = mapit->second.find_last_of ( "\n" ); + + if ( pos == std::string::npos ) pos = 0; + + if ( mapit->second.size ( ) - pos > 100 ) + mapit->second += "\n"; + else + mapit->second += " "; + + mapit->second += symbol2; + } + } + } + + for ( const auto & transition : pda.getReturnTransitions ( ) ) { + // input symbol + std::string symbol = alib::StringDataFactory::toString ( std::get < 1 > ( transition.first ) ); + + symbol += " |"; + + // Pop part + symbol += " " + alib::StringDataFactory::toString ( std::get < 2 > ( transition.first ) ); + symbol += " ->"; + + std::string symbol2; + + for ( const auto & to : transition.second ) { + symbol2 = symbol; + symbol2 += " ε"; + + // Insert into map + std::pair < int, int > key ( states.find ( std::get < 0 > ( transition.first ) )->second, states.find ( to )->second ); + std::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key ); + + if ( mapit == transitions.end ( ) ) { + transitions.insert ( std::make_pair ( key, symbol2 ) ); + } else { + mapit->second += ","; + + size_t pos = mapit->second.find_last_of ( "\n" ); + + if ( pos == std::string::npos ) pos = 0; + + if ( mapit->second.size ( ) - pos > 100 ) + mapit->second += "\n"; + else + mapit->second += " "; + + mapit->second += symbol2; + } + } + } + + for ( const auto & transition : pda.getLocalTransitions ( ) ) { + std::string symbol; + + // input symbol + symbol = alib::StringDataFactory::toString ( transition.first.second ); + + symbol += " |"; + + // Pop part + symbol += " ε"; + symbol += " ->"; + + std::string symbol2; + + for ( const auto & to : transition.second ) { + symbol2 = symbol; + symbol2 += " ε"; + + // Insert into map + std::pair < int, int > key ( states.find ( transition.first.first )->second, states.find ( to )->second ); + std::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key ); + + if ( mapit == transitions.end ( ) ) { + transitions.insert ( std::make_pair ( key, symbol2 ) ); + } else { + mapit->second += ","; + + size_t pos = mapit->second.find_last_of ( "\n" ); + + if ( pos == std::string::npos ) pos = 0; + + if ( mapit->second.size ( ) - pos > 100 ) + mapit->second += "\n"; + else + mapit->second += " "; + + mapit->second += symbol2; + } + } + } + + out << "\\path[->]"; + + // print the map + for ( std::pair < const std::pair < int, int >, std::string > & transition : transitions ) { + replace ( transition.second, "\n", "\\n" ); + + out << "(" << transition.first.first << ") edge [left] node [align=center] "; + out << "{$" << transition.second << "$}"; + out << "(" << transition.first.second << ")\n"; + } +} + +template<class SymbolType, class EpsilonType, class StateType> +void TikZConverter::transitions ( const automaton::RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType > & pda, const std::map < StateType, int > & states, std::ostream & out ) { + std::map < std::pair < int, int >, std::string > transitions; + + for ( const auto & transition : pda.getCallTransitions ( ) ) { + std::string symbol; + + // input symbol + if ( transition.first.second.template is < EpsilonType > ( ) ) + symbol = "&epsilon"; + else + symbol = alib::StringDataFactory::toString ( transition.first.second.template get < SymbolType > ( ) ); + + symbol += " |"; + + // Pop part + symbol += " ε"; + symbol += " ->"; + + symbol += " " + alib::StringDataFactory::toString ( transition.second.second ); + + // Insert into map + std::pair < int, int > key ( states.find ( transition.first.first )->second, states.find ( transition.second.first )->second ); + std::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key ); + + if ( mapit == transitions.end ( ) ) { + transitions.insert ( std::make_pair ( key, symbol ) ); + } else { + mapit->second += ","; + + size_t pos = mapit->second.find_last_of ( "\n" ); + + if ( pos == std::string::npos ) pos = 0; + + if ( mapit->second.size ( ) - pos > 100 ) + mapit->second += "\n"; + else + mapit->second += " "; + + mapit->second += symbol; + } + } + + for ( const auto & transition : pda.getReturnTransitions ( ) ) { + std::string symbol; + + // input symbol + if ( std::get < 1 > ( transition.first ).template is < EpsilonType > ( ) ) + symbol = "&epsilon"; + else + symbol = alib::StringDataFactory::toString ( std::get < 1 > ( transition.first ).template get < SymbolType > ( ) ); + + symbol += " |"; + + // Pop part + symbol += " " + alib::StringDataFactory::toString ( std::get < 2 > ( transition.first ) ); + symbol += " ->"; + + symbol += " ε"; + + // Insert into map + std::pair < int, int > key ( states.find ( std::get < 0 > ( transition.first ) )->second, states.find ( transition.second )->second ); + std::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key ); + + if ( mapit == transitions.end ( ) ) { + transitions.insert ( std::make_pair ( key, symbol ) ); + } else { + mapit->second += ","; + + size_t pos = mapit->second.find_last_of ( "\n" ); + + if ( pos == std::string::npos ) pos = 0; + + if ( mapit->second.size ( ) - pos > 100 ) + mapit->second += "\n"; + else + mapit->second += " "; + + mapit->second += symbol; + } + } + + for ( const auto & transition : pda.getLocalTransitions ( ) ) { + std::string symbol; + + // input symbol + if ( transition.first.second.template is < EpsilonType > ( ) ) + symbol = "&epsilon"; + else + symbol = alib::StringDataFactory::toString ( transition.first.second.template get < SymbolType > ( ) ); + + symbol += " |"; + + // Pop part + symbol += " ε"; + symbol += " ->"; + + symbol += " ε"; + + // Insert into map + std::pair < int, int > key ( states.find ( transition.first.first )->second, states.find ( transition.second )->second ); + std::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key ); + + if ( mapit == transitions.end ( ) ) { + transitions.insert ( std::make_pair ( key, symbol ) ); + } else { + mapit->second += ","; + + size_t pos = mapit->second.find_last_of ( "\n" ); + + if ( pos == std::string::npos ) pos = 0; + + if ( mapit->second.size ( ) - pos > 100 ) + mapit->second += "\n"; + else + mapit->second += " "; + + mapit->second += symbol; + } + } + + out << "\\path[->]"; + + // print the map + for ( std::pair < const std::pair < int, int >, std::string > & transition : transitions ) { + replace ( transition.second, "\n", "\\n" ); + + out << "(" << transition.first.first << ") edge [left] node [align=center] "; + out << "{$" << transition.second << "$}"; + out << "(" << transition.first.second << ")\n"; + } +} + +template<class SymbolType, class EpsilonType, class StateType> +void TikZConverter::transitions ( const automaton::RealTimeHeightDeterministicNPDA < SymbolType, EpsilonType, StateType > & pda, const std::map < StateType, int > & states, std::ostream & out ) { + std::map < std::pair < int, int >, std::string > transitions; + + for ( const auto & transition : pda.getCallTransitions ( ) ) { + std::string symbol; + + // input symbol + if ( transition.first.second.template is < EpsilonType > ( ) ) + symbol = "&epsilon"; + else + symbol = alib::StringDataFactory::toString ( transition.first.second.template get < SymbolType > ( ) ); + + symbol += " |"; + + // Pop part + symbol += " ε"; + symbol += " ->"; + + std::string symbol2; + + for ( const auto & to : transition.second ) { + symbol2 = symbol; + symbol2 += " " + alib::StringDataFactory::toString ( to.second ); + + // Insert into map + std::pair < int, int > key ( states.find ( transition.first.first )->second, states.find ( to.first )->second ); + std::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key ); + + if ( mapit == transitions.end ( ) ) { + transitions.insert ( std::make_pair ( key, symbol2 ) ); + } else { + mapit->second += ","; + + size_t pos = mapit->second.find_last_of ( "\n" ); + + if ( pos == std::string::npos ) pos = 0; + + if ( mapit->second.size ( ) - pos > 100 ) + mapit->second += "\n"; + else + mapit->second += " "; + + mapit->second += symbol2; + } + } + } + + for ( const auto & transition : pda.getReturnTransitions ( ) ) { + std::string symbol; + + // input symbol + if ( std::get < 1 > ( transition.first ).template is < EpsilonType > ( ) ) + symbol = "ε"; + else + symbol = alib::StringDataFactory::toString ( std::get < 1 > ( transition.first ).template get < SymbolType > ( ) ); + + symbol += " |"; + + // Pop part + symbol += " " + alib::StringDataFactory::toString ( std::get < 2 > ( transition.first ) ); + symbol += " ->"; + + std::string symbol2; + + for ( const auto & to : transition.second ) { + symbol2 = symbol; + symbol2 += " ε"; + + // Insert into map + std::pair < int, int > key ( states.find ( std::get < 0 > ( transition.first ) )->second, states.find ( to )->second ); + std::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key ); + + if ( mapit == transitions.end ( ) ) { + transitions.insert ( std::make_pair ( key, symbol2 ) ); + } else { + mapit->second += ","; + + size_t pos = mapit->second.find_last_of ( "\n" ); + + if ( pos == std::string::npos ) pos = 0; + + if ( mapit->second.size ( ) - pos > 100 ) + mapit->second += "\n"; + else + mapit->second += " "; + + mapit->second += symbol2; + } + } + } + + for ( const auto & transition : pda.getLocalTransitions ( ) ) { + std::string symbol; + + // input symbol + if ( transition.first.second.template is < EpsilonType > ( ) ) + symbol = "ε"; + else + symbol = alib::StringDataFactory::toString ( transition.first.second.template get < SymbolType > ( ) ); + + symbol += " |"; + + // Pop part + symbol += " ε"; + symbol += " ->"; + + std::string symbol2; + + for ( const auto & to : transition.second ) { + symbol2 = symbol; + symbol2 += " ε"; + + // Insert into map + std::pair < int, int > key ( states.find ( transition.first.first )->second, states.find ( to )->second ); + std::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key ); + + if ( mapit == transitions.end ( ) ) { + transitions.insert ( std::make_pair ( key, symbol2 ) ); + } else { + mapit->second += ","; + + size_t pos = mapit->second.find_last_of ( "\n" ); + + if ( pos == std::string::npos ) pos = 0; + + if ( mapit->second.size ( ) - pos > 100 ) + mapit->second += "\n"; + else + mapit->second += " "; + + mapit->second += symbol2; + } + } + } + + out << "\\path[->]"; + + // print the map + for ( std::pair < const std::pair < int, int >, std::string > & transition : transitions ) { + replace ( transition.second, "\n", "\\n" ); + + out << "(" << transition.first.first << ") edge [left] node [align=center] "; + out << "{$" << transition.second << "$}"; + out << "(" << transition.first.second << ")\n"; + } +} + +template<class SymbolType, class EpsilonType, class StateType> +void TikZConverter::transitions ( const automaton::NPDA < SymbolType, EpsilonType, StateType > & pda, const std::map < StateType, int > & states, std::ostream & out ) { + std::map < std::pair < int, int >, std::string > transitions; + + for ( const auto & transition : pda.getTransitions ( ) ) { + std::string symbol; + + // input symbol + if ( std::get < 1 > ( transition.first ).template is < EpsilonType > ( ) ) + symbol = "ε"; + else + symbol = alib::StringDataFactory::toString ( std::get < 1 > ( transition.first ).template get < SymbolType > ( ) ); + + symbol += " |"; + + // Pop part + if ( std::get < 2 > ( transition.first ).size ( ) == 0 ) + symbol += " ε"; + else + for ( SymbolType symb : std::get < 2 > ( transition.first ) ) + symbol += " " + alib::StringDataFactory::toString ( symb ); + + symbol += " ->"; + + std::string symbol2; + + for ( const auto & to : transition.second ) { + symbol2 = symbol; + + // Push part + if ( to.second.size ( ) == 0 ) + symbol2 += " ε"; + else + for ( const SymbolType & symb : to.second ) + symbol2 += " " + alib::StringDataFactory::toString ( symb ); + + // Insert into map + std::pair < int, int > key ( states.find ( std::get < 0 > ( transition.first ) )->second, states.find ( to.first )->second ); + std::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key ); + + if ( mapit == transitions.end ( ) ) { + transitions.insert ( std::make_pair ( key, symbol2 ) ); + } else { + mapit->second += ","; + + size_t pos = mapit->second.find_last_of ( "\n" ); + + if ( pos == std::string::npos ) pos = 0; + + if ( mapit->second.size ( ) - pos > 100 ) + mapit->second += "\n"; + else + mapit->second += " "; + + mapit->second += symbol2; + } + } + } + + out << "\\path[->]"; + + // print the map + for ( std::pair < const std::pair < int, int >, std::string > & transition : transitions ) { + replace ( transition.second, "\n", "\\n" ); + + out << "(" << transition.first.first << ") edge [left] node [align=center] "; + out << "{$" << transition.second << "$}"; + out << "(" << transition.first.second << ")\n"; + } +} + +template<class SymbolType, class EpsilonType, class StateType> +void TikZConverter::transitions ( const automaton::SinglePopNPDA < SymbolType, EpsilonType, StateType > & pda, const std::map < StateType, int > & states, std::ostream & out ) { + std::map < std::pair < int, int >, std::string > transitions; + + for ( const auto & transition : pda.getTransitions ( ) ) { + std::string symbol; + + // input symbol + if ( std::get < 1 > ( transition.first ).template is < EpsilonType > ( ) ) + symbol = "ε"; + else + symbol = alib::StringDataFactory::toString ( std::get < 1 > ( transition.first ).template get < SymbolType > ( ) ); + + symbol += " |"; + + // Pop part + symbol += " " + alib::StringDataFactory::toString ( std::get < 2 > ( transition.first ) ); + + symbol += " ->"; + + std::string symbol2; + + for ( const auto & to : transition.second ) { + symbol2 = symbol; + + // Push part + if ( to.second.size ( ) == 0 ) + symbol2 += " ε"; + else + for ( const SymbolType & symb : to.second ) + symbol2 += " " + alib::StringDataFactory::toString ( symb ); + + // Insert into map + std::pair < int, int > key ( states.find ( std::get < 0 > ( transition.first ) )->second, states.find ( to.first )->second ); + std::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key ); + + if ( mapit == transitions.end ( ) ) { + transitions.insert ( std::make_pair ( key, symbol2 ) ); + } else { + mapit->second += ","; + + size_t pos = mapit->second.find_last_of ( "\n" ); + + if ( pos == std::string::npos ) pos = 0; + + if ( mapit->second.size ( ) - pos > 100 ) + mapit->second += "\n"; + else + mapit->second += " "; + + mapit->second += symbol2; + } + } + } + + out << "\\path[->]"; + + // print the map + for ( std::pair < const std::pair < int, int >, std::string > & transition : transitions ) { + replace ( transition.second, "\n", "\\n" ); + + out << "(" << transition.first.first << ") edge [left] node [align=center] "; + out << "{$" << transition.second << "$}"; + out << "(" << transition.first.second << ")\n"; + } +} + +template<class SymbolType, class StateType> +void TikZConverter::transitions ( const automaton::OneTapeDTM < SymbolType, StateType > & tm, const std::map < StateType, int > & states, std::ostream & out ) { + std::map < std::pair < int, int >, std::string > transitions; + + for ( const auto & transition : tm.getTransitions ( ) ) { + std::string symbol; + + // input symbol + symbol = "("; + symbol += alib::StringDataFactory::toString ( transition.first.second ); + symbol += ", "; + symbol += alib::StringDataFactory::toString ( std::get < 1 > ( transition.second ) ); + symbol += " "; + + switch ( std::get < 2 > ( transition.second ) ) { + case automaton::Shift::LEFT: + symbol += "←"; + break; + + case automaton::Shift::RIGHT: + symbol += "→"; + break; + + case automaton::Shift::NONE: + symbol += "×"; + break; + + default: + throw exception::CommonException ( "Unexpected shift direction" ); + } + + // Insert into map + std::pair < int, int > key ( states.find ( transition.first.first )->second, states.find ( std::get < 0 > ( transition.second ) )->second ); + std::map < std::pair < int, int >, std::string >::iterator mapit = transitions.find ( key ); + + if ( mapit == transitions.end ( ) ) { + transitions.insert ( std::make_pair ( key, symbol ) ); + } else { + mapit->second += ","; + + size_t pos = mapit->second.find_last_of ( "\n" ); + + if ( pos == std::string::npos ) pos = 0; + + if ( mapit->second.size ( ) - pos > 100 ) + mapit->second += "\n"; + else + mapit->second += " "; + + mapit->second += symbol; + } + } + + out << "\\path[->]"; + + // print the map + for ( std::pair < const std::pair < int, int >, std::string > & transition : transitions ) { + replace ( transition.second, "\n", "\\n" ); + + out << "(" << transition.first.first << ") edge [left] node [align=center] "; + out << "{$" << transition.second << "$}"; + out << "(" << transition.first.second << ")\n"; + } +} + #endif /* TIKZ_CONVERTER_H_ */ diff --git a/aconvert2/src/common/converterCommon.hpp b/aconvert2/src/common/converterCommon.hpp new file mode 100644 index 0000000000..2cc6969655 --- /dev/null +++ b/aconvert2/src/common/converterCommon.hpp @@ -0,0 +1,20 @@ +/* + * ConverterCommon.hpp + * + * Created on: Nov 24, 2016 + * Author: Jan Travnicek + */ + +#ifndef CONVERTER_COMMON_HPP_ +#define CONVERTER_COMMON_HPP_ + +auto replace = [] ( std::string & str, const std::string & what, const std::string & with ) { + size_t index = 0; + + while ( ( index = str.find ( what, index ) ) != std::string::npos ) { + str.replace ( index, what.length ( ), with ); + index += with.length ( ); + } +}; + +#endif /* CONVERTER_COMMON_HPP_ */ -- GitLab