Index: /branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/ArtificialAnt/GEArtificialAntEvaluator.cs
===================================================================
--- /branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/ArtificialAnt/GEArtificialAntEvaluator.cs	(revision 10289)
+++ /branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/ArtificialAnt/GEArtificialAntEvaluator.cs	(revision 10290)
@@ -66,4 +66,10 @@
       get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
     }
+    public ILookupParameter<IntMatrix> BoundsParameter {
+      get { return (ILookupParameter<IntMatrix>)Parameters["Bounds"]; }
+    }
+    public ILookupParameter<IntValue> MaxExpressionLengthParameter {
+      get { return (ILookupParameter<IntValue>)Parameters["MaximumExpressionLength"]; }
+    }
     #endregion
 
@@ -82,4 +88,7 @@
       Parameters.Add(new LookupParameter<IGenotypeToPhenotypeMapper>("GenotypeToPhenotypeMapper", "Maps the genotype (an integer vector) to the phenotype (a symbolic expression tree)."));
       Parameters.Add(new LookupParameter<IRandom>("Random", "Random number generator for the genotype creation and the genotype-to-phenotype mapping."));
+
+      Parameters.Add(new LookupParameter<IntMatrix>("Bounds", "The integer number range in which the single genomes of a genotype are created."));
+      Parameters.Add(new LookupParameter<IntValue>("MaximumExpressionLength", "Maximal length of the expression to control the artificial ant."));
     }
 
@@ -87,4 +96,6 @@
       SymbolicExpressionTree tree = GenotypeToPhenotypeMapperParameter.ActualValue.Map(
         RandomParameter.ActualValue,
+        BoundsParameter.ActualValue,
+        MaxExpressionLengthParameter.ActualValue.Value,
         SymbolicExpressionTreeGrammarParameter.ActualValue,
         IntegerVectorParameter.ActualValue
Index: /branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Mappers/BreathFirstMapper.cs
===================================================================
--- /branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Mappers/BreathFirstMapper.cs	(revision 10289)
+++ /branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Mappers/BreathFirstMapper.cs	(revision 10290)
@@ -24,4 +24,5 @@
 using HeuristicLab.Common;
 using HeuristicLab.Core;
+using HeuristicLab.Data;
 using HeuristicLab.Encodings.IntegerVectorEncoding;
 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
@@ -54,5 +55,5 @@
     /// <param name="genotype">integer vector, which should be mapped to a tree</param>
     /// <returns>phenotype (a symbolic expression tree)</returns>
-    public override SymbolicExpressionTree Map(IRandom random,
+    public override SymbolicExpressionTree Map(IRandom random, IntMatrix bounds, int length,
                                                ISymbolicExpressionGrammar grammar,
                                                IntegerVector genotype) {
@@ -87,9 +88,7 @@
 
       int genotypeIndex = 0;
-      int currSubtreeCount = 1;
-
       queue.Enqueue(new Tuple<ISymbolicExpressionTreeNode, int>(startNode, 1));
 
-      while ((currSubtreeCount < maxSubtreeCount) && (queue.Count > 0)) {
+      while (queue.Count > 0) {
 
         Tuple<ISymbolicExpressionTreeNode, int> current = queue.Dequeue();
@@ -98,13 +97,13 @@
         for (int i = 0; i < current.Item2; ++i) {
 
-          var newNode = GetNewChildNode(current.Item1, genotype, grammar, genotypeIndex, random);
-          int arity = SampleArity(random, newNode, maxSubtreeCount - currSubtreeCount, grammar);
-
-          if (arity < 0) {
+          if (genotypeIndex >= maxSubtreeCount) {
+            // if all genomes were used, only add terminal nodes to the remaining subtrees
             current.Item1.AddSubtree(GetRandomTerminalNode(current.Item1, grammar, random));
           } else {
+            var newNode = GetNewChildNode(current.Item1, genotype, grammar, genotypeIndex, random);
+            int arity = SampleArity(random, newNode, grammar);
+
             current.Item1.AddSubtree(newNode);
             genotypeIndex++;
-            currSubtreeCount += arity;
             if (arity > 0) {
               // new node has subtrees so enqueue the node 
@@ -114,14 +113,4 @@
         }
       }
-
-      // maximum allowed subtree count was already reached, but there are still
-      // incomplete subtrees (non-terminal symbols) in the tree
-      // -> fill them with terminal symbols
-      while (queue.Count > 0) {
-        Tuple<ISymbolicExpressionTreeNode, int> current = queue.Dequeue();
-        for (int i = 0; i < current.Item2; ++i) {
-          current.Item1.AddSubtree(GetRandomTerminalNode(current.Item1, grammar, random));
-        }
-      }
     }
   }
Index: /branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Mappers/DepthFirstMapper.cs
===================================================================
--- /branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Mappers/DepthFirstMapper.cs	(revision 10289)
+++ /branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Mappers/DepthFirstMapper.cs	(revision 10290)
@@ -24,4 +24,5 @@
 using HeuristicLab.Common;
 using HeuristicLab.Core;
+using HeuristicLab.Data;
 using HeuristicLab.Encodings.IntegerVectorEncoding;
 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
@@ -54,5 +55,5 @@
     /// <param name="genotype">integer vector, which should be mapped to a tree</param>
     /// <returns>phenotype (a symbolic expression tree)</returns>
-    public override SymbolicExpressionTree Map(IRandom random,
+    public override SymbolicExpressionTree Map(IRandom random, IntMatrix bounds, int length,
                                                ISymbolicExpressionGrammar grammar,
                                                IntegerVector genotype) {
@@ -89,9 +90,7 @@
 
       int genotypeIndex = 0;
-      int currSubtreeCount = 1;
-
       stack.Push(new Tuple<ISymbolicExpressionTreeNode, int>(startNode, 1));
 
-      while ((currSubtreeCount < maxSubtreeCount) && (stack.Count > 0)) {
+      while (stack.Count > 0) {
 
         // get next node from stack and re-push it, if this node still has unhandled subtrees ...
@@ -101,13 +100,13 @@
         }
 
-        var newNode = GetNewChildNode(current.Item1, genotype, grammar, genotypeIndex, random);
-        int arity = SampleArity(random, newNode, maxSubtreeCount - currSubtreeCount, grammar);
-
-        if (arity < 0) {
+        if (genotypeIndex >= maxSubtreeCount) {
+          // if all genomes were used, only add terminal nodes to the remaining subtrees
           current.Item1.AddSubtree(GetRandomTerminalNode(current.Item1, grammar, random));
         } else {
+          var newNode = GetNewChildNode(current.Item1, genotype, grammar, genotypeIndex, random);
+          int arity = SampleArity(random, newNode, grammar);
+
           current.Item1.AddSubtree(newNode);
           genotypeIndex++;
-          currSubtreeCount += arity;
           if (arity > 0) {
             // new node has subtrees so push it onto the stack 
@@ -116,15 +115,4 @@
         }
       }
-
-      // maximum allowed subtree count was already reached, but there are still
-      // incomplete subtrees (non-terminal symbols) in the tree
-      // -> fill them with terminal symbols
-      while (stack.Count > 0) {
-        Tuple<ISymbolicExpressionTreeNode, int> current = stack.Pop();
-        if (current.Item2 > 1) {
-          stack.Push(new Tuple<ISymbolicExpressionTreeNode, int>(current.Item1, current.Item2 - 1));
-        }
-        current.Item1.AddSubtree(GetRandomTerminalNode(current.Item1, grammar, random));
-      }
     }
   }
Index: /branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Mappers/GenotypeToPhenotypeMapper.cs
===================================================================
--- /branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Mappers/GenotypeToPhenotypeMapper.cs	(revision 10289)
+++ /branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Mappers/GenotypeToPhenotypeMapper.cs	(revision 10290)
@@ -24,4 +24,5 @@
 using HeuristicLab.Common;
 using HeuristicLab.Core;
+using HeuristicLab.Data;
 using HeuristicLab.Encodings.IntegerVectorEncoding;
 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
@@ -40,5 +41,5 @@
     protected GenotypeToPhenotypeMapper() : base() { }
 
-    public abstract SymbolicExpressionTree Map(IRandom random,
+    public abstract SymbolicExpressionTree Map(IRandom random, IntMatrix bounds, int length,
                                                ISymbolicExpressionGrammar grammar,
                                                IntegerVector genotype);
@@ -96,5 +97,6 @@
       if (prodRuleCount < 1) return null;
 
-      int prodRuleIndex = genotype[genotypeIndex % genotype.Length] % prodRuleCount;
+      // genotypeIndex % genotype.Length
+      int prodRuleIndex = genotype[genotypeIndex] % prodRuleCount;
 
       var newNode = symbolList.ElementAt(prodRuleIndex).CreateTreeNode();
@@ -109,23 +111,12 @@
     /// <param name="random">random number generator</param>
     /// <param name="node">node, for which a random arity is determined</param>
-    /// <param name="maxAllowedArity">the resulting arity must not exceed this maximum arity</param>
     /// <param name="grammar">symbolic expression grammar to use</param>
-    /// <returns>random arity in the interval [minArity, maxArity] of the node or
-    ///          -1, if minArity exceeds maxAllowedArity</returns>
+    /// <returns>random arity in the interval [minArity, maxArity]</returns>
     protected int SampleArity(IRandom random,
                               ISymbolicExpressionTreeNode node,
-                              int maxAllowedArity,
                               ISymbolicExpressionGrammar grammar) {
 
       int minArity = grammar.GetMinimumSubtreeCount(node.Symbol);
       int maxArity = grammar.GetMaximumSubtreeCount(node.Symbol);
-
-      if (maxAllowedArity < maxArity) {
-        maxArity = maxAllowedArity;
-      }
-
-      if (maxAllowedArity < minArity) {
-        return -1;
-      }
 
       if (minArity == maxArity) {
Index: /branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Mappers/IGenotypeToPhenotypeMapper.cs
===================================================================
--- /branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Mappers/IGenotypeToPhenotypeMapper.cs	(revision 10289)
+++ /branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Mappers/IGenotypeToPhenotypeMapper.cs	(revision 10290)
@@ -21,4 +21,5 @@
 
 using HeuristicLab.Core;
+using HeuristicLab.Data;
 using HeuristicLab.Encodings.IntegerVectorEncoding;
 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
@@ -29,5 +30,5 @@
   /// </summary>
   public interface IGenotypeToPhenotypeMapper : IIntegerVectorOperator {
-    SymbolicExpressionTree Map(IRandom random,
+    SymbolicExpressionTree Map(IRandom random, IntMatrix bounds, int length,
                                ISymbolicExpressionGrammar grammar,
                                IntegerVector genotype);
Index: /branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Mappers/PIGEMapper.cs
===================================================================
--- /branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Mappers/PIGEMapper.cs	(revision 10289)
+++ /branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Mappers/PIGEMapper.cs	(revision 10290)
@@ -20,6 +20,8 @@
 #endregion
 
+using System.Collections.Generic;
 using HeuristicLab.Common;
 using HeuristicLab.Core;
+using HeuristicLab.Data;
 using HeuristicLab.Encodings.IntegerVectorEncoding;
 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
@@ -27,10 +29,56 @@
 
 namespace HeuristicLab.Problems.GrammaticalEvolution {
+
   /// <summary>
   /// Position Independent (PI) Grammatical Evolution Mapper
+  /// -----------------------------------------------------------------------------------
+  /// Standard GE mappers:
+  ///   Rule = Codon Value % Number Of Rules
+  ///   
+  /// 𝜋GE:
+  ///   𝜋GE codons consist of (nont, rule) tuples, where nont may be one value from an "order"
+  ///   integer vector and rule may be one value from a "content" integer vector.
+  ///   
+  ///   Order:   NT   = nont % Num. NT      ... determines, which non-terminal to expand next
+  ///   Content: Rule = rule % Num. Rules   ... rule determination as with standard GE mappers
+  /// 
+  /// Four mutation and crossover strategies possible:
+  ///  * Order-only:    only "order" vector is modified, "content" vector is fixed (1:0),
+  ///                   worst result according to [2]
+  ///  * Content-only:  only "content" vector is modified, "order" vector is fixed (0:1),
+  ///                   best result according to [2]
+  ///  * 𝜋GE:           genetic operators are applied equally (1:1), 
+  ///  * Content:Order: genetic operators are applied unequally (e.g. 2:1 or 1:2),
+  /// 
+  /// Here, the "content-only" strategy is implemented, as it is the best solution according to [2]
+  /// and it does not require much to change in the problem and evaluator classes.
+  /// 
   /// </summary>
-  [Item("PIGEMapper", "")]
+  /// <remarks>
+  /// Described in
+  /// 
+  /// [1] Michael O’Neill et al. 𝜋Grammatical Evolution. In: GECCO 2004.
+  /// Vol. 3103. LNCS. Heidelberg: Springer-Verlag Berlin, 2004, pp. 617–629.
+  /// url: http://dynamics.org/Altenberg/UH_ICS/EC_REFS/GP_REFS/GECCO/2004/31030617.pdf.
+  /// 
+  /// [2] David Fagan et al. Investigating Mapping Order in πGE. IEEE, 2010
+  /// url: http://ncra.ucd.ie/papers/pigeWCCI2010.pdf
+  /// </remarks>
+  [Item("PIGEMapper", "Position Independent (PI) Grammatical Evolution Mapper")]
   [StorableClass]
   public class PIGEMapper : GenotypeToPhenotypeMapper {
+
+    private IntegerVector nontVector;
+
+    public IntegerVector NontVector {
+      get { return nontVector; }
+      set { nontVector = value; }
+    }
+
+    private IntegerVector GetNontVector(IRandom random, IntMatrix bounds, int length) {
+      IntegerVector v = new IntegerVector(length);
+      v.Randomize(random, bounds);
+      return v;
+    }
 
     [StorableConstructor]
@@ -52,5 +100,5 @@
     /// <param name="genotype">integer vector, which should be mapped to a tree</param>
     /// <returns>phenotype (a symbolic expression tree)</returns>
-    public override SymbolicExpressionTree Map(IRandom random,
+    public override SymbolicExpressionTree Map(IRandom random, IntMatrix bounds, int length,
                                                ISymbolicExpressionGrammar grammar,
                                                IntegerVector genotype) {
@@ -62,8 +110,51 @@
       tree.Root = rootNode;
 
-      // TODO
+      if (NontVector == null) {
+        NontVector = GetNontVector(random, bounds, length);
+      }
+
+      MapPIGEIteratively(startNode, genotype, grammar,
+                         genotype.Length, random);
 
       return tree;
     }
+
+
+    private void MapPIGEIteratively(ISymbolicExpressionTreeNode startNode,
+                                    IntegerVector genotype,
+                                    ISymbolicExpressionGrammar grammar,
+                                    int maxSubtreeCount, IRandom random) {
+
+      List<ISymbolicExpressionTreeNode> nonTerminals = new List<ISymbolicExpressionTreeNode>();
+
+      int genotypeIndex = 0;
+      nonTerminals.Add(startNode);
+
+      while (nonTerminals.Count > 0) {
+
+        if (genotypeIndex >= maxSubtreeCount) {
+          // if all genomes were used, only add terminal nodes to the remaining subtrees
+          ISymbolicExpressionTreeNode current = nonTerminals[0];
+          nonTerminals.RemoveAt(0);
+          current.AddSubtree(GetRandomTerminalNode(current, grammar, random));
+        } else {
+          // Order:   NT   = nont % Num. NT
+          int nt = NontVector[genotypeIndex] % nonTerminals.Count;
+          ISymbolicExpressionTreeNode current = nonTerminals[nt];
+          nonTerminals.RemoveAt(nt);
+
+          // Content: Rule = rule % Num. Rules
+          ISymbolicExpressionTreeNode newNode = GetNewChildNode(current, genotype, grammar, genotypeIndex, random);
+          int arity = SampleArity(random, newNode, grammar);
+
+          current.AddSubtree(newNode);
+          genotypeIndex++;
+          // new node has subtrees, so add "arity" number of copies of this node to the nonTerminals list
+          for (int i = 0; i < arity; ++i) {
+            nonTerminals.Add(newNode);
+          }
+        }
+      }
+    }
   }
 }
Index: /branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Mappers/RandomMapper.cs
===================================================================
--- /branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Mappers/RandomMapper.cs	(revision 10289)
+++ /branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Mappers/RandomMapper.cs	(revision 10290)
@@ -22,4 +22,5 @@
 using HeuristicLab.Common;
 using HeuristicLab.Core;
+using HeuristicLab.Data;
 using HeuristicLab.Encodings.IntegerVectorEncoding;
 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
@@ -52,5 +53,5 @@
     /// <param name="genotype">integer vector, which should be mapped to a tree</param>
     /// <returns>phenotype (a symbolic expression tree)</returns>
-    public override SymbolicExpressionTree Map(IRandom random,
+    public override SymbolicExpressionTree Map(IRandom random, IntMatrix bounds, int length,
                                                ISymbolicExpressionGrammar grammar,
                                                IntegerVector genotype) {
Index: /branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Symbolic/GESymbolicRegressionSingleObjectiveEvaluator.cs
===================================================================
--- /branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Symbolic/GESymbolicRegressionSingleObjectiveEvaluator.cs	(revision 10289)
+++ /branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Symbolic/GESymbolicRegressionSingleObjectiveEvaluator.cs	(revision 10290)
@@ -22,4 +22,5 @@
 using HeuristicLab.Common;
 using HeuristicLab.Core;
+using HeuristicLab.Data;
 using HeuristicLab.Parameters;
 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
@@ -34,4 +35,6 @@
     public const string EvaluatorParameterName = "Evaluator";
     public const string RandomParameterName = "Random";
+    public const string BoundsParameterName = "Bounds";
+    public const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength";
 
     public IValueParameter<ISymbolicRegressionSingleObjectiveEvaluator> EvaluatorParameter {
@@ -40,4 +43,10 @@
     public ILookupParameter<IRandom> RandomParameter {
       get { return (ILookupParameter<IRandom>)Parameters[RandomParameterName]; }
+    }
+    public ILookupParameter<IntMatrix> BoundsParameter {
+      get { return (ILookupParameter<IntMatrix>)Parameters[BoundsParameterName]; }
+    }
+    public ILookupParameter<IntValue> MaximumSymbolicExpressionTreeLengthParameter {
+      get { return (ILookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeLengthParameterName]; }
     }
 
@@ -53,4 +62,6 @@
       : base() {
       Parameters.Add(new ValueParameter<ISymbolicRegressionSingleObjectiveEvaluator>(EvaluatorParameterName, "The symbolic regression evaluator that should be used to assess the quality of trees.", new SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator()));
+      Parameters.Add(new LookupParameter<IntMatrix>(BoundsParameterName, "The integer number range in which the single genomes of a genotype are created."));
+      Parameters.Add(new LookupParameter<IntValue>(MaximumSymbolicExpressionTreeLengthParameterName, "Genotype length."));
     }
 
@@ -69,4 +80,6 @@
       var tree = GenotypeToPhenotypeMapperParameter.ActualValue.Map(
         RandomParameter.ActualValue,
+        BoundsParameter.ActualValue,
+        MaximumSymbolicExpressionTreeLengthParameter.ActualValue.Value,
         SymbolicExpressionTreeGrammarParameter.ActualValue,
         genotype
