Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/22/15 14:27:37 (9 years ago)
Author:
bburlacu
Message:

#1772: Merge trunk changes. Remove dead code from the genealogy analyzer.

Location:
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding

  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/FullTreeCreator.cs

    r12155 r12891  
    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
     
    10677      rootNode.AddSubtree(startNode);
    10778
    108       Create(random, startNode, maxTreeDepth - 2);
     79      Create(random, startNode, maxTreeDepth-1);
    10980      tree.Root = rootNode;
    11081      return tree;
     
    12899      for (var i = 0; i < arity; i++) {
    129100        var possibleSymbols = allowedSymbols
    130           .Where(s => seedNode.Grammar.IsAllowedChildSymbol(seedNode.Symbol, s, i))
     101          .Where(s => seedNode.Grammar.IsAllowedChildSymbol(seedNode.Symbol, s, i)
     102                   && seedNode.Grammar.GetMinimumExpressionDepth(s) <= maxDepth
     103                   && seedNode.Grammar.GetMaximumExpressionDepth(s) >= maxDepth)
    131104          .ToList();
    132105        var weights = possibleSymbols.Select(s => s.InitialFrequency).ToList();
     106
     107#pragma warning disable 612, 618
    133108        var selectedSymbol = possibleSymbols.SelectRandom(weights, random);
     109#pragma warning restore 612, 618
     110
    134111        var tree = selectedSymbol.CreateTreeNode();
    135112        if (tree.HasLocalParameters) tree.ResetLocalParameters(random);
     
    163140          throw new InvalidOperationException("No symbols are available for the tree.");
    164141        var weights = possibleSymbols.Select(s => s.InitialFrequency).ToList();
     142
     143#pragma warning disable 612, 618
    165144        var selectedSymbol = possibleSymbols.SelectRandom(weights, random);
     145#pragma warning restore 612, 618
     146
    166147        var tree = selectedSymbol.CreateTreeNode();
    167148        if (tree.HasLocalParameters) tree.ResetLocalParameters(random);
     
    169150      }
    170151
    171       foreach (var subTree in root.Subtrees)
    172         if (subTree.Grammar.GetMaximumSubtreeCount(subTree.Symbol) > 0)
    173           RecursiveCreate(random, subTree, currentDepth + 1, maxDepth);
     152      //additional levels should only be added if the maximum depth is not reached yet
     153      if (maxDepth > currentDepth) {
     154        foreach (var subTree in root.Subtrees)
     155          if (subTree.Grammar.GetMaximumSubtreeCount(subTree.Symbol) > 0)
     156            RecursiveCreate(random, subTree, currentDepth + 1, maxDepth);
     157      }
    174158    }
    175159  }
Note: See TracChangeset for help on using the changeset viewer.