Index: branches/HeuristicLab.TimeSeries/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Analyzers/SymbolicExpressionTreeLengthAnalyzer.cs
===================================================================
--- branches/HeuristicLab.TimeSeries/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Analyzers/SymbolicExpressionTreeLengthAnalyzer.cs	(revision 7615)
+++ branches/HeuristicLab.TimeSeries/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Analyzers/SymbolicExpressionTreeLengthAnalyzer.cs	(revision 7842)
@@ -153,5 +153,5 @@
         // if the table was not created yet, we create it here
         if (treeLengthsTable == null) {
-          treeLengthsTable = new DataTable("Histogram");
+          treeLengthsTable = new DataTable("Tree Length Histogram");
           SymbolicExpressionTreeLengthsParameter.ActualValue = treeLengthsTable;
         }
Index: branches/HeuristicLab.TimeSeries/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/ISymbolicExpressionTree.cs
===================================================================
--- branches/HeuristicLab.TimeSeries/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/ISymbolicExpressionTree.cs	(revision 7615)
+++ branches/HeuristicLab.TimeSeries/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/ISymbolicExpressionTree.cs	(revision 7842)
@@ -29,4 +29,5 @@
     int Depth { get; }
 
+    IEnumerable<ISymbolicExpressionTreeNode> IterateNodesBreadth();
     IEnumerable<ISymbolicExpressionTreeNode> IterateNodesPrefix();
     IEnumerable<ISymbolicExpressionTreeNode> IterateNodesPostfix();
Index: branches/HeuristicLab.TimeSeries/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/ISymbolicExpressionTreeNode.cs
===================================================================
--- branches/HeuristicLab.TimeSeries/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/ISymbolicExpressionTreeNode.cs	(revision 7615)
+++ branches/HeuristicLab.TimeSeries/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/ISymbolicExpressionTreeNode.cs	(revision 7842)
@@ -34,4 +34,5 @@
     int GetBranchLevel(ISymbolicExpressionTreeNode child);
 
+    IEnumerable<ISymbolicExpressionTreeNode> IterateNodesBreadth();
     IEnumerable<ISymbolicExpressionTreeNode> IterateNodesPostfix();
     IEnumerable<ISymbolicExpressionTreeNode> IterateNodesPrefix();
Index: branches/HeuristicLab.TimeSeries/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Manipulators/ChangeNodeTypeManipulation.cs
===================================================================
--- branches/HeuristicLab.TimeSeries/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Manipulators/ChangeNodeTypeManipulation.cs	(revision 7615)
+++ branches/HeuristicLab.TimeSeries/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Manipulators/ChangeNodeTypeManipulation.cs	(revision 7842)
@@ -24,4 +24,5 @@
 using HeuristicLab.Core;
 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+using System.Collections.Generic;
 
 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
@@ -29,4 +30,6 @@
   [Item("ChangeNodeTypeManipulation", "Selects a random tree node and changes the symbol.")]
   public sealed class ChangeNodeTypeManipulation : SymbolicExpressionTreeManipulator {
+    private const int MAX_TRIES = 100;
+
     [StorableConstructor]
     private ChangeNodeTypeManipulation(bool deserializing) : base(deserializing) { }
@@ -43,41 +46,50 @@
 
     public static void ChangeNodeType(IRandom random, ISymbolicExpressionTree symbolicExpressionTree) {
-      // select any node as parent (except the root node)
-      var manipulationPoints = (from parent in symbolicExpressionTree.Root.IterateNodesPrefix().Skip(1)
-                                let subtreeCount = parent.Subtrees.Count()
-                                from subtreeIndex in Enumerable.Range(0, subtreeCount)
-                                let subtree = parent.GetSubtree(subtreeIndex)
-                                let existingSubtreeCount = subtree.Subtrees.Count()
-                                // find possible symbols for the node (also considering the existing branches below it)
-                                let allowedSymbols = (from symbol in parent.Grammar.GetAllowedChildSymbols(parent.Symbol, subtreeIndex)
-                                                      // do not replace the existing symbol with itself
-                                                      where symbol.Name != subtree.Symbol.Name
-                                                      where symbol.InitialFrequency > 0
-                                                      where existingSubtreeCount <= parent.Grammar.GetMaximumSubtreeCount(symbol)
-                                                      where existingSubtreeCount >= parent.Grammar.GetMinimumSubtreeCount(symbol)
-                                                      // keep only symbols that are still possible considering the existing sub-trees
-                                                      where (from existingSubtreeIndex in Enumerable.Range(0, existingSubtreeCount)
-                                                             let existingSubtree = subtree.GetSubtree(existingSubtreeIndex)
-                                                             select parent.Grammar.IsAllowedChildSymbol(symbol, existingSubtree.Symbol, existingSubtreeIndex))
-                                                             .All(x => x == true)
-                                                      select symbol)
-                                                      .ToList()
-                                where allowedSymbols.Count() > 0
-                                select new { Parent = parent, Child = subtree, Index = subtreeIndex, AllowedSymbols = allowedSymbols })
-                               .ToList();
-      if (manipulationPoints.Count == 0) { return; }
-      var selectedManipulationPoint = manipulationPoints.SelectRandom(random);
+      List<ISymbol> allowedSymbols = new List<ISymbol>();
+      ISymbolicExpressionTreeNode parent;
+      int childIndex;
+      ISymbolicExpressionTreeNode child;
+      // repeat until a fitting parent and child are found (MAX_TRIES times)
+      int tries = 0;
+      do {
+        parent = symbolicExpressionTree.Root.IterateNodesPrefix().Skip(1).Where(n => n.SubtreeCount > 0).SelectRandom(random);
+        childIndex = random.Next(parent.SubtreeCount);
 
-      var weights = selectedManipulationPoint.AllowedSymbols.Select(s => s.InitialFrequency).ToList();
-      var newSymbol = selectedManipulationPoint.AllowedSymbols.SelectRandom(weights, random);
+        child = parent.GetSubtree(childIndex);
+        int existingSubtreeCount = child.SubtreeCount;
+        allowedSymbols.Clear();
+        foreach (var symbol in parent.Grammar.GetAllowedChildSymbols(parent.Symbol, childIndex)) {
+          // check basic properties that the new symbol must have
+          if (symbol.Name != child.Symbol.Name &&
+            symbol.InitialFrequency > 0 &&
+            existingSubtreeCount <= parent.Grammar.GetMinimumSubtreeCount(symbol) &&
+            existingSubtreeCount >= parent.Grammar.GetMaximumSubtreeCount(symbol)) {
+            // check that all existing subtrees are also allowed for the new symbol
+            bool allExistingSubtreesAllowed = true;
+            for (int existingSubtreeIndex = 0; existingSubtreeIndex < existingSubtreeCount && allExistingSubtreesAllowed; existingSubtreeIndex++) {
+              var existingSubtree = child.GetSubtree(existingSubtreeIndex);
+              allExistingSubtreesAllowed &= parent.Grammar.IsAllowedChildSymbol(symbol, existingSubtree.Symbol, existingSubtreeIndex);
+            }
+            if (allExistingSubtreesAllowed) {
+              allowedSymbols.Add(symbol);
+            }
+          }
+        }
+        tries++;
+      } while (tries < MAX_TRIES && allowedSymbols.Count == 0);
 
-      // replace the old node with the new node
-      var newNode = newSymbol.CreateTreeNode();
-      if (newNode.HasLocalParameters)
-        newNode.ResetLocalParameters(random);
-      foreach (var subtree in selectedManipulationPoint.Child.Subtrees)
-        newNode.AddSubtree(subtree);
-      selectedManipulationPoint.Parent.RemoveSubtree(selectedManipulationPoint.Index);
-      selectedManipulationPoint.Parent.InsertSubtree(selectedManipulationPoint.Index, newNode);
+      if (tries < MAX_TRIES) {
+        var weights = allowedSymbols.Select(s => s.InitialFrequency).ToList();
+        var newSymbol = allowedSymbols.SelectRandom(weights, random);
+
+        // replace the old node with the new node
+        var newNode = newSymbol.CreateTreeNode();
+        if (newNode.HasLocalParameters)
+          newNode.ResetLocalParameters(random);
+        foreach (var subtree in child.Subtrees)
+          newNode.AddSubtree(subtree);
+        parent.RemoveSubtree(childIndex);
+        parent.InsertSubtree(childIndex, newNode);
+      }
     }
   }
Index: branches/HeuristicLab.TimeSeries/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Manipulators/ReplaceBranchManipulation.cs
===================================================================
--- branches/HeuristicLab.TimeSeries/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Manipulators/ReplaceBranchManipulation.cs	(revision 7615)
+++ branches/HeuristicLab.TimeSeries/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Manipulators/ReplaceBranchManipulation.cs	(revision 7842)
@@ -26,4 +26,5 @@
 using HeuristicLab.Parameters;
 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+using System.Collections.Generic;
 
 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
@@ -31,4 +32,5 @@
   [Item("ReplaceBranchManipulation", "Selects a branch of the tree randomly and replaces it with a newly initialized branch (using PTC2).")]
   public sealed class ReplaceBranchManipulation : SymbolicExpressionTreeManipulator, ISymbolicExpressionTreeSizeConstraintOperator {
+    private const int MAX_TRIES = 100;
     private const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength";
     private const string MaximumSymbolicExpressionTreeDepthParameterName = "MaximumSymbolicExpressionTreeDepth";
@@ -68,43 +70,43 @@
 
     public static void ReplaceRandomBranch(IRandom random, ISymbolicExpressionTree symbolicExpressionTree, int maxTreeLength, int maxTreeDepth) {
-      // select any node as parent (except the root node)
-      var manipulationPoints = (from parent in symbolicExpressionTree.Root.IterateNodesPrefix().Skip(1)
-                                from subtree in parent.Subtrees
-                                let subtreeIndex = parent.IndexOfSubtree(subtree)
-                                let maxLength = maxTreeLength - symbolicExpressionTree.Length + subtree.GetLength()
-                                let maxDepth = maxTreeDepth - symbolicExpressionTree.Depth + subtree.GetDepth()
-                                // find possible symbols for the node (also considering the existing branches below it)
-                                let allowedSymbols = (from symbol in parent.Grammar.GetAllowedChildSymbols(parent.Symbol, subtreeIndex)
-                                                      // do not replace symbol with the same symbol
-                                                      where symbol.Name != subtree.Symbol.Name
-                                                      where symbol.InitialFrequency > 0
-                                                      where parent.Grammar.GetMinimumExpressionDepth(symbol) + 1 <= maxDepth
-                                                      where parent.Grammar.GetMinimumExpressionLength(symbol) <= maxLength
-                                                      select symbol)
-                                                      .ToList()
-                                where allowedSymbols.Count > 0
-                                select new {
-                                  Parent = parent,
-                                  Child = subtree,
-                                  Index = subtreeIndex,
-                                  AllowedSymbols = allowedSymbols,
-                                  MaxLength = maxLength,
-                                  MaxDepth = maxDepth
-                                })
-                               .ToList();
+      var allowedSymbols = new List<ISymbol>();
+      ISymbolicExpressionTreeNode parent;
+      int childIndex;
+      int maxLength;
+      int maxDepth;
+      // repeat until a fitting parent and child are found (MAX_TRIES times)
+      int tries = 0;
+      do {
+        parent = symbolicExpressionTree.Root.IterateNodesPrefix().Skip(1).Where(n => n.SubtreeCount > 0).SelectRandom(random);
+        childIndex = random.Next(parent.SubtreeCount);
+        var child = parent.GetSubtree(childIndex);
+        maxLength = maxTreeLength - symbolicExpressionTree.Length + child.GetLength();
+        maxDepth = maxTreeDepth - symbolicExpressionTree.Depth + child.GetDepth();
 
-      if (manipulationPoints.Count == 0) return;
-      var selectedManipulationPoint = manipulationPoints.SelectRandom(random);
+        allowedSymbols.Clear();
+        foreach (var symbol in parent.Grammar.GetAllowedChildSymbols(parent.Symbol, childIndex)) {
+          // check basic properties that the new symbol must have
+          if (symbol.Name != child.Symbol.Name &&
+            symbol.InitialFrequency > 0 &&
+            parent.Grammar.GetMinimumExpressionDepth(symbol) + 1 <= maxDepth &&
+            parent.Grammar.GetMinimumExpressionLength(symbol) <= maxLength) {
+            allowedSymbols.Add(symbol);
+          }
+        }
+        tries++;
+      } while (tries < MAX_TRIES && allowedSymbols.Count == 0);
 
-      var weights = selectedManipulationPoint.AllowedSymbols.Select(s => s.InitialFrequency).ToList();
-      var seedSymbol = selectedManipulationPoint.AllowedSymbols.SelectRandom(weights, random);
-      // replace the old node with the new node
-      var seedNode = seedSymbol.CreateTreeNode();
-      if (seedNode.HasLocalParameters)
-        seedNode.ResetLocalParameters(random);
+      if (tries < MAX_TRIES) {
+        var weights = allowedSymbols.Select(s => s.InitialFrequency).ToList();
+        var seedSymbol = allowedSymbols.SelectRandom(weights, random);
+        // replace the old node with the new node
+        var seedNode = seedSymbol.CreateTreeNode();
+        if (seedNode.HasLocalParameters)
+          seedNode.ResetLocalParameters(random);
 
-      selectedManipulationPoint.Parent.RemoveSubtree(selectedManipulationPoint.Index);
-      selectedManipulationPoint.Parent.InsertSubtree(selectedManipulationPoint.Index, seedNode);
-      ProbabilisticTreeCreator.PTC2(random, seedNode, selectedManipulationPoint.MaxLength, selectedManipulationPoint.MaxDepth);
+        parent.RemoveSubtree(childIndex);
+        parent.InsertSubtree(childIndex, seedNode);
+        ProbabilisticTreeCreator.PTC2(random, seedNode, maxLength, maxDepth);
+      }
     }
   }
Index: branches/HeuristicLab.TimeSeries/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionGrammar.cs
===================================================================
--- branches/HeuristicLab.TimeSeries/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionGrammar.cs	(revision 7615)
+++ branches/HeuristicLab.TimeSeries/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionGrammar.cs	(revision 7842)
@@ -181,5 +181,8 @@
 
     #region IStatefulItem methods
-    void IStatefulItem.InitializeState() { }
+    void IStatefulItem.InitializeState()
+    {
+      ReadOnly = false;
+    }
     void IStatefulItem.ClearState() {
       ReadOnly = false;
Index: branches/HeuristicLab.TimeSeries/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionGrammarBase.cs
===================================================================
--- branches/HeuristicLab.TimeSeries/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionGrammarBase.cs	(revision 7615)
+++ branches/HeuristicLab.TimeSeries/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionGrammarBase.cs	(revision 7842)
@@ -308,5 +308,5 @@
     }
     public virtual IEnumerable<ISymbol> AllowedSymbols {
-      get { return Symbols.Where(s => s.Enabled); }
+      get { foreach (var s in Symbols) if (s.Enabled) yield return s; }
     }
     public virtual bool ContainsSymbol(ISymbol symbol) {
@@ -316,17 +316,20 @@
     private readonly Dictionary<Tuple<string, string>, bool> cachedIsAllowedChildSymbol;
     public virtual bool IsAllowedChildSymbol(ISymbol parent, ISymbol child) {
+      if (allowedChildSymbols.Count == 0) return false;
       if (!child.Enabled) return false;
 
       bool result;
-      if (cachedIsAllowedChildSymbol.TryGetValue(Tuple.Create(parent.Name, child.Name), out result)) return result;
+      var key = Tuple.Create(parent.Name, child.Name);
+      if (cachedIsAllowedChildSymbol.TryGetValue(key, 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()).Where(s => s.Name == child.Name).Any()) {
-          cachedIsAllowedChildSymbol.Add(Tuple.Create(parent.Name, child.Name), true);
+        if (temp.SelectMany(s => GetSymbol(s).Flatten()).Any(s => s.Name == child.Name)) {
+          cachedIsAllowedChildSymbol.Add(key, true);
           return true;
         }
       }
-      cachedIsAllowedChildSymbol.Add(Tuple.Create(parent.Name, child.Name), false);
+      cachedIsAllowedChildSymbol.Add(key, false);
       return false;
     }
@@ -336,30 +339,31 @@
       if (!child.Enabled) return false;
       if (IsAllowedChildSymbol(parent, child)) return true;
+      if (allowedChildSymbolsPerIndex.Count == 0) return false;
 
       bool result;
-      if (cachedIsAllowedChildSymbolIndex.TryGetValue(Tuple.Create(parent.Name, child.Name, argumentIndex), out result)) return result;
+      var key = Tuple.Create(parent.Name, child.Name, argumentIndex);
+      if (cachedIsAllowedChildSymbolIndex.TryGetValue(key, 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()).Where(s => s.Name == child.Name).Any()) {
-          cachedIsAllowedChildSymbolIndex.Add(Tuple.Create(parent.Name, child.Name, argumentIndex), true);
+      if (allowedChildSymbolsPerIndex.TryGetValue(Tuple.Create(parent.Name, argumentIndex), out temp)) {
+        if (temp.SelectMany(s => GetSymbol(s).Flatten()).Any(s => s.Name == child.Name)) {
+          cachedIsAllowedChildSymbolIndex.Add(key, true);
           return true;
         }
       }
-      cachedIsAllowedChildSymbolIndex.Add(Tuple.Create(parent.Name, child.Name, argumentIndex), false);
+      cachedIsAllowedChildSymbolIndex.Add(key, false);
       return false;
     }
 
     public IEnumerable<ISymbol> GetAllowedChildSymbols(ISymbol parent) {
-      return from child in AllowedSymbols
-             where IsAllowedChildSymbol(parent, child)
-             select child;
+      foreach (ISymbol child in AllowedSymbols) {
+        if (IsAllowedChildSymbol(parent, child)) yield return child;
+      }
     }
 
     public IEnumerable<ISymbol> GetAllowedChildSymbols(ISymbol parent, int argumentIndex) {
-      return from child in AllowedSymbols
-             where IsAllowedChildSymbol(parent, child, argumentIndex)
-             select child;
+      foreach (ISymbol child in AllowedSymbols) {
+        if (IsAllowedChildSymbol(parent, child, argumentIndex)) yield return child;
+      }
     }
 
Index: branches/HeuristicLab.TimeSeries/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTree.cs
===================================================================
--- branches/HeuristicLab.TimeSeries/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTree.cs	(revision 7615)
+++ branches/HeuristicLab.TimeSeries/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTree.cs	(revision 7842)
@@ -75,4 +75,10 @@
     }
 
+    public IEnumerable<ISymbolicExpressionTreeNode> IterateNodesBreadth() {
+      if (root == null)
+        return new SymbolicExpressionTreeNode[0];
+      return root.IterateNodesBreadth();
+    }
+
     public IEnumerable<ISymbolicExpressionTreeNode> IterateNodesPrefix() {
       if (root == null)
Index: branches/HeuristicLab.TimeSeries/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeGrammar.cs
===================================================================
--- branches/HeuristicLab.TimeSeries/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeGrammar.cs	(revision 7615)
+++ branches/HeuristicLab.TimeSeries/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeGrammar.cs	(revision 7842)
@@ -22,5 +22,4 @@
 using System;
 using System.Collections.Generic;
-using System.Linq;
 using HeuristicLab.Common;
 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
@@ -51,5 +50,8 @@
 
     public override IEnumerable<ISymbol> Symbols {
-      get { return grammar.Symbols.Union(base.Symbols); }
+      get {
+        foreach (var s in grammar.Symbols) yield return s;
+        foreach (var s in base.symbols.Values) yield return s;
+      }
     }
     public override IEnumerable<ISymbol> AllowedSymbols {
Index: branches/HeuristicLab.TimeSeries/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeNode.cs
===================================================================
--- branches/HeuristicLab.TimeSeries/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeNode.cs	(revision 7615)
+++ branches/HeuristicLab.TimeSeries/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeNode.cs	(revision 7842)
@@ -53,6 +53,8 @@
     protected SymbolicExpressionTreeNode(bool deserializing) { }
     protected SymbolicExpressionTreeNode(SymbolicExpressionTreeNode original, Cloner cloner)
-      : base() {
+      : base(original, cloner) {
       symbol = original.symbol; // symbols are reused
+      length = original.length;
+      depth = original.depth;
       if (original.subtrees != null) {
         subtrees = new List<ISymbolicExpressionTreeNode>(original.subtrees.Count);
@@ -172,4 +174,15 @@
     }
 
+    public IEnumerable<ISymbolicExpressionTreeNode> IterateNodesBreadth() {
+      var list = new List<ISymbolicExpressionTreeNode>() { this };
+      int i = 0;
+      while (i != list.Count) {
+        for (int j = 0; j != list[i].SubtreeCount; ++j)
+          list.Add(list[i].GetSubtree(j));
+        ++i;
+      }
+      return list;
+    }
+
     public IEnumerable<ISymbolicExpressionTreeNode> IterateNodesPrefix() {
       List<ISymbolicExpressionTreeNode> list = new List<ISymbolicExpressionTreeNode>();
