Index: /branches/HeuristicLab.Problems.GPDL/CodeGenerator/ProblemCodeGen.cs
===================================================================
--- /branches/HeuristicLab.Problems.GPDL/CodeGenerator/ProblemCodeGen.cs	(revision 10337)
+++ /branches/HeuristicLab.Problems.GPDL/CodeGenerator/ProblemCodeGen.cs	(revision 10338)
@@ -18,4 +18,17 @@
     private const string problemTemplate = @"
 namespace ?PROBLEMNAME? {
+  public class Tree {
+    public int altIdx;
+    public List<Tree> subtrees;
+    protected Tree() {
+      // leave subtrees uninitialized
+    }
+    public Tree(int state, int altIdx, int numSubTrees) {
+      subtrees = new List<Tree>();
+      this.altIdx = altIdx;
+    }
+  }
+
+  ?TERMINALNODECLASSDEFINITIONS?
 
   // generic interface for communication from problem interpretation to solver
@@ -94,5 +107,6 @@
         .Replace("?INTERPRETERSOURCE?", GenerateInterpreterSource(grammar))
         .Replace("?CONSTRAINTSSOURCE?", GenerateConstraintMethods(ast.Terminals))
-          ;
+        .Replace("?TERMINALNODECLASSDEFINITIONS?", GenerateTerminalNodeClassDefinitions(ast.Terminals.OfType<TerminalNode>()))
+       ;
     }
 
@@ -100,5 +114,5 @@
       var grammar = CreateGrammarFromAst(ast);
       var randomSearchCodeGen = new RandomSearchCodeGen();
-      randomSearchCodeGen.Generate(grammar, ast.Terminals.OfType<TerminalNode>(), ast.FitnessFunctionNode.Maximization, solverSourceCode);
+      randomSearchCodeGen.Generate(grammar, ast.FitnessFunctionNode.Maximization, solverSourceCode);
       //var bruteForceSearchCodeGen = new BruteForceCodeGen();
       //bruteForceSearchCodeGen.Generate(grammar, ast.FitnessFunctionNode.Maximization, solverSourceCode);
@@ -190,4 +204,37 @@
     #endregion
 
+    private string GenerateTerminalNodeClassDefinitions(IEnumerable<TerminalNode> terminals) {
+      var sb = new SourceBuilder();
+
+      foreach (var terminal in terminals) {
+        GenerateTerminalNodeClassDefinitions(terminal, sb);
+      }
+      return sb.ToString();
+    }
+
+    private void GenerateTerminalNodeClassDefinitions(TerminalNode terminal, SourceBuilder sb) {
+      sb.AppendFormat("public class {0}Tree : Tree {{", terminal.Ident).BeginBlock();
+      foreach (var att in terminal.FieldDefinitions) {
+        sb.AppendFormat("{0} {1};", att.Type, att.Identifier).AppendLine();
+      }
+      sb.AppendFormat(" public {0}Tree(Random random, ?IDENT?Problem problem) : base() {{", terminal.Ident).BeginBlock();
+      foreach (var constr in terminal.Constraints) {
+        if (constr.Type == ConstraintNodeType.Set) {
+          sb.AppendLine("{").BeginBlock();
+          sb.AppendFormat(" var elements = problem.GetAllowed{0}_{1}().ToArray();", terminal.Ident, constr.Ident).AppendLine();
+          sb.AppendFormat("{0} = elements[random.Next(elements.Length)]; ", constr.Ident).AppendLine();
+          sb.AppendLine("}").EndBlock();
+        } else {
+          sb.AppendLine("{").BeginBlock();
+          sb.AppendFormat(" var max = problem.GetMax{0}_{1}();", terminal.Ident, constr.Ident).AppendLine();
+          sb.AppendFormat(" var min = problem.GetMin{0}_{1}();", terminal.Ident, constr.Ident).AppendLine();
+          sb.AppendFormat("{0} = random.NextDouble() * (max - min) + min ", constr.Ident).AppendLine();
+          sb.AppendLine("}").EndBlock();
+        }
+      }
+      sb.AppendLine("}").EndBlock();
+      sb.AppendLine("}").EndBlock();
+    }
+
     private string GenerateInterpreterSource(AttributedGrammar grammar) {
       var sb = new SourceBuilder();
Index: /branches/HeuristicLab.Problems.GPDL/CodeGenerator/RandomSearchCodeGen.cs
===================================================================
--- /branches/HeuristicLab.Problems.GPDL/CodeGenerator/RandomSearchCodeGen.cs	(revision 10337)
+++ /branches/HeuristicLab.Problems.GPDL/CodeGenerator/RandomSearchCodeGen.cs	(revision 10338)
@@ -26,16 +26,4 @@
     
     public sealed class SolverState : ISolverState {
-      private class Tree {
-        public int altIdx;
-        // public string symbol; // for debugging
-        public List<Tree> subtrees;
-        public Tree(int state, int altIdx) {
-          subtrees = new List<Tree>(subtreeCount[state]);
-          this.altIdx = altIdx;
-        }
-      }
-
-      ?TERMINALNODEDEFINITIONS?
-
       public int curDepth;
       public int steps;
@@ -63,5 +51,5 @@
         steps += 1;
         depth = Math.Max(depth, curDepth);
-        var t = new Tree(state, altIdx);
+        var t = new Tree(state, altIdx, subtreeCount[state]);
 
         // t.symbol = symb.Length > state ? symb[state] : ""TERM"";
@@ -200,9 +188,8 @@
 }";
 
-    public void Generate(IGrammar grammar, IEnumerable<TerminalNode> terminals, bool maximization, SourceBuilder problemSourceCode) {
+    public void Generate(IGrammar grammar, bool maximization, SourceBuilder problemSourceCode) {
       var solverSourceCode = new SourceBuilder();
       solverSourceCode.Append(solverTemplate)
         // .Replace("?TERMINALFIELDS?", GenerateTerminalFields(grammar))
-        .Replace("?TERMINALNODEDEFINITIONS?", GenerateTerminalNodeDefinitions(terminals))
         // .Replace("?CONSTRUCTORCODE?", GenerateConstructorCode(grammar))
         .Replace("?MAXIMIZATION?", maximization.ToString().ToLowerInvariant())
@@ -217,38 +204,4 @@
     }
 
-    private string GenerateTerminalNodeDefinitions(IEnumerable<TerminalNode> terminals) {
-      var sb = new SourceBuilder();
-
-      foreach (var terminal in terminals) {
-        GenerateTerminalNodeDefinitions(terminal, sb);
-      }
-      return sb.ToString();
-    }
-
-    private void GenerateTerminalNodeDefinitions(TerminalNode terminal, SourceBuilder sb) {
-      sb.AppendFormat("private class {0}Tree {{", terminal.Ident).BeginBlock();
-      foreach (var att in terminal.FieldDefinitions) {
-        sb.AppendFormat("{0} {1};", att.Type, att.Identifier).AppendLine();
-      }
-      sb.AppendFormat(" static {0}Tree Create(Random random, ?IDENT?Problem problem) {{", terminal.Ident).BeginBlock();
-      sb.AppendFormat("var t = new {0}Tree();", terminal.Ident);
-      foreach (var constr in terminal.Constraints) {
-        if (constr.Type == ConstraintNodeType.Set) {
-          sb.AppendLine("{").BeginBlock();
-          sb.AppendFormat(" var elements = problem.GetAllowed{0}_{1}().ToArray();", terminal.Ident, constr.Ident);
-          sb.AppendFormat("t.{0} = elements[random.Next(elements.Length)]; ", constr.Ident).AppendLine();
-          sb.AppendLine("}").EndBlock();
-        } else {
-          sb.AppendLine("{").BeginBlock();
-          sb.AppendFormat(" var max = problem.GetMax{0}_{1}();", terminal.Ident, constr.Ident);
-          sb.AppendFormat(" var min = problem.GetMin{0}_{1}();", terminal.Ident, constr.Ident);
-          sb.AppendFormat("t.{0} = random.NextDouble() * (max - min) + min ", constr.Ident).AppendLine();
-          sb.AppendLine("}").EndBlock();
-        }
-      }
-      sb.AppendLine("return t;");
-      sb.AppendLine("}").EndBlock();
-      sb.AppendLine("}").EndBlock();
-    }
 
     //private string GenerateSampleTerminalSource(IGrammar grammar) {
Index: /branches/HeuristicLab.Problems.GPDL/Examples/symbreg Koza.txt
===================================================================
--- /branches/HeuristicLab.Problems.GPDL/Examples/symbreg Koza.txt	(revision 10337)
+++ /branches/HeuristicLab.Problems.GPDL/Examples/symbreg Koza.txt	(revision 10338)
@@ -106,5 +106,5 @@
     | Multiplication<<row, out val>>
     | Var<<out varName>>                                   SEM << val = GetValue(x, varName, row); >>
-    /* | ERC<<out val>> */
+    | ERC<<out val>> 
   .
 
Index: /branches/HeuristicLab.Problems.GPDL/HeuristicLab.Problems.GPDL.sln
===================================================================
--- /branches/HeuristicLab.Problems.GPDL/HeuristicLab.Problems.GPDL.sln	(revision 10337)
+++ /branches/HeuristicLab.Problems.GPDL/HeuristicLab.Problems.GPDL.sln	(revision 10338)
@@ -1,5 +1,7 @@
 ﻿
 Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 2012
+# Visual Studio 2013
+VisualStudioVersion = 12.0.21005.1
+MinimumVisualStudioVersion = 10.0.40219.1
 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{3768D612-38EB-47D8-9E79-75D8E5AB00A8}"
 	ProjectSection(SolutionItems) = preProject
@@ -115,6 +117,3 @@
 		{E2060931-6700-464B-9E82-50846D7AE4E9} = {3768D612-38EB-47D8-9E79-75D8E5AB00A8}
 	EndGlobalSection
-	GlobalSection(Performance) = preSolution
-		HasPerformanceSessions = true
-	EndGlobalSection
 EndGlobal
