Index: trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/ProbabilisticTreeCreator.cs
===================================================================
--- trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/ProbabilisticTreeCreator.cs	(revision 6003)
+++ trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/ProbabilisticTreeCreator.cs	(revision 6009)
@@ -103,4 +103,10 @@
     public static void PTC2(IRandom random, ISymbolicExpressionTreeNode seedNode,
       int maxLength, int maxDepth) {
+      // make sure it is possible to create a trees smaller than maxLength and maxDepth
+      if (seedNode.Grammar.GetMinimumExpressionLength(seedNode.Symbol) > maxLength)
+        throw new ArgumentException("Cannot create trees of length " + maxLength + " or shorter because of grammar constraints.", "maxLength");
+      if (seedNode.Grammar.GetMinimumExpressionDepth(seedNode.Symbol) > maxDepth)
+        throw new ArgumentException("Cannot create trees of depth " + maxDepth + " or smaller because of grammar constraints.", "maxDepth");
+
       // tree length is limited by the grammar and by the explicit size constraints
       int allowedMinLength = seedNode.Grammar.GetMinimumExpressionLength(seedNode.Symbol);
@@ -149,5 +155,5 @@
         int argumentIndex = nextExtension.ChildIndex;
         int extensionDepth = nextExtension.ExtensionPointDepth;
-        if (extensionDepth + parent.Grammar.GetMinimumExpressionDepth(parent.Symbol) >= maxDepth) {
+        if (parent.Grammar.GetMinimumExpressionDepth(parent.Symbol) >= maxDepth - extensionDepth) {
           ReplaceWithMinimalTree(random, root, parent, argumentIndex);
         } else {
@@ -155,5 +161,5 @@
                                 where s.InitialFrequency > 0.0
                                 where parent.Grammar.IsAllowedChildSymbol(parent.Symbol, s, argumentIndex)
-                                where parent.Grammar.GetMinimumExpressionDepth(s) + extensionDepth - 1 < maxDepth
+                                where parent.Grammar.GetMinimumExpressionDepth(s) < maxDepth - extensionDepth + 1
                                 where parent.Grammar.GetMaximumExpressionLength(s) > targetLength - totalListMinLength - currentLength
                                 select s)
Index: trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionGrammarBase.cs
===================================================================
--- trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionGrammarBase.cs	(revision 6003)
+++ trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionGrammarBase.cs	(revision 6009)
@@ -229,5 +229,5 @@
 
     public virtual IEnumerable<ISymbol> GetAllowedChildSymbols(ISymbol parent) {
-      return from s in Symbols where IsAllowedChildSymbol(parent, s) select s;
+      return from s in AllowedSymbols where IsAllowedChildSymbol(parent, s) select s;
     }
 
@@ -265,5 +265,5 @@
         cachedMinExpressionLength[symbol.Name] = int.MaxValue; // prevent infinite recursion
         long sumOfMinExpressionLengths = 1 + (from argIndex in Enumerable.Range(0, GetMinimumSubtreeCount(symbol))
-                                              let minForSlot = (long)(from s in Symbols
+                                              let minForSlot = (long)(from s in AllowedSymbols
                                                                       where IsAllowedChildSymbol(symbol, s, argIndex)
                                                                       select GetMinimumExpressionLength(s)).DefaultIfEmpty(0).Min()
@@ -282,10 +282,9 @@
         cachedMaxExpressionLength[symbol.Name] = int.MaxValue; // prevent infinite recursion
         long sumOfMaxTrees = 1 + (from argIndex in Enumerable.Range(0, GetMaximumSubtreeCount(symbol))
-                                  let maxForSlot = (long)(from s in Symbols
+                                  let maxForSlot = (long)(from s in AllowedSymbols
                                                           where IsAllowedChildSymbol(symbol, s, argIndex)
                                                           select GetMaximumExpressionLength(s)).DefaultIfEmpty(0).Max()
                                   select maxForSlot).DefaultIfEmpty(0).Sum();
-        long limit = int.MaxValue;
-        cachedMaxExpressionLength[symbol.Name] = (int)Math.Min(sumOfMaxTrees, limit);
+        cachedMaxExpressionLength[symbol.Name] = (int)Math.Min(sumOfMaxTrees, int.MaxValue);
         return cachedMaxExpressionLength[symbol.Name];
       }
@@ -298,9 +297,10 @@
       if (!cachedMinExpressionDepth.TryGetValue(symbol.Name, out temp)) {
         cachedMinExpressionDepth[symbol.Name] = int.MaxValue; // prevent infinite recursion
-        cachedMinExpressionDepth[symbol.Name] = 1 + (from argIndex in Enumerable.Range(0, GetMinimumSubtreeCount(symbol))
-                                                     let minForSlot = (from s in Symbols
-                                                                       where IsAllowedChildSymbol(symbol, s, argIndex)
-                                                                       select GetMinimumExpressionDepth(s)).DefaultIfEmpty(0).Min()
-                                                     select minForSlot).DefaultIfEmpty(0).Max();
+        long minDepth = 1 + (from argIndex in Enumerable.Range(0, GetMinimumSubtreeCount(symbol))
+                             let minForSlot = (long)(from s in AllowedSymbols
+                                                     where IsAllowedChildSymbol(symbol, s, argIndex)
+                                                     select GetMinimumExpressionDepth(s)).DefaultIfEmpty(0).Min()
+                             select minForSlot).DefaultIfEmpty(0).Max();
+        cachedMinExpressionDepth[symbol.Name] = (int)Math.Min(minDepth, int.MaxValue);
         return cachedMinExpressionDepth[symbol.Name];
       }
