Index: branches/HeuristicLab.Problems.GPDL/Examples/Artificial Ant.txt
===================================================================
--- branches/HeuristicLab.Problems.GPDL/Examples/Artificial Ant.txt	(revision 10061)
+++ branches/HeuristicLab.Problems.GPDL/Examples/Artificial Ant.txt	(revision 10061)
@@ -0,0 +1,229 @@
+PROBLEM ArtificialAnt
+
+CODE <<
+public struct Point { 
+  public int x; public int y; 
+  public Point(int x, int y) {
+    this.x = x;
+	this.y = y;
+  }
+};
+
+class World {
+
+private static string[] LosAltosTrail = new string[] {
+" ###                                          ",
+"   #                                  .###..  ",
+"   #                                  #    #  ",
+"   #                                  #    #  ",
+"   ####.#####           .############..    .  ",
+"            #           .                  #  ",
+"            #           #                  .  ",
+"            #           #                  .  ",
+"            #           #                  #  ",
+"            .           #                  .  ",
+"            #           .                  .  ",
+"            #           .                  #  ",
+"            #           #                  .  ",
+"            #           #            ...###.  ",
+"            .       .#...            #        ",
+"            .       .                .        ",
+"            #       .                .        ",
+"            #       #                .#...    ",
+"            #       #                    #    ",
+"            #       #                    .    ",
+"            #       #                    .    ",
+"            #       .                ...#.    ",
+"            #       .                #        ",
+" ..##..#####.       #                #        ",
+" #                  #                #        ",
+" #                  #                #        ",
+" #                  #                #        ",
+" #                  #                #        ",
+" #                  #                #        ",
+" #     .#####....##..                #        ",
+" #     #                             #        ",
+" .     #                             #        ",
+" .####..                             #        ",
+"                                   #.#        ",
+"                                   #          ",
+"                                   #          ",
+"                                   #          ",
+"                                   #          ",
+"                                   #          ",
+"                                   #          ",
+"                                   #          ",
+"                              ######          ",
+"                              .               ",
+"                              #               ",
+"                              #               ",
+"                              #               ",
+"                              #               ",
+"                              #               ",
+"                              #               ",
+"                            #..               ",
+"                            #                 ",
+"                            #                 ",
+"                            #                 ",
+"                            #                 ",
+"                            #                 ",
+"                      .######                 ",
+"                      .                       ",
+"                      #                       ",
+"                      #                       ",
+"                      #                       ",
+"                      #                       ",
+"                      #                       ",
+"                      #                       ",
+"                      #                       ",
+"                      #                       ",
+"                      #                       "
+};
+  private char[][] world = LosAltosTrail.Select(l=>l.ToArray()).ToArray();
+  public int TotalFood = LosAltosTrail.Select(l=>l.Where(c=>c=='#').Count()).Sum();
+  public int Width { get { return 100; } }
+  public int Height { get { return 100; } }
+  
+  public void Reset() {
+    world = LosAltosTrail.Select(l=>l.ToArray()).ToArray();
+  }
+  
+  public bool FoodAt(Point p) {
+    if(p.x < 0 || p.y < 0) return false;
+    if(world.Length <= p.y) return false;
+	if(world[p.y].Length <= p.x) return false;
+    return world[p.y][p.x] == '#';
+  }
+  public void RemoveFoodAt(Point p) {
+    if(world.Length < p.y) return;
+	if(world[p.y].Length < p.x) return;
+    world[p.y][p.x] = ' ';
+  }
+}
+
+enum Direction {West, East, North, South};
+
+class AntState {
+  public Point Position { get; set;} 
+  public int MaxSteps { get; set;}
+  public Direction Direction { get; set; }
+  public World World { get; set; }
+  public int Steps { get; set; }
+  public int FoodEaten { get; set; }
+ 
+  public AntState() {
+    Steps = 0;	
+	FoodEaten = 0;
+  }
+ 
+  public void TurnLeft() {
+    Steps++;
+    switch(Direction) {
+	  case Direction.West: Direction = Direction.South; break;
+	  case Direction.South: Direction = Direction.East; break;
+	  case Direction.East: Direction = Direction.North; break;
+	  case Direction.North: Direction = Direction.West; break;
+	}
+  }
+  public void TurnRight() {
+    Steps++;
+    switch(Direction) {
+	  case Direction.West: Direction = Direction.North; break;
+	  case Direction.South: Direction = Direction.West; break;
+	  case Direction.East: Direction = Direction.South; break;
+	  case Direction.North: Direction = Direction.East; break;
+	}
+  }
+  public void MoveForward() { 
+    Position = NextPosition; 
+	Steps++; 
+	if(World.FoodAt(Position)) {
+    	World.RemoveFoodAt(Position);
+		FoodEaten++;
+    }
+  }
+  public Point NextPosition { 
+    get { 
+	    int x, y;
+        switch(Direction) {
+    	  case Direction.West: 
+		    x = (Position.x + World.Width - 1) % World.Width;
+			y = Position.y;
+			return new Point(x, y);
+    	  case Direction.South: 
+  		    x = Position.x;
+			y = (Position.y + World.Height + 1) % World.Height;
+			return new Point(x, y);
+    	  case Direction.East:
+  		    x = (Position.x + World.Width + 1) % World.Width;
+			y = Position.y;
+			return new Point(x, y);
+    	  case Direction.North:
+  		    x = Position.x;
+			y = (Position.y + World.Height - 1) % World.Height;
+			return new Point(x, y);
+    	}
+ 		return new Point(-1,-1);
+    } 
+  }  
+}
+
+World CreateWorld() {   
+  var w = new World();
+  Console.WriteLine("Total food: "+w.TotalFood);
+  return w;
+}
+
+World world;
+>>
+INIT <<
+  world = CreateWorld();
+>>
+
+NONTERMINALS
+  Ant<<World world, AntState state>>. 
+  IfFoodAhead<<World world, AntState state>>.
+  Prog2<<World world, AntState state>>.
+  Prog3<<World world, AntState state>>.
+
+TERMINALS
+  Left. Right. Move.
+ 
+RULES
+  Ant<<World world, AntState state>> = 
+    IfFoodAhead<<world, state>>
+    | Prog2<<world, state>>
+    | Prog3<<world, state>>
+    | Left                                             SEM << state.TurnLeft(); >>
+    | Right                                            SEM << state.TurnRight(); >>
+    | Move                                             SEM << state.MoveForward(); >>
+    .
+    
+  IfFoodAhead<<World world, AntState state>> =     
+                                                   SEM <<
+                                                      if(world.FoodAt(state.NextPosition)) {
+                                                   >>
+                                                   
+    Ant<<world, state>>                            SEM << } else { >>
+    Ant<<world, state>>                            SEM << } >> 
+  .
+
+  Prog2<<World world, AntState state>> = 
+    Ant<<world, state>> Ant<<world, state>>
+  .
+  
+  Prog3<<World world, AntState state>> =
+    Ant<<world, state>> Ant<<world, state>> Ant<<world, state>>
+  .
+
+
+MAXIMIZE                                                   /* could also use the keyword MINIMIZE here */
+  <<    
+    world.Reset();
+    var state = new AntState() {Position = new Point(0,0), MaxSteps=400, Direction=Direction.East, World = world};
+    while(state.Steps < state.MaxSteps) {
+      Ant(world, state);
+    }
+    return (double)state.FoodEaten;
+  >>  
+END ArtificialAnt.
Index: branches/HeuristicLab.Problems.GPDL/Examples/EvenParity.txt
===================================================================
--- branches/HeuristicLab.Problems.GPDL/Examples/EvenParity.txt	(revision 10061)
+++ branches/HeuristicLab.Problems.GPDL/Examples/EvenParity.txt	(revision 10061)
@@ -0,0 +1,70 @@
+PROBLEM EvenParity
+CODE <<
+  const int N = 5;
+>>
+
+NONTERMINALS
+  Expr<<bool[] d, out bool p>>.
+  AND<<bool[] d, out bool p>>.
+  OR<<bool[] d, out bool p>>.
+  NAND<<bool[] d, out bool p>>.
+  NOR<<bool[] d, out bool p>>.
+
+TERMINALS
+  D<<out int val>> 
+    CONSTRAINTS 
+      val IN SET <<Enumerable.Range(0, N);>>
+  .
+
+RULES
+  Expr<<bool[] d, out bool p>> =                           LOCAL<< int val = 0; >>
+    AND<<d, out p>>
+    | OR<<d, out p>>
+    | NAND<<d, out p>>
+    | NOR<<d, out p>>
+    | D<<out val>>                                         SEM<< p = d[val]; >>
+  .
+
+  AND<<bool[] d, out bool p>> =                            LOCAL << bool p1, p2; >>
+    Expr<<d, out p1>> Expr<<d, out p2>>                    SEM << p = p1 & p2; >>
+  .
+
+  OR<<bool[] d, out bool p>> =                             LOCAL << bool p1, p2; >>
+    Expr<<d, out p1>> Expr<<d, out p2>>                    SEM << p = p1 | p2; >>
+  .
+
+  NAND<<bool[] d, out bool p>> =                           LOCAL << bool p1, p2; >>
+    Expr<<d, out p1>> Expr<<d, out p2>>                    SEM << p = !(p1 & p2); >>
+  .
+
+  NOR<<bool[] d, out bool p>> =                            LOCAL << bool p1, p2; >>
+    Expr<<d, out p1>> Expr<<d, out p2>>                    SEM << p = !(p1 | p2); >>
+  .
+
+MINIMIZE
+  << 
+    bool[] d = new bool[N];
+    int mistakes = 0;
+    for(int i = 0; i < Math.Pow(2, N); i++) {
+      // generate bit-vector and count number of 1-bits
+      int x = i;
+      int nBitsOne = 0;
+      for(int j = 0; j < N; j++) {
+        if((x % 2) == 1) {
+          d[N - j - 1] = true;
+          nBitsOne++;
+        } else {
+          d[N - j - 1] = false;
+        }
+        x = (x / 2);
+      }
+      bool target = (nBitsOne % 2) == 0;
+      // apply model
+      bool p;
+      Expr(d, out p);
+
+      if(p != target) mistakes++;
+    }
+    return mistakes;
+  >>
+END EvenParity.
Index: branches/HeuristicLab.Problems.GPDL/Examples/Factorial.txt
===================================================================
--- branches/HeuristicLab.Problems.GPDL/Examples/Factorial.txt	(revision 10061)
+++ branches/HeuristicLab.Problems.GPDL/Examples/Factorial.txt	(revision 10061)
@@ -0,0 +1,146 @@
+PROBLEM Factorial
+CODE<<
+  string[] allTerminals = new string[] {"a", "b", "c", "d", "e", "n"} ; 
+  SymTab symTab = new SymTab();
+
+  class SymTab {
+    private Dictionary<string, int> values = new Dictionary<string,int>();
+    public void SetValue(string id, int val) {
+      values[id] = val;
+    }
+    public int GetValue(string id) {
+      int val = 0;
+      values.TryGetValue(id, out val);      
+      return val;
+    }
+  }
+>>
+
+NONTERMINALS
+  Program<<int n, out int r>>.                                       /* return value is the result of the last statement. */
+  StatSeq<<out int r>>.                                                  
+  AssignStat<<out int r>>.                                               /* result of assignment is the assigned value */
+  IncStat<<out int r>>.
+  DecStat<<out int r>>.
+  WhileStat<<out int r>>.                                                /* result of while loop is the result of the last executed statement */
+  ReturnStat<<out int r>>.  
+  Expr<<out int r>>.
+  AdditionExpr<<out int r>>.
+  SubtractionExpr<<out int r>>.
+  DivisionExpr<<out int r>>.
+  MultiplicationExpr<<out int r>>.
+  BooleanExpr<<out bool b>>.
+  NotExpr<<out bool b>>.
+  LessThanExpr<<out bool b>>.
+  EqualExpr<<out bool b>>.
+  AssignStatAndStatSeq<<out int r>>.
+  WhileStatAndStatSeq<<out int r>>.
+  ReturnStatAndStatSeq<<out int r>>.
+
+TERMINALS
+  ident<<out string id>> 
+    CONSTRAINTS
+    id IN SET << allTerminals; >>
+  .
+  Const<<out int val>> 
+    CONSTRAINTS
+    val IN SET << Enumerable.Range(0, 100); >>
+  .
+  Nothing<<out int val>>
+     CONSTRAINTS
+     val IN SET << Enumerable.Repeat(0, 1); >>
+  .
+  
+RULES
+  Program<<int n, out int r>> = StatSeq<<out r>>                         SEM << symTab.SetValue("n", n); >>
+  .
+  StatSeq<<out int r>> =                                                 LOCAL << r = 0; >>
+    Nothing<<out r>>                                                              
+    | AssignStatAndStatSeq<<out r>>
+    | WhileStatAndStatSeq<<out r>>
+    | ReturnStatAndStatSeq<<out r>>
+	| IncStat<<out r>>
+	| DecStat<<out r>>
+  .
+  
+  AssignStatAndStatSeq<<out int r>> = 
+    StatSeq<<out r>>  AssignStat<<out r>> 
+  .
+  WhileStatAndStatSeq<<out int r>> = 
+    StatSeq<<out r>> WhileStat<<out r>> 
+  .
+  ReturnStatAndStatSeq<<out int r>> = 
+    StatSeq<<out r>>  ReturnStat<<out r>> 
+  .
+
+  AssignStat<<out int r>> =                                               LOCAL << int e; string id;>>
+    ident<<out id>> Expr<<out e>>                                         SEM  << symTab.SetValue(id, e); r = e; >>
+  .
+  IncStat<<out int r>> =                                                  LOCAL << int e; string id;>>
+    ident<<out id>>                                                       SEM  << r = symTab.GetValue(id) + 1; symTab.SetValue(id, r); >>
+  .
+  DecStat<<out int r>> =                                                  LOCAL << int e; string id;>>
+    ident<<out id>>                                                       SEM  << r = symTab.GetValue(id) - 1; symTab.SetValue(id, r); >>
+  .
+
+  WhileStat<<out int r>> =                                                LOCAL << bool b; int c = 0; >>
+                                                                          SEM  << r = 0; >>
+                                                                          SEM  << while(true && c++ < 100) { >>
+    BooleanExpr<<out b>>                                                  SEM  << if(!b) break; >>
+    StatSeq<<out r>>                                                      SEM  << } >>
+  .
+  ReturnStat<<out int r>> = Expr<<out r>>                                 SEM  << return; >>
+  .
+  Expr<<out int r>> =                                                     LOCAL << string id; >>
+    AdditionExpr<<out r>> 
+    | SubtractionExpr<<out r>> 
+    | MultiplicationExpr<<out r>> 
+    | DivisionExpr<<out r>> 
+    | Const<<out r>> 
+    | ident<<out id>>                                                      SEM  << r = symTab.GetValue(id); >>
+  .
+  AdditionExpr<<out int r>> =                                              LOCAL << int e1, e2; >>
+     Expr<<out e1>> Expr<<out e2>>                                         SEM  << r = e1 + e2; >>
+  .
+  SubtractionExpr<<out int r>> =                                           LOCAL << int e1, e2; >>
+    Expr<<out e1>> Expr<<out e2>>                                          SEM  << r = e1 - e2; >>
+  .
+  MultiplicationExpr<<out int r>> =                                        LOCAL << int e1, e2; >>
+    Expr<<out e1>> Expr<<out e2>>                                          SEM  << r = e1 * e2; >>
+  .
+  DivisionExpr<<out int r>> =                                              LOCAL << int e1, e2; >>
+    Expr<<out e1>> Expr<<out e2>>                                          SEM  << r = e2 == 0 ? 1 : e1 / e2; >>
+  .
+  BooleanExpr<<out bool b>> = 
+    LessThanExpr<<out b>> 
+    | EqualExpr<<out b>> 
+    | NotExpr<<out b>> 
+  .
+  NotExpr<<out bool b>> =                                                  LOCAL << bool notB; >>
+    BooleanExpr<<out notB>>                                                SEM  << b = !notB; >>
+  .
+  LessThanExpr<<out bool b>> =                                             LOCAL << int lhs, rhs; >>
+    Expr<<out lhs>> Expr<<out rhs>>                                        SEM  << b = lhs < rhs; >>
+  .
+  EqualExpr<<out bool b>> =                                                LOCAL << int lhs, rhs; >>
+    Expr<<out lhs>> Expr<<out rhs>>                                        SEM  << b = lhs == rhs; >>
+  .
+  
+  
+MINIMIZE                                                   /* could also use the keyword MAXIMIZE here */
+  <<
+    var ns = new int[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
+    var expected = new int[] { 1,1,2,6,24,120,720,5040,40320,362880,3628800 };
+    
+    double sumOfLogAbsoluteErrors = 0;
+    for(int i=0;i<ns.Length;i++) {
+      int actualResult;
+      Program(ns[i], out actualResult);
+      sumOfLogAbsoluteErrors += Math.Log(Math.Abs(expected[i] - actualResult) + 1);
+    }
+    
+    return sumOfLogAbsoluteErrors;
+  >>
+
+  
+END Factorial.
Index: branches/HeuristicLab.Problems.GPDL/Examples/Fib.txt
===================================================================
--- branches/HeuristicLab.Problems.GPDL/Examples/Fib.txt	(revision 10061)
+++ branches/HeuristicLab.Problems.GPDL/Examples/Fib.txt	(revision 10061)
@@ -0,0 +1,146 @@
+PROBLEM Fib
+CODE<<
+  string[] allTerminals = new string[] {"a", "b", "c", "d", "e", "n"} ; 
+  SymTab symTab = new SymTab();
+
+  class SymTab {
+    private Dictionary<string, int> values = new Dictionary<string,int>();
+    public void SetValue(string id, int val) {
+      values[id] = val;
+    }
+    public int GetValue(string id) {
+      int val = 0;
+      values.TryGetValue(id, out val);      
+      return val;
+    }
+  }
+>>
+
+NONTERMINALS
+  Program<<int n, out int r>>.                                       /* return value is the result of the last statement. */
+  StatSeq<<out int r>>.                                                  
+  AssignStat<<out int r>>.                                               /* result of assignment is the assigned value */
+  IncStat<<out int r>>.
+  DecStat<<out int r>>.
+  WhileStat<<out int r>>.                                                /* result of while loop is the result of the last executed statement */
+  ReturnStat<<out int r>>.  
+  Expr<<out int r>>.
+  AdditionExpr<<out int r>>.
+  SubtractionExpr<<out int r>>.
+  DivisionExpr<<out int r>>.
+  MultiplicationExpr<<out int r>>.
+  BooleanExpr<<out bool b>>.
+  NotExpr<<out bool b>>.
+  LessThanExpr<<out bool b>>.
+  EqualExpr<<out bool b>>.
+  AssignStatAndStatSeq<<out int r>>.
+  WhileStatAndStatSeq<<out int r>>.
+  ReturnStatAndStatSeq<<out int r>>.
+
+TERMINALS
+  ident<<out string id>> 
+    CONSTRAINTS
+    id IN SET << allTerminals; >>
+  .
+  Const<<out int val>> 
+    CONSTRAINTS
+    val IN SET << Enumerable.Range(0, 100); >>
+  .
+  Nothing<<out int val>>
+     CONSTRAINTS
+     val IN SET << Enumerable.Repeat(0, 1); >>
+  .
+  
+RULES
+  Program<<int n, out int r>> = StatSeq<<out r>>                         SEM << symTab.SetValue("n", n); >>
+  .
+  StatSeq<<out int r>> =                                                 LOCAL << r = 0; >>
+    Nothing<<out r>>                                                              
+    | AssignStatAndStatSeq<<out r>>
+    | WhileStatAndStatSeq<<out r>>
+    | ReturnStatAndStatSeq<<out r>>
+	| IncStat<<out r>>
+	| DecStat<<out r>>
+  .
+  
+  AssignStatAndStatSeq<<out int r>> = 
+    StatSeq<<out r>>  AssignStat<<out r>> 
+  .
+  WhileStatAndStatSeq<<out int r>> = 
+    StatSeq<<out r>> WhileStat<<out r>> 
+  .
+  ReturnStatAndStatSeq<<out int r>> = 
+    StatSeq<<out r>>  ReturnStat<<out r>> 
+  .
+
+  AssignStat<<out int r>> =                                               LOCAL << int e; string id;>>
+    ident<<out id>> Expr<<out e>>                                         SEM  << symTab.SetValue(id, e); r = e; >>
+  .
+  IncStat<<out int r>> =                                                  LOCAL << int e; string id;>>
+    ident<<out id>>                                                       SEM  << r = symTab.GetValue(id) + 1; symTab.SetValue(id, r); >>
+  .
+  DecStat<<out int r>> =                                                  LOCAL << int e; string id;>>
+    ident<<out id>>                                                       SEM  << r = symTab.GetValue(id) - 1; symTab.SetValue(id, r); >>
+  .
+
+  WhileStat<<out int r>> =                                                LOCAL << bool b; int c = 0; >>
+                                                                          SEM  << r = 0; >>
+                                                                          SEM  << while(true && c++ < 100) { >>
+    BooleanExpr<<out b>>                                                  SEM  << if(!b) break; >>
+    StatSeq<<out r>>                                                      SEM  << } >>
+  .
+  ReturnStat<<out int r>> = Expr<<out r>>                                 SEM  << return; >>
+  .
+  Expr<<out int r>> =                                                     LOCAL << string id; >>
+    AdditionExpr<<out r>> 
+    | SubtractionExpr<<out r>> 
+    | MultiplicationExpr<<out r>> 
+    | DivisionExpr<<out r>> 
+    | Const<<out r>> 
+    | ident<<out id>>                                                      SEM  << r = symTab.GetValue(id); >>
+  .
+  AdditionExpr<<out int r>> =                                              LOCAL << int e1, e2; >>
+     Expr<<out e1>> Expr<<out e2>>                                         SEM  << r = e1 + e2; >>
+  .
+  SubtractionExpr<<out int r>> =                                           LOCAL << int e1, e2; >>
+    Expr<<out e1>> Expr<<out e2>>                                          SEM  << r = e1 - e2; >>
+  .
+  MultiplicationExpr<<out int r>> =                                        LOCAL << int e1, e2; >>
+    Expr<<out e1>> Expr<<out e2>>                                          SEM  << r = e1 * e2; >>
+  .
+  DivisionExpr<<out int r>> =                                              LOCAL << int e1, e2; >>
+    Expr<<out e1>> Expr<<out e2>>                                          SEM  << r = e2 == 0 ? 1 : e1 / e2; >>
+  .
+  BooleanExpr<<out bool b>> = 
+    LessThanExpr<<out b>> 
+    | EqualExpr<<out b>> 
+    | NotExpr<<out b>> 
+  .
+  NotExpr<<out bool b>> =                                                  LOCAL << bool notB; >>
+    BooleanExpr<<out notB>>                                                SEM  << b = !notB; >>
+  .
+  LessThanExpr<<out bool b>> =                                             LOCAL << int lhs, rhs; >>
+    Expr<<out lhs>> Expr<<out rhs>>                                        SEM  << b = lhs < rhs; >>
+  .
+  EqualExpr<<out bool b>> =                                                LOCAL << int lhs, rhs; >>
+    Expr<<out lhs>> Expr<<out rhs>>                                        SEM  << b = lhs == rhs; >>
+  .
+  
+  
+MINIMIZE                                                   /* could also use the keyword MAXIMIZE here */
+  <<
+    var ns = new int[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
+    var expected = new int[] { 1,1,2,3,5,8,13,21,34,55, 89};
+    
+    double sumOfAbsoluteErrors = 0;
+    for(int i=0;i<ns.Length;i++) {
+      int actualResult;
+      Program(ns[i], out actualResult);
+      sumOfAbsoluteErrors += Math.Abs(expected[i] - actualResult);
+    }
+    
+    return sumOfAbsoluteErrors;
+  >>
+
+  
+END Fib.
Index: branches/HeuristicLab.Problems.GPDL/Examples/LawnMower.txt
===================================================================
--- branches/HeuristicLab.Problems.GPDL/Examples/LawnMower.txt	(revision 10061)
+++ branches/HeuristicLab.Problems.GPDL/Examples/LawnMower.txt	(revision 10061)
@@ -0,0 +1,160 @@
+PROBLEM LawnMower
+/* the lawn mower problem with syntax to enforce that constants and sums are only used
+ * in sub-trees under the "frog" symbol. (Original formulation by Koza did not use a grammar)
+ */ 
+CODE <<
+  public static int Width { get { return 16; } }
+  public static int Height { get { return 16; } }
+
+  enum Direction {West, East, North, South};
+
+  class Point { 
+    public int x; 
+    public int y; 
+    public Point(int x, int y) { 
+      this.x = x; this.y = y; 
+    } 
+  }
+
+  class World {
+    private bool[,] mowed = new bool[Width, Height];
+
+    public void SetCellMowed(Point p) {
+      mowed[p.x, p.y] = true;
+    }
+    public bool IsCellMowed(Point p) {
+      return mowed[p.x, p.y];
+    }
+  }
+
+  class MowerState {
+    public Point Position { get; set;} 
+    public Direction Direction { get; set; }
+    public World World { get; set; }
+    public int Energy { get; set; }
+    public int MowedCells { get; set; }
+   
+    public MowerState() {
+      Energy = 0;
+      MowedCells = 0;
+    }
+ 
+    public void TurnLeft() {
+      if (Energy <= 0) return; // don't move when no energy left
+      Energy--;
+      switch(Direction) {
+        case Direction.West: Direction = Direction.South; break;
+        case Direction.South: Direction = Direction.East; break;
+        case Direction.East: Direction = Direction.North; break;
+        case Direction.North: Direction = Direction.West; break;
+      }
+    }
+  
+    public void Forward() { 
+      if(Energy <= 0) return; // don't move when no energy left
+      Position = NextPosition; 
+      Energy--; 
+      if(!World.IsCellMowed(Position)) {
+        World.SetCellMowed(Position);
+        MowedCells++;
+      }
+    }
+
+    public void Jump(int x, int y) {
+      if(Energy <= 0) return; // don't move when no energy left
+      while(x<0) x += Width; // make sure offset is positive for mod-operation
+      while(y<0) y += Height;
+      Position = new Point((Position.x + x) % Width, (Position.y + y) % Height);
+      Energy--; 
+      if(!World.IsCellMowed(Position)) {
+        World.SetCellMowed(Position);
+        MowedCells++;
+      }
+    }
+  
+    public Point NextPosition { 
+      get { 
+        int x, y;
+        switch(Direction) {
+          case Direction.West: 
+            x = (Position.x + Width - 1) % Width;
+            y = Position.y;
+            return new Point(x, y);
+          case Direction.South: 
+            x = Position.x;
+            y = (Position.y + Height + 1) % Height;
+            return new Point(x, y);
+          case Direction.East:
+            x = (Position.x + Width + 1) % Width;
+            y = Position.y;
+            return new Point(x, y);
+          case Direction.North:
+            x = Position.x;
+            y = (Position.y + Height - 1) % Height;
+            return new Point(x, y);
+        }
+        return new Point(-1,-1);
+      }
+    }
+  }
+
+/* set of possible values for constants [-100, 100] */
+int[] ints = Enumerable.Range(-100, 201).ToArray();
+>>
+
+NONTERMINALS
+  LawnMower<<MowerState state>>. 
+  Sum<<out int x, out int y>>.
+  Expr<<out int x, out int y>>. /* helper for expressions containing const and sum */
+  Frog<<MowerState state>>.
+  Prog2<<MowerState state>>.
+
+TERMINALS
+  Left.
+  Forward.
+  Const<<out int x, out int y>>
+    CONSTRAINTS
+      x IN SET <<ints; >> /* x \in [-100, 100] */
+      y IN SET <<ints; >> /* y \in [-100, 100] */
+  .
+
+RULES
+  LawnMower<<MowerState state>> = 
+    Prog2<<state>>
+    | Frog<<state>>
+    | Left                                             SEM << state.TurnLeft(); >>
+    | Forward                                          SEM << state.Forward(); >>
+  .
+    
+  Sum<<out int x, out int y>> =                        LOCAL << int x1, y1, x2, y2; >>
+    Expr<<out x1, out y1>>
+    Expr<<out x2, out y2>>                             SEM << x = x1 + x2; y = y1 + y2; >>
+  .
+
+  Expr<<out int x, out int y>> =
+    Const<<out x, out y>>
+    | Sum<<out x, out y>>
+  .
+
+  Prog2<<MowerState state>> = 
+    LawnMower<<state>> 
+    LawnMower<<state>>
+  .
+  
+  Frog<<MowerState state>> =                          LOCAL << int x; int y; >>
+     Expr<<out x, out y>>                             SEM << state.Jump(x, y); >>
+  .
+
+MAXIMIZE
+  <<    
+    var world = new World();
+    var state = new MowerState() {Position = new Point(0,0), 
+                                  Energy = 2 * Height * Width, 
+                                  Direction = Direction.South, 
+                                  World = world};
+    world.SetCellMowed(state.Position); // set initial cell mowed
+    // execute the mower program once
+    LawnMower(state);
+    return (double)state.MowedCells;
+  >>  
+END LawnMower.
Index: branches/HeuristicLab.Problems.GPDL/Examples/Multiplexer.txt
===================================================================
--- branches/HeuristicLab.Problems.GPDL/Examples/Multiplexer.txt	(revision 10061)
+++ branches/HeuristicLab.Problems.GPDL/Examples/Multiplexer.txt	(revision 10061)
@@ -0,0 +1,72 @@
+PROBLEM Multiplexer
+
+NONTERMINALS
+  Expr<<bool[] d, out bool o>>.
+  AND<<bool[] d, out bool o>>.
+  OR<<bool[] d, out bool o>>.
+  NOT<<bool[] d, out bool o>>.
+  IF<<bool[] d, out bool o>>.
+
+TERMINALS
+  A0. A1. A2. D0. D1. D2. D3. D4. D5. D6. D7.
+
+RULES
+  Expr<<bool[] d, out bool o>> =
+    AND<<d, out o>>
+    | OR<<d, out o>>
+    | NOT<<d, out o>>
+    | IF<<d, out o>>
+    | A0                                                   SEM<< o = d[0]; >>
+    | A1                                                   SEM<< o = d[1]; >>
+    | A2                                                   SEM<< o = d[2]; >>
+    | D0                                                   SEM<< o = d[3]; >>
+    | D1                                                   SEM<< o = d[4]; >>
+    | D2                                                   SEM<< o = d[5]; >>
+    | D3                                                   SEM<< o = d[6]; >>
+    | D4                                                   SEM<< o = d[7]; >>
+    | D5                                                   SEM<< o = d[8]; >>
+    | D6                                                   SEM<< o = d[9]; >>
+    | D7                                                   SEM<< o = d[10]; >>
+  .
+
+  AND<<bool[] d, out bool o>> =                            LOCAL << bool o1, o2; >>
+    Expr<<d, out o1>> Expr<<d, out o2>>                    SEM << o = o1 & o2; >>
+  .
+
+  OR<<bool[] d, out bool o>> =                             LOCAL << bool o1, o2; >>
+    Expr<<d, out o1>> Expr<<d, out o2>>                    SEM << o = o1 | o2; >>
+  .
+
+  NOT<<bool[] d, out bool o>> =
+    Expr<<d, out o>>                                       SEM << o = !o; >>
+  .
+
+  IF<<bool[] d, out bool o>> =                             LOCAL << bool pred; >>
+    Expr<<d, out pred>>                                    SEM << if(pred) { >> 
+    Expr<<d, out o>>                                       SEM << } else { >>
+    Expr<<d, out o>>                                       SEM << } >>
+  .
+
+MINIMIZE
+  << 
+    int N = 11;
+    bool[] d = new bool[N];
+    int mistakes = 0;
+    for(int i = 0; i < Math.Pow(2, N); i++) {
+      // generate bit-vector and count number of 1-bits
+      int x = i;
+      for(int j = 0; j < N; j++) {
+        d[N - j - 1] = ((x % 2) == 1);
+        x = (x / 2);
+      }
+      bool target = d[3 + (d[0] ? 1:0) + 2 * (d[1] ? 1:0) + 4 * (d[2] ? 1:0)];
+
+      // apply model
+      bool p;
+      Expr(d, out p);
+
+      if(p != target) mistakes++;
+    }
+    return mistakes;
+  >>
+END Multiplexer.
Index: branches/HeuristicLab.Problems.GPDL/Examples/multi-output-multiplier.txt
===================================================================
--- branches/HeuristicLab.Problems.GPDL/Examples/multi-output-multiplier.txt	(revision 10061)
+++ branches/HeuristicLab.Problems.GPDL/Examples/multi-output-multiplier.txt	(revision 10061)
@@ -0,0 +1,102 @@
+PROBLEM MultiOutputMultiplier
+
+CODE <<
+  const int N = 4;
+  class State { public bool[] x1; public bool[] x2; public bool[] output; }
+  private void GenerateProblemData(int n, out bool[][] a, out bool[][] b, out bool[][] expectedOutput) {
+    var nConfigurations = (int)Math.Pow(2, n);
+    var e = from i in Enumerable.Range(0, nConfigurations)
+            from j in Enumerable.Range(0, i+1)
+            select new {a = ToBitArray(N, i), b = ToBitArray(N, j), res = ToBitArray(2*N, i*j) };
+    
+    a = e.Select(x=>x.a).ToArray();
+    b = e.Select(x=>x.b).ToArray();
+    expectedOutput = e.Select(x=>x.res).ToArray();
+  }
+  
+  private bool[] ToBitArray(int n, int x) {
+    var b = new bool[n];
+    for(int i=0; i<n; i++) {
+      b[n - i - 1] = (x % 2) == 0;
+      x = x / 2;
+    }
+    if(x>0) throw new ArgumentException();
+    return b;
+  }
+>>
+
+NONTERMINALS
+  Expr<<State state, out bool res>>.
+  Assign<<State state, out bool res>>.
+  AND<<State state, out bool res>>.
+  AND1<<State state, out bool res>>.
+  XOR<<State state, out bool res>>.
+  OR<<State state, out bool res>>.
+  
+
+TERMINALS
+  InputA<<out int id>> 
+    CONSTRAINTS
+      id IN SET << Enumerable.Range(0, N) >>
+  .
+  
+  InputB<<out int id>> 
+    CONSTRAINTS
+      id IN SET << Enumerable.Range(0, N) >>
+  .
+  
+  Output<<out int id>>  
+    CONSTRAINTS
+      id IN SET << Enumerable.Range(0, 2 * N) >>
+  .
+
+RULES
+  Expr<<State state, out bool res>> =                   LOCAL << int id; >>
+    Assign<<state, out res>>
+    | AND<<state, out res>>
+    | AND1<<state, out res>>
+    | XOR<<state, out res>>
+    | OR<<state, out res>>
+    | InputA<<out id>>                                                          SEM<< res = state.x1[id]; >>
+    | InputB<<out id>>                                                          SEM<< res = state.x2[id]; >>
+    | Output<<out id>>                                                          SEM<< res = state.output[id]; >>
+  .                                                                             
+                                                                                
+  Assign<<State state, out bool res>> =                 LOCAL << int outId; >>
+    Output<<out outId>>  Expr<<state, out res>>                        SEM<< state.output[outId] = res; >>
+  .
+  
+  AND<<State state, out bool res>> =                    LOCAL << bool resA, resB; >>
+    Expr<<state, out resA>> Expr<<state, out resB>>           SEM << res = resA & resB; >>
+  .
+  AND1<<State state, out bool res>> =                   LOCAL << bool resA, resB; >>
+    Expr<<state, out resA>> Expr<<state, out resB>>           SEM << res = resA & !resB; >>
+  .
+  XOR<<State state, out bool res>> =                    LOCAL << bool resA, resB; >>
+    Expr<<state, out resA>> Expr<<state, out resB>>           SEM << res = resA ^ !resB; >>
+  .
+  OR<<State state, out bool res>> =                     LOCAL << bool resA, resB; >>
+    Expr<<state, out resA>> Expr<<state, out resB>>           SEM << res = resA | resB; >>
+  .
+
+MINIMIZE
+  <<
+    bool[][] a, b, expectedOutput;
+    GenerateProblemData(N, out a, out b, out expectedOutput);
+    
+    int sumErr = 0;
+    for(int i=0; i<expectedOutput.Length; i++) {
+      bool tmp;
+      // evaluate tree for inputs a and b
+      var state = new State();
+      state.x1 = a[i]; state.x2 = b[i]; state.output = new bool[2*N];
+      Expr(state, out tmp);
+
+      // count incorrect bits
+      for(int j=0;j<state.output.Length;j++) {
+        if(state.output[j] != expectedOutput[i][j]) sumErr++;
+      }
+    }
+    return (double)sumErr;
+  >>
+END MultiOutputMultiplier.
Index: branches/HeuristicLab.Problems.GPDL/Examples/symbreg HEAL.txt
===================================================================
--- branches/HeuristicLab.Problems.GPDL/Examples/symbreg HEAL.txt	(revision 10061)
+++ branches/HeuristicLab.Problems.GPDL/Examples/symbreg HEAL.txt	(revision 10061)
@@ -0,0 +1,102 @@
+PROBLEM SymbReg
+
+CODE <<
+  double[,] x;
+  double[] y;
+  string[] variableNames;
+  Dictionary<string,int> nameToCol;
+  
+  double GetValue(double[,] data, string varName, int row) {
+    if(nameToCol == null) {
+      /* init mapping */
+      nameToCol = new Dictionary<string, int>();
+      for(int i=0; i<variableNames.Length; i++) {
+        nameToCol[variableNames[i]] = i;
+      }
+    }
+    return x[row, nameToCol[varName]];
+  }
+
+  double RSquared(IEnumerable<double> xs, IEnumerable<double> ys) {
+     HeuristicLab.Problems.DataAnalysis.OnlineCalculatorError error;
+     var r2 = HeuristicLab.Problems.DataAnalysis.OnlinePearsonsRSquaredCalculator.Calculate(xs, ys, out error);
+     if(error == HeuristicLab.Problems.DataAnalysis.OnlineCalculatorError.None) return r2;
+     else return 0.0;
+  }
+>>
+
+INIT <<
+  // generate 500 case of poly-10 benchmark function
+  int n = 500;
+  variableNames = new string[] {"x1", "x2", "x3", "x4", "x5", "x6", "x7", "x8", "x9", "x10" };
+  var rand = new System.Random();
+  x = new double[n, 10];
+  y = new double[n];
+  for(int row = 0; row < 500; row++) {
+    for(int col = 0; col < 10; col++) {
+      x[row, col] = rand.NextDouble() * 2.0 - 1.0;
+    }
+    y[row] = x[row, 0] * x[row, 1] +
+             x[row, 2] * x[row, 3] +
+             x[row, 4] * x[row, 5] +
+             x[row, 0] * x[row, 6] + x[row, 8] +
+             x[row, 2] * x[row, 5] + x[row, 9];
+  }
+>>
+
+NONTERMINALS
+  Model<<int row, out double val>>.
+  RPB<<int row, out double val>>.
+  Addition<<int row, out double val>>.
+  Subtraction<<int row, out double val>>.
+  Multiplication<<int row, out double val>>.
+  Division<<int row, out double val>>.
+
+TERMINALS
+  Const<<out double val>> 
+    CONSTRAINTS
+      val IN RANGE <<-100>> .. <<100>>
+  .
+  Var<<out string varName, out double weight>>  
+    CONSTRAINTS
+      varName IN SET <<variableNames>>
+      weight IN RANGE <<-100>> .. <<100>>
+  .
+
+RULES
+  Model<<int row, out double val>> =                       
+    RPB<<row, out val>> .
+    
+  RPB<<int row, out double val>> =                         LOCAL << string varName; double w; >> 
+    Addition<<row, out val>>
+    | Subtraction<<row, out val>>
+    | Division<<row, out val>>
+    | Multiplication<<row, out val>>                       
+    | Var<<out varName, out w>>                            SEM << val = w * GetValue(x, varName, row); >>
+    | Const<<out val>>
+  .
+
+  Addition<<int row, out double val>> =                    LOCAL << double x1, x2; >>
+    RPB<<row, out x1>> RPB<<row, out x2>>                  SEM << val = x1 + x2; >>
+  .
+  Subtraction<<int row, out double val>> =                 LOCAL << double x1, x2; >>
+    RPB<<row, out x1>> RPB<<row, out x2>>                  SEM << val = x1 - x2; >>
+  .
+  Division<<int row, out double val>> =                    LOCAL << double x1, x2; >>
+    RPB<<row, out x1>> RPB<<row, out x2>>                  SEM << val = x1 / x2; >>
+  .
+  Multiplication<<int row, out double val>> =              LOCAL << double x1, x2; >>
+    RPB<<row, out x1>> RPB<<row, out x2>>                  SEM << val = x1 * x2; >>
+  .
+
+MAXIMIZE                                                   /* could also use the keyword MINIMIZE here */
+  << 
+    var rows = System.Linq.Enumerable.Range(0, x.GetLength(0));
+    var predicted = rows.Select(r => {
+      double result;
+      Model(r, out result);                                /* we can call the root symbol directly */
+      return result;
+    });
+    return RSquared(predicted, y);
+  >>
+END SymbReg.
Index: branches/HeuristicLab.Problems.GPDL/Examples/symbreg Koza.txt
===================================================================
--- branches/HeuristicLab.Problems.GPDL/Examples/symbreg Koza.txt	(revision 10061)
+++ branches/HeuristicLab.Problems.GPDL/Examples/symbreg Koza.txt	(revision 10061)
@@ -0,0 +1,101 @@
+PROBLEM SymbRegKoza
+CODE <<
+  double[,] x;
+  double[] y;
+  string[] variableNames;
+  Dictionary<string,int> nameToCol;
+  
+  double GetValue(double[,] data, string varName, int row) {
+    if(nameToCol == null) {
+      /* init mapping */
+      nameToCol = new Dictionary<string, int>();
+      for(int i=0; i<variableNames.Length; i++) {
+        nameToCol[variableNames[i]] = i;
+      }
+    }
+    return x[row, nameToCol[varName]];
+  }
+
+  double RSquared(IEnumerable<double> xs, IEnumerable<double> ys) {
+     HeuristicLab.Problems.DataAnalysis.OnlineCalculatorError error;
+     var r2 = HeuristicLab.Problems.DataAnalysis.OnlinePearsonsRSquaredCalculator.Calculate(xs, ys, out error);
+     if(error == HeuristicLab.Problems.DataAnalysis.OnlineCalculatorError.None) return r2;
+     else return 0.0;
+  }
+>>
+
+INIT <<
+  // generate 500 case of poly-10 benchmark function
+  int n = 500;
+  variableNames = new string[] {"x1", "x2", "x3", "x4", "x5", "x6", "x7", "x8", "x9", "x10" };
+  var rand = new System.Random();
+  x = new double[n, 10];
+  y = new double[n];
+  for(int row = 0; row < 500; row++) {
+    for(int col = 0; col < 10; col++) {
+      x[row, col] = rand.NextDouble() * 2.0 - 1.0;
+    }
+    y[row] = x[row, 0] * x[row, 1] +
+             x[row, 2] * x[row, 3] +
+             x[row, 4] * x[row, 5] +
+             x[row, 0] * x[row, 6] + x[row, 8] +
+             x[row, 2] * x[row, 5] + x[row, 9];
+  }
+>>
+
+NONTERMINALS
+  Model<<int row, out double val>>.
+  RPB<<int row, out double val>>.
+  Addition<<int row, out double val>>.
+  Subtraction<<int row, out double val>>.
+  Multiplication<<int row, out double val>>.
+  Division<<int row, out double val>>.
+
+TERMINALS
+  ERC<<out double val>> 
+    CONSTRAINTS
+	  val IN RANGE <<-100>> .. <<100>>
+  .
+
+  Var<<out string varName>> 
+    CONSTRAINTS
+	  varName IN SET <<variableNames>>
+  .
+
+RULES
+  Model<<int row, out double val>> =
+    RPB<<row, out val>> .
+
+  RPB<<int row, out double val>> =                         LOCAL << string varName; >>
+    Addition<<row, out val>>
+    | Subtraction<<row, out val>>
+    | Division<<row, out val>>
+    | Multiplication<<row, out val>>
+    | Var<<out varName>>                                   SEM << val = GetValue(x, varName, row); >>
+    | ERC<<out val>>
+  .
+
+  Addition<<int row, out double val>> =                    LOCAL << double x1, x2; >>
+      RPB<<row, out x1>> RPB<<row, out x2>>                SEM<< val = x1 + x2; >>
+  .
+  Subtraction<<int row, out double val>> =                 LOCAL << double x1, x2; >>
+      RPB<<row, out x1>> RPB<<row, out x2>>                SEM<< val = x1 - x2; >>
+  .
+  Division<<int row, out double val>> =                    LOCAL << double x1, x2; >>
+      RPB<<row, out x1>> RPB<<row, out x2>>                SEM<< val = x1 / x2; >>
+  .
+  Multiplication<<int row, out double val>> =              LOCAL << double x1, x2; >>
+      RPB<<row, out x1>> RPB<<row, out x2>>                SEM<< val = x1 * x2; >>
+  .
+
+MAXIMIZE                                                   /* could also use the keyword MINIMIZE here */
+  << 
+    var rows = System.Linq.Enumerable.Range(0, x.GetLength(0));
+    var predicted = rows.Select(r => {
+      double result;
+      Model(r, out result);                                /* we can call the root symbol directly */
+      return result;
+    });
+    return RSquared(predicted, y);
+  >>
+END SymbRegKoza.
