Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/13/11 16:02:40 (13 years ago)
Author:
gkronber
Message:

#1472 implemented a check in PTC2 operator, fixed bugs in SymbolicExpressionGrammarBase and made some small changes in both classes to prevent numeric overflow exceptions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionGrammarBase.cs

    r5809 r6009  
    229229
    230230    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;
    232232    }
    233233
     
    265265        cachedMinExpressionLength[symbol.Name] = int.MaxValue; // prevent infinite recursion
    266266        long sumOfMinExpressionLengths = 1 + (from argIndex in Enumerable.Range(0, GetMinimumSubtreeCount(symbol))
    267                                               let minForSlot = (long)(from s in Symbols
     267                                              let minForSlot = (long)(from s in AllowedSymbols
    268268                                                                      where IsAllowedChildSymbol(symbol, s, argIndex)
    269269                                                                      select GetMinimumExpressionLength(s)).DefaultIfEmpty(0).Min()
     
    282282        cachedMaxExpressionLength[symbol.Name] = int.MaxValue; // prevent infinite recursion
    283283        long sumOfMaxTrees = 1 + (from argIndex in Enumerable.Range(0, GetMaximumSubtreeCount(symbol))
    284                                   let maxForSlot = (long)(from s in Symbols
     284                                  let maxForSlot = (long)(from s in AllowedSymbols
    285285                                                          where IsAllowedChildSymbol(symbol, s, argIndex)
    286286                                                          select GetMaximumExpressionLength(s)).DefaultIfEmpty(0).Max()
    287287                                  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);
    290289        return cachedMaxExpressionLength[symbol.Name];
    291290      }
     
    298297      if (!cachedMinExpressionDepth.TryGetValue(symbol.Name, out temp)) {
    299298        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);
    305305        return cachedMinExpressionDepth[symbol.Name];
    306306      }
Note: See TracChangeset for help on using the changeset viewer.