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
Show more breadcrumbs
Algorithms Library Toolkit
Algorithms Library Toolkit Core
Commits
c3ae7ccc
Commit
c3ae7ccc
authored
6 years ago
by
Tomáš Pecka
Committed by
Jan Trávníček
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Algo: Normalize DFTA
parent
cbdf1502
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!85
Merge jt
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
alib2algo/src/automaton/simplify/Normalize.cpp
+9
-0
9 additions, 0 deletions
alib2algo/src/automaton/simplify/Normalize.cpp
alib2algo/src/automaton/simplify/Normalize.h
+72
-0
72 additions, 0 deletions
alib2algo/src/automaton/simplify/Normalize.h
with
81 additions
and
0 deletions
alib2algo/src/automaton/simplify/Normalize.cpp
+
9
−
0
View file @
c3ae7ccc
...
...
@@ -40,6 +40,15 @@ We normalize also the pushdown store symbols.\n\
\
n
\
@
throws
exception
::
CommonException
if
the
passed
dpda
was
not
deterministic
connected
pda
" );
auto
NormalizeDFTA
=
registration
::
AbstractRegister
<
Normalize
,
automaton
::
DFTA
<
DefaultSymbolType
,
DefaultRankType
,
unsigned
>
,
const
automaton
::
DFTA
<
>
&
>
(
Normalize
::
normalize
,
"automaton"
).
setDocumentation
(
"Normalization of deterministic finite tree automata.
\n
\
The
process
of
normalization
is
a
BFS
traversal
through
the
graph
representing
the
automaton
.
The
states
are
named
by
integers
in
the
visited
order
.
\
n
\
\
n
\
@
param
dfa
determinsitic
finite
tree
automaton
to
normalize
\
n
\
@
return
@
p
dfta
with
state
labels
normalized
\
n
\
\
n
\
@
throws
exception
::
CommonException
if
the
passed
dfta
was
not
minimal
connected
dfta
" );
}
/* namespace simplify */
}
/* namespace automaton */
This diff is collapsed.
Click to expand it.
alib2algo/src/automaton/simplify/Normalize.h
+
72
−
0
View file @
c3ae7ccc
...
...
@@ -26,6 +26,7 @@
#include <automaton/FSM/DFA.h>
#include <automaton/FSM/CompactDFA.h>
#include <automaton/TA/DFTA.h>
#include <automaton/PDA/DPDA.h>
namespace automaton {
...
...
@@ -86,6 +87,21 @@ public:
*/
template < class InputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType >
static automaton::DPDA < InputSymbolType, EpsilonType, unsigned, unsigned > normalize(const automaton::DPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > & dpda);
/**
* Normalization of deterministic finite tree automata.
* The process of normalization is a BFS traversal through the graph representing the automaton. The states are named by integers in the visited order.
*
* @tparam SymbolType Type for input symbols.
* @tparam RankType Type for input symbols rank.
* @tparam StateType Type for states.
* @param dfa determinsitic finite tree automaton to normalize
* @return @p fta with state labels normalized
*
* @throws exception::CommonException if the passed dfa was not minimal dfta
*/
template < class SymbolType, class RankType, class StateType >
static automaton::DFTA < SymbolType, RankType, unsigned > normalize ( const automaton::DFTA < SymbolType, RankType, StateType > & fta );
};
template < class SymbolType, class StateType >
...
...
@@ -266,6 +282,62 @@ automaton::DPDA < InputSymbolType, EpsilonType, unsigned, unsigned > Normalize::
return result;
}
template < class SymbolType, class RankType, class StateType >
automaton::DFTA < SymbolType, RankType, unsigned > Normalize::normalize ( const automaton::DFTA < SymbolType, RankType, StateType > & fta ) {
unsigned counter = 0;
ext::map < StateType, unsigned > normalizationData;
auto isNormalized = [ & normalizationData ] ( const StateType & origName ) {
return normalizationData.count ( origName ) > 0;
};
ext::map < ext::pair < common::ranked_symbol < SymbolType, RankType >, ext::vector < unsigned > >, StateType > processing;
do {
processing.clear ( );
// accumulate all transitions from normalized states to not yet normalized state
for ( const auto & transition : fta.getTransitions ( ) )
if ( std::all_of ( transition.first.second.begin ( ), transition.first.second.end ( ), isNormalized ) && ! isNormalized ( transition.second ) ) {
ext::vector < unsigned > from;
for ( const StateType & state : transition.first.second )
from.push_back ( normalizationData.at ( state ) );
processing.insert ( ext::make_pair ( transition.first.first, from ), transition.second );
}
for ( const std::pair < const ext::pair < common::ranked_symbol < SymbolType, RankType >, ext::vector < unsigned > >, StateType > & transition : processing )
// accumuated transition inducing normalization might have contained two or more transitions to the same state, but we want to normalize only once
if ( ! isNormalized ( transition.second ) )
normalizationData [ transition.second ] = counter ++;
} while ( processing.size ( ) > 0 );
if ( normalizationData.size ( ) != fta.getStates ( ).size ( ) ) {
throw exception::CommonException ( "Automaton normalize require minimal deterministic finite tree automaton" );
}
automaton::DFTA < SymbolType, RankType, unsigned > result;
result.setInputAlphabet ( fta.getInputAlphabet ( ) );
for ( const StateType & state : fta.getStates ( ) ) {
result.addState ( normalizationData.at ( state ) );
}
for ( const StateType & finalState : fta.getFinalStates ( ) ) {
result.addFinalState ( normalizationData.at ( finalState ) );
}
for ( const auto & transition : fta.getTransitions ( ) ) {
ext::vector < unsigned > prevStates;
for ( const StateType & prev : transition.first.second )
prevStates.push_back ( normalizationData.at ( prev ) );
result.addTransition ( transition.first.first, prevStates, normalizationData.at ( transition.second ) );
}
return result;
}
} /* namespace simplify */
} /* namespace automaton */
...
...
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