Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2521_ProblemRefactoring/HeuristicLab.Problems.GrammaticalEvolution/3.4/SymbolicRegression/GESymbolicDataAnalysisSingleObjectiveProblem.cs @ 17695

Last change on this file since 17695 was 17695, checked in by abeham, 4 years ago

#2521:

  • Moving solution creator parameter from problems to algorithms (breaking wiring in some HeuristicOptimizationProblems)
  • Disallowing evaluator or encoding changes in encoding-specific base problems (to avoid confusion in derived problems whether this needs to be handled or not)
  • Added private set to ReferenceParameter property (serialization)
File size: 4.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * Author: Sabine Winkler
21 */
22#endregion
23
24using System;
25using System.Linq;
26using HEAL.Attic;
27using HeuristicLab.Common;
28using HeuristicLab.Core;
29using HeuristicLab.Data;
30using HeuristicLab.Optimization;
31using HeuristicLab.Parameters;
32using HeuristicLab.Problems.DataAnalysis;
33using HeuristicLab.Problems.DataAnalysis.Symbolic;
34
35namespace HeuristicLab.Problems.GrammaticalEvolution {
36  [StorableType("27E01C21-6772-4CE5-8301-EF3102D1BB28")]
37  public abstract class GESymbolicDataAnalysisSingleObjectiveProblem<T, U> : GESymbolicDataAnalysisProblem<T, U>,
38                                                                                IGESymbolicDataAnalysisSingleObjectiveProblem
39    where T : class, IDataAnalysisProblemData
40    where U : class, IGESymbolicDataAnalysisSingleObjectiveEvaluator<T> {
41    private const string MaximizationParameterName = "Maximization";
42    private const string BestKnownQualityParameterName = "BestKnownQuality";
43
44    #region parameter properties
45    public IFixedValueParameter<BoolValue> MaximizationParameter {
46      get { return (IFixedValueParameter<BoolValue>)Parameters[MaximizationParameterName]; }
47    }
48    IParameter ISingleObjectiveHeuristicOptimizationProblem.MaximizationParameter {
49      get { return MaximizationParameter; }
50    }
51    public IFixedValueParameter<DoubleValue> BestKnownQualityParameter {
52      get { return (IFixedValueParameter<DoubleValue>)Parameters[BestKnownQualityParameterName]; }
53    }
54    IParameter ISingleObjectiveHeuristicOptimizationProblem.BestKnownQualityParameter {
55      get { return BestKnownQualityParameter; }
56    }
57    #endregion
58
59    #region properties
60    public BoolValue Maximization {
61      get { return MaximizationParameter.Value; }
62    }
63    public DoubleValue BestKnownQuality {
64      get { return BestKnownQualityParameter.Value; }
65    }
66    ISingleObjectiveEvaluator ISingleObjectiveHeuristicOptimizationProblem.Evaluator {
67      get { return Evaluator; }
68    }
69    #endregion
70
71    [StorableConstructor]
72    protected GESymbolicDataAnalysisSingleObjectiveProblem(StorableConstructorFlag _) : base(_) { }
73    protected GESymbolicDataAnalysisSingleObjectiveProblem(GESymbolicDataAnalysisSingleObjectiveProblem<T, U> original, Cloner cloner)
74      : base(original, cloner) {
75      RegisterEventHandler();
76      MaximizationParameter.Hidden = true;
77    }
78
79    public GESymbolicDataAnalysisSingleObjectiveProblem(T problemData, U evaluator)
80      : base(problemData, evaluator) {
81      Parameters.Add(new FixedValueParameter<BoolValue>(MaximizationParameterName, "Set to false if the problem should be minimized."));
82      Parameters.Add(new FixedValueParameter<DoubleValue>(BestKnownQualityParameterName, "The quality of the best known solution of this problem."));
83
84      MaximizationParameter.Hidden = true;
85      InitializeOperators();
86      RegisterEventHandler();
87    }
88
89    [StorableHook(HookType.AfterDeserialization)]
90    private void AfterDeserialization() {
91      RegisterEventHandler();
92    }
93
94    private void InitializeOperators() {
95      Operators.Add(new SymbolicDataAnalysisAlleleFrequencyAnalyzer());
96      ParameterizeOperators();
97    }
98
99    private void RegisterEventHandler() {
100      Evaluator.QualityParameter.ActualNameChanged += new EventHandler(QualityParameter_ActualNameChanged);
101    }
102
103    protected override void OnEvaluatorChanged() {
104      base.OnEvaluatorChanged();
105      Evaluator.QualityParameter.ActualNameChanged += new EventHandler(QualityParameter_ActualNameChanged);
106      Maximization.Value = base.Evaluator.Maximization;
107      ParameterizeOperators();
108    }
109
110    private void QualityParameter_ActualNameChanged(object sender, EventArgs e) {
111      ParameterizeOperators();
112    }
113
114    protected override void ParameterizeOperators() {
115      base.ParameterizeOperators();
116
117      foreach (var op in Operators.OfType<ISymbolicDataAnalysisSingleObjectiveAnalyzer>()) {
118        op.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
119        op.MaximizationParameter.ActualName = MaximizationParameterName;
120      }
121    }
122  }
123}
Note: See TracBrowser for help on using the repository browser.