Changeset 1212


Ignore:
Timestamp:
02/10/09 12:59:37 (13 years ago)
Author:
gkronber
Message:

merged r1200 and r1209 from CEDMA refactoring branch into trunk. #479 (Crossover operators create trees that are larger than the allowed max size)

Location:
trunk/sources/HeuristicLab.GP/Recombination
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.GP/Recombination/SizeConstrictedGPCrossoverBase.cs

    r1197 r1212  
    5050      int tries = 0;
    5151      do {
     52        if (tries++ > MaxRecombinationTries)
     53          // if after so many tries it was not possible to create a solution within the given size constraints just return the tree without changes.
     54          return tree0;
    5255        if (tree0.SubTrees.Count > 0) {
    5356          newTree = Cross(gardener, random, (IFunctionTree)tree0.Clone(), (IFunctionTree)tree1.Clone(), maxTreeSize, maxTreeHeight);
     
    5558          newTree = Cross(gardener, random, (IFunctionTree)tree1.Clone(), (IFunctionTree)tree0.Clone(), maxTreeSize, maxTreeHeight);
    5659        } else newTree = tree0;
    57         if (tries++ > MaxRecombinationTries)
    58           throw new InvalidOperationException("Couldn't recombine parents to create a valid child not larger than " + maxTreeSize + " and not higher than " + maxTreeHeight + ".");
    5960      } while (newTree.Size > maxTreeSize || newTree.Height > maxTreeHeight);
    6061      return newTree;
  • trunk/sources/HeuristicLab.GP/Recombination/SizeFairCrossOver.cs

    r1197 r1212  
    8383      if (shorterBranches.Count > 0 && longerBranches.Count > 0) {
    8484        double pEqualLength = equalLengthBranches.Count > 0 ? 1.0 / removedBranchSize : 0.0;
    85         double pLonger = (1.0 - pEqualLength) / (longerBranches.Count * (1.0 + longerBranches.Average(p => p.branchSize) / shorterBranches.Average(p => p.branchSize)));
     85        double pLonger;
     86        if (parent.Size == maxTreeSize) {
     87          pLonger = 0.0;
     88        } else {
     89          pLonger = (1.0 - pEqualLength) / (longerBranches.Count * (1.0 + longerBranches.Average(p => p.branchSize) / shorterBranches.Average(p => p.branchSize)));
     90        }
    8691        double pShorter = (1.0 - pEqualLength - pLonger);
    8792
Note: See TracChangeset for help on using the changeset viewer.