Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/10/15 11:29:34 (9 years ago)
Author:
mkommend
Message:

#2320: Merged the encoding class and all accompanying changes in the trunk.

Location:
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding

  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/FullTreeCreator.cs

    r12012 r12422  
    2424using HeuristicLab.Common;
    2525using HeuristicLab.Core;
    26 using HeuristicLab.Data;
    27 using HeuristicLab.Parameters;
    2826using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2927using HeuristicLab.PluginInfrastructure;
     
    3634                                 ISymbolicExpressionTreeSizeConstraintOperator,
    3735                                 ISymbolicExpressionTreeGrammarBasedOperator {
    38     private const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength";
    39     private const string MaximumSymbolicExpressionTreeDepthParameterName = "MaximumSymbolicExpressionTreeDepth";
    40 
    41     #region Parameter Properties
    42     public IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeLengthParameter {
    43       get { return (IValueLookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeLengthParameterName]; }
    44     }
    45 
    46     public IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeDepthParameter {
    47       get { return (IValueLookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeDepthParameterName]; }
    48     }
    49     #endregion
    50     #region Properties
    51     public IntValue MaximumSymbolicExpressionTreeDepth {
    52       get { return MaximumSymbolicExpressionTreeDepthParameter.ActualValue; }
    53     }
    54 
    55     public IntValue MaximumSymbolicExpressionTreeLength {
    56       get { return MaximumSymbolicExpressionTreeLengthParameter.ActualValue; }
    57     }
    58 
    59     #endregion
    6036
    6137    [StorableConstructor]
     
    6339    protected FullTreeCreator(FullTreeCreator original, Cloner cloner) : base(original, cloner) { }
    6440
    65     public FullTreeCreator()
    66       : base() {
    67       Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeLengthParameterName,
    68         "The maximal length (number of nodes) of the symbolic expression tree (this parameter is ignored)."));
    69       Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeDepthParameterName,
    70         "The maximal depth of the symbolic expression tree (a tree with one node has depth = 0)."));
    71     }
     41    public FullTreeCreator() : base() { }
    7242
    7343    public override IDeepCloneable Clone(Cloner cloner) {
     
    7747
    7848    protected override ISymbolicExpressionTree Create(IRandom random) {
    79       return Create(random, ClonedSymbolicExpressionTreeGrammarParameter.ActualValue, MaximumSymbolicExpressionTreeLength.Value, MaximumSymbolicExpressionTreeDepth.Value);
     49      return Create(random, ClonedSymbolicExpressionTreeGrammarParameter.ActualValue,
     50          MaximumSymbolicExpressionTreeLengthParameter.ActualValue.Value, MaximumSymbolicExpressionTreeDepthParameter.ActualValue.Value);
    8051    }
    8152
     
    131102          .ToList();
    132103        var weights = possibleSymbols.Select(s => s.InitialFrequency).ToList();
     104
     105#pragma warning disable 612, 618
    133106        var selectedSymbol = possibleSymbols.SelectRandom(weights, random);
     107#pragma warning restore 612, 618
     108
    134109        var tree = selectedSymbol.CreateTreeNode();
    135110        if (tree.HasLocalParameters) tree.ResetLocalParameters(random);
     
    163138          throw new InvalidOperationException("No symbols are available for the tree.");
    164139        var weights = possibleSymbols.Select(s => s.InitialFrequency).ToList();
     140
     141#pragma warning disable 612, 618
    165142        var selectedSymbol = possibleSymbols.SelectRandom(weights, random);
     143#pragma warning restore 612, 618
     144       
    166145        var tree = selectedSymbol.CreateTreeNode();
    167146        if (tree.HasLocalParameters) tree.ResetLocalParameters(random);
     
    169148      }
    170149
    171       foreach (var subTree in root.Subtrees)
    172         if (subTree.Grammar.GetMaximumSubtreeCount(subTree.Symbol) > 0)
    173           RecursiveCreate(random, subTree, currentDepth + 1, maxDepth);
     150      //additional levels should only be added if the maximum depth is not reached yet
     151      if (maxDepth > currentDepth) {
     152        foreach (var subTree in root.Subtrees)
     153          if (subTree.Grammar.GetMaximumSubtreeCount(subTree.Symbol) > 0)
     154            RecursiveCreate(random, subTree, currentDepth + 1, maxDepth);
     155      }
    174156    }
    175157  }
Note: See TracChangeset for help on using the changeset viewer.