Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2521_ProblemRefactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisSingleObjectiveProblem.cs @ 17946

Last change on this file since 17946 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: 5.0 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#endregion
21
22using System;
23using System.Linq;
24using HEAL.Attic;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HeuristicLab.Data;
28using HeuristicLab.Optimization;
29using HeuristicLab.Parameters;
30
31namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
32  [StorableType("BC7E7414-64B5-4428-AA89-270F8EF6E35E")]
33  public abstract class SymbolicDataAnalysisSingleObjectiveProblem<T, U> : SymbolicDataAnalysisProblem<T, U>, ISymbolicDataAnalysisSingleObjectiveProblem
34    where T : class,IDataAnalysisProblemData
35    where U : class, ISymbolicDataAnalysisSingleObjectiveEvaluator<T> {
36    private const string MaximizationParameterName = "Maximization";
37    private const string BestKnownQualityParameterName = "BestKnownQuality";
38
39    #region parameter properties
40    public IFixedValueParameter<BoolValue> MaximizationParameter {
41      get { return (IFixedValueParameter<BoolValue>)Parameters[MaximizationParameterName]; }
42    }
43    IParameter ISingleObjectiveHeuristicOptimizationProblem.MaximizationParameter {
44      get { return MaximizationParameter; }
45    }
46    public IFixedValueParameter<DoubleValue> BestKnownQualityParameter {
47      get { return (IFixedValueParameter<DoubleValue>)Parameters[BestKnownQualityParameterName]; }
48    }
49    IParameter ISingleObjectiveHeuristicOptimizationProblem.BestKnownQualityParameter {
50      get { return BestKnownQualityParameter; }
51    }
52    #endregion
53
54    #region properties
55    public BoolValue Maximization {
56      get { return MaximizationParameter.Value; }
57    }
58    public DoubleValue BestKnownQuality {
59      get { return BestKnownQualityParameter.Value; }
60    }
61    ISingleObjectiveEvaluator ISingleObjectiveHeuristicOptimizationProblem.Evaluator {
62      get { return Evaluator; }
63    }
64    #endregion
65
66    [StorableConstructor]
67    protected SymbolicDataAnalysisSingleObjectiveProblem(StorableConstructorFlag _) : base(_) { }
68    protected SymbolicDataAnalysisSingleObjectiveProblem(SymbolicDataAnalysisSingleObjectiveProblem<T, U> original, Cloner cloner)
69      : base(original, cloner) {
70      RegisterEventHandler();
71      MaximizationParameter.Hidden = true;
72    }
73
74    protected SymbolicDataAnalysisSingleObjectiveProblem(T problemData, U evaluator)
75      : base(problemData, evaluator) {
76      Parameters.Add(new FixedValueParameter<BoolValue>(MaximizationParameterName, "Set to false if the problem should be minimized."));
77      Parameters.Add(new FixedValueParameter<DoubleValue>(BestKnownQualityParameterName, "The quality of the best known solution of this problem."));
78
79      MaximizationParameter.Hidden = true;
80      InitializeOperators();
81      RegisterEventHandler();
82    }
83
84    [StorableHook(HookType.AfterDeserialization)]
85    private void AfterDeserialization() {
86      RegisterEventHandler();
87    }
88
89    private void InitializeOperators() {
90      Operators.Add(new SymbolicDataAnalysisAlleleFrequencyAnalyzer());
91      ParameterizeOperators();
92    }
93
94    private void RegisterEventHandler() {
95      Evaluator.QualityParameter.ActualNameChanged += new EventHandler(QualityParameter_ActualNameChanged);
96      MaximizationParameter.ValueChanged += MaximizationParameter_ValueChanged;
97    }
98
99    protected override void OnEvaluatorChanged() {
100      base.OnEvaluatorChanged();
101      Evaluator.QualityParameter.ActualNameChanged += new EventHandler(QualityParameter_ActualNameChanged);
102      Maximization.Value = base.Evaluator.Maximization;
103      ParameterizeOperators();
104    }
105
106    private void QualityParameter_ActualNameChanged(object sender, EventArgs e) {
107      ParameterizeOperators();
108    }
109
110    private void MaximizationParameter_ValueChanged(object sender, EventArgs e) {
111      OnMaximizationChanged();
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    public event EventHandler MaximizationChanged;
124    protected void OnMaximizationChanged() {
125      MaximizationChanged?.Invoke(this, EventArgs.Empty);
126    }
127  }
128}
Note: See TracBrowser for help on using the repository browser.