Index: branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/Analysis/RSquaredEvaluator.cs
===================================================================
--- branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/Analysis/RSquaredEvaluator.cs	(revision 15907)
+++ branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/Analysis/RSquaredEvaluator.cs	(revision 15910)
@@ -23,5 +23,5 @@
     public RSquaredEvaluator() { }
 
-    protected RSquaredEvaluator(RSquaredEvaluator original, Cloner cloner) {
+    protected RSquaredEvaluator(RSquaredEvaluator original, Cloner cloner) : base(original, cloner) {
       this.OptimizeConstants = original.OptimizeConstants;
     }
@@ -52,5 +52,4 @@
     private void OnStarted(object sender, EventArgs eventArgs) {
       GrammarEnumerationAlgorithm algorithm = (GrammarEnumerationAlgorithm)sender;
-      algorithm.Results.Add(new Result(BestTrainingQualityResultName, new DoubleValue(-1.0)));
 
       algorithm.BestTrainingSentence = null;
@@ -75,7 +74,9 @@
       double r2 = Evaluate(problemData, tree, OptimizeConstants);
 
-      var bestR2Result = (DoubleValue)algorithm.Results[BestTrainingQualityResultName].Value;
-      bool better = r2 > bestR2Result.Value;
-      bool equallyGood = r2.IsAlmost(bestR2Result.Value);
+      double bestR2 = 0.0;
+      if (algorithm.Results.ContainsKey(BestTrainingQualityResultName))
+        bestR2 = ((DoubleValue)algorithm.Results[BestTrainingQualityResultName].Value).Value;
+      bool better = r2 > bestR2;
+      bool equallyGood = r2.IsAlmost(bestR2);
       bool shorter = false;
 
@@ -85,5 +86,5 @@
       }
       if (better || (equallyGood && shorter)) {
-        bestR2Result.Value = r2;
+        algorithm.Results.AddOrUpdateResult(BestTrainingQualityResultName, new DoubleValue(r2));
 
         SymbolicRegressionModel model = new SymbolicRegressionModel(
Index: branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/Analysis/SearchGraphVisualizer.cs
===================================================================
--- branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/Analysis/SearchGraphVisualizer.cs	(revision 15907)
+++ branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/Analysis/SearchGraphVisualizer.cs	(revision 15910)
@@ -14,5 +14,5 @@
     public SearchGraphVisualizer() { }
 
-    protected SearchGraphVisualizer(SearchGraphVisualizer original, Cloner cloner) { }
+    protected SearchGraphVisualizer(SearchGraphVisualizer original, Cloner cloner) : base(original, cloner) { }
 
     public override IDeepCloneable Clone(Cloner cloner) {
Index: branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/Analysis/SentenceLogger.cs
===================================================================
--- branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/Analysis/SentenceLogger.cs	(revision 15907)
+++ branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/Analysis/SentenceLogger.cs	(revision 15910)
@@ -20,5 +20,5 @@
     public SentenceLogger() { }
 
-    protected SentenceLogger(SentenceLogger original, Cloner cloner) { }
+    protected SentenceLogger(SentenceLogger original, Cloner cloner) : base(original, cloner) { }
 
     public override IDeepCloneable Clone(Cloner cloner) {
Index: branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/GrammarEnumeration/GrammarEnumerationAlgorithm.cs
===================================================================
--- branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/GrammarEnumeration/GrammarEnumerationAlgorithm.cs	(revision 15907)
+++ branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/GrammarEnumeration/GrammarEnumerationAlgorithm.cs	(revision 15910)
@@ -2,5 +2,4 @@
 using System.Collections.Generic;
 using System.Linq;
-using System.Security.Cryptography;
 using System.Threading;
 using HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration.GrammarEnumeration;
@@ -32,4 +31,5 @@
 
     private readonly string OptimizeConstantsParameterName = "Optimize Constants";
+    private readonly string ErrorWeightParameterName = "Error Weight";
     private readonly string SearchDataStructureParameterName = "Search Data Structure";
     private readonly string MaxComplexityParameterName = "Max. Complexity";
@@ -53,4 +53,12 @@
       get { return MaxComplexityParameter.Value.Value; }
       set { MaxComplexityParameter.Value.Value = value; }
+    }
+
+    protected IValueParameter<DoubleValue> ErrorWeightParameter {
+      get { return (IValueParameter<DoubleValue>)Parameters[ErrorWeightParameterName]; }
+    }
+    public double ErrorWeight {
+      get { return ErrorWeightParameter.Value.Value; }
+      set { ErrorWeightParameter.Value.Value = value; }
     }
 
@@ -105,11 +113,12 @@
     public GrammarEnumerationAlgorithm() {
       Problem = new RegressionProblem() {
-        ProblemData = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenFunctionNine(seed: 1234).GenerateRegressionData()
+        ProblemData = new HeuristicLab.Problems.Instances.DataAnalysis.PolyTen(seed: 1234).GenerateRegressionData()
       };
 
-      Parameters.Add(new ValueParameter<BoolValue>(OptimizeConstantsParameterName, "Run constant optimization in sentence evaluation.", new BoolValue(true)));
-      Parameters.Add(new ValueParameter<IntValue>(MaxComplexityParameterName, "The maximum number of variable symbols in a sentence.", new IntValue(5)));
-      Parameters.Add(new ValueParameter<IntValue>(GuiUpdateIntervalParameterName, "Number of generated sentences, until GUI is refreshed.", new IntValue(100000)));
-      Parameters.Add(new ValueParameter<EnumValue<StorageType>>(SearchDataStructureParameterName, new EnumValue<StorageType>(StorageType.Stack)));
+      Parameters.Add(new ValueParameter<BoolValue>(OptimizeConstantsParameterName, "Run constant optimization in sentence evaluation.", new BoolValue(false)));
+      Parameters.Add(new ValueParameter<DoubleValue>(ErrorWeightParameterName, "Defines, how much weight is put on a phrase's r² value when priorizing phrases during search.", new DoubleValue(0.8)));
+      Parameters.Add(new ValueParameter<IntValue>(MaxComplexityParameterName, "The maximum number of variable symbols in a sentence.", new IntValue(12)));
+      Parameters.Add(new ValueParameter<IntValue>(GuiUpdateIntervalParameterName, "Number of generated sentences, until GUI is refreshed.", new IntValue(5000)));
+      Parameters.Add(new ValueParameter<EnumValue<StorageType>>(SearchDataStructureParameterName, new EnumValue<StorageType>(StorageType.PriorityQueue)));
 
       var availableAnalyzers = new IGrammarEnumerationAnalyzer[] {
@@ -125,10 +134,12 @@
         Analyzers.SetItemCheckedState(analyzer, false);
       }
-      Analyzers.CheckedItemsChanged += AnalyzersOnCheckedItemsChanged;
       Analyzers.SetItemCheckedState(Analyzers.First(analyzer => analyzer is RSquaredEvaluator), true);
-      Analyzers.SetItemCheckedState(Analyzers.First(analyzer => analyzer is SentenceLogger), true);
-    }
-
-    public GrammarEnumerationAlgorithm(GrammarEnumerationAlgorithm original, Cloner cloner) : base(original, cloner) { }
+      //Analyzers.SetItemCheckedState(Analyzers.First(analyzer => analyzer is SentenceLogger), true);
+    }
+
+    public GrammarEnumerationAlgorithm(GrammarEnumerationAlgorithm original, Cloner cloner) : base(original, cloner) {
+
+
+    }
     #endregion
 
@@ -136,4 +147,12 @@
       #region init
       InitResults();
+
+      foreach (IGrammarEnumerationAnalyzer grammarEnumerationAnalyzer in Analyzers) {
+        if (Analyzers.ItemChecked(grammarEnumerationAnalyzer)) {
+          grammarEnumerationAnalyzer.Register(this);
+        } else {
+          grammarEnumerationAnalyzer.Deregister(this);
+        }
+      }
 
       Analyzers.OfType<RSquaredEvaluator>().First().OptimizeConstants = OptimizeConstants;
@@ -152,4 +171,6 @@
       var phrase0Hash = Grammar.Hasher.CalcHashCode(phrase0);
       #endregion
+
+      int maxSentenceLength = GetMaxSentenceLength();
 
       OpenPhrases.Store(phrase0Hash, 0.0, phrase0);
@@ -203,5 +224,5 @@
 
             } else if (!OpenPhrases.Contains(phraseHash) && !ArchivedPhrases.Contains(phraseHash)) {
-              double phrasePriority = GetPriority(newPhrase);
+              double phrasePriority = GetPriority(newPhrase, maxSentenceLength);
               OpenPhrases.Store(phraseHash, phrasePriority, newPhrase);
             }
@@ -212,20 +233,38 @@
     }
 
-    protected double GetPriority(SymbolString phrase) {
-      double complexity = (double)Grammar.GetComplexity(phrase);
-
-      double length = phrase.Count();
-      double relLength = (length - 2) / (MaxComplexity * 7);
+    protected double GetPriority(SymbolString phrase, int maxSentenceLength) {
+      double relLength = (double)phrase.Count() / maxSentenceLength;
+
       double r2 = Grammar.EvaluatePhrase(phrase, Problem.ProblemData, OptimizeConstants);
       double error = 1.0 - r2;
 
-      double variables = 0;
-      for (int i = 0; i < phrase.Count(); i++) {
-        if (phrase[i] is VariableTerminalSymbol) variables++;
-      }
-
-      double variableRatio = 1.0 - variables / complexity;
-
-      return 1.5*relLength + error;
+      return relLength + ErrorWeight * error;
+    }
+
+    private int GetMaxSentenceLength() {
+      SymbolString s = new SymbolString(Grammar.StartSymbol);
+
+      while (Grammar.GetComplexity(s) <= MaxComplexity) {
+        int expandedSymbolIndex = s.NextNonterminalIndex();
+        NonterminalSymbol expandedSymbol = (NonterminalSymbol)s[expandedSymbolIndex];
+
+        var productions = Grammar.Productions[expandedSymbol];
+        var longestProduction = productions // Find production with most terminal symbols to expand as much as possible...
+          .OrderBy(CountTerminals)          // but with lowest complexity/nonterminal count to keep complexity low.                                                                                     
+          .ThenByDescending(CountNonTerminals)
+          .First();
+
+        s = s.DerivePhrase(expandedSymbolIndex, longestProduction);
+      }
+
+      return s.Count();
+    }
+
+    private int CountTerminals(Production p) {
+      return p.Count(s => s is TerminalSymbol);
+    }
+
+    private int CountNonTerminals(Production p) {
+      return p.Count(s => s is NonterminalSymbol);
     }
 
@@ -263,14 +302,4 @@
 
     #region events
-    private void AnalyzersOnCheckedItemsChanged(object sender, CollectionItemsChangedEventArgs<IGrammarEnumerationAnalyzer> collectionItemsChangedEventArgs) {
-      foreach (IGrammarEnumerationAnalyzer grammarEnumerationAnalyzer in collectionItemsChangedEventArgs.Items) {
-        if (Analyzers.ItemChecked(grammarEnumerationAnalyzer)) {
-          grammarEnumerationAnalyzer.Register(this);
-        } else {
-          grammarEnumerationAnalyzer.Deregister(this);
-        }
-      }
-    }
-
     public event EventHandler<PhraseEventArgs> PhraseFetched;
     private void OnPhraseFetched(int hash, SymbolString symbolString) {
