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

algo: generate trees with minimal alphabet only

parent 7b7c469a
No related branches found
No related tags found
1 merge request!205Merge jt
......@@ -337,9 +337,7 @@ UnrankedTree < > RandomUnrankedTreeFactory::generateUnrankedTree ( int depth, in
 
root->generateUnrankedSymbols ( alphabet );
 
ext::set < DefaultSymbolType > treeAlphabet ( alphabet.begin ( ), alphabet.end ( ) );
UnrankedTree < > tree ( treeAlphabet, root->createUnrankedNode ( ) );
UnrankedTree < > tree ( root->createUnrankedNode ( ) );
delete root;
return tree;
}
......@@ -352,15 +350,10 @@ UnrankedPattern < > RandomUnrankedPatternFactory::generateUnrankedPattern ( int
 
root->generateUnrankedSymbols ( alphabet );
 
ext::set < DefaultSymbolType > treeAlphabet ( alphabet.begin ( ), alphabet.end ( ) );
DefaultSymbolType subtreeWildcard = alphabet::WildcardSymbol::instance < DefaultSymbolType > ( );
treeAlphabet.insert ( subtreeWildcard );
DefaultSymbolType subtreeGap = alphabet::GapSymbol::instance < DefaultSymbolType > ( );
treeAlphabet.insert ( subtreeGap );
 
UnrankedPattern < > tree ( std::move ( subtreeWildcard ), std::move ( subtreeGap ), treeAlphabet, root->createUnrankedPatternNode ( ) );
UnrankedPattern < > tree ( std::move ( subtreeWildcard ), std::move ( subtreeGap ), root->createUnrankedPatternNode ( ) );
delete root;
return tree;
}
......@@ -373,27 +366,17 @@ UnrankedExtendedPattern < > RandomUnrankedExtendedPatternFactory::generateUnrank
 
root->generateUnrankedSymbols ( alphabet );
 
ext::set < DefaultSymbolType > treeAlphabet ( alphabet.begin ( ), alphabet.end ( ) );
DefaultSymbolType subtreeWildcard = alphabet::WildcardSymbol::instance < DefaultSymbolType > ( );
treeAlphabet.insert ( subtreeWildcard );
DefaultSymbolType subtreeGap = alphabet::GapSymbol::instance < DefaultSymbolType > ( );
treeAlphabet.insert ( subtreeGap );
DefaultSymbolType nodeWildcard = alphabet::NodeWildcardSymbol::instance < DefaultSymbolType > ( );
treeAlphabet.insert ( nodeWildcard );
ext::set < DefaultSymbolType > selectedNodeWildcards;
for ( const DefaultSymbolType & symbol : treeAlphabet ) {
if ( symbol == subtreeWildcard || symbol == subtreeGap )
continue;
for ( const DefaultSymbolType & symbol : alphabet ) {
if ( ext::random_devices::semirandom ( ) % 100 < nodeWildcardProbability )
selectedNodeWildcards.insert ( symbol );
}
 
UnrankedExtendedPattern < > tree ( std::move ( subtreeWildcard ), std::move ( subtreeGap ), std::move ( nodeWildcard ), treeAlphabet, root->createUnrankedExtendedPatternNode ( selectedNodeWildcards ) );
DefaultSymbolType nodeWildcard = alphabet::NodeWildcardSymbol::instance < DefaultSymbolType > ( );
DefaultSymbolType subtreeWildcard = alphabet::WildcardSymbol::instance < DefaultSymbolType > ( );
DefaultSymbolType subtreeGap = alphabet::GapSymbol::instance < DefaultSymbolType > ( );
UnrankedExtendedPattern < > tree ( std::move ( subtreeWildcard ), std::move ( subtreeGap ), std::move ( nodeWildcard ), root->createUnrankedExtendedPatternNode ( selectedNodeWildcards ) );
delete root;
return tree;
}
......@@ -408,13 +391,7 @@ RankedTree < > RandomRankedTreeFactory::generateRankedTree ( int depth, int node
generateRankedAlphabet ( rankedAlphabet, maxAlphabetSize, randomizedAlphabet );
root->generateRankedSymbols ( rankedAlphabet );
 
ext::set < common::ranked_symbol < > > treeRankedAlphabet;
for ( const std::pair < const size_t, ext::vector < DefaultSymbolType > > & it : rankedAlphabet )
for ( DefaultSymbolType i : it.second )
treeRankedAlphabet.insert ( common::ranked_symbol < > ( i, it.first ) );
RankedTree < > tree ( treeRankedAlphabet, root->createRankedNode ( ) );
RankedTree < > tree ( root->createRankedNode ( ) );
delete root;
return tree;
}
......@@ -429,16 +406,9 @@ RankedPattern < > RandomRankedPatternFactory::generateRankedPattern ( int depth,
generateRankedAlphabet ( rankedAlphabet, maxAlphabetSize, randomizedAlphabet );
root->generateRankedSymbols ( rankedAlphabet );
 
ext::set < common::ranked_symbol < > > treeRankedAlphabet;
for ( const std::pair < const size_t, ext::vector < DefaultSymbolType > > & it : rankedAlphabet )
for ( DefaultSymbolType i : it.second )
treeRankedAlphabet.insert ( common::ranked_symbol < > ( i, it.first ) );
common::ranked_symbol < > subtreeWildcard = alphabet::WildcardSymbol::instance < common::ranked_symbol < > > ( );
treeRankedAlphabet.insert ( subtreeWildcard );
 
RankedPattern < > tree ( std::move ( subtreeWildcard ), treeRankedAlphabet, root->createRankedPatternNode ( ) );
RankedPattern < > tree ( std::move ( subtreeWildcard ), root->createRankedPatternNode ( ) );
delete root;
return tree;
}
......@@ -453,32 +423,20 @@ RankedExtendedPattern < > RandomRankedExtendedPatternFactory::generateRankedExte
generateRankedAlphabet ( rankedAlphabet, maxAlphabetSize, randomizedAlphabet );
root->generateRankedSymbols ( rankedAlphabet );
 
ext::set < common::ranked_symbol < > > treeRankedAlphabet;
ext::set < common::ranked_symbol < > > selectedNodeWildcards;
for ( const std::pair < const size_t, ext::vector < DefaultSymbolType > > & it : rankedAlphabet )
for ( DefaultSymbolType i : it.second )
treeRankedAlphabet.insert ( common::ranked_symbol < > ( i, it.first ) );
common::ranked_symbol < > subtreeWildcard = alphabet::WildcardSymbol::instance < common::ranked_symbol < > > ( );
treeRankedAlphabet.insert ( subtreeWildcard );
ext::set < common::ranked_symbol < > > selectedNodeWildcards;
for ( const common::ranked_symbol < > & symbol : treeRankedAlphabet ) {
if ( symbol == subtreeWildcard )
continue;
if ( ext::random_devices::semirandom ( ) % 100 < nodeWildcardProbability )
selectedNodeWildcards.insert ( symbol );
}
if ( ext::random_devices::semirandom ( ) % 100 < nodeWildcardProbability )
selectedNodeWildcards.insert ( common::ranked_symbol < > ( i, it.first ) );
 
ext::set < common::ranked_symbol < > > nodeWildcards;
for ( const common::ranked_symbol < > & symbol : selectedNodeWildcards ) {
common::ranked_symbol < > wildcard ( alphabet::NodeWildcardSymbol::template instance < DefaultSymbolType > ( ), symbol.getRank ( ) );
nodeWildcards.insert ( wildcard );
treeRankedAlphabet.insert ( std::move ( wildcard ) );
}
 
RankedExtendedPattern < > tree ( std::move ( subtreeWildcard ), std::move ( nodeWildcards ), std::move ( treeRankedAlphabet ), root->createRankedExtendedPatternNode ( selectedNodeWildcards ) );
common::ranked_symbol < > subtreeWildcard = alphabet::WildcardSymbol::instance < common::ranked_symbol < > > ( );
RankedExtendedPattern < > tree ( std::move ( subtreeWildcard ), std::move ( nodeWildcards ), root->createRankedExtendedPatternNode ( selectedNodeWildcards ) );
delete root;
return tree;
}
......@@ -493,13 +451,8 @@ RankedNonlinearPattern < > RandomRankedNonlinearPatternFactory::generateRankedNo
generateRankedAlphabet ( rankedAlphabet, maxAlphabetSize, randomizedAlphabet );
root->generateRankedSymbols ( rankedAlphabet );
 
ext::set < common::ranked_symbol < > > treeRankedAlphabet;
ext::set < common::ranked_symbol < > > nonlinearVariables;
 
for ( const std::pair < const size_t, ext::vector < DefaultSymbolType > > & it : rankedAlphabet )
for ( DefaultSymbolType i : it.second )
treeRankedAlphabet.insert ( common::ranked_symbol < > ( i, it.first ) );
if ( singleNonlinearVariable )
nonlinearVariables.insert ( common::ranked_symbol < > ( DefaultSymbolType ( alphabet::NonlinearVariableSymbol < > ( DefaultSymbolType ( "A" ) ) ), 0 ) );
else
......@@ -507,9 +460,7 @@ RankedNonlinearPattern < > RandomRankedNonlinearPatternFactory::generateRankedNo
nonlinearVariables.insert ( common::ranked_symbol < > ( DefaultSymbolType ( alphabet::NonlinearVariableSymbol < > ( DefaultSymbolType ( i ) ) ), 0 ) );
 
common::ranked_symbol < > subtreeWildcard = alphabet::WildcardSymbol::instance < common::ranked_symbol < > > ( );
treeRankedAlphabet.insert ( subtreeWildcard );
treeRankedAlphabet.insert ( nonlinearVariables.begin ( ), nonlinearVariables.end ( ) );
RankedNonlinearPattern < > tree ( std::move ( subtreeWildcard ), nonlinearVariables, treeRankedAlphabet, root->createRankedNonlinearPatternNode ( singleNonlinearVariable ) );
RankedNonlinearPattern < > tree ( std::move ( subtreeWildcard ), nonlinearVariables, root->createRankedNonlinearPatternNode ( singleNonlinearVariable ) );
delete root;
return tree;
}
......
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