Changeset 1181 for branches/CEDMA-Refactoring-Ticket419
- Timestamp:
- 01/27/09 22:35:52 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/CEDMA-Refactoring-Ticket419/HeuristicLab.GP/ProbabilisticTreeCreator.cs
r656 r1181 30 30 namespace HeuristicLab.GP { 31 31 public class ProbabilisticTreeCreator : OperatorBase { 32 private int MAX_TRIES { get { return 100; } } 33 32 34 public override string Description { 33 35 get { return @"Generates a new random operator tree."; } … … 56 58 57 59 int treeSize = random.Next(minTreeSize, maxTreeSize + 1); 58 IFunctionTree root = gardener.PTC2(random, treeSize, maxTreeHeight);59 60 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); 62 75 63 76 scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("FunctionTree"), root)); … … 65 78 scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("TreeHeight"), new IntData(actualTreeHeight))); 66 79 67 Debug.Assert(gardener.IsValidTree(root) && actualTreeHeight<=maxTreeHeight);68 69 80 return gardener.CreateInitializationOperation(gardener.GetAllSubTrees(root), scope); 70 81 }
Note: See TracChangeset
for help on using the changeset viewer.