Index: /branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Algorithms.GrammaticalOptimization/SequentialDecisionPolicies/GenericFunctionApproximationGrammarPolicy.cs
===================================================================
--- /branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Algorithms.GrammaticalOptimization/SequentialDecisionPolicies/GenericFunctionApproximationGrammarPolicy.cs	(revision 11979)
+++ /branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Algorithms.GrammaticalOptimization/SequentialDecisionPolicies/GenericFunctionApproximationGrammarPolicy.cs	(revision 11980)
@@ -61,7 +61,7 @@
       }
 
-
-      
-      const double beta = 20;
+      
+      /*
+      const double beta = 10;
       var w = from idx in Enumerable.Range(0, maxIdx)
               let afterStateQ = activeAfterStates[idx]
@@ -71,8 +71,8 @@
       selectedStateIdx = actionIndexMap[bestAction];
       Debug.Assert(selectedStateIdx >= 0);
-      
-
-      /*
-      if (random.NextDouble() < 0.2) {
+      */
+      
+      
+      if (random.NextDouble() < 0.5) {
         selectedStateIdx = actionIndexMap[random.Next(maxIdx)];
       } else {
@@ -91,5 +91,5 @@
         selectedStateIdx = actionIndexMap[bestIdxs[random.Next(bestIdxs.Count)]];
       }
-      */
+      
       return true;
     }
@@ -140,5 +140,5 @@
       double delta = reward - GetValue(state);
       // delta /= problem.GetFeatures(state).Count();
-      //const double alpha = 0.01;
+      //const double alpha = 0.001;
       foreach (var feature in problem.GetFeatures(state)) {
         featureTries[feature.Id] = GetFeatureTries(feature.Id) + 1;
Index: /branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Problems.GrammaticalOptimization/Grammar.cs
===================================================================
--- /branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Problems.GrammaticalOptimization/Grammar.cs	(revision 11979)
+++ /branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Problems.GrammaticalOptimization/Grammar.cs	(revision 11980)
@@ -184,5 +184,5 @@
         Debug.Assert(maxLenOfReplacement > 0);
 
-        var alts = GetAlternatives(nt).Where(alt => MinPhraseLength(alt) <= maxLenOfReplacement);
+        var alts = GetTerminalAlternatives(nt).Where(alt => MinPhraseLength(alt) <= maxLenOfReplacement);
         Debug.Assert(alts.Any());
 
Index: /branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Problems.GrammaticalOptimization/Problems/SantaFeAntProblem.cs
===================================================================
--- /branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Problems.GrammaticalOptimization/Problems/SantaFeAntProblem.cs	(revision 11979)
+++ /branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Problems.GrammaticalOptimization/Problems/SantaFeAntProblem.cs	(revision 11980)
@@ -123,5 +123,5 @@
 
     public string CanonicalRepresentation(string phrase) {
-      phrase = phrase.Replace("A", ".");
+      //phrase = phrase.Replace("A", ".");
       var sb = new StringBuilder(phrase);
       string canonicalPhrase = phrase;
@@ -133,5 +133,5 @@
         canonicalPhrase = sb.ToString();
       } while (canonicalPhrase != oldPhrase);
-      return sb.ToString();
+      return canonicalPhrase;
     }
 
@@ -141,5 +141,5 @@
 
 
-      //yield return new Feature("const", 0.0);
+      yield return new Feature(isTerminal + ToString(), 1.0);
       //if (phrase.Length > 0) {
       //  var ant = new Ant(recordTrail: true);
@@ -157,13 +157,13 @@
       //}
       //
-      ////yield return new Feature("$" + phrase[0], 1.0);
-      // if (!isTerminal) {
-      //   for (int i = 4; i < phrase.Length; i++) {
-      //     if (grammar.IsNonTerminal(phrase[i])) {
-      //       yield return new Feature(phrase[i - 4].ToString() + phrase[i - 3].ToString() + phrase[i - 2] + phrase[i - 1], 0.1);
-      //       break;
-      //     }
-      //   }
-      // }
+      yield return new Feature("$" + (phrase.Length > 0 ? phrase[0] : ' '), 1.0);
+      if (!isTerminal) {
+        for (int i = 4; i < phrase.Length; i++) {
+          if (!grammar.IsTerminal(phrase[i])) {
+            yield return new Feature(phrase[i - 4].ToString() + phrase[i - 3].ToString() + phrase[i - 2] + phrase[i - 1], 1.0);
+            break;
+          }
+        }
+      }
       // var d = 0;
       // var ls = 0;
Index: /branches/HeuristicLab.Problems.GrammaticalOptimization/Main/Program.cs
===================================================================
--- /branches/HeuristicLab.Problems.GrammaticalOptimization/Main/Program.cs	(revision 11979)
+++ /branches/HeuristicLab.Problems.GrammaticalOptimization/Main/Program.cs	(revision 11980)
@@ -179,8 +179,5 @@
 
     private static void RunDemo() {
-      // TODO: unify MCTS, TD and ContextMCTS Solvers (stateInfos)
-      // TODO: test with eps-greedy using max instead of average as value (seems to work well for symb-reg! explore further!)
-      // TODO: separate value function from policy
-      // TODO: warum funktioniert die alte Implementierung von GaussianThompson besser fÃŒr SantaFe als neue? Siehe Vergleich: alte vs. neue implementierung GaussianThompsonSampling
+      // TODO: cleanup nach EuroCAST
       // TODO: why does GaussianThompsonSampling work so well with MCTS for the artificial ant problem?
       // TODO: research thompson sampling for max bandit?
@@ -316,5 +313,5 @@
       {
         () => Tuple.Create(100000, 23,  (ISymbolicExpressionTreeProblem)new SymbolicRegressionPoly10Problem()), 
-        () => Tuple.Create(100000, 17, (ISymbolicExpressionTreeProblem)new SantaFeAntProblem()), 
+        //() => Tuple.Create(100000, 17, (ISymbolicExpressionTreeProblem)new SantaFeAntProblem()), 
         //() => Tuple.Create(50000, 32,(ISymbolicExpressionTreeProblem)new RoyalSymbolProblem()), 
         //() => Tuple.Create(50000, 64, (ISymbolicExpressionTreeProblem)new RoyalPairProblem()), 
@@ -345,5 +342,5 @@
             int iterations = 0;
             double bestQuality = double.NegativeInfinity;
-            var globalStatistics = new SentenceSetStatistics(prob.BestKnownQuality(maxSize));
+            var globalStatistics = new SentenceSetStatistics();
             var algName = alg.GetType().Name;
             var probName = prob.GetType().Name;
@@ -358,5 +355,5 @@
               //}
               //Console.WriteLine("{0:N5} {1}", quality, sentence);
-              if (iterations % 200 == 0) {
+              if (iterations % 1000 == 0) {
                 Console.WriteLine("\"{0,25}\" {1} \"{2,25}\" {3}", algName, maxSize, probName, globalStatistics);
                 if (bestQuality.IsAlmost(1.0)) {
@@ -368,6 +365,16 @@
             alg.Run(maxIters);
 
+
+            while (iterations < maxIters) {
+              iterations++;
+              globalStatistics.AddSentence("BEST", bestQuality);
+              if (iterations % 1000 == 0) {
+                Console.WriteLine("\"{0,25}\" {1} \"{2,25}\" {3}", algName, maxSize, probName, globalStatistics);
+                if (bestQuality.IsAlmost(1.0)) {
+                  alg.StopRequested = true;
+                }
+              }
+            }
           }
-
         }
       }
