Index: /branches/CEDMA-Refactoring-Ticket419/HeuristicLab.GP/Recombination/OnePointCrossOver.cs
===================================================================
--- /branches/CEDMA-Refactoring-Ticket419/HeuristicLab.GP/Recombination/OnePointCrossOver.cs	(revision 1195)
+++ /branches/CEDMA-Refactoring-Ticket419/HeuristicLab.GP/Recombination/OnePointCrossOver.cs	(revision 1196)
@@ -36,5 +36,5 @@
   /// W. B. Langdon and R. Poli.  Foundations of Genetic Programming. Springer-Verlag, 2002.
   /// </summary>
-  public class OnePointCrossOver : GPCrossoverBase {
+  public class OnePointCrossOver : SizeConstrictedGPCrossoverBase {
     // internal data structure to represent crossover points
     private class CrossoverPoint {
@@ -45,11 +45,11 @@
     public override string Description {
       get {
-        return @"";
+        return @"One point crossover for trees as described in W. B. Langdon and R. Poli. Foundations of Genetic Programming. Springer-Verlag, 2002.";
       }
     }
 
-    internal override IFunctionTree Cross(IScope scope, TreeGardener gardener, MersenneTwister random, IFunctionTree tree0, IFunctionTree tree1) {
+    internal override IFunctionTree Cross(TreeGardener gardener, MersenneTwister random, IFunctionTree tree0, IFunctionTree tree1, int maxTreeSize, int maxTreeHeight) {
       List<CrossoverPoint> allowedCrossOverPoints = new List<CrossoverPoint>();
-      GetCrossOverPoints(gardener, tree0, tree1, allowedCrossOverPoints);
+      GetCrossOverPoints(gardener, tree0, tree1, maxTreeSize - tree0.Size, allowedCrossOverPoints);
       if (allowedCrossOverPoints.Count > 0) {
         CrossoverPoint crossOverPoint = allowedCrossOverPoints[random.Next(allowedCrossOverPoints.Count)];
@@ -62,10 +62,11 @@
     }
 
-    private void GetCrossOverPoints(TreeGardener gardener, IFunctionTree branch0, IFunctionTree branch1, List<CrossoverPoint> crossoverPoints) {
+    private void GetCrossOverPoints(TreeGardener gardener, IFunctionTree branch0, IFunctionTree branch1, int maxNewNodes, List<CrossoverPoint> crossoverPoints) {
       if (branch0.SubTrees.Count != branch1.SubTrees.Count) return;
 
       for (int i = 0; i < branch0.SubTrees.Count; i++) {
         // if the current branch can be attached as a sub-tree to branch0
-        if (gardener.GetAllowedSubFunctions(branch0.Function, i).Contains(branch1.SubTrees[i].Function)) {
+        if (gardener.GetAllowedSubFunctions(branch0.Function, i).Contains(branch1.SubTrees[i].Function) &&
+           branch1.SubTrees[i].Size - branch0.SubTrees[i].Size <= maxNewNodes) {
           CrossoverPoint p = new CrossoverPoint();
           p.childIndex = i;
@@ -74,5 +75,5 @@
           crossoverPoints.Add(p);
         }
-        GetCrossOverPoints(gardener, branch0.SubTrees[i], branch1.SubTrees[i], crossoverPoints);
+        GetCrossOverPoints(gardener, branch0.SubTrees[i], branch1.SubTrees[i], maxNewNodes, crossoverPoints);
       }
     }
Index: /branches/CEDMA-Refactoring-Ticket419/HeuristicLab.GP/Recombination/SizeConstrictedGPCrossoverBase.cs
===================================================================
--- /branches/CEDMA-Refactoring-Ticket419/HeuristicLab.GP/Recombination/SizeConstrictedGPCrossoverBase.cs	(revision 1195)
+++ /branches/CEDMA-Refactoring-Ticket419/HeuristicLab.GP/Recombination/SizeConstrictedGPCrossoverBase.cs	(revision 1196)
@@ -32,5 +32,8 @@
 
 namespace HeuristicLab.GP {
-  public abstract class SizeConstrictedGPCrossoverBase : GPCrossoverBase{
+  public abstract class SizeConstrictedGPCrossoverBase : GPCrossoverBase {
+
+    private int MaxRecombinationTries { get { return 20; } }
+
     public SizeConstrictedGPCrossoverBase()
       : base() {
@@ -45,13 +48,14 @@
       // when tree0 is terminal then try to cross into tree1, when tree1 is also terminal just return tree0 unchanged.
       IFunctionTree newTree;
-      if (tree0.SubTrees.Count > 0) {
-        newTree = Cross(gardener, random, tree0, tree1, maxTreeSize, maxTreeHeight);
-      } else if (tree1.SubTrees.Count > 0) {
-        newTree = Cross(gardener, random, tree1, tree0, maxTreeSize, maxTreeHeight);
-      } else newTree = tree0;
-
-      // check if the size and height of the new tree are still within the allowed bounds
-      Debug.Assert(newTree.Height <= maxTreeHeight);
-      Debug.Assert(newTree.Size <= maxTreeSize);
+      int tries = 0;
+      do {
+        if (tree0.SubTrees.Count > 0) {
+          newTree = Cross(gardener, random, (IFunctionTree)tree0.Clone(), (IFunctionTree)tree1.Clone(), maxTreeSize, maxTreeHeight);
+        } else if (tree1.SubTrees.Count > 0) {
+          newTree = Cross(gardener, random, (IFunctionTree)tree1.Clone(), (IFunctionTree)tree0.Clone(), maxTreeSize, maxTreeHeight);
+        } else newTree = tree0;
+        if (tries++ > MaxRecombinationTries)
+          throw new InvalidOperationException("Couldn't recombine parents to create a valid child not larger than " + maxTreeSize + " and not higher than " + maxTreeHeight + ".");
+      } while (newTree.Size > maxTreeSize || newTree.Height > maxTreeHeight);
       return newTree;
     }
Index: /branches/CEDMA-Refactoring-Ticket419/HeuristicLab.GP/Recombination/SizeFairCrossOver.cs
===================================================================
--- /branches/CEDMA-Refactoring-Ticket419/HeuristicLab.GP/Recombination/SizeFairCrossOver.cs	(revision 1195)
+++ /branches/CEDMA-Refactoring-Ticket419/HeuristicLab.GP/Recombination/SizeFairCrossOver.cs	(revision 1196)
@@ -39,5 +39,5 @@
   /// </summary>
   public class SizeFairCrossOver : SizeConstrictedGPCrossoverBase {
-    private const int MAX_RECOMBINATION_TRIES = 20;
+    private int MaxRecombinationTries { get { return 20; } }
     // private data structure for crossover points
     protected class CrossoverPoint {
@@ -57,5 +57,5 @@
         removedBranchIndex = random.Next(parent.SubTrees.Count);
         insertedBranch = GetReplacementBranch(random, gardener, tree0, parent, removedBranchIndex, tree1, maxTreeSize, maxTreeHeight);
-      } while (insertedBranch == null && tries++ < MAX_RECOMBINATION_TRIES);
+      } while (insertedBranch == null && tries++ < MaxRecombinationTries);
 
       if (insertedBranch != null) {
@@ -139,5 +139,5 @@
       for (int i = 0; i < root.SubTrees.Count; i++) {
         GetTrail(root.SubTrees[i], branch, trail);
-        if (trail.Count>0) {
+        if (trail.Count > 0) {
           trail.Add(i);
           return;
Index: /branches/CEDMA-Refactoring-Ticket419/HeuristicLab.GP/Recombination/StandardCrossOver.cs
===================================================================
--- /branches/CEDMA-Refactoring-Ticket419/HeuristicLab.GP/Recombination/StandardCrossOver.cs	(revision 1195)
+++ /branches/CEDMA-Refactoring-Ticket419/HeuristicLab.GP/Recombination/StandardCrossOver.cs	(revision 1196)
@@ -33,5 +33,5 @@
 namespace HeuristicLab.GP {
   public class StandardCrossOver : SizeConstrictedGPCrossoverBase {
-    private const int MAX_RECOMBINATION_TRIES = 20;
+    private int MaxRecombinationTries { get { return 20; } }
 
     public override string Description {
@@ -52,5 +52,5 @@
         // select a random crossover point in the first parent tree0
         parent0 = null;
-        while(parent0 == null) parent0 = gardener.GetRandomParentNode(tree0);
+        while (parent0 == null) parent0 = gardener.GetRandomParentNode(tree0);
         // select a random branch to replace
         replacedChildIndex = random.Next(parent0.SubTrees.Count);
@@ -62,7 +62,7 @@
         IList<IFunction> allowedFunctions = gardener.GetAllowedSubFunctions(parent0.Function, replacedChildIndex);
         allowedCrossoverPoints = GetPossibleCrossoverPoints(gardener, tree1, maxInsertedBranchSize, maxInsertedBranchHeight, allowedFunctions);
-      } while(allowedCrossoverPoints.Count == 0 && tries++ < MAX_RECOMBINATION_TRIES);
+      } while (allowedCrossoverPoints.Count == 0 && tries++ < MaxRecombinationTries);
 
-      if(allowedCrossoverPoints.Count > 0) {
+      if (allowedCrossoverPoints.Count > 0) {
         IFunctionTree branch1 = allowedCrossoverPoints[random.Next(allowedCrossoverPoints.Count)];
 
@@ -76,6 +76,6 @@
     private List<IFunctionTree> GetPossibleCrossoverPoints(TreeGardener gardener, IFunctionTree tree, int maxInsertedBranchSize, int maxInsertedBranchHeight, IList<IFunction> allowedFunctions) {
       List<IFunctionTree> crossoverPoints = new List<IFunctionTree>();
-      foreach(IFunctionTree possiblePoint in gardener.GetAllSubTrees(tree)) {
-        if(allowedFunctions.Contains(possiblePoint.Function) && possiblePoint.Size <= maxInsertedBranchSize && possiblePoint.Height <= maxInsertedBranchHeight)
+      foreach (IFunctionTree possiblePoint in gardener.GetAllSubTrees(tree)) {
+        if (allowedFunctions.Contains(possiblePoint.Function) && possiblePoint.Size <= maxInsertedBranchSize && possiblePoint.Height <= maxInsertedBranchHeight)
           crossoverPoints.Add(possiblePoint);
       }
Index: /branches/CEDMA-Refactoring-Ticket419/HeuristicLab.GP/Recombination/UniformCrossover.cs
===================================================================
--- /branches/CEDMA-Refactoring-Ticket419/HeuristicLab.GP/Recombination/UniformCrossover.cs	(revision 1195)
+++ /branches/CEDMA-Refactoring-Ticket419/HeuristicLab.GP/Recombination/UniformCrossover.cs	(revision 1196)
@@ -37,5 +37,5 @@
   /// In Proceedings of Genetic Programming '98, Madison, Wisconsin, 1998.
   /// </summary>
-  public class UniformCrossover : GPCrossoverBase {
+  public class UniformCrossover : SizeConstrictedGPCrossoverBase {
     // internal datastructure to represent crossover points
     private class CrossoverPoint {
@@ -52,5 +52,5 @@
     }
 
-    internal override IFunctionTree Cross(IScope scope, TreeGardener gardener, MersenneTwister random, IFunctionTree tree0, IFunctionTree tree1) {
+    internal override IFunctionTree Cross(TreeGardener gardener, MersenneTwister random, IFunctionTree tree0, IFunctionTree tree1, int maxTreeSize, int maxTreeHeight) {
       List<CrossoverPoint> allowedCrossOverPoints = new List<CrossoverPoint>();
       GetCrossOverPoints(gardener, tree0, tree1, allowedCrossOverPoints);
