Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/28/11 13:47:28 (12 years ago)
Author:
sforsten
Message:

#1669: branch has been merged with the trunk in revision 7081 and methods in RegressionBenchmark have been renamed.

Location:
branches/RegressionBenchmarks
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/RegressionBenchmarks

  • branches/RegressionBenchmarks/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionGrammarBase.cs

    r6911 r7085  
    8282      cachedMaxExpressionLength = new Dictionary<Tuple<string, int>, int>();
    8383      cachedMinExpressionDepth = new Dictionary<string, int>();
     84      cachedMaxExpressionDepth = new Dictionary<string, int>();
    8485
    8586      cachedIsAllowedChildSymbol = new Dictionary<Tuple<string, string>, bool>();
     
    9495      cachedMaxExpressionLength = new Dictionary<Tuple<string, int>, int>();
    9596      cachedMinExpressionDepth = new Dictionary<string, int>();
     97      cachedMaxExpressionDepth = new Dictionary<string, int>();
    9698
    9799      cachedIsAllowedChildSymbol = new Dictionary<Tuple<string, string>, bool>();
     
    117119      cachedMaxExpressionLength = new Dictionary<Tuple<string, int>, int>();
    118120      cachedMinExpressionDepth = new Dictionary<string, int>();
     121      cachedMaxExpressionDepth = new Dictionary<string, int>();
    119122
    120123      cachedIsAllowedChildSymbol = new Dictionary<Tuple<string, string>, bool>();
     
    134137      foreach (var s in symbol.Flatten()) {
    135138        symbols.Add(s.Name, s);
    136         symbolSubtreeCount.Add(s.Name, Tuple.Create(s.MinimumArity, s.MaximumArity));
     139        int maxSubTreeCount = Math.Min(s.MinimumArity + 1, s.MaximumArity);
     140        symbolSubtreeCount.Add(s.Name, Tuple.Create(s.MinimumArity, maxSubTreeCount));
    137141      }
    138142      ClearCaches();
     
    371375      cachedMaxExpressionLength.Clear();
    372376      cachedMinExpressionDepth.Clear();
     377      cachedMaxExpressionDepth.Clear();
    373378
    374379      cachedIsAllowedChildSymbol.Clear();
     
    427432    }
    428433
     434    private readonly Dictionary<string, int> cachedMaxExpressionDepth;
     435    public int GetMaximumExpressionDepth(ISymbol symbol) {
     436      int temp;
     437      if (!cachedMaxExpressionDepth.TryGetValue(symbol.Name, out temp)) {
     438        cachedMaxExpressionDepth[symbol.Name] = int.MaxValue;
     439        long maxDepth = 1 + (from argIndex in Enumerable.Range(0, GetMaximumSubtreeCount(symbol))
     440                             let maxForSlot = (long)(from s in GetAllowedChildSymbols(symbol, argIndex)
     441                                                     where s.InitialFrequency > 0.0
     442                                                     select GetMaximumExpressionDepth(s)).DefaultIfEmpty(0).Max()
     443                             select maxForSlot).DefaultIfEmpty(0).Max();
     444        cachedMaxExpressionDepth[symbol.Name] = (int)Math.Min(maxDepth, int.MaxValue);
     445        return cachedMaxExpressionDepth[symbol.Name];
     446      }
     447      return temp;
     448    }
     449
    429450    public event EventHandler Changed;
    430451    protected virtual void OnChanged() {
Note: See TracChangeset for help on using the changeset viewer.