Changeset 5727
- Timestamp:
- 03/17/11 10:56:23 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/ProbabilisticTreeCreator.cs
r5686 r5727 113 113 if (targetTreeLength <= 1 || maxDepth <= 1) return; 114 114 115 bool success = CreateFullTreeFromSeed(random, seedNode, seedNode.Grammar, targetTreeLength, maxDepth);115 bool success = TryCreateFullTreeFromSeed(random, seedNode, seedNode.Grammar, targetTreeLength, maxDepth); 116 116 117 117 // if successful => check constraints and return the tree if everything looks ok … … 127 127 } 128 128 129 private static bool CreateFullTreeFromSeed(IRandom random, ISymbolicExpressionTreeNode root, ISymbolicExpressionTreeGrammar globalGrammar, 130 int targetLength, int maxDepth) { 131 try { 132 TryCreateFullTreeFromSeed(random, root, globalGrammar, targetLength, maxDepth); 133 return true; 134 } 135 catch (ArgumentException) { return false; } 136 } 137 138 private static void TryCreateFullTreeFromSeed(IRandom random, ISymbolicExpressionTreeNode root, ISymbolicExpressionTreeGrammar globalGrammar, 129 private static bool TryCreateFullTreeFromSeed(IRandom random, ISymbolicExpressionTreeNode root, ISymbolicExpressionTreeGrammar globalGrammar, 139 130 int targetLength, int maxDepth) { 140 131 List<TreeExtensionPoint> extensionPoints = new List<TreeExtensionPoint>(); … … 142 133 int totalListMinLength = globalGrammar.GetMinimumExpressionLength(root.Symbol) - 1; 143 134 int actualArity = SampleArity(random, root, targetLength); 135 if (actualArity < 0) return false; 136 144 137 for (int i = 0; i < actualArity; i++) { 145 138 // insert a dummy sub-tree and add the pending extension to the list … … 180 173 181 174 actualArity = SampleArity(random, newTree, targetLength - currentLength); 175 if (actualArity < 0) return false; 182 176 for (int i = 0; i < actualArity; i++) { 183 177 // insert a dummy sub-tree and add the pending extension to the list … … 199 193 ReplaceWithMinimalTree(random, root, parent, a); 200 194 } 195 return true; 201 196 } 202 197 … … 260 255 } 261 256 } 262 if (minArity > maxArity) throw new ArgumentException();257 if (minArity > maxArity) return -1; 263 258 return random.Next(minArity, maxArity + 1); 264 259 }
Note: See TracChangeset
for help on using the changeset viewer.