- Timestamp:
- 04/29/13 14:33:43 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionGrammarBase.cs
r7660 r9402 387 387 private readonly Dictionary<string, int> cachedMinExpressionLength; 388 388 public int GetMinimumExpressionLength(ISymbol symbol) { 389 int res; 390 if (cachedMinExpressionLength.TryGetValue(symbol.Name, out res)) 391 return res; 392 393 res = GetMinimumExpressionLengthRec(symbol); 394 foreach (var entry in cachedMinExpressionLength.Where(e => e.Value >= int.MaxValue).ToList()) { 395 if (entry.Key != symbol.Name) cachedMinExpressionLength.Remove(entry.Key); 396 } 397 return res; 398 } 399 400 public int GetMinimumExpressionLengthRec(ISymbol symbol) { 389 401 int temp; 390 402 if (!cachedMinExpressionLength.TryGetValue(symbol.Name, out temp)) { … … 393 405 let minForSlot = (long)(from s in GetAllowedChildSymbols(symbol, argIndex) 394 406 where s.InitialFrequency > 0.0 395 select GetMinimumExpressionLength (s)).DefaultIfEmpty(0).Min()407 select GetMinimumExpressionLengthRec(s)).DefaultIfEmpty(0).Min() 396 408 select minForSlot).DefaultIfEmpty(0).Sum(); 397 409 … … 422 434 private readonly Dictionary<string, int> cachedMinExpressionDepth; 423 435 public int GetMinimumExpressionDepth(ISymbol symbol) { 436 int res; 437 if (cachedMinExpressionDepth.TryGetValue(symbol.Name, out res)) 438 return res; 439 440 res = GetMinimumExpressionDepthRec(symbol); 441 foreach (var entry in cachedMinExpressionDepth.Where(e => e.Value >= int.MaxValue).ToList()) { 442 if (entry.Key != symbol.Name) cachedMinExpressionDepth.Remove(entry.Key); 443 } 444 return res; 445 } 446 private int GetMinimumExpressionDepthRec(ISymbol symbol) { 424 447 int temp; 425 448 if (!cachedMinExpressionDepth.TryGetValue(symbol.Name, out temp)) { … … 428 451 let minForSlot = (long)(from s in GetAllowedChildSymbols(symbol, argIndex) 429 452 where s.InitialFrequency > 0.0 430 select GetMinimumExpressionDepth (s)).DefaultIfEmpty(0).Min()453 select GetMinimumExpressionDepthRec(s)).DefaultIfEmpty(0).Min() 431 454 select minForSlot).DefaultIfEmpty(0).Max(); 432 455 cachedMinExpressionDepth[symbol.Name] = (int)Math.Min(minDepth, int.MaxValue);
Note: See TracChangeset
for help on using the changeset viewer.