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
7bf70e3f
Commit
7bf70e3f
authored
3 years ago
by
Jan Trávníček
Browse files
Options
Downloads
Patches
Plain Diff
algo: introduce remove unused states and symbols from a RHDPDA
parent
d431dea1
No related branches found
Branches containing commit
No related tags found
1 merge request
!190
Improvements in RHDPDA and NPDA determinisation
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
alib2algo/src/automaton/simplify/RemoveUnused.cpp
+12
-0
12 additions, 0 deletions
alib2algo/src/automaton/simplify/RemoveUnused.cpp
alib2algo/src/automaton/simplify/RemoveUnused.h
+110
-0
110 additions, 0 deletions
alib2algo/src/automaton/simplify/RemoveUnused.h
with
122 additions
and
0 deletions
alib2algo/src/automaton/simplify/RemoveUnused.cpp
0 → 100644
+
12
−
0
View file @
7bf70e3f
#include
"RemoveUnused.h"
#include
<registration/AlgoRegistration.hpp>
namespace
{
auto
RenameRealTimeHeightDeterministicDPDA
=
registration
::
AbstractRegister
<
automaton
::
simplify
::
RemoveUnused
,
automaton
::
RealTimeHeightDeterministicDPDA
<
>
,
const
automaton
::
RealTimeHeightDeterministicDPDA
<
>
&
>
(
automaton
::
simplify
::
RemoveUnused
::
removeUnused
,
"automaton"
).
setDocumentation
(
"Remove automaton's unused states and pushdown store or input symbols.
\n
\
\
n
\
@
param
automaton
pushdown
automaton
to
remove
unused
states
and
symbols
from
\
n
\
@
return
@
p
automaton
with
removed
states
and
symbols
" );
}
/* namespace */
This diff is collapsed.
Click to expand it.
alib2algo/src/automaton/simplify/RemoveUnused.h
0 → 100644
+
110
−
0
View file @
7bf70e3f
/*
* This file is part of Algorithms library toolkit.
* Copyright (C) 2017 Jan Travnicek (jan.travnicek@fit.cvut.cz)
* Algorithms library toolkit is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* Algorithms library toolkit is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with Algorithms library toolkit. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <alib/algorithm>
#include <alib/iostream>
#include <alib/map>
#include <alib/vector>
#include <sstream>
#include <automaton/PDA/RealTimeHeightDeterministicDPDA.h>
namespace automaton {
namespace simplify {
/**
* Removes unused states/symbols in an automaton's structures based on its transitions .
*/
class RemoveUnused {
public:
/**
* Removes unused automaton's states and pushdown store or input symbols.
*
* @tparam InputSymbolType Type for input symbols
* @tparam PushdownStoreSymbolType Type of epsilon representation
* @tparam StateType Type for states
*
* @param pda pushdown automaton to rename
*
* @return @p pda with renamed states and pushdown store symbols
*/
template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
static automaton::RealTimeHeightDeterministicDPDA < InputSymbolType, PushdownStoreSymbolType, StateType > removeUnused ( const automaton::RealTimeHeightDeterministicDPDA < InputSymbolType, PushdownStoreSymbolType, StateType > & pda );
};
template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
automaton::RealTimeHeightDeterministicDPDA < InputSymbolType, PushdownStoreSymbolType, StateType > RemoveUnused::removeUnused ( const automaton::RealTimeHeightDeterministicDPDA < InputSymbolType, PushdownStoreSymbolType, StateType > & pda ) {
ext::set < InputSymbolType > alphabet;
ext::set < PushdownStoreSymbolType > pushdownAlphabet;
ext::set < StateType > states;
states.insert ( pda.getInitialState ( ) );
pushdownAlphabet.insert ( pda.getBottomOfTheStackSymbol ( ) );
for ( const auto & transition : pda.getCallTransitions ( ) ) {
if ( ! transition.first.second.is_epsilon ( ) )
alphabet.insert ( transition.first.second.getSymbol ( ) );
pushdownAlphabet.insert ( transition.second.second );
states.insert ( transition.first.first );
states.insert ( transition.second.first );
}
for ( const auto & transition : pda.getLocalTransitions ( ) ) {
if ( ! transition.first.second.is_epsilon ( ) )
alphabet.insert ( transition.first.second.getSymbol ( ) );
states.insert ( transition.first.first );
states.insert ( transition.second );
}
for ( const auto & transition : pda.getReturnTransitions ( ) ) {
if ( ! std::get < 1 > ( transition.first ).is_epsilon ( ) )
alphabet.insert ( std::get < 1 > ( transition.first ).getSymbol ( ) );
pushdownAlphabet.insert ( std::get < 2 > ( transition.first ) );
states.insert ( std::get < 0 > ( transition.first ) );
states.insert ( transition.second );
}
automaton::RealTimeHeightDeterministicDPDA < InputSymbolType, PushdownStoreSymbolType, StateType > result ( pda.getInitialState ( ), pda.getBottomOfTheStackSymbol ( ) );
result.setInputAlphabet ( alphabet );
result.setPushdownStoreAlphabet ( pushdownAlphabet );
result.setStates ( states );
for ( const StateType & state : pda.getFinalStates ( ) )
if ( states.contains ( state ) )
result.addFinalState ( state );
for ( const auto & transition : pda.getCallTransitions ( ) )
result.addCallTransition ( transition.first.first, transition.first.second, transition.second.first, transition.second.second );
for ( const auto & transition : pda.getLocalTransitions ( ) )
result.addLocalTransition ( transition.first.first, transition.first.second, transition.second );
for ( const auto & transition : pda.getReturnTransitions ( ) )
result.addReturnTransition ( std::get < 0 > ( transition.first ), std::get < 1 > ( transition.first ), std::get < 2 > ( transition.first ), 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