Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/16/21 14:23:48 (3 years ago)
Author:
mkommend
Message:

#3136: Merged trunk changes into branch.

Location:
branches/3136_Structural_GP
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • branches/3136_Structural_GP

  • branches/3136_Structural_GP/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding

  • branches/3136_Structural_GP/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Analyzers/SymbolicExpressionTreeLengthAnalyzer.cs

    r17180 r18146  
    5252    }
    5353
    54     public ILookupParameter<IntValue> MaximumSymbolicExpressionTreeLengthParameter {
    55       get { return (ILookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeLengthParameterName]; }
     54    public IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeLengthParameter {
     55      get { return (IValueLookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeLengthParameterName]; }
    5656    }
    5757    public ValueLookupParameter<DataTable> SymbolicExpressionTreeLengthsParameter {
     
    102102      : base() {
    103103      Parameters.Add(new ScopeTreeLookupParameter<ISymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression tree whose length should be calculated."));
    104       Parameters.Add(new LookupParameter<IntValue>(MaximumSymbolicExpressionTreeLengthParameterName, "The maximum allowed symbolic expression tree length"));
     104      Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeLengthParameterName, "The maximum allowed symbolic expression tree length"));
    105105      Parameters.Add(new ValueLookupParameter<DataTable>(SymbolicExpressionTreeLengthsParameterName, "The data table to store the symbolic expression tree lengths."));
    106106      Parameters.Add(new ValueLookupParameter<DataTableHistory>(SymbolicExpressionTreeLengthsHistoryParameterName, "The data table to store the symbolic expression tree lengths history."));
     
    118118    [StorableHook(HookType.AfterDeserialization)]
    119119    private void AfterDeserialization() {
     120      // reset MaximumSymbolicExpressionTreeLengthParameterName to ValueLookupParameter
     121      if (Parameters.TryGetValue(MaximumSymbolicExpressionTreeLengthParameterName, out IParameter treeLengthParam) && !(treeLengthParam is ValueLookupParameter<IntValue>))
     122        Parameters.Remove(MaximumSymbolicExpressionTreeLengthParameterName);
     123      if(!Parameters.ContainsKey(MaximumSymbolicExpressionTreeLengthParameterName))
     124        Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeLengthParameterName, "The maximum allowed symbolic expression tree length"));
     125
    120126      // check if all the parameters are present and accounted for
    121       if (!Parameters.ContainsKey(StoreHistoryParameterName)) {
     127      if (!Parameters.ContainsKey(StoreHistoryParameterName))
    122128        Parameters.Add(new ValueParameter<BoolValue>(StoreHistoryParameterName, "True if the tree lengths history of the population should be stored.", new BoolValue(false)));
    123       }
    124       if (!Parameters.ContainsKey(UpdateIntervalParameterName)) {
     129     
     130      if (!Parameters.ContainsKey(UpdateIntervalParameterName))
    125131        Parameters.Add(new ValueParameter<IntValue>(UpdateIntervalParameterName, "The interval in which the tree length analysis should be applied.", new IntValue(1)));
    126       }
     132
    127133      //necessary code to correct UpdateCounterParameter - type was changed from LookupParameter to ValueParameter
    128       if (Parameters.ContainsKey(UpdateCounterParameterName) && (Parameters[UpdateCounterParameterName] is LookupParameter<IntValue>))
     134      if (Parameters.TryGetValue(UpdateCounterParameterName, out IParameter updateCounterParam) && updateCounterParam is LookupParameter<IntValue>)
    129135        Parameters.Remove(UpdateCounterParameterName);
    130136      if (!Parameters.ContainsKey(UpdateCounterParameterName)) {
  • branches/3136_Structural_GP/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/BalancedTreeCreator.cs

    r18018 r18146  
    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 {
  • branches/3136_Structural_GP/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/FullTreeCreator.cs

    r17180 r18146  
    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) {
  • branches/3136_Structural_GP/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/GrowTreeCreator.cs

    r17180 r18146  
    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
  • branches/3136_Structural_GP/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/ProbabilisticTreeCreator.cs

    r17180 r18146  
    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);
  • branches/3136_Structural_GP/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/RampedHalfAndHalfTreeCreator.cs

    r17180 r18146  
    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);
  • branches/3136_Structural_GP/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/SymbolicExpressionTreeCreator.cs

    r17180 r18146  
    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  }
  • branches/3136_Structural_GP/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Grammars/SymbolicExpressionGrammar.cs

    r17180 r18146  
    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) {
  • branches/3136_Structural_GP/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/ISymbolicExpressionGrammar.cs

    r17180 r18146  
    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; }
  • branches/3136_Structural_GP/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/ISymbolicExpressionTreeNodeSimilarityComparer.cs

    r16565 r18146  
    66  [StorableType("c4de8ab2-616d-4c73-9f9c-59545ac38199")]
    77  public interface ISymbolicExpressionTreeNodeSimilarityComparer : IEqualityComparer<ISymbolicExpressionTreeNode>, IItem {
    8     bool MatchConstantValues { get; set; }
     8    bool MatchParameterValues { get; set; }
    99    bool MatchVariableWeights { get; set; }
    1010    bool MatchVariableNames { get; set; }
  • branches/3136_Structural_GP/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Manipulators/FullTreeShaker.cs

    r17180 r18146  
    4747    public FullTreeShaker()
    4848      : base() {
    49       Parameters.Add(new FixedValueParameter<DoubleValue>(ShakingFactorParameterName, "The shaking factor that should be used for the manipulation of constants (default=1.0).", new DoubleValue(1.0)));
     49      Parameters.Add(new FixedValueParameter<DoubleValue>(ShakingFactorParameterName, "The shaking factor that should be used for the manipulation of parameters (default=1.0).", new DoubleValue(1.0)));
    5050    }
    5151
  • branches/3136_Structural_GP/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Manipulators/OnePointShaker.cs

    r17180 r18146  
    4949    public OnePointShaker()
    5050      : base() {
    51       Parameters.Add(new FixedValueParameter<DoubleValue>(ShakingFactorParameterName, "The shaking factor that should be used for the manipulation of constants (default=1.0).", new DoubleValue(1.0)));
     51      Parameters.Add(new FixedValueParameter<DoubleValue>(ShakingFactorParameterName, "The shaking factor that should be used for the manipulation of parameters (default=1.0).", new DoubleValue(1.0)));
    5252    }
    5353
Note: See TracChangeset for help on using the changeset viewer.