Skip to content
Snippets Groups Projects
Commit 8fff2988 authored by Jan Trávníček's avatar Jan Trávníček
Browse files

subtree repeats from subtree automaton algo

parent 02de1636
No related branches found
No related tags found
No related merge requests found
......@@ -42,6 +42,7 @@ int main ( int argc, char * argv[] ) {
allowed.push_back ( "nonlinearFullAndLinearIndex" );
 
allowed.push_back ( "exactSubtreeRepeatsNaive" );
allowed.push_back ( "exactSubtreeRepeatsFromSubtreeAutomaton" );
allowed.push_back ( "exactSubtreeRepeats" );
allowed.push_back ( "normalizeTreeLabels" );
allowed.push_back ( "badCharacterShiftTable" );
......@@ -99,6 +100,7 @@ int main ( int argc, char * argv[] ) {
|| algorithm.getValue ( ) == "exactTreePatternAutomaton"
|| algorithm.getValue ( ) == "exactNonlinearTreePatternAutomaton"
|| algorithm.getValue ( ) == "exactSubtreeRepeatsNaive"
|| algorithm.getValue ( ) == "exactSubtreeRepeatsFromSubtreeAutomaton"
|| algorithm.getValue ( ) == "normalizeTreeLabels"
|| algorithm.getValue ( ) == "exactSubtreeRepeats"
|| algorithm.getValue ( ) == "compressedBitParallelIndex"
......@@ -225,6 +227,8 @@ int main ( int argc, char * argv[] ) {
cliCommand = "execute arbology::exact::ExactNonlinearTreePatternAutomaton $subject $subtreeWildcard $nonlinearVariables > $output";
} else if ( algorithm.getValue ( ) == "exactSubtreeRepeatsNaive" ) {
cliCommand = "execute tree::properties::ExactSubtreeRepeatsNaive $subject > $output";
} else if ( algorithm.getValue ( ) == "exactSubtreeRepeatsFromSubtreeAutomaton" ) {
cliCommand = "execute arbology::properties::ExactSubtreeRepeatsFromSubtreeAutomaton $subject > $output";
} else if ( algorithm.getValue ( ) == "normalizeTreeLabels" ) {
cliCommand = "execute tree::NormalizeTreeLabels $subject > $output";
} else if ( algorithm.getValue ( ) == "exactSubtreeRepeats" ) {
......
/*
* ExactSubtreeRepeatsFromSubtreeAutomaton.cpp
*
* Created on: 1. 4. 2016
* Author: Jan Travnicek
*/
#include "ExactSubtreeRepeatsFromSubtreeAutomaton.h"
#include <registration/AlgoRegistration.hpp>
namespace {
auto ExactRepeatsFromSubtreeAutomatonPrefixRankedTree = registration::AbstractRegister < arbology::properties::ExactSubtreeRepeatsFromSubtreeAutomaton, tree::PrefixRankedTree < unsigned, DefaultRankType >, const tree::PrefixRankedTree < > & > ( arbology::properties::ExactSubtreeRepeatsFromSubtreeAutomaton::repeats );
} /* namespace tree */
/*
* ExactSubtreeRepeatsFromSubtreeAutomaton.h
*
* Created on: 5. 11. 2014
* Author: Jan Travnicek
*/
#ifndef _ARBOLOGY_SUBTREE_REPEATS_FROM_SUBTREE_AUTOMATON_H_
#define _ARBOLOGY_SUBTREE_REPEATS_FROM_SUBTREE_AUTOMATON_H_
#include <common/ranked_symbol.hpp>
#include <tree/ranked/PrefixRankedTree.h>
#include <arbology/exact/ExactSubtreeAutomaton.h>
#include <automaton/determinize/Determinize.h>
namespace arbology {
namespace properties {
/**
* Simple computation of subtree repeats
*/
class ExactSubtreeRepeatsFromSubtreeAutomaton {
template < class SymbolType, class RankType >
static void repeatsInternal ( const tree::PrefixRankedTree < SymbolType, RankType > & originalTree, const automaton::InputDrivenDPDA < common::ranked_symbol < SymbolType, RankType >, char, ext::set < unsigned > > & automaton, ext::vector < common::ranked_symbol < unsigned, RankType > > & repeats, const ext::set < unsigned > & state, unsigned size, unsigned ac );
public:
/**
* Compute a same shaped tree with nodes containing unique subtree ids.
* @return Tree of repeats
*/
template < class SymbolType, class RankType >
static tree::PrefixRankedTree < unsigned, RankType > repeats ( const tree::PrefixRankedTree < SymbolType, RankType > & tree );
};
template < class SymbolType, class RankType >
void ExactSubtreeRepeatsFromSubtreeAutomaton::repeatsInternal ( const tree::PrefixRankedTree < SymbolType, RankType > & originalTree, const automaton::InputDrivenDPDA < common::ranked_symbol < SymbolType, RankType >, char, ext::set < unsigned > > & automaton, ext::vector < common::ranked_symbol < unsigned, RankType > > & repeats, const ext::set < unsigned > & state, unsigned size, unsigned ac ) {
if ( state.size ( ) == 0 )
return;
if ( ac == 0 )
for ( unsigned label : state )
repeats [ label - size ] = common::ranked_symbol < unsigned, RankType > ( * state.begin ( ) - size, originalTree.getContent ( ) [ * state.begin ( ) - size ].getRank ( ) );
else
for ( const std::pair < ext::pair < ext::set < unsigned >, common::ranked_symbol < SymbolType, RankType > >, ext::set < unsigned > > transition : automaton.getTransitionsFromState ( state ) )
repeatsInternal ( originalTree, automaton, repeats, transition.second, size + 1, ac - 1 + ( unsigned ) transition.first.second.getRank ( ) );
}
template < class SymbolType, class RankType >
tree::PrefixRankedTree < unsigned, RankType > ExactSubtreeRepeatsFromSubtreeAutomaton::repeats ( const tree::PrefixRankedTree < SymbolType, RankType > & tree ) {
automaton::InputDrivenNPDA < common::ranked_symbol < SymbolType, RankType >, char, unsigned > subtreePushdownAutomaton = arbology::exact::ExactSubtreeAutomaton::construct ( tree );
automaton::InputDrivenDPDA < common::ranked_symbol < SymbolType, RankType >, char, ext::set < unsigned > > deterministicSubtreePushdownAutomaton = automaton::determinize::Determinize::determinize ( subtreePushdownAutomaton );
ext::vector < common::ranked_symbol < unsigned, RankType > > data ( tree.getContent ( ).size ( ), common::ranked_symbol < unsigned, RankType > ( 0, RankType ( 0 ) ) );
repeatsInternal ( tree, deterministicSubtreePushdownAutomaton, data, deterministicSubtreePushdownAutomaton.getInitialState ( ), 0, 1 );
return tree::PrefixRankedTree < unsigned, RankType > ( data );
}
} /* namespace properties */
} /* namespace arbology */
#endif /* _ARBOLOGY_SUBTREE_REPEATS_FROM_SUBTREE_AUTOMATON_H_ */
......@@ -157,9 +157,11 @@ function runRepeatsAlgorithmTest {
 
NAIVE_OUTPUT=$(mktemp)
ADVANCED_OUTPUT=$(mktemp)
ARBOLOGY_OUTPUT=$(mktemp)
 
./aarbology2 -s $1 -a exactSubtreeRepeatsNaive | ./aarbology2 -a normalizeTreeLabels > $NAIVE_OUTPUT
./acast2 -t PostfixRankedTree -i $1 | ./aarbology2 -a exactSubtreeRepeats | ./acast2 -t RankedTree | ./aarbology2 -a normalizeTreeLabels > $ADVANCED_OUTPUT
./acast2 -t PostfixRankedTree -i $1 | ./aarbology2 -a exactSubtreeRepeats | ./acast2 -t RankedTree | ./aarbology2 -a normalizeTreeLabels > $ADVANCED_OUTPUT
./acast2 -t PrefixRankedTree -i $1 | ./aarbology2 -a exactSubtreeRepeatsFromSubtreeAutomaton | ./acast2 -t RankedTree | ./aarbology2 -a normalizeTreeLabels > $ARBOLOGY_OUTPUT
 
OUT=`timeout $TESTCASE_TIMEOUT bash -c "diff $NAIVE_OUTPUT $ADVANCED_OUTPUT"`
RET=$?
......@@ -168,7 +170,14 @@ function runRepeatsAlgorithmTest {
log "$1" $RET "$OUT" "$1" "$NAIVE_OUTPUT" "$ADVANCED_OUTPUT"
fi
 
rm $1 $NAIVE_OUTPUT $ADVANCED_OUTPUT
OUT=`timeout $TESTCASE_TIMEOUT bash -c "diff $NAIVE_OUTPUT $ARBOLOGY_OUTPUT"`
RET=$?
if [ $RET != 0 ]; then # fail
log "$1" $RET "$OUT" "$1" "$NAIVE_OUTPUT" "$ARBOLOGY_OUTPUT"
fi
rm $1 $NAIVE_OUTPUT $ADVANCED_OUTPUT $ARBOLOGY_OUTPUT
 
if [ $RET == 124 ]; then # timeout
registerResult 2
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment