Free cookie consent management tool by TermsFeed Policy Generator

Changeset 1209


Ignore:
Timestamp:
02/05/09 12:56:43 (15 years ago)
Author:
gkronber
Message:

Return the parent tree without changes if it's not possible to create a valid tree within the size constraints after N tries. #479 (Crossover operators create trees that are larger than the allowed max size)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/CEDMA-Refactoring-Ticket419/HeuristicLab.GP/Recombination/SizeConstrictedGPCrossoverBase.cs

    r1196 r1209  
    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;
Note: See TracChangeset for help on using the changeset viewer.