Index: trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionGrammar.cs
===================================================================
--- trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionGrammar.cs	(revision 6233)
+++ trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionGrammar.cs	(revision 6443)
@@ -21,7 +21,9 @@
 
 using System;
+using System.Linq;
 using HeuristicLab.Common;
 using HeuristicLab.Core;
 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+using System.Collections.Generic;
 
 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
@@ -111,8 +113,16 @@
     #endregion
 
+    [StorableHook(HookType.AfterDeserialization)]
+    private void AfterDeserialization() {
+      foreach (ISymbol symbol in symbols.Values)
+        RegisterSymbolEvents(symbol);
+    }
     [StorableConstructor]
     protected SymbolicExpressionGrammar(bool deserializing) : base(deserializing) { }
     protected SymbolicExpressionGrammar(SymbolicExpressionGrammar original, Cloner cloner)
       : base(original, cloner) {
+      foreach (ISymbol symbol in Symbols)
+        RegisterSymbolEvents(symbol);
+
       programRootSymbol = cloner.Clone(original.programRootSymbol);
       startSymbol = cloner.Clone(original.StartSymbol);
@@ -153,4 +163,13 @@
     }
 
+    protected override void AddSymbol(ISymbol symbol) {
+      base.AddSymbol(symbol);
+      RegisterSymbolEvents(symbol);
+    }
+    protected override void RemoveSymbol(ISymbol symbol) {
+      DeregisterSymbolEvents(symbol);
+      base.RemoveSymbol(symbol);
+    }
+
     public event EventHandler ReadOnlyChanged;
     protected virtual void OnReadOnlyChanged() {
@@ -166,4 +185,57 @@
     }
     #endregion
+
+    #region symbol events
+    protected virtual void RegisterSymbolEvents(ISymbol symbol) {
+      symbol.NameChanging += new EventHandler<CancelEventArgs<string>>(Symbol_NameChanging);
+      symbol.NameChanged += new EventHandler(Symbol_NameChanged);
+    }
+    protected virtual void DeregisterSymbolEvents(ISymbol symbol) {
+      symbol.NameChanging -= new EventHandler<CancelEventArgs<string>>(Symbol_NameChanging);
+      symbol.NameChanged -= new EventHandler(Symbol_NameChanged);
+    }
+
+    private void Symbol_NameChanging(object sender, CancelEventArgs<string> e) {
+      if (symbols.ContainsKey(e.Value)) e.Cancel = true;
+    }
+    private void Symbol_NameChanged(object sender, EventArgs e) {
+      ISymbol symbol = (ISymbol)sender;
+      string oldName = symbols.Where(x => x.Value == symbol).First().Key;
+      string newName = symbol.Name;
+
+      symbols.Remove(oldName);
+      symbols.Add(newName, symbol);
+
+      var subtreeCount = symbolSubtreeCount[oldName];
+      symbolSubtreeCount.Remove(oldName);
+      symbolSubtreeCount.Add(newName, subtreeCount);
+
+      List<string> allowedChilds;
+      if (allowedChildSymbols.TryGetValue(oldName, out allowedChilds)) {
+        allowedChildSymbols.Remove(oldName);
+        allowedChildSymbols.Add(newName, allowedChilds);
+      }
+
+      for (int i = 0; i < GetMaximumSubtreeCount(symbol); i++) {
+        if (allowedChildSymbolsPerIndex.TryGetValue(Tuple.Create(oldName, i), out allowedChilds)) {
+          allowedChildSymbolsPerIndex.Remove(Tuple.Create(oldName, i));
+          allowedChildSymbolsPerIndex.Add(Tuple.Create(newName, i), allowedChilds);
+        }
+      }
+
+      foreach (var parent in Symbols) {
+        if (allowedChildSymbols.TryGetValue(parent.Name, out allowedChilds))
+          if (allowedChilds.Remove(oldName))
+            allowedChilds.Add(newName);
+
+        for (int i = 0; i < GetMaximumSubtreeCount(parent); i++) {
+          if (allowedChildSymbolsPerIndex.TryGetValue(Tuple.Create(parent.Name, i), out allowedChilds))
+            if (allowedChilds.Remove(oldName)) allowedChilds.Add(newName);
+        }
+      }
+
+      ClearCaches();
+    }
+    #endregion
   }
 }
