Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/27/09 09:47:03 (15 years ago)
Author:
gkronber
Message:

Added until test project for HeuristicLab.GP plugins. #791 (Tests for GP operators and structure identification evaluators)

File:
1 edited

Legend:

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

    r2222 r2447  
    2727namespace HeuristicLab.GP.Operators {
    2828  public class ProbabilisticTreeCreator : OperatorBase {
    29     private int MAX_TRIES { get { return 100; } }
     29    private static int MAX_TRIES { get { return 100; } }
    3030
    3131    public override string Description {
     
    5050      int maxTreeHeight = GetVariableValue<IntData>("MaxTreeHeight", scope, true).Data;
    5151
    52       int treeSize = random.Next(minTreeSize, maxTreeSize + 1);
    53       IFunctionTree root;
    54       int tries = 0;
    55       TreeGardener gardener = new TreeGardener(random, funLibrary);
    56       do {
    57         root = gardener.PTC2(treeSize, maxTreeHeight);
    58         if (tries++ >= MAX_TRIES) {
    59           // try a different size
    60           treeSize = random.Next(minTreeSize, maxTreeSize + 1);
    61           tries = 0;
    62         }
    63       } while (root.GetSize() > maxTreeSize || root.GetHeight() > maxTreeHeight);
    64 
     52      IFunctionTree root = Create(random, funLibrary, minTreeSize, maxTreeSize, maxTreeHeight);
    6553      scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("FunctionTree"), new GeneticProgrammingModel(root)));
    6654      return Util.CreateInitializationOperation(TreeGardener.GetAllSubTrees(root), scope);
    6755    }
    6856
    69  }
     57
     58    public static IFunctionTree Create(IRandom random, FunctionLibrary funLib, int minSize, int maxSize, int maxHeight) {
     59      int treeSize = random.Next(minSize, maxSize + 1);
     60      IFunctionTree root;
     61      int tries = 0;
     62      TreeGardener gardener = new TreeGardener(random, funLib);
     63      do {
     64        root = gardener.PTC2(treeSize, maxHeight);
     65        if (tries++ >= MAX_TRIES) {
     66          // try a different size
     67          treeSize = random.Next(minSize, maxSize + 1);
     68          tries = 0;
     69        }
     70      } while (root.GetSize() > maxHeight || root.GetHeight() > maxHeight);
     71      return root;
     72    }
     73  }
    7074}
Note: See TracChangeset for help on using the changeset viewer.