Free cookie consent management tool by TermsFeed Policy Generator

Changeset 1198


Ignore:
Timestamp:
02/02/09 12:49:44 (16 years ago)
Author:
gkronber
Message:

merged fix for #476 (ProbabilisticTreeCreator can create trees that are slightly larger than allowed) (r1181) from CEDMA refactoring branch to trunk.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.GP/ProbabilisticTreeCreator.cs

    r656 r1198  
    3030namespace HeuristicLab.GP {
    3131  public class ProbabilisticTreeCreator : OperatorBase {
     32    private int MAX_TRIES { get { return 100; } }
     33
    3234    public override string Description {
    3335      get { return @"Generates a new random operator tree."; }
     
    5658
    5759      int treeSize = random.Next(minTreeSize, maxTreeSize + 1);
    58       IFunctionTree root = gardener.PTC2(random, treeSize, maxTreeHeight);
    5960
    60       int actualTreeSize = root.Size;
    61       int actualTreeHeight = root.Height;
     61      IFunctionTree root;
     62      int actualTreeSize;
     63      int actualTreeHeight;
     64      int tries = 0;
     65      do {
     66        root = gardener.PTC2(random, treeSize, maxTreeHeight);
     67        actualTreeSize = root.Size;
     68        actualTreeHeight = root.Height;
     69        if (tries++ >= MAX_TRIES) {
     70          // try a different size
     71          treeSize = random.Next(minTreeSize, maxTreeSize + 1);
     72          tries = 0;
     73        }
     74      } while (actualTreeSize > maxTreeSize || actualTreeHeight > maxTreeHeight);
    6275
    6376      scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("FunctionTree"), root));
     
    6578      scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("TreeHeight"), new IntData(actualTreeHeight)));
    6679
    67       Debug.Assert(gardener.IsValidTree(root) && actualTreeHeight<=maxTreeHeight);
    68 
    6980      return gardener.CreateInitializationOperation(gardener.GetAllSubTrees(root), scope);
    7081    }
Note: See TracChangeset for help on using the changeset viewer.