Free cookie consent management tool by TermsFeed Policy Generator

Changeset 18064


Ignore:
Timestamp:
10/06/21 16:13:37 (2 years ago)
Author:
mkommend
Message:

#2997: Simplified tree creator interface and removed cloning of grammars,

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/BalancedTreeCreator.cs

    r18018 r18064  
    171171    }
    172172
    173     protected override ISymbolicExpressionTree Create(IRandom random) {
    174       var maxLength = MaximumSymbolicExpressionTreeLengthParameter.ActualValue.Value;
    175       var maxDepth = MaximumSymbolicExpressionTreeDepthParameter.ActualValue.Value;
    176       var grammar = ClonedSymbolicExpressionTreeGrammarParameter.ActualValue;
    177       return Create(random, grammar, maxLength, maxDepth);
    178     }
    179 
    180173    #region helpers
    181174    private class NodeInfo {
  • trunk/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/FullTreeCreator.cs

    r17180 r18064  
    4545    }
    4646
    47 
    48     protected override ISymbolicExpressionTree Create(IRandom random) {
    49       return Create(random, ClonedSymbolicExpressionTreeGrammarParameter.ActualValue,
    50           MaximumSymbolicExpressionTreeLengthParameter.ActualValue.Value, MaximumSymbolicExpressionTreeDepthParameter.ActualValue.Value);
    51     }
    5247
    5348    public override ISymbolicExpressionTree CreateTree(IRandom random, ISymbolicExpressionGrammar grammar, int maxTreeLength, int maxTreeDepth) {
  • trunk/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/GrowTreeCreator.cs

    r17180 r18064  
    4040    public override IDeepCloneable Clone(Cloner cloner) {
    4141      return new GrowTreeCreator(this, cloner);
    42     }
    43 
    44 
    45     protected override ISymbolicExpressionTree Create(IRandom random) {
    46       return Create(random, ClonedSymbolicExpressionTreeGrammarParameter.ActualValue,
    47         MaximumSymbolicExpressionTreeLengthParameter.ActualValue.Value, MaximumSymbolicExpressionTreeDepthParameter.ActualValue.Value);
    4842    }
    4943
  • trunk/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/ProbabilisticTreeCreator.cs

    r17180 r18064  
    4848    }
    4949
    50 
    51     protected override ISymbolicExpressionTree Create(IRandom random) {
    52       return Create(random, ClonedSymbolicExpressionTreeGrammarParameter.ActualValue,
    53         MaximumSymbolicExpressionTreeLengthParameter.ActualValue.Value, MaximumSymbolicExpressionTreeDepthParameter.ActualValue.Value);
    54     }
    55 
    5650    public override ISymbolicExpressionTree CreateTree(IRandom random, ISymbolicExpressionGrammar grammar, int maxTreeLength, int maxTreeDepth) {
    5751      return Create(random, grammar, maxTreeLength, maxTreeDepth);
  • trunk/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/RampedHalfAndHalfTreeCreator.cs

    r17180 r18064  
    4040    }
    4141
    42     protected override ISymbolicExpressionTree Create(IRandom random) {
    43       return Create(random, ClonedSymbolicExpressionTreeGrammarParameter.ActualValue,
    44         MaximumSymbolicExpressionTreeLengthParameter.ActualValue.Value, MaximumSymbolicExpressionTreeDepthParameter.ActualValue.Value);
    45     }
    46 
    4742    public override ISymbolicExpressionTree CreateTree(IRandom random, ISymbolicExpressionGrammar grammar, int maxTreeLength, int maxTreeDepth) {
    4843      return Create(random, grammar, maxTreeLength, maxTreeDepth);
  • trunk/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/SymbolicExpressionTreeCreator.cs

    r17180 r18064  
    3737
    3838    private const string SymbolicExpressionTreeGrammarParameterName = "SymbolicExpressionTreeGrammar";
    39     private const string ClonedSymbolicExpressionTreeGrammarParameterName = "ClonedSymbolicExpressionTreeGrammar";
    4039
    4140    #region Parameter Properties
     
    4948      get { return (IValueLookupParameter<ISymbolicExpressionGrammar>)Parameters[SymbolicExpressionTreeGrammarParameterName]; }
    5049    }
    51 
    52     public ILookupParameter<ISymbolicExpressionGrammar> ClonedSymbolicExpressionTreeGrammarParameter {
    53       get { return (ILookupParameter<ISymbolicExpressionGrammar>)Parameters[ClonedSymbolicExpressionTreeGrammarParameterName]; }
    54     }
    5550    #endregion
    5651
     
    6358      Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeDepthParameterName, "The maximal depth of the symbolic expression tree (a tree with one node has depth = 0)."));
    6459      Parameters.Add(new ValueLookupParameter<ISymbolicExpressionGrammar>(SymbolicExpressionTreeGrammarParameterName, "The tree grammar that defines the correct syntax of symbolic expression trees that should be created."));
    65       Parameters.Add(new LookupParameter<ISymbolicExpressionGrammar>(ClonedSymbolicExpressionTreeGrammarParameterName, "An immutable clone of the concrete grammar that is actually used to create and manipulate trees."));
    66     }
    67 
    68     [StorableHook(HookType.AfterDeserialization)]
    69     private void AfterDeserialization() {
    70       if (!Parameters.ContainsKey(ClonedSymbolicExpressionTreeGrammarParameterName))
    71         Parameters.Add(new LookupParameter<ISymbolicExpressionGrammar>(ClonedSymbolicExpressionTreeGrammarParameterName, "An immutable clone of the concrete grammar that is actually used to create and manipulate trees."));
    7260    }
    7361
    7462    public override IOperation InstrumentedApply() {
    75       if (ClonedSymbolicExpressionTreeGrammarParameter.ActualValue == null) {
    76         SymbolicExpressionTreeGrammarParameter.ActualValue.ReadOnly = true;
    77         IScope globalScope = ExecutionContext.Scope;
    78         while (globalScope.Parent != null)
    79           globalScope = globalScope.Parent;
     63      var rand = RandomParameter.ActualValue;
     64      var grammar = SymbolicExpressionTreeGrammarParameter.ActualValue;
     65      var maxTreeLength = MaximumSymbolicExpressionTreeLengthParameter.ActualValue.Value;
     66      var maxTreeDepth = MaximumSymbolicExpressionTreeDepthParameter.ActualValue.Value;
    8067
    81         globalScope.Variables.Add(new Variable(ClonedSymbolicExpressionTreeGrammarParameterName,
    82           (ISymbolicExpressionGrammar)SymbolicExpressionTreeGrammarParameter.ActualValue.Clone()));
    83       }
    84       SymbolicExpressionTreeParameter.ActualValue = Create(RandomParameter.ActualValue);
     68      SymbolicExpressionTreeParameter.ActualValue = CreateTree(rand, grammar, maxTreeLength, maxTreeDepth);
    8569      return base.InstrumentedApply();
    8670    }
    87 
    88     protected abstract ISymbolicExpressionTree Create(IRandom random);
    8971    public abstract ISymbolicExpressionTree CreateTree(IRandom random, ISymbolicExpressionGrammar grammar, int maxTreeLength, int maxTreeDepth);
    9072  }
  • trunk/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Grammars/SymbolicExpressionGrammar.cs

    r17180 r18064  
    191191    public event EventHandler ReadOnlyChanged;
    192192    protected virtual void OnReadOnlyChanged() {
    193       var handler = ReadOnlyChanged;
    194       if (handler != null)
    195         handler(this, EventArgs.Empty);
    196     }
    197 
    198     #region IStatefulItem methods
    199     void IStatefulItem.InitializeState() {
    200       ReadOnly = false;
    201     }
    202     void IStatefulItem.ClearState() {
    203       ReadOnly = false;
    204     }
    205     #endregion
     193      ReadOnlyChanged?.Invoke(this, EventArgs.Empty);
     194    }
    206195
    207196    public sealed override void AddAllowedChildSymbol(ISymbol parent, ISymbol child) {
  • trunk/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/ISymbolicExpressionGrammar.cs

    r17180 r18064  
    2727namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
    2828  [StorableType("1f6afcbe-b309-44e2-8d35-2d33eaeb9649")]
    29   public interface ISymbolicExpressionGrammar : ISymbolicExpressionGrammarBase, IStatefulItem {
     29  public interface ISymbolicExpressionGrammar : ISymbolicExpressionGrammarBase {
    3030    ISymbol ProgramRootSymbol { get; }
    3131    ISymbol StartSymbol { get; }
  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Creators/MultiSymbolicDataAnalysisExpressionCreator.cs

    r17180 r18064  
    4444    private const string MaximumSymbolicExpressionTreeDepthParameterName = "MaximumSymbolicExpressionTreeDepth";
    4545    private const string SymbolicExpressionTreeGrammarParameterName = "SymbolicExpressionTreeGrammar";
    46     private const string ClonedSymbolicExpressionTreeGrammarParameterName = "ClonedSymbolicExpressionTreeGrammar";
    4746
    4847    public override bool CanChangeName {
     
    6665      get { return (IValueLookupParameter<ISymbolicExpressionGrammar>)Parameters[SymbolicExpressionTreeGrammarParameterName]; }
    6766    }
    68     public ILookupParameter<ISymbolicExpressionGrammar> ClonedSymbolicExpressionTreeGrammarParameter {
    69       get { return (ILookupParameter<ISymbolicExpressionGrammar>)Parameters[ClonedSymbolicExpressionTreeGrammarParameterName]; }
    70     }
    7167    #endregion
    7268
     
    8076      Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeLengthParameterName, "The maximal length (number of nodes) of the symbolic expression tree."));
    8177      Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeDepthParameterName, "The maximal depth of the symbolic expression tree (a tree with one node has depth = 0)."));
    82       Parameters.Add(new ValueLookupParameter<ISymbolicExpressionGrammar>(SymbolicExpressionTreeGrammarParameterName, "The tree grammar that defines the correct syntax of symbolic expression trees that should be created."));
    83       Parameters.Add(new LookupParameter<ISymbolicExpressionGrammar>(ClonedSymbolicExpressionTreeGrammarParameterName, "An immutable clone of the concrete grammar that is actually used to create and manipulate trees."));
     78      Parameters.Add(new ValueLookupParameter<ISymbolicExpressionGrammar>(SymbolicExpressionTreeGrammarParameterName, "The tree grammar that defines the correct syntax of symbolic expression trees that should be created."));     
    8479
    8580      List<ISymbolicDataAnalysisSolutionCreator> list = new List<ISymbolicDataAnalysisSolutionCreator>();
     
    9691    }
    9792
    98     public override IOperation InstrumentedApply() {
    99       if (ClonedSymbolicExpressionTreeGrammarParameter.ActualValue == null) {
    100         SymbolicExpressionTreeGrammarParameter.ActualValue.ReadOnly = true;
    101         IScope globalScope = ExecutionContext.Scope;
    102         while (globalScope.Parent != null)
    103           globalScope = globalScope.Parent;
    104 
    105         globalScope.Variables.Add(new Core.Variable(ClonedSymbolicExpressionTreeGrammarParameterName, (ISymbolicExpressionGrammar)SymbolicExpressionTreeGrammarParameter.ActualValue.Clone()));
    106       }
    107       return base.InstrumentedApply();
    108     }
    10993
    11094    public ISymbolicExpressionTree CreateTree(IRandom random, ISymbolicExpressionGrammar grammar, int maxTreeLength, int maxTreeDepth) {
Note: See TracChangeset for help on using the changeset viewer.