Changeset 2730 for trunk/sources/HeuristicLab.GP.Operators
- Timestamp:
- 02/01/10 16:43:56 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.GP.Operators/3.3/Initialization/ProbabilisticTreeCreator.cs
r2566 r2730 24 24 using HeuristicLab.Random; 25 25 using HeuristicLab.GP.Interfaces; 26 using System; 26 27 27 28 namespace HeuristicLab.GP.Operators { … … 58 59 public static IFunctionTree Create(IRandom random, FunctionLibrary funLib, int minSize, int maxSize, int maxHeight) { 59 60 int treeSize = random.Next(minSize, maxSize); 60 IFunctionTree root ;61 IFunctionTree root = null; 61 62 int tries = 0; 62 63 TreeGardener gardener = new TreeGardener(random, funLib); 63 64 do { 64 root = gardener.PTC2(treeSize, maxHeight); 65 try { 66 root = gardener.PTC2(treeSize, maxHeight); 67 } 68 catch (ArgumentException) { 69 // try a different size 70 treeSize = random.Next(minSize, maxSize); 71 tries = 0; 72 } 65 73 if (tries++ >= MAX_TRIES) { 66 74 // try a different size … … 68 76 tries = 0; 69 77 } 70 } while (root .GetSize() > maxSize || root.GetHeight() > maxHeight);78 } while (root == null || root.GetSize() > maxSize || root.GetHeight() > maxHeight); 71 79 return root; 72 80 }
Note: See TracChangeset
for help on using the changeset viewer.