Changeset 17614 for branches/2521_ProblemRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeMultiObjectiveProblem.cs
- Timestamp:
- 06/19/20 17:53:36 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeMultiObjectiveProblem.cs
r17315 r17614 27 27 using HeuristicLab.Common; 28 28 using HeuristicLab.Core; 29 using HeuristicLab.Data; 29 30 using HeuristicLab.Optimization; 31 using HeuristicLab.Parameters; 30 32 31 33 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 32 34 [StorableType("f4819c68-b6fc-469f-bcb5-cb5b2a9d8aff")] 33 35 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 } 34 54 35 55 // persistence … … 37 57 protected SymbolicExpressionTreeMultiObjectiveProblem(StorableConstructorFlag _) : base(_) { } 38 58 [StorableHook(HookType.AfterDeserialization)] 39 private void AfterDeserialization() { } 59 private void AfterDeserialization() { 60 RegisterEventHandlers(); 61 } 40 62 41 63 … … 43 65 protected SymbolicExpressionTreeMultiObjectiveProblem(SymbolicExpressionTreeMultiObjectiveProblem original, Cloner cloner) 44 66 : base(original, cloner) { 67 TreeLengthRefParameter = cloner.Clone(original.TreeLengthRefParameter); 68 TreeDepthRefParameter = cloner.Clone(original.TreeDepthRefParameter); 69 GrammarRefParameter = cloner.Clone(original.GrammarRefParameter); 70 RegisterEventHandlers(); 45 71 } 46 72 … … 48 74 : base(encoding) { 49 75 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(); 50 82 } 51 83 … … 59 91 } 60 92 61 protected override void OnEncodingChanged() {62 base.OnEncodingChanged();63 Parameterize();64 }65 66 93 private void Parameterize() { 67 94 foreach (var similarityCalculator in Operators.OfType<ISolutionSimilarityCalculator>()) { … … 70 97 } 71 98 } 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() { } 72 109 } 73 110 }
Note: See TracChangeset
for help on using the changeset viewer.