- Timestamp:
- 10/27/09 09:47:03 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.GP.Operators/3.3/Initialization/ProbabilisticTreeCreator.cs
r2222 r2447 27 27 namespace HeuristicLab.GP.Operators { 28 28 public class ProbabilisticTreeCreator : OperatorBase { 29 private int MAX_TRIES { get { return 100; } }29 private static int MAX_TRIES { get { return 100; } } 30 30 31 31 public override string Description { … … 50 50 int maxTreeHeight = GetVariableValue<IntData>("MaxTreeHeight", scope, true).Data; 51 51 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); 65 53 scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("FunctionTree"), new GeneticProgrammingModel(root))); 66 54 return Util.CreateInitializationOperation(TreeGardener.GetAllSubTrees(root), scope); 67 55 } 68 56 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 } 70 74 }
Note: See TracChangeset
for help on using the changeset viewer.