Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/19/20 17:53:36 (4 years ago)
Author:
abeham
Message:

#2521: work in progress (removed solution creator parameter from encoding), OrienteeringProblem and test functions are broken

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeMultiObjectiveProblem.cs

    r17315 r17614  
    2727using HeuristicLab.Common;
    2828using HeuristicLab.Core;
     29using HeuristicLab.Data;
    2930using HeuristicLab.Optimization;
     31using HeuristicLab.Parameters;
    3032
    3133namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
    3234  [StorableType("f4819c68-b6fc-469f-bcb5-cb5b2a9d8aff")]
    3335  public abstract class SymbolicExpressionTreeMultiObjectiveProblem : MultiObjectiveProblem<SymbolicExpressionTreeEncoding, ISymbolicExpressionTree> {
     36    [Storable] private ReferenceParameter<IntValue> TreeLengthRefParameter { get; set; }
     37    [Storable] private ReferenceParameter<IntValue> TreeDepthRefParameter { get; set; }
     38    [Storable] private ReferenceParameter<ISymbolicExpressionGrammar> GrammarRefParameter { get; set; }
     39
     40    public int TreeLength {
     41      get => TreeLengthRefParameter.Value.Value;
     42      set => TreeLengthRefParameter.Value.Value = value;
     43    }
     44
     45    public int TreeDepth {
     46      get => TreeDepthRefParameter.Value.Value;
     47      set => TreeDepthRefParameter.Value.Value = value;
     48    }
     49
     50    public ISymbolicExpressionGrammar Grammar {
     51      get => GrammarRefParameter.Value;
     52      set => GrammarRefParameter.Value = value;
     53    }
    3454
    3555    // persistence
     
    3757    protected SymbolicExpressionTreeMultiObjectiveProblem(StorableConstructorFlag _) : base(_) { }
    3858    [StorableHook(HookType.AfterDeserialization)]
    39     private void AfterDeserialization() { }
     59    private void AfterDeserialization() {
     60      RegisterEventHandlers();
     61    }
    4062
    4163
     
    4365    protected SymbolicExpressionTreeMultiObjectiveProblem(SymbolicExpressionTreeMultiObjectiveProblem original, Cloner cloner)
    4466      : base(original, cloner) {
     67      TreeLengthRefParameter = cloner.Clone(original.TreeLengthRefParameter);
     68      TreeDepthRefParameter = cloner.Clone(original.TreeDepthRefParameter);
     69      GrammarRefParameter = cloner.Clone(original.GrammarRefParameter);
     70      RegisterEventHandlers();
    4571    }
    4672
     
    4874      : base(encoding) {
    4975      EncodingParameter.ReadOnly = true;
     76      Parameters.Add(TreeLengthRefParameter = new ReferenceParameter<IntValue>("TreeLength", "The maximum amount of nodes.", Encoding.TreeLengthParameter));
     77      Parameters.Add(TreeDepthRefParameter = new ReferenceParameter<IntValue>("TreeDepth", "The maximum depth of the tree.", Encoding.TreeDepthParameter));
     78      Parameters.Add(GrammarRefParameter = new ReferenceParameter<ISymbolicExpressionGrammar>("Grammar", "The grammar that describes a valid tree.", Encoding.GrammarParameter));
     79
     80      Parameterize();
     81      RegisterEventHandlers();
    5082    }
    5183
     
    5991    }
    6092
    61     protected override void OnEncodingChanged() {
    62       base.OnEncodingChanged();
    63       Parameterize();
    64     }
    65 
    6693    private void Parameterize() {
    6794      foreach (var similarityCalculator in Operators.OfType<ISolutionSimilarityCalculator>()) {
     
    7097      }
    7198    }
     99
     100    private void RegisterEventHandlers() {
     101      IntValueParameterChangeHandler.Create(TreeLengthRefParameter, TreeLengthOnChanged);
     102      IntValueParameterChangeHandler.Create(TreeDepthRefParameter, TreeDepthOnChanged);
     103      ParameterChangeHandler<ISymbolicExpressionGrammar>.Create(GrammarRefParameter, GrammarOnChanged);
     104    }
     105
     106    protected virtual void TreeLengthOnChanged() { }
     107    protected virtual void TreeDepthOnChanged() { }
     108    protected virtual void GrammarOnChanged() { }
    72109  }
    73110}
Note: See TracChangeset for help on using the changeset viewer.