Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Algorithms Library Toolkit Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Container Registry
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
Hello
GitLab will be updated tonight at 22:00. Expect short outage.
Show more breadcrumbs
Algorithms Library Toolkit
Algorithms Library Toolkit Core
Commits
90b87ee2
Commit
90b87ee2
authored
5 years ago
by
Jan Trávníček
Browse files
Options
Downloads
Patches
Plain Diff
UnorderedNFTA to Dot
parent
994c874c
No related branches found
No related tags found
1 merge request
!133
Merge unordered automata and fixes
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
alib2aux/src/convert/DotConverter.cpp
+1
-0
1 addition, 0 deletions
alib2aux/src/convert/DotConverter.cpp
alib2aux/src/convert/DotConverter.h
+84
-0
84 additions, 0 deletions
alib2aux/src/convert/DotConverter.h
with
85 additions
and
0 deletions
alib2aux/src/convert/DotConverter.cpp
+
1
−
0
View file @
90b87ee2
...
@@ -18,6 +18,7 @@ auto DotConverterDFA = registration::AbstractRegister < convert::DotConverter, s
...
@@ -18,6 +18,7 @@ auto DotConverterDFA = registration::AbstractRegister < convert::DotConverter, s
auto
DotConverterExtendedNFA
=
registration
::
AbstractRegister
<
convert
::
DotConverter
,
std
::
string
,
const
automaton
::
ExtendedNFA
<
>
&
>
(
convert
::
DotConverter
::
convert
);
auto
DotConverterExtendedNFA
=
registration
::
AbstractRegister
<
convert
::
DotConverter
,
std
::
string
,
const
automaton
::
ExtendedNFA
<
>
&
>
(
convert
::
DotConverter
::
convert
);
auto
DotConverterCompactNFA
=
registration
::
AbstractRegister
<
convert
::
DotConverter
,
std
::
string
,
const
automaton
::
CompactNFA
<
>
&
>
(
convert
::
DotConverter
::
convert
);
auto
DotConverterCompactNFA
=
registration
::
AbstractRegister
<
convert
::
DotConverter
,
std
::
string
,
const
automaton
::
CompactNFA
<
>
&
>
(
convert
::
DotConverter
::
convert
);
auto
DotConverterNFTA
=
registration
::
AbstractRegister
<
convert
::
DotConverter
,
std
::
string
,
const
automaton
::
NFTA
<
>
&
>
(
convert
::
DotConverter
::
convert
);
auto
DotConverterNFTA
=
registration
::
AbstractRegister
<
convert
::
DotConverter
,
std
::
string
,
const
automaton
::
NFTA
<
>
&
>
(
convert
::
DotConverter
::
convert
);
auto
DotConverterUnorderedNFTA
=
registration
::
AbstractRegister
<
convert
::
DotConverter
,
std
::
string
,
const
automaton
::
UnorderedNFTA
<
>
&
>
(
convert
::
DotConverter
::
convert
);
auto
DotConverterDFTA
=
registration
::
AbstractRegister
<
convert
::
DotConverter
,
std
::
string
,
const
automaton
::
DFTA
<
>
&
>
(
convert
::
DotConverter
::
convert
);
auto
DotConverterDFTA
=
registration
::
AbstractRegister
<
convert
::
DotConverter
,
std
::
string
,
const
automaton
::
DFTA
<
>
&
>
(
convert
::
DotConverter
::
convert
);
auto
DotConverterDPDA
=
registration
::
AbstractRegister
<
convert
::
DotConverter
,
std
::
string
,
const
automaton
::
DPDA
<
>
&
>
(
convert
::
DotConverter
::
convert
);
auto
DotConverterDPDA
=
registration
::
AbstractRegister
<
convert
::
DotConverter
,
std
::
string
,
const
automaton
::
DPDA
<
>
&
>
(
convert
::
DotConverter
::
convert
);
auto
DotConverterSinglePopDPDA
=
registration
::
AbstractRegister
<
convert
::
DotConverter
,
std
::
string
,
const
automaton
::
SinglePopDPDA
<
>
&
>
(
convert
::
DotConverter
::
convert
);
auto
DotConverterSinglePopDPDA
=
registration
::
AbstractRegister
<
convert
::
DotConverter
,
std
::
string
,
const
automaton
::
SinglePopDPDA
<
>
&
>
(
convert
::
DotConverter
::
convert
);
...
...
This diff is collapsed.
Click to expand it.
alib2aux/src/convert/DotConverter.h
+
84
−
0
View file @
90b87ee2
...
@@ -26,6 +26,7 @@
...
@@ -26,6 +26,7 @@
#include <automaton/FSM/ExtendedNFA.h>
#include <automaton/FSM/ExtendedNFA.h>
#include <automaton/FSM/CompactNFA.h>
#include <automaton/FSM/CompactNFA.h>
#include <automaton/TA/NFTA.h>
#include <automaton/TA/NFTA.h>
#include <automaton/TA/UnorderedNFTA.h>
#include <automaton/TA/ExtendedNFTA.h>
#include <automaton/TA/ExtendedNFTA.h>
#include <automaton/TA/DFTA.h>
#include <automaton/TA/DFTA.h>
#include <automaton/PDA/NPDA.h>
#include <automaton/PDA/NPDA.h>
...
@@ -72,6 +73,9 @@ class DotConverter {
...
@@ -72,6 +73,9 @@ class DotConverter {
template < class SymbolType, class StateType >
template < class SymbolType, class StateType >
static void transitions(const automaton::NFTA < SymbolType, StateType > & fta, const ext::map < StateType, int > & states, std::ostream & out);
static void transitions(const automaton::NFTA < SymbolType, StateType > & fta, const ext::map < StateType, int > & states, std::ostream & out);
template < class SymbolType, class StateType >
static void transitions(const automaton::UnorderedNFTA < SymbolType, StateType > & fta, const ext::map < StateType, int > & states, std::ostream & out);
template < class SymbolType, class StateType >
template < class SymbolType, class StateType >
static void transitions(const automaton::ExtendedNFTA < SymbolType, StateType > & fta, const ext::map < StateType, int > & states, std::ostream & out);
static void transitions(const automaton::ExtendedNFTA < SymbolType, StateType > & fta, const ext::map < StateType, int > & states, std::ostream & out);
...
@@ -132,6 +136,9 @@ public:
...
@@ -132,6 +136,9 @@ public:
template < class SymbolType, class StateType >
template < class SymbolType, class StateType >
static void convert(std::ostream& out, const automaton::NFTA < SymbolType, StateType > & a);
static void convert(std::ostream& out, const automaton::NFTA < SymbolType, StateType > & a);
template < class SymbolType, class StateType >
static void convert(std::ostream& out, const automaton::UnorderedNFTA < SymbolType, StateType > & a);
template < class SymbolType, class StateType >
template < class SymbolType, class StateType >
static void convert(std::ostream& out, const automaton::ExtendedNFTA < SymbolType, StateType > & a);
static void convert(std::ostream& out, const automaton::ExtendedNFTA < SymbolType, StateType > & a);
...
@@ -404,6 +411,34 @@ void DotConverter::convert(std::ostream& out, const automaton::NFTA < SymbolType
...
@@ -404,6 +411,34 @@ void DotConverter::convert(std::ostream& out, const automaton::NFTA < SymbolType
out << "}";
out << "}";
}
}
template < class SymbolType, class StateType >
void DotConverter::convert(std::ostream& out, const automaton::UnorderedNFTA < SymbolType, StateType > & a) {
out << "digraph automaton {\n";
out << "rankdir=LR;\n";
int cnt = 1;
//Map states to indices
ext::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=\"" << replace ( factory::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=\"" << replace ( factory::StringDataFactory::toString ( state.first ), "\"", "\\\"" ) << "\" ]; " << state.second << ";\n";
}
}
transitions(a, states, out);
out << "}";
}
template < class SymbolType, class StateType >
template < class SymbolType, class StateType >
void DotConverter::convert(std::ostream& out, const automaton::ExtendedNFTA < SymbolType, StateType > & a) {
void DotConverter::convert(std::ostream& out, const automaton::ExtendedNFTA < SymbolType, StateType > & a) {
out << "digraph automaton {\n";
out << "digraph automaton {\n";
...
@@ -1100,6 +1135,55 @@ void DotConverter::transitions(const automaton::NFTA < SymbolType, StateType > &
...
@@ -1100,6 +1135,55 @@ void DotConverter::transitions(const automaton::NFTA < SymbolType, StateType > &
}
}
}
}
template < class SymbolType, class StateType >
void DotConverter::transitions(const automaton::UnorderedNFTA < SymbolType, StateType > & fta, const ext::map<StateType, int>& states, std::ostream& out) {
ext::map<std::pair<int, ext::vector<int>>, std::string> transitions;
//put transitions from automaton to "transitions"
for (const auto& transition : fta.getTransitions()) {
std::string symbol = replace ( factory::StringDataFactory::toString ( transition.first.first.getSymbol( )), "\"", "\\\"" );
symbol += ext::to_string(transition.first.first.getRank());
std::pair<int, ext::vector<int>> key(states.find(transition.second)->second, {});
for(const StateType& state : transition.first.second) {
key.second.push_back(states.find(state)->second);
}
ext::map<std::pair<int, ext::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, ext::vector<int>>, std::string>& transition : transitions) {
out << i << " -> " << transition.first.first;
replaceInplace(transition.second, "\n", "\\n");
out << "[label=\"" << transition.second << "\"]\n";
unsigned j = 0;
for(int from : transition.first.second) {
out << from << " -> " << i << "\n";
j++;
}
i++;
}
}
template < class SymbolType, class StateType >
template < class SymbolType, class StateType >
void DotConverter::transitions(const automaton::DFTA < SymbolType, StateType > & fta, const ext::map<StateType, int>& states, std::ostream& out) {
void DotConverter::transitions(const automaton::DFTA < SymbolType, StateType > & fta, const ext::map<StateType, int>& states, std::ostream& out) {
ext::map<std::pair<int, ext::vector<int>>, std::string> transitions;
ext::map<std::pair<int, ext::vector<int>>, std::string> transitions;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment