Index: /branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/GrammarEnumeration/Grammar.cs
===================================================================
--- /branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/GrammarEnumeration/Grammar.cs	(revision 15811)
+++ /branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/GrammarEnumeration/Grammar.cs	(revision 15812)
@@ -143,5 +143,5 @@
     }
 
-    private int CalcHashCode<THashType>(SymbolString sentence, Func<Symbol, IEnumerable<THashType>, THashType> aggregateFunction) {
+    private int CalcHashCode<THashType>(SymbolString sentence, Func<Symbol, THashType[], THashType> aggregateFunction) {
       Debug.Assert(sentence.Any(), "Trying to evaluate empty sentence!");
 
@@ -152,5 +152,5 @@
     }
 
-    private THashType[] GetSubtreeHashes<THashType>(Stack<Symbol> parseStack, Func<Symbol, IEnumerable<THashType>, THashType> aggregateHashes) {
+    private THashType[] GetSubtreeHashes<THashType>(Stack<Symbol> parseStack, Func<Symbol, THashType[], THashType> aggregateHashes) {
       Symbol currentSymbol = parseStack.Pop();
 
@@ -207,5 +207,5 @@
 
           var currFactor = childHashes[i];
-          var invFactor = aggregateHashes(Inv, currFactor.ToEnumerable());
+          var invFactor = aggregateHashes(Inv, new[] { currFactor });
 
           int indexOfInv = childHashes.IndexOf(invFactor);
@@ -228,8 +228,8 @@
 
       // var or nonterminal symbol
-      return new[] { aggregateHashes(currentSymbol, Enumerable.Empty<THashType>()) };
-    }
-
-    private string AggregateStringHashes(Symbol operatorSym, IEnumerable<string> hashes) {
+      return new[] { aggregateHashes(currentSymbol, new THashType[0]) };
+    }
+
+    private string AggregateStringHashes(Symbol operatorSym, string[] hashes) {
       var hashesArray = hashes.ToArray();
 
@@ -237,5 +237,5 @@
         return hashesArray[0];
       }
-      if (operatorSym is NonterminalSymbol || Var.VariableTerminalSymbols.Contains(operatorSym)) {
+      if (operatorSym is NonterminalSymbol || ((TerminalSymbol)operatorSym).IsVariable) {
         return operatorSym.StringRepresentation;
       }
@@ -244,13 +244,11 @@
     }
 
-    private int AggregateIntHashes(Symbol operatorSym, IEnumerable<int> hashes) {
-      var hashesArray = hashes.ToArray();
-
+    private int AggregateIntHashes(Symbol operatorSym, int[] hashes) {
       int start;
       if ((ReferenceEquals(operatorSym, Addition) || ReferenceEquals(operatorSym, Multiplication)) &&
-          hashesArray.Count() <= 1) {
+          hashes.Length <= 1) {
         start = 0;
 
-      } else if (operatorSym is NonterminalSymbol || Var.VariableTerminalSymbols.Contains(operatorSym)) {
+      } else if (operatorSym is NonterminalSymbol || ((TerminalSymbol)operatorSym).IsVariable) {
         return operatorSym.StringRepresentation.GetHashCode();
 
@@ -259,5 +257,8 @@
       }
 
-      return hashesArray.Aggregate(start, (result, ti) => ((result << 5) + result) ^ ti.GetHashCode());
+      for (int i = 0; i < hashes.Length; i++) {
+        start = ((start << 5) + start) ^ hashes[i];
+      }
+      return start;
     }
     #endregion
@@ -314,5 +315,5 @@
         parsedSubTree.AddSubtree(ParseSymbolicExpressionTree(parseStack));
 
-      } else if (Var.VariableTerminalSymbols.Contains(currentSymbol)) {
+      } else if (currentSymbol.IsVariable) {
         VariableTreeNode varNode = (VariableTreeNode)varSy.CreateTreeNode();
         varNode.Weight = 1.0;
@@ -337,5 +338,5 @@
       Symbol head = parseStack.Pop();
 
-      SymbolString result = new SymbolString();
+      SymbolString result = new SymbolString(parseStack.Count);
 
       if (ReferenceEquals(head, Addition) || ReferenceEquals(head, Multiplication)) {
Index: /branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/GrammarEnumeration/GrammarEnumerationAlgorithm.cs
===================================================================
--- /branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/GrammarEnumeration/GrammarEnumerationAlgorithm.cs	(revision 15811)
+++ /branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/GrammarEnumeration/GrammarEnumerationAlgorithm.cs	(revision 15812)
@@ -70,5 +70,6 @@
     public Dictionary<int, SymbolString> DistinctSentences { get; private set; }  // Semantically distinct sentences in a run.
     public Dictionary<int, List<SymbolString>> AllSentences { get; private set; } // All sentences ever generated in a run.
-    public Dictionary<int, SymbolString> ArchivedPhrases { get; private set; }    // Nodes in the search tree
+    public HashSet<int> ArchivedPhrases { get; private set; }
+
     internal SearchDataStore OpenPhrases { get; private set; }                    // Stack/Queue/etc. for fetching the next node in the search tree.  
 
@@ -104,5 +105,6 @@
 
       AllSentences = new Dictionary<int, List<SymbolString>>();
-      ArchivedPhrases = new Dictionary<int, SymbolString>(); // Nodes in the search tree
+      ArchivedPhrases = new HashSet<int>();
+
       DistinctSentences = new Dictionary<int, SymbolString>();
       Expansions = 0;
@@ -125,8 +127,8 @@
           StoredSymbolString fetchedPhrase = OpenPhrases.GetNext();
           SymbolString currPhrase = fetchedPhrase.SymbolString;
-
+#if DEBUG
           LogSearchGraph(dotFileTrace, $"{fetchedPhrase.Hash} [label=\"{Grammar.PostfixToInfixParser(fetchedPhrase.SymbolString)}\"];");
-
-          ArchivedPhrases.Add(fetchedPhrase.Hash, currPhrase);
+#endif
+          ArchivedPhrases.Add(fetchedPhrase.Hash);
 
           // expand next nonterminal symbols
@@ -135,5 +137,6 @@
 
           foreach (Production productionAlternative in expandedSymbol.Alternatives) {
-            SymbolString newPhrase = new SymbolString(currPhrase);
+            SymbolString newPhrase = new SymbolString(currPhrase.Count + productionAlternative.Count);
+            newPhrase.AddRange(currPhrase);
             newPhrase.RemoveAt(nonterminalSymbolIndex);     // TODO: removeat and insertRange are both O(n)
             newPhrase.InsertRange(nonterminalSymbolIndex, productionAlternative);
@@ -142,7 +145,7 @@
             if (newPhrase.Count <= MaxTreeSize) {
               var phraseHash = Grammar.CalcHashCode(newPhrase);
-
+#if DEBUG
               LogSearchGraph(dotFileTrace, $"{fetchedPhrase.Hash} -> {phraseHash} [label=\"{expandedSymbol.StringRepresentation} + &rarr; {productionAlternative}\"];");
-
+#endif
               if (newPhrase.IsSentence()) {
                 // Sentence was generated.
@@ -155,9 +158,11 @@
                   EvaluateSentence(newPhrase);
 
+#if DEBUG
                   LogSearchGraph(dotFileTrace, $"{phraseHash} [label=\"{Grammar.PostfixToInfixParser(newPhrase)}\", style=\"filled\"];");
+#endif
                 }
-                UpdateView(AllSentences, DistinctSentences);
-
-              } else if (!OpenPhrases.Contains(phraseHash) && !ArchivedPhrases.ContainsKey(phraseHash)) {
+                UpdateView();
+
+              } else if (!OpenPhrases.Contains(phraseHash) && !ArchivedPhrases.Contains(phraseHash)) {
                 OpenPhrases.Store(phraseHash, newPhrase);
               }
@@ -165,12 +170,13 @@
           }
         }
-
+#if DEBUG
         // Overwrite formatting of start search node and best found solution.
         LogSearchGraph(dotFileTrace, $"{Grammar.CalcHashCode(BestTrainingSentence)} [label=\"{Grammar.PostfixToInfixParser(BestTrainingSentence)}\", shape=Mcircle, style=\"filled,bold\"];");
         LogSearchGraph(dotFileTrace, $"{phrase0Hash} [label=\"{Grammar.PostfixToInfixParser(phrase0)}\", shape=doublecircle];}}");
         dotFileTrace.Flush();
-      }
-
-      UpdateView(AllSentences, DistinctSentences, force: true);
+#endif
+      }
+
+      UpdateView(force: true);
       UpdateFinalResults();
     }
@@ -184,5 +190,5 @@
     }
 
-    #region Evaluation of generated models.
+#region Evaluation of generated models.
 
     // Evaluate sentence within an algorithm run.
@@ -208,7 +214,7 @@
     }
 
-    #endregion
-
-    #region Visualization in HL
+#endregion
+
+#region Visualization in HL
     // Initialize entries in result set.
     private void InitResults() {
@@ -228,14 +234,13 @@
     // Update the view for intermediate results in an algorithm run.
     private int updates;
-    private void UpdateView(Dictionary<int, List<SymbolString>> allGenerated,
-        Dictionary<int, SymbolString> distinctGenerated, bool force = false) {
+    private void UpdateView(bool force = false) {
       updates++;
 
-      if (force || updates % GuiUpdateInterval == 0) {
-        var allGeneratedEnum = allGenerated.Values.SelectMany(x => x).ToArray();
+      if (force || updates % GuiUpdateInterval == 1) {
+        var allGeneratedEnum = AllSentences.Values.SelectMany(x => x).ToArray();
         ((IntValue)Results[GeneratedPhrasesName].Value).Value = ArchivedPhrases.Count;
         ((IntValue)Results[SearchStructureSizeName].Value).Value = OpenPhrases.Count;
         ((IntValue)Results[GeneratedSentencesName].Value).Value = allGeneratedEnum.Length;
-        ((IntValue)Results[DistinctSentencesName].Value).Value = distinctGenerated.Count;
+        ((IntValue)Results[DistinctSentencesName].Value).Value = DistinctSentences.Count;
         ((IntValue)Results[PhraseExpansionsName].Value).Value = Expansions;
         ((IntValue)Results[GeneratedEqualSentencesName].Value).Value = EqualGeneratedSentences;
@@ -279,11 +284,9 @@
       Results.Add(new Result("Distinct generated sentences", new StringMatrix(distinctSentencesMatrix)));
     }
-   
-    private void LogSearchGraph(TraceListener listener, String msg) {
-#if false
+
+    private void LogSearchGraph(TraceListener listener, string msg) {
       listener.Write(msg);
-#endif
-    }
-    #endregion
+    }
+#endregion
 
   }
Index: /branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/GrammarEnumeration/Sentence.cs
===================================================================
--- /branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/GrammarEnumeration/Sentence.cs	(revision 15811)
+++ /branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/GrammarEnumeration/Sentence.cs	(revision 15812)
@@ -8,5 +8,5 @@
   public class SymbolString : List<Symbol> {
 
-    public SymbolString() { }
+    public SymbolString(int capacity) : base(capacity) { }
 
     public SymbolString(IEnumerable<Symbol> symbols) : base(symbols) { }
Index: /branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/GrammarEnumeration/Symbol.cs
===================================================================
--- /branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/GrammarEnumeration/Symbol.cs	(revision 15811)
+++ /branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/GrammarEnumeration/Symbol.cs	(revision 15812)
@@ -16,5 +16,9 @@
 
   public class TerminalSymbol : Symbol {
-    public TerminalSymbol(string representation) : base(representation) { }
+    public readonly bool IsVariable;
+
+    public TerminalSymbol(string representation, bool isVariable = false) : base(representation) {
+      IsVariable = isVariable;
+    }
   }
 
@@ -39,5 +43,5 @@
 
       foreach (string variableName in variableNames) {
-        TerminalSymbol s = new TerminalSymbol(variableName);
+        TerminalSymbol s = new TerminalSymbol(variableName, isVariable: true);
         createdSymbols.Add(s);
         AddProduction(s);
