From e1eaac36a8fafdb38924f09698cb52d865bee4ca Mon Sep 17 00:00:00 2001
From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz>
Date: Wed, 19 Sep 2018 13:47:25 +0200
Subject: [PATCH] adapt randomize grammar to new templating of grammars

---
 .../src/grammar/generate/RandomizeGrammar.h   | 88 +++++++++----------
 1 file changed, 44 insertions(+), 44 deletions(-)

diff --git a/alib2algo/src/grammar/generate/RandomizeGrammar.h b/alib2algo/src/grammar/generate/RandomizeGrammar.h
index 0fadf8bae5..ed75379d51 100644
--- a/alib2algo/src/grammar/generate/RandomizeGrammar.h
+++ b/alib2algo/src/grammar/generate/RandomizeGrammar.h
@@ -22,91 +22,91 @@ namespace generate {
 
 class RandomizeGrammar {
 public:
-	template < class SymbolType >
-	static grammar::LeftRG < SymbolType > randomize ( const grammar::LeftRG < SymbolType > & gram );
-	template < class SymbolType >
-	static grammar::LeftLG < SymbolType > randomize ( const grammar::LeftLG < SymbolType > & gram );
-	template < class SymbolType >
-	static grammar::RightRG < SymbolType > randomize ( const grammar::RightRG < SymbolType > & gram );
-	template < class SymbolType >
-	static grammar::RightLG < SymbolType > randomize ( const grammar::RightLG < SymbolType > & gram );
+	template < class TerminalSymbolType, class NonterminalSymbolType >
+	static grammar::LeftRG < TerminalSymbolType, NonterminalSymbolType > randomize ( const grammar::LeftRG < TerminalSymbolType, NonterminalSymbolType > & gram );
+	template < class TerminalSymbolType, class NonterminalSymbolType >
+	static grammar::LeftLG < TerminalSymbolType, NonterminalSymbolType > randomize ( const grammar::LeftLG < TerminalSymbolType, NonterminalSymbolType > & gram );
+	template < class TerminalSymbolType, class NonterminalSymbolType >
+	static grammar::RightRG < TerminalSymbolType, NonterminalSymbolType > randomize ( const grammar::RightRG < TerminalSymbolType, NonterminalSymbolType > & gram );
+	template < class TerminalSymbolType, class NonterminalSymbolType >
+	static grammar::RightLG < TerminalSymbolType, NonterminalSymbolType > randomize ( const grammar::RightLG < TerminalSymbolType, NonterminalSymbolType > & gram );
 	template < class TerminalSymbolType, class NonterminalSymbolType >
 	static grammar::CFG < TerminalSymbolType, NonterminalSymbolType > randomize ( const grammar::CFG < TerminalSymbolType, NonterminalSymbolType > & gram );
 
 };
 
-template < class SymbolType >
-grammar::LeftRG < SymbolType > RandomizeGrammar::randomize ( const grammar::LeftRG < SymbolType > & gram ) {
-	ext::map < SymbolType, SymbolType > symbolPermutationMap = common::Permutation::permutationMap ( gram.getNonterminalAlphabet ( ) );
+template < class TerminalSymbolType, class NonterminalSymbolType >
+grammar::LeftRG < TerminalSymbolType, NonterminalSymbolType > RandomizeGrammar::randomize ( const grammar::LeftRG < TerminalSymbolType, NonterminalSymbolType > & gram ) {
+	ext::map < NonterminalSymbolType, NonterminalSymbolType > symbolPermutationMap = common::Permutation::permutationMap ( gram.getNonterminalAlphabet ( ) );
 
-	grammar::LeftRG < SymbolType > res ( symbolPermutationMap.find ( gram.getInitialSymbol ( ) )->second );
+	grammar::LeftRG < TerminalSymbolType, NonterminalSymbolType > res ( symbolPermutationMap.at ( gram.getInitialSymbol ( ) ) );
 
 	res.setNonterminalAlphabet ( gram.getNonterminalAlphabet ( ) );
 	res.setTerminalAlphabet ( gram.getTerminalAlphabet ( ) );
 
-	for ( const std::pair < SymbolType, ext::set < ext::variant < SymbolType, ext::pair < SymbolType, SymbolType > > > > & rule : gram.getRules ( ) )
-		for ( const ext::variant < SymbolType, ext::pair < SymbolType, SymbolType > > & rhs : rule.second )
-			if ( rhs.template is < SymbolType > ( ) )
-				res.addRule ( symbolPermutationMap.find ( rule.first )->second, rhs );
+	for ( const std::pair < NonterminalSymbolType, ext::set < ext::variant < TerminalSymbolType, ext::pair < NonterminalSymbolType, TerminalSymbolType > > > > & rule : gram.getRules ( ) )
+		for ( const ext::variant < TerminalSymbolType, ext::pair < NonterminalSymbolType, NonterminalSymbolType > > & rhs : rule.second )
+			if ( rhs.template is < TerminalSymbolType > ( ) )
+				res.addRule ( symbolPermutationMap.at ( rule.first ), rhs );
 			else
-				res.addRule ( symbolPermutationMap.find ( rule.first )->second, ext::make_pair ( symbolPermutationMap.find ( rhs.template get < ext::pair < SymbolType, SymbolType > > ( ).first )->second, rhs.template get < ext::pair < SymbolType, SymbolType > > ( ).second ) );
+				res.addRule ( symbolPermutationMap.at ( rule.first ), ext::make_pair ( symbolPermutationMap.at ( rhs.template get < ext::pair < NonterminalSymbolType, TerminalSymbolType > > ( ).first ), rhs.template get < ext::pair < NonterminalSymbolType, TerminalSymbolType > > ( ).second ) );
 
 	return res;
 }
 
-template < class SymbolType >
-grammar::LeftLG < SymbolType > RandomizeGrammar::randomize ( const grammar::LeftLG < SymbolType > & gram ) {
-	ext::map < SymbolType, SymbolType > symbolPermutationMap = common::Permutation::permutationMap ( gram.getNonterminalAlphabet ( ) );
+template < class TerminalSymbolType, class NonterminalSymbolType >
+grammar::LeftLG < TerminalSymbolType, NonterminalSymbolType > RandomizeGrammar::randomize ( const grammar::LeftLG < TerminalSymbolType, NonterminalSymbolType > & gram ) {
+	ext::map < NonterminalSymbolType, NonterminalSymbolType > symbolPermutationMap = common::Permutation::permutationMap ( gram.getNonterminalAlphabet ( ) );
 
-	grammar::LeftLG < SymbolType > res ( symbolPermutationMap.find ( gram.getInitialSymbol ( ) )->second );
+	grammar::LeftLG < TerminalSymbolType, NonterminalSymbolType > res ( symbolPermutationMap.at ( gram.getInitialSymbol ( ) ) );
 
 	res.setNonterminalAlphabet ( gram.getNonterminalAlphabet ( ) );
 	res.setTerminalAlphabet ( gram.getTerminalAlphabet ( ) );
 
-	for ( const std::pair < SymbolType, ext::set < ext::variant < ext::vector < SymbolType >, ext::pair < SymbolType, ext::vector < SymbolType > > > > > & rule : gram.getRules ( ) )
-		for ( const ext::variant < ext::vector < SymbolType >, ext::pair < SymbolType, ext::vector < SymbolType > > > & rhs : rule.second )
-			if ( rhs.template is < ext::vector < SymbolType > > ( ) )
-				res.addRule ( symbolPermutationMap.find ( rule.first )->second, rhs );
+	for ( const std::pair < NonterminalSymbolType, ext::set < ext::variant < ext::vector < TerminalSymbolType >, ext::pair < NonterminalSymbolType, ext::vector < TerminalSymbolType > > > > > & rule : gram.getRules ( ) )
+		for ( const ext::variant < ext::vector < TerminalSymbolType >, ext::pair < NonterminalSymbolType, ext::vector < TerminalSymbolType > > > & rhs : rule.second )
+			if ( rhs.template is < ext::vector < TerminalSymbolType > > ( ) )
+				res.addRule ( symbolPermutationMap.at ( rule.first ), rhs );
 			else
-				res.addRule ( symbolPermutationMap.find ( rule.first )->second, ext::make_pair ( symbolPermutationMap.find ( rhs.template get < ext::pair < SymbolType, ext::vector < SymbolType > > > ( ).first )->second, rhs.template get < ext::pair < SymbolType, ext::vector < SymbolType > > > ( ).second ) );
+				res.addRule ( symbolPermutationMap.at ( rule.first ), ext::make_pair ( symbolPermutationMap.at ( rhs.template get < ext::pair < NonterminalSymbolType, ext::vector < TerminalSymbolType > > > ( ).first ), rhs.template get < ext::pair < NonterminalSymbolType, ext::vector < TerminalSymbolType > > > ( ).second ) );
 
 	return res;
 }
 
-template < class SymbolType >
-grammar::RightRG < SymbolType > RandomizeGrammar::randomize ( const grammar::RightRG < SymbolType > & gram ) {
-	ext::map < SymbolType, SymbolType > symbolPermutationMap = common::Permutation::permutationMap ( gram.getNonterminalAlphabet ( ) );
+template < class TerminalSymbolType, class NonterminalSymbolType >
+grammar::RightRG < TerminalSymbolType, NonterminalSymbolType > RandomizeGrammar::randomize ( const grammar::RightRG < TerminalSymbolType, NonterminalSymbolType > & gram ) {
+	ext::map < NonterminalSymbolType, NonterminalSymbolType > symbolPermutationMap = common::Permutation::permutationMap ( gram.getNonterminalAlphabet ( ) );
 
-	grammar::RightRG < SymbolType > res ( symbolPermutationMap.find ( gram.getInitialSymbol ( ) )->second );
+	grammar::RightRG < TerminalSymbolType, NonterminalSymbolType > res ( symbolPermutationMap.at ( gram.getInitialSymbol ( ) ) );
 
 	res.setNonterminalAlphabet ( gram.getNonterminalAlphabet ( ) );
 	res.setTerminalAlphabet ( gram.getTerminalAlphabet ( ) );
 
-	for ( const std::pair < SymbolType, ext::set < ext::variant < SymbolType, ext::pair < SymbolType, SymbolType > > > > & rule : gram.getRules ( ) )
-		for ( const ext::variant < SymbolType, ext::pair < SymbolType, SymbolType > > & rhs : rule.second )
-			if ( rhs.template is < SymbolType > ( ) )
-				res.addRule ( symbolPermutationMap.find ( rule.first )->second, rhs );
+	for ( const std::pair < NonterminalSymbolType, ext::set < ext::variant < TerminalSymbolType, ext::pair < TerminalSymbolType, NonterminalSymbolType > > > > & rule : gram.getRules ( ) )
+		for ( const ext::variant < TerminalSymbolType, ext::pair < TerminalSymbolType, NonterminalSymbolType > > & rhs : rule.second )
+			if ( rhs.template is < TerminalSymbolType > ( ) )
+				res.addRule ( symbolPermutationMap.at ( rule.first ), rhs );
 			else
-				res.addRule ( symbolPermutationMap.find ( rule.first )->second, ext::make_pair ( rhs.template get < ext::pair < SymbolType, SymbolType > > ( ).first, symbolPermutationMap.find ( rhs.template get < ext::pair < SymbolType, SymbolType > > ( ).second )->second ) );
+				res.addRule ( symbolPermutationMap.at ( rule.first ), ext::make_pair ( rhs.template get < ext::pair < TerminalSymbolType, NonterminalSymbolType > > ( ).first, symbolPermutationMap.at ( rhs.template get < ext::pair < TerminalSymbolType, NonterminalSymbolType > > ( ).second ) ) );
 
 	return res;
 }
 
-template < class SymbolType >
-grammar::RightLG < SymbolType > RandomizeGrammar::randomize ( const grammar::RightLG < SymbolType > & gram ) {
-	ext::map < SymbolType, SymbolType > symbolPermutationMap = common::Permutation::permutationMap ( gram.getNonterminalAlphabet ( ) );
+template < class TerminalSymbolType, class NonterminalSymbolType >
+grammar::RightLG < TerminalSymbolType, NonterminalSymbolType > RandomizeGrammar::randomize ( const grammar::RightLG < TerminalSymbolType, NonterminalSymbolType > & gram ) {
+	ext::map < NonterminalSymbolType, NonterminalSymbolType > symbolPermutationMap = common::Permutation::permutationMap ( gram.getNonterminalAlphabet ( ) );
 
-	grammar::RightLG < SymbolType > res ( symbolPermutationMap.find ( gram.getInitialSymbol ( ) )->second );
+	grammar::RightLG < TerminalSymbolType, NonterminalSymbolType > res ( symbolPermutationMap.at ( gram.getInitialSymbol ( ) ) );
 
 	res.setNonterminalAlphabet ( gram.getNonterminalAlphabet ( ) );
 	res.setTerminalAlphabet ( gram.getTerminalAlphabet ( ) );
 
-	for ( const std::pair < SymbolType, ext::set < ext::variant < ext::vector < SymbolType >, ext::pair < ext::vector < SymbolType >, SymbolType > > > > & rule : gram.getRules ( ) )
-		for ( const ext::variant < ext::vector < SymbolType >, ext::pair < ext::vector < SymbolType >, SymbolType > > & rhs : rule.second )
-			if ( rhs.template is < ext::vector < SymbolType > > ( ) )
-				res.addRule ( symbolPermutationMap.find ( rule.first )->second, rhs );
+	for ( const std::pair < NonterminalSymbolType, ext::set < ext::variant < ext::vector < TerminalSymbolType >, ext::pair < ext::vector < TerminalSymbolType >, NonterminalSymbolType > > > > & rule : gram.getRules ( ) )
+		for ( const ext::variant < ext::vector < TerminalSymbolType >, ext::pair < ext::vector < TerminalSymbolType >, NonterminalSymbolType > > & rhs : rule.second )
+			if ( rhs.template is < ext::vector < TerminalSymbolType > > ( ) )
+				res.addRule ( symbolPermutationMap.at ( rule.first ), rhs );
 			else
-				res.addRule ( symbolPermutationMap.find ( rule.first )->second, ext::make_pair ( rhs.template get < ext::pair < ext::vector < SymbolType >, SymbolType > > ( ).first, symbolPermutationMap.find ( rhs.template get < ext::pair < ext::vector < SymbolType >, SymbolType > > ( ).second )->second ) );
+				res.addRule ( symbolPermutationMap.at ( rule.first ), ext::make_pair ( rhs.template get < ext::pair < ext::vector < TerminalSymbolType >, NonterminalSymbolType > > ( ).first, symbolPermutationMap.at ( rhs.template get < ext::pair < ext::vector < TerminalSymbolType >, NonterminalSymbolType > > ( ).second ) ) );
 
 	return res;
 }
-- 
GitLab