Index: branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/TypeCoherentExpressionGrammar.cs
===================================================================
--- branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/TypeCoherentExpressionGrammar.cs	(revision 6618)
+++ branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/TypeCoherentExpressionGrammar.cs	(revision 6782)
@@ -21,4 +21,5 @@
 
 using System.Collections.Generic;
+using System.Linq;
 using HeuristicLab.Common;
 using HeuristicLab.Core;
@@ -29,4 +30,15 @@
   [Item("TypeCoherentExpressionGrammar", "Represents a grammar for functional expressions in which special syntactic constraints are enforced so that boolean and real-valued expressions are not mixed.")]
   public class TypeCoherentExpressionGrammar : SymbolicExpressionGrammar, ISymbolicDataAnalysisGrammar {
+    private const string ArithmeticFunctionsName = "Arithmetic Functions";
+    private const string TrigonometricFunctionsName = "Trigonometric Functions";
+    private const string ExponentialFunctionsName = "Exponential and Logarithmic Functions";
+    private const string RealValuedSymbolsName = "Real Valued Symbols";
+    private const string TerminalsName = "Terminals";
+    private const string PowerFunctionsName = "Power Functions";
+    private const string ConditionsName = "Conditions";
+    private const string ComparisonsName = "Comparisons";
+    private const string BooleanOperatorsName = "Boolean Operators";
+    private const string ConditionalSymbolsName = "ConditionalSymbols";
+    private const string TimeSeriesSymbolsName = "Time Series Symbols";
 
     [StorableConstructor]
@@ -42,4 +54,5 @@
 
     private void Initialize() {
+      #region symbol declaration
       var add = new Addition();
       var sub = new Subtraction();
@@ -52,7 +65,5 @@
       var log = new Logarithm();
       var pow = new Power();
-      pow.InitialFrequency = 0.0;
       var root = new Root();
-      root.InitialFrequency = 0.0;
       var exp = new Exponential();
       var @if = new IfThenElse();
@@ -62,58 +73,40 @@
       var or = new Or();
       var not = new Not();
+      var variableCondition = new VariableCondition();
 
       var timeLag = new TimeLag();
-      timeLag.InitialFrequency = 0.0;
       var integral = new Integral();
-      integral.InitialFrequency = 0.0;
       var derivative = new Derivative();
-      derivative.InitialFrequency = 0.0;
-      var variableCondition = new VariableCondition();
-      variableCondition.InitialFrequency = 0.0;
 
       var constant = new Constant();
       constant.MinValue = -20;
       constant.MaxValue = 20;
-      var variableSymbol = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable();
+      var variableSymbol = new Variable();
       var laggedVariable = new LaggedVariable();
+      #endregion
 
-      laggedVariable.InitialFrequency = 0.0;
-      mean.InitialFrequency = 0.0;
+      #region group symbol declaration
+      var arithmeticSymbols = new GroupSymbol(ArithmeticFunctionsName, new List<ISymbol>() { add, sub, mul, div, mean });
+      var trigonometricSymbols = new GroupSymbol(TrigonometricFunctionsName, new List<ISymbol>() { sin, cos, tan });
+      var exponentialAndLogarithmicSymbols = new GroupSymbol(ExponentialFunctionsName, new List<ISymbol> { exp, log });
+      var terminalSymbols = new GroupSymbol(TerminalsName, new List<ISymbol> { constant, variableSymbol });
+      var realValuedSymbols = new GroupSymbol(RealValuedSymbolsName, new List<ISymbol>() { arithmeticSymbols, trigonometricSymbols, exponentialAndLogarithmicSymbols, terminalSymbols });
 
-      /*
-       * Start = RealValueExpression
-       * 
-       * RealValueExpression = 
-       *   "Variable"  |
-       *   "Constant" | 
-       *   BinaryOperator RealValueExpression RealValueExpression |
-       *   UnaryOperator RealValueExpression | 
-       *   "IF" BooleanExpression RealValueExpression RealValueExpression | 
-       *   "VariableCondition" RealValueExpression RealValueExpression
-       * 
-       * BinaryOperator = 
-       *   "+" | "-" | "*" | "/" | "Power" | "Root"
-       * 
-       * UnaryOperator = 
-       *   "Sin" | "Cos" | "Tan" | "Log" | "Exp"
-       * 
-       * BooleanExpression = 
-       *   "AND" BooleanExpression BooleanExpression |
-       *   "OR" BooleanExpression BooleanExpression |
-       *   "NOT" BooleanExpression |
-       *   ">" RealValueExpression RealValueExpression |
-       *   "<" RealValueExpression RealValueExpression
-       */
+      var powerSymbols = new GroupSymbol(PowerFunctionsName, new List<ISymbol> { pow, root });
 
-      var arithmeticSymbols = new GroupSymbol("Arithmetic Functions", new List<ISymbol>() { add, sub, mul, div });
-      var trigonometricSymbols = new GroupSymbol("Trigonometric Functions", new List<ISymbol>() { sin, cos, tan });
-      var powerSymbols = new GroupSymbol("Power Functions", new List<ISymbol> { pow, root });
-      var exponentialAndLogarithmicSymbols = new GroupSymbol("Exponential and Logarithmic Functions", new List<ISymbol> { exp, log });
-      var terminalSymbols = new GroupSymbol("Terminals", new List<ISymbol> { constant, variableSymbol });
-      var realValuedSymbols = new GroupSymbol("Real valued Symbols",
-        new List<ISymbol>() { arithmeticSymbols, trigonometricSymbols, powerSymbols, exponentialAndLogarithmicSymbols, terminalSymbols });
+      var conditionSymbols = new GroupSymbol(ConditionsName, new List<ISymbol> { @if, variableCondition });
+      var comparisonSymbols = new GroupSymbol(ComparisonsName, new List<ISymbol> { gt, lt });
+      var booleanOperationSymbols = new GroupSymbol(BooleanOperatorsName, new List<ISymbol> { and, or, not });
+      var conditionalSymbols = new GroupSymbol(ConditionalSymbolsName, new List<ISymbol> { conditionSymbols, comparisonSymbols, booleanOperationSymbols });
+
+      var timeSeriesSymbols = new GroupSymbol(TimeSeriesSymbolsName, new List<ISymbol> { timeLag, integral, derivative, laggedVariable });
+      #endregion
 
       AddSymbol(realValuedSymbols);
+      AddSymbol(powerSymbols);
+      AddSymbol(conditionalSymbols);
+      AddSymbol(timeSeriesSymbols);
 
+      #region subtree count configuration
       SetSubtreeCount(arithmeticSymbols, 2, 2);
       SetSubtreeCount(trigonometricSymbols, 1, 1);
@@ -122,82 +115,80 @@
       SetSubtreeCount(terminalSymbols, 0, 0);
 
+      SetSubtreeCount(@if, 3, 3);
+      SetSubtreeCount(variableCondition, 2, 2);
+      SetSubtreeCount(comparisonSymbols, 2, 2);
+      SetSubtreeCount(and, 2, 2);
+      SetSubtreeCount(or, 2, 2);
+      SetSubtreeCount(not, 1, 1);
+
+      SetSubtreeCount(timeLag, 1, 1);
+      SetSubtreeCount(integral, 1, 1);
+      SetSubtreeCount(derivative, 1, 1);
+      SetSubtreeCount(laggedVariable, 0, 0);
+      #endregion
+
+      #region alloed child symbols configuration
       AddAllowedChildSymbol(StartSymbol, realValuedSymbols);
       AddAllowedChildSymbol(DefunSymbol, realValuedSymbols);
+
       AddAllowedChildSymbol(realValuedSymbols, realValuedSymbols);
+      AddAllowedChildSymbol(realValuedSymbols, powerSymbols);
+      AddAllowedChildSymbol(realValuedSymbols, conditionSymbols);
+      AddAllowedChildSymbol(realValuedSymbols, timeSeriesSymbols);
 
-      //var unaryBooleanFunctionSymbols = new List<Symbol>() { not };
-      //var binaryBooleanFunctionSymbols = new List<Symbol>() { or, and };
-      //var relationalFunctionSymbols = new List<Symbol>() { gt, lt };
-      //var booleanSymbols = unaryBooleanFunctionSymbols.Concat(binaryBooleanFunctionSymbols).Concat(relationalFunctionSymbols);
+      AddAllowedChildSymbol(powerSymbols, variableSymbol, 0);
+      AddAllowedChildSymbol(powerSymbols, constant, 1);
 
-      var allSymbols = new List<Symbol>() { add, sub, mul, div, mean, sin, cos, tan, log, pow, root, exp, @if, gt, lt, and, or, not, timeLag, integral, derivative, constant, variableSymbol, laggedVariable, variableCondition };
+      AddAllowedChildSymbol(@if, comparisonSymbols, 0);
+      AddAllowedChildSymbol(@if, booleanOperationSymbols, 0);
+      AddAllowedChildSymbol(@if, conditionSymbols, 1);
+      AddAllowedChildSymbol(@if, realValuedSymbols, 1);
+      AddAllowedChildSymbol(@if, powerSymbols, 1);
+      AddAllowedChildSymbol(@if, timeSeriesSymbols, 1);
+      AddAllowedChildSymbol(@if, conditionSymbols, 2);
+      AddAllowedChildSymbol(@if, realValuedSymbols, 2);
+      AddAllowedChildSymbol(@if, powerSymbols, 2);
+      AddAllowedChildSymbol(@if, timeSeriesSymbols, 2);
 
-      var unaryFunctionSymbols = new List<Symbol>() { sin, cos, tan, log, exp, timeLag, integral, derivative };
-      var binaryFunctionSymbols = new List<Symbol>() { add, sub, mul, div, mean, pow, root, variableCondition };
+      AddAllowedChildSymbol(booleanOperationSymbols, comparisonSymbols);
+      AddAllowedChildSymbol(comparisonSymbols, realValuedSymbols);
+      AddAllowedChildSymbol(comparisonSymbols, powerSymbols);
+      AddAllowedChildSymbol(comparisonSymbols, conditionSymbols);
+      AddAllowedChildSymbol(comparisonSymbols, timeSeriesSymbols);
+
+      AddAllowedChildSymbol(variableCondition, realValuedSymbols);
+      AddAllowedChildSymbol(variableCondition, powerSymbols);
+      AddAllowedChildSymbol(variableCondition, conditionSymbols);
+      AddAllowedChildSymbol(variableCondition, timeSeriesSymbols);
 
 
+      AddAllowedChildSymbol(timeLag, realValuedSymbols);
+      AddAllowedChildSymbol(timeLag, powerSymbols);
+      AddAllowedChildSymbol(timeLag, conditionSymbols);
 
-      //var terminalSymbols = new List<Symbol>() { variableSymbol, constant, laggedVariable };
-      //var realValuedSymbols = unaryFunctionSymbols.Concat(binaryFunctionSymbols).Concat(terminalSymbols).Concat(new List<Symbol>() { @if });
+      AddAllowedChildSymbol(integral, realValuedSymbols);
+      AddAllowedChildSymbol(integral, powerSymbols);
+      AddAllowedChildSymbol(integral, conditionSymbols);
 
+      AddAllowedChildSymbol(derivative, realValuedSymbols);
+      AddAllowedChildSymbol(derivative, powerSymbols);
+      AddAllowedChildSymbol(derivative, conditionSymbols);
+      #endregion
+    }
 
-      //foreach (var symb in allSymbols)
-      //  AddSymbol(symb);
+    public void ConfigureAsDefaultRegressionGrammar() {
+      Symbols.Where(s => s is Average).First().Enabled = false;
+      Symbols.Where(s => s.Name == TrigonometricFunctionsName).First().Enabled = false;
+      Symbols.Where(s => s.Name == PowerFunctionsName).First().Enabled = false;
+      Symbols.Where(s => s.Name == ConditionalSymbolsName).First().Enabled = false;
+      Symbols.Where(s => s.Name == TimeSeriesSymbolsName).First().Enabled = false;
+    }
 
-      //foreach (var unaryFun in unaryFunctionSymbols.Concat(unaryBooleanFunctionSymbols)) {
-      //  SetSubtreeCount(unaryFun, 1, 1);
-      //}
-      //foreach (var binaryFun in binaryFunctionSymbols.Concat(binaryBooleanFunctionSymbols).Concat(relationalFunctionSymbols)) {
-      //  SetSubtreeCount(binaryFun, 2, 2);
-      //}
-
-      //foreach (var terminalSymbol in terminalSymbols) {
-      //  SetSubtreeCount(terminalSymbol, 0, 0);
-      //}
-
-      //SetSubtreeCount(@if, 3, 3);
-
-
-      // allow only real-valued expressions as child of the start symbol
-      //foreach (var symb in realValuedSymbols) {
-      //  AddAllowedChildSymbol(StartSymbol, symb);
-      //  AddAllowedChildSymbol(DefunSymbol, symb);
-      //}
-
-      //foreach (var symb in unaryFunctionSymbols) {
-      //  foreach (var childSymb in realValuedSymbols) {
-      //    AddAllowedChildSymbol(symb, childSymb);
-      //  }
-      //}
-
-      //foreach (var symb in binaryFunctionSymbols) {
-      //  foreach (var childSymb in realValuedSymbols) {
-      //    AddAllowedChildSymbol(symb, childSymb);
-      //  }
-      //}
-
-      //foreach (var childSymb in booleanSymbols) {
-      //  AddAllowedChildSymbol(@if, childSymb, 0);
-      //}
-      //foreach (var childSymb in realValuedSymbols) {
-      //  AddAllowedChildSymbol(@if, childSymb, 1);
-      //  AddAllowedChildSymbol(@if, childSymb, 2);
-      //}
-
-      //foreach (var symb in relationalFunctionSymbols) {
-      //  foreach (var childSymb in realValuedSymbols) {
-      //    AddAllowedChildSymbol(symb, childSymb);
-      //  }
-      //}
-      //foreach (var symb in binaryBooleanFunctionSymbols) {
-      //  foreach (var childSymb in booleanSymbols) {
-      //    AddAllowedChildSymbol(symb, childSymb);
-      //  }
-      //}
-      //foreach (var symb in unaryBooleanFunctionSymbols) {
-      //  foreach (var childSymb in booleanSymbols) {
-      //    AddAllowedChildSymbol(symb, childSymb);
-      //  }
-      //}
+    public void ConfigureAsDefaultClassificationGrammar() {
+      Symbols.Where(s => s is Average).First().Enabled = false;
+      Symbols.Where(s => s.Name == TrigonometricFunctionsName).First().Enabled = false;
+      Symbols.Where(s => s.Name == ExponentialFunctionsName).First().Enabled = false;
+      Symbols.Where(s => s.Name == PowerFunctionsName).First().Enabled = false;
+      Symbols.Where(s => s.Name == TimeSeriesSymbolsName).First().Enabled = false;
     }
   }
