- Timestamp:
- 04/13/11 16:02:40 (14 years ago)
- Location:
- trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/ProbabilisticTreeCreator.cs
r5925 r6009 103 103 public static void PTC2(IRandom random, ISymbolicExpressionTreeNode seedNode, 104 104 int maxLength, int maxDepth) { 105 // make sure it is possible to create a trees smaller than maxLength and maxDepth 106 if (seedNode.Grammar.GetMinimumExpressionLength(seedNode.Symbol) > maxLength) 107 throw new ArgumentException("Cannot create trees of length " + maxLength + " or shorter because of grammar constraints.", "maxLength"); 108 if (seedNode.Grammar.GetMinimumExpressionDepth(seedNode.Symbol) > maxDepth) 109 throw new ArgumentException("Cannot create trees of depth " + maxDepth + " or smaller because of grammar constraints.", "maxDepth"); 110 105 111 // tree length is limited by the grammar and by the explicit size constraints 106 112 int allowedMinLength = seedNode.Grammar.GetMinimumExpressionLength(seedNode.Symbol); … … 149 155 int argumentIndex = nextExtension.ChildIndex; 150 156 int extensionDepth = nextExtension.ExtensionPointDepth; 151 if ( extensionDepth + parent.Grammar.GetMinimumExpressionDepth(parent.Symbol) >= maxDepth) {157 if (parent.Grammar.GetMinimumExpressionDepth(parent.Symbol) >= maxDepth - extensionDepth) { 152 158 ReplaceWithMinimalTree(random, root, parent, argumentIndex); 153 159 } else { … … 155 161 where s.InitialFrequency > 0.0 156 162 where parent.Grammar.IsAllowedChildSymbol(parent.Symbol, s, argumentIndex) 157 where parent.Grammar.GetMinimumExpressionDepth(s) + extensionDepth - 1 < maxDepth163 where parent.Grammar.GetMinimumExpressionDepth(s) < maxDepth - extensionDepth + 1 158 164 where parent.Grammar.GetMaximumExpressionLength(s) > targetLength - totalListMinLength - currentLength 159 165 select s) -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionGrammarBase.cs
r5809 r6009 229 229 230 230 public virtual IEnumerable<ISymbol> GetAllowedChildSymbols(ISymbol parent) { 231 return from s in Symbols where IsAllowedChildSymbol(parent, s) select s;231 return from s in AllowedSymbols where IsAllowedChildSymbol(parent, s) select s; 232 232 } 233 233 … … 265 265 cachedMinExpressionLength[symbol.Name] = int.MaxValue; // prevent infinite recursion 266 266 long sumOfMinExpressionLengths = 1 + (from argIndex in Enumerable.Range(0, GetMinimumSubtreeCount(symbol)) 267 let minForSlot = (long)(from s in Symbols267 let minForSlot = (long)(from s in AllowedSymbols 268 268 where IsAllowedChildSymbol(symbol, s, argIndex) 269 269 select GetMinimumExpressionLength(s)).DefaultIfEmpty(0).Min() … … 282 282 cachedMaxExpressionLength[symbol.Name] = int.MaxValue; // prevent infinite recursion 283 283 long sumOfMaxTrees = 1 + (from argIndex in Enumerable.Range(0, GetMaximumSubtreeCount(symbol)) 284 let maxForSlot = (long)(from s in Symbols284 let maxForSlot = (long)(from s in AllowedSymbols 285 285 where IsAllowedChildSymbol(symbol, s, argIndex) 286 286 select GetMaximumExpressionLength(s)).DefaultIfEmpty(0).Max() 287 287 select maxForSlot).DefaultIfEmpty(0).Sum(); 288 long limit = int.MaxValue; 289 cachedMaxExpressionLength[symbol.Name] = (int)Math.Min(sumOfMaxTrees, limit); 288 cachedMaxExpressionLength[symbol.Name] = (int)Math.Min(sumOfMaxTrees, int.MaxValue); 290 289 return cachedMaxExpressionLength[symbol.Name]; 291 290 } … … 298 297 if (!cachedMinExpressionDepth.TryGetValue(symbol.Name, out temp)) { 299 298 cachedMinExpressionDepth[symbol.Name] = int.MaxValue; // prevent infinite recursion 300 cachedMinExpressionDepth[symbol.Name] = 1 + (from argIndex in Enumerable.Range(0, GetMinimumSubtreeCount(symbol)) 301 let minForSlot = (from s in Symbols 302 where IsAllowedChildSymbol(symbol, s, argIndex) 303 select GetMinimumExpressionDepth(s)).DefaultIfEmpty(0).Min() 304 select minForSlot).DefaultIfEmpty(0).Max(); 299 long minDepth = 1 + (from argIndex in Enumerable.Range(0, GetMinimumSubtreeCount(symbol)) 300 let minForSlot = (long)(from s in AllowedSymbols 301 where IsAllowedChildSymbol(symbol, s, argIndex) 302 select GetMinimumExpressionDepth(s)).DefaultIfEmpty(0).Min() 303 select minForSlot).DefaultIfEmpty(0).Max(); 304 cachedMinExpressionDepth[symbol.Name] = (int)Math.Min(minDepth, int.MaxValue); 305 305 return cachedMinExpressionDepth[symbol.Name]; 306 306 }
Note: See TracChangeset
for help on using the changeset viewer.