Index: /trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionGrammarBase.cs
===================================================================
--- /trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionGrammarBase.cs	(revision 6813)
+++ /trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionGrammarBase.cs	(revision 6814)
@@ -52,5 +52,5 @@
     [Storable(Name = "AllowedChildSymbols")]
     private IEnumerable<KeyValuePair<ISymbol, IEnumerable<ISymbol>>> StorableAllowedChildSymbols {
-      get { return allowedChildSymbols.Select(x => new KeyValuePair<ISymbol, IEnumerable<ISymbol>>(GetSymbol(x.Key), x.Value.Select(y => GetSymbol(y)).ToArray())).ToArray(); }
+      get { return allowedChildSymbols.Select(x => new KeyValuePair<ISymbol, IEnumerable<ISymbol>>(GetSymbol(x.Key), x.Value.Select(GetSymbol).ToArray())).ToArray(); }
       set { allowedChildSymbols = value.ToDictionary(x => x.Key.Name, x => x.Value.Select(y => y.Name).ToList()); }
     }
@@ -83,4 +83,7 @@
       cachedMinExpressionDepth = new Dictionary<string, int>();
 
+      cachedIsAllowedChildSymbol = new Dictionary<Tuple<string, string>, bool>();
+      cachedIsAllowedChildSymbolIndex = new Dictionary<Tuple<string, string, int>, bool>();
+
       suppressEvents = false;
     }
@@ -92,5 +95,8 @@
       cachedMinExpressionDepth = new Dictionary<string, int>();
 
-      symbols = original.symbols.ToDictionary(x => x.Key, y => (ISymbol)cloner.Clone(y.Value));
+      cachedIsAllowedChildSymbol = new Dictionary<Tuple<string, string>, bool>();
+      cachedIsAllowedChildSymbolIndex = new Dictionary<Tuple<string, string, int>, bool>();
+
+      symbols = original.symbols.ToDictionary(x => x.Key, y => cloner.Clone(y.Value));
       symbolSubtreeCount = new Dictionary<string, Tuple<int, int>>(original.symbolSubtreeCount);
 
@@ -111,4 +117,7 @@
       cachedMaxExpressionLength = new Dictionary<string, int>();
       cachedMinExpressionDepth = new Dictionary<string, int>();
+
+      cachedIsAllowedChildSymbol = new Dictionary<Tuple<string, string>, bool>();
+      cachedIsAllowedChildSymbolIndex = new Dictionary<Tuple<string, string, int>, bool>();
 
       symbols = new Dictionary<string, ISymbol>();
@@ -301,25 +310,39 @@
     }
 
+    private readonly Dictionary<Tuple<string, string>, bool> cachedIsAllowedChildSymbol;
     public virtual bool IsAllowedChildSymbol(ISymbol parent, ISymbol child) {
       if (!child.Enabled) return false;
 
+      bool result;
+      if (cachedIsAllowedChildSymbol.TryGetValue(Tuple.Create(parent.Name, child.Name), out result)) return result;
       List<string> temp;
       if (allowedChildSymbols.TryGetValue(parent.Name, out temp)) {
-        if (temp.Contains(child.Name)) return true;
-        if (temp.SelectMany(s => GetSymbol(s).Flatten().Select(n => n.Name)).Contains(child.Name)) return true;
-      }
+        //if (temp.Contains(child.Name)) return true;
+        if (temp.SelectMany(s => GetSymbol(s).Flatten()).Where(s => s.Name == child.Name).Any()) {
+          cachedIsAllowedChildSymbol.Add(Tuple.Create(parent.Name, child.Name), true);
+          return true;
+        }
+      }
+      cachedIsAllowedChildSymbol.Add(Tuple.Create(parent.Name, child.Name), false);
       return false;
     }
 
+    private readonly Dictionary<Tuple<string, string, int>, bool> cachedIsAllowedChildSymbolIndex;
     public virtual bool IsAllowedChildSymbol(ISymbol parent, ISymbol child, int argumentIndex) {
       if (!child.Enabled) return false;
       if (IsAllowedChildSymbol(parent, child)) return true;
 
+      bool result;
+      if (cachedIsAllowedChildSymbolIndex.TryGetValue(Tuple.Create(parent.Name, child.Name, argumentIndex), out result)) return result;
       List<string> temp;
       var key = Tuple.Create(parent.Name, argumentIndex);
       if (allowedChildSymbolsPerIndex.TryGetValue(key, out temp)) {
-        if (temp.Contains(child.Name)) return true;
-        if (temp.SelectMany(s => GetSymbol(s).Flatten().Select(n => n.Name)).Contains(child.Name)) return true;
-      }
+        //if (temp.Contains(child.Name)) return true;
+        if (temp.SelectMany(s => GetSymbol(s).Flatten()).Where(s => s.Name == child.Name).Any()) {
+          cachedIsAllowedChildSymbolIndex.Add(Tuple.Create(parent.Name, child.Name, argumentIndex), true);
+          return true;
+        }
+      }
+      cachedIsAllowedChildSymbolIndex.Add(Tuple.Create(parent.Name, child.Name, argumentIndex), false);
       return false;
     }
@@ -330,5 +353,5 @@
         return Enumerable.Empty<ISymbol>();
 
-      return childs.Select(x => GetSymbol(x)).Where(s => s.Enabled);
+      return childs.Select(GetSymbol).Where(s => s.Enabled);
     }
 
@@ -343,5 +366,5 @@
         result = result.Union(temp);
 
-      return result.Select(x => GetSymbol(x)).Where(s => s.Enabled);
+      return result.Select(GetSymbol).Where(s => s.Enabled);
     }
 
@@ -357,7 +380,10 @@
       cachedMaxExpressionLength.Clear();
       cachedMinExpressionDepth.Clear();
-    }
-
-    private Dictionary<string, int> cachedMinExpressionLength;
+
+      cachedIsAllowedChildSymbol.Clear();
+      cachedIsAllowedChildSymbolIndex.Clear();
+    }
+
+    private readonly Dictionary<string, int> cachedMinExpressionLength;
     public int GetMinimumExpressionLength(ISymbol symbol) {
       int temp;
@@ -375,5 +401,5 @@
     }
 
-    private Dictionary<string, int> cachedMaxExpressionLength;
+    private readonly Dictionary<string, int> cachedMaxExpressionLength;
     public int GetMaximumExpressionLength(ISymbol symbol) {
       int temp;
@@ -390,5 +416,5 @@
     }
 
-    private Dictionary<string, int> cachedMinExpressionDepth;
+    private readonly Dictionary<string, int> cachedMinExpressionDepth;
     public int GetMinimumExpressionDepth(ISymbol symbol) {
       int temp;
Index: /trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeGrammar.cs
===================================================================
--- /trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeGrammar.cs	(revision 6813)
+++ /trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeGrammar.cs	(revision 6814)
@@ -82,9 +82,9 @@
     public override IEnumerable<ISymbol> GetAllowedChildSymbols(ISymbol parent) {
       var symbols = grammar.GetAllowedChildSymbols(parent).Union(base.GetAllowedChildSymbols(parent));
-      return symbols.SelectMany(s => s.Flatten()).Where(s => s.Enabled && !(s is GroupSymbol));
+      return symbols.SelectMany(s => s.Flatten()).Where(s => s.Enabled).Distinct();
     }
     public override IEnumerable<ISymbol> GetAllowedChildSymbols(ISymbol parent, int argumentIndex) {
       var symbols = grammar.GetAllowedChildSymbols(parent, argumentIndex).Union(base.GetAllowedChildSymbols(parent, argumentIndex));
-      return symbols.SelectMany(s => s.Flatten()).Where(s => s.Enabled && !(s is GroupSymbol));
+      return symbols.SelectMany(s => s.Flatten()).Where(s => s.Enabled).Distinct();
     }
 
Index: /trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Tests/Grammars.cs
===================================================================
--- /trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Tests/Grammars.cs	(revision 6813)
+++ /trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Tests/Grammars.cs	(revision 6814)
@@ -21,7 +21,9 @@
 
 using System.Collections.Generic;
+using System.Linq;
 using HeuristicLab.Common;
 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+using HeuristicLab.Problems.DataAnalysis.Symbolic;
 
 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding_3._4.Tests {
@@ -212,5 +214,8 @@
 
     public static ISymbolicExpressionGrammar CreateSimpleArithmeticGrammar() {
-      var g = new SimpleArithmeticGrammar();
+      var g = new TypeCoherentExpressionGrammar();
+      g.ConfigureAsDefaultRegressionGrammar();
+      g.Symbols.OfType<Variable>().First().Enabled = false;
+      //var g = new SimpleArithmeticGrammar();
       g.MaximumFunctionArguments = 0;
       g.MinimumFunctionArguments = 0;
@@ -221,5 +226,7 @@
 
     public static ISymbolicExpressionGrammar CreateArithmeticAndAdfGrammar() {
-      var g = new SimpleArithmeticGrammar();
+      var g = new TypeCoherentExpressionGrammar();
+      g.ConfigureAsDefaultRegressionGrammar();
+      g.Symbols.OfType<Variable>().First().Enabled = false;
       g.MaximumFunctionArguments = 3;
       g.MinimumFunctionArguments = 0;
Index: /trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Tests/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4.Tests.csproj
===================================================================
--- /trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Tests/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4.Tests.csproj	(revision 6813)
+++ /trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Tests/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4.Tests.csproj	(revision 6814)
@@ -149,4 +149,8 @@
       <Name>HeuristicLab.PluginInfrastructure-3.3</Name>
     </ProjectReference>
+    <ProjectReference Include="..\..\..\HeuristicLab.Problems.DataAnalysis.Symbolic\3.4\HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj">
+      <Project>{3D28463F-EC96-4D82-AFEE-38BE91A0CA00}</Project>
+      <Name>HeuristicLab.Problems.DataAnalysis.Symbolic-3.4</Name>
+    </ProjectReference>
     <ProjectReference Include="..\..\..\HeuristicLab.Random\3.3\HeuristicLab.Random-3.3.csproj">
       <Project>{F4539FB6-4708-40C9-BE64-0A1390AEA197}</Project>
Index: /trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Tests/ProbabilisticTreeCreaterTest.cs
===================================================================
--- /trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Tests/ProbabilisticTreeCreaterTest.cs	(revision 6813)
+++ /trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Tests/ProbabilisticTreeCreaterTest.cs	(revision 6814)
@@ -72,5 +72,5 @@
         Util.GetTerminalDistributionString(randomTrees) + Environment.NewLine
         );
-      Assert.IsTrue(Math.Round(1000.0 / (msPerRandomTreeCreation)) > 500); // must achieve more than 500 random trees / s
+      Assert.IsTrue(Math.Round(1000.0 / (msPerRandomTreeCreation)) > 300); // must achieve more than 500 random trees / s
     }
   }
Index: /trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Tests/Util.cs
===================================================================
--- /trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Tests/Util.cs	(revision 6813)
+++ /trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Tests/Util.cs	(revision 6814)
@@ -153,5 +153,5 @@
     public static void IsValid(ISymbolicExpressionTreeGrammar grammar) {
       Assert.IsTrue(grammar.Symbols.Count() == grammar.Symbols.Distinct().Count());
-      foreach (ISymbol symbol in grammar.Symbols) {
+      foreach (ISymbol symbol in grammar.AllowedSymbols) {
         Assert.IsTrue(grammar.GetMinimumSubtreeCount(symbol) <= grammar.GetMaximumExpressionLength(symbol));
         Assert.IsTrue(grammar.GetAllowedChildSymbols(symbol).Count() == grammar.GetAllowedChildSymbols(symbol).Distinct().Count());
