Index: /trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Grammars/GrammarUtils.cs
===================================================================
--- /trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Grammars/GrammarUtils.cs	(revision 14356)
+++ /trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Grammars/GrammarUtils.cs	(revision 14357)
@@ -44,12 +44,12 @@
     }
 
-    private static IEnumerable<ISymbol> IterateBreadthReverse(this ISymbolicExpressionGrammarBase grammar, ISymbol topSymbol) {
+    private static IReadOnlyCollection<ISymbol> IterateBreadthReverse(this ISymbolicExpressionGrammarBase grammar, ISymbol topSymbol) {
       // sort symbols in reverse breadth order (starting from the topSymbol)
       // each symbol is visited only once (this avoids infinite recursion)
-      var numberedSymbols = new List<Tuple<ISymbol, int>> { Tuple.Create(topSymbol, 0) };
+      var symbols = new List<ISymbol> { topSymbol };
       var visited = new HashSet<ISymbol> { topSymbol };
-      int i = 0, index = 0;
-      while (i < numberedSymbols.Count) {
-        var symbol = numberedSymbols[i].Item1;
+      int i = 0;
+      while (i < symbols.Count) {
+        var symbol = symbols[i];
         var minSubtreeCount = grammar.GetMinimumSubtreeCount(symbol);
 
@@ -60,11 +60,11 @@
 
             if (visited.Add(childSymbol))
-              numberedSymbols.Add(Tuple.Create(childSymbol, ++index));
+              symbols.Add(childSymbol);
           }
         }
         ++i;
       }
-      numberedSymbols.Reverse();
-      return numberedSymbols.Select(x => x.Item1);
+      symbols.Reverse();
+      return symbols;
     }
 
@@ -77,11 +77,15 @@
       minimumExpressionLengths.Clear();
       //terminal symbols => minimum expression length = 1
-      foreach (var s in grammar.Symbols.Where(x => grammar.GetMinimumSubtreeCount(x) == 0))
-        minimumExpressionLengths[s.Name] = 1;
+      foreach (var s in grammar.Symbols) {
+        if (grammar.GetMinimumSubtreeCount(s) == 0)
+          minimumExpressionLengths[s.Name] = 1;
+        else
+          minimumExpressionLengths[s.Name] = int.MaxValue;
+      }
 
       foreach (var topSymbol in grammar.GetTopmostSymbols()) {
         // get all symbols below in reverse breadth order
         // this way we ensure lengths are calculated bottom-up
-        var symbols = grammar.IterateBreadthReverse(topSymbol).ToList();
+        var symbols = grammar.IterateBreadthReverse(topSymbol);
         foreach (var symbol in symbols) {
           long minLength = 1;
@@ -112,10 +116,4 @@
         }
       }
-
-      //set minLength to int.MaxValue for all symbols that are not reacheable
-      foreach (var remainingSymbols in grammar.Symbols) {
-        if (!minimumExpressionLengths.ContainsKey(remainingSymbols.Name))
-          minimumExpressionLengths[remainingSymbols.Name] = int.MaxValue;
-      }
     }
 
@@ -125,11 +123,15 @@
       minimumExpressionDepths.Clear();
       //terminal symbols => minimum expression depth = 1
-      foreach (var s in grammar.Symbols.Where(s => grammar.GetMinimumSubtreeCount(s) == 0))
-        minimumExpressionDepths[s.Name] = 1;
+      foreach (var s in grammar.Symbols) {
+        if (grammar.GetMinimumSubtreeCount(s) == 0)
+          minimumExpressionDepths[s.Name] = 1;
+        else
+          minimumExpressionDepths[s.Name] = int.MaxValue;
+      }
 
       foreach (var topSymbol in grammar.GetTopmostSymbols()) {
         // get all symbols below in reverse breadth order
         // this way we ensure lengths are calculated bottom-up
-        var symbols = grammar.IterateBreadthReverse(topSymbol).ToList();
+        var symbols = grammar.IterateBreadthReverse(topSymbol);
         foreach (var symbol in symbols) {
           long minDepth = -1;
@@ -160,10 +162,4 @@
         }
       }
-
-      //set minDepth to int.Maxvalue for all symbols that are not reacheable
-      foreach (var remainingSymbols in grammar.Symbols) {
-        if (!minimumExpressionDepths.ContainsKey(remainingSymbols.Name))
-          minimumExpressionDepths[remainingSymbols.Name] = int.MaxValue;
-      }
     }
   }
