Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2522_RefactorPluginInfrastructure/HeuristicLab.Problems.GrammaticalEvolution/3.4/SymbolicRegression/GESymbolicDataAnalysisSingleObjectiveProblem.cs

Last change on this file was 15973, checked in by gkronber, 6 years ago

#2522: merged trunk changes from r13402:15972 to branch resolving conflicts where necessary

File size: 5.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2018 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 HeuristicLab.Common;
27using HeuristicLab.Core;
28using HeuristicLab.Data;
29using HeuristicLab.Encodings.IntegerVectorEncoding;
30using HeuristicLab.Optimization;
31using HeuristicLab.Parameters;
32using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
33using HeuristicLab.Problems.DataAnalysis;
34using HeuristicLab.Problems.DataAnalysis.Symbolic;
35
36namespace HeuristicLab.Problems.GrammaticalEvolution {
37  [StorableClass]
38  public abstract class GESymbolicDataAnalysisSingleObjectiveProblem<T, U, V> : GESymbolicDataAnalysisProblem<T, U, V>,
39                                                                                IGESymbolicDataAnalysisSingleObjectiveProblem
40    where T : class, IDataAnalysisProblemData
41    where U : class, IGESymbolicDataAnalysisSingleObjectiveEvaluator<T>
42    where V : class, IIntegerVectorCreator {
43    private const string MaximizationParameterName = "Maximization";
44    private const string BestKnownQualityParameterName = "BestKnownQuality";
45
46    #region parameter properties
47    public IFixedValueParameter<BoolValue> MaximizationParameter {
48      get { return (IFixedValueParameter<BoolValue>)Parameters[MaximizationParameterName]; }
49    }
50    IParameter ISingleObjectiveHeuristicOptimizationProblem.MaximizationParameter {
51      get { return MaximizationParameter; }
52    }
53    public IFixedValueParameter<DoubleValue> BestKnownQualityParameter {
54      get { return (IFixedValueParameter<DoubleValue>)Parameters[BestKnownQualityParameterName]; }
55    }
56    IParameter ISingleObjectiveHeuristicOptimizationProblem.BestKnownQualityParameter {
57      get { return BestKnownQualityParameter; }
58    }
59    #endregion
60
61    #region properties
62    public BoolValue Maximization {
63      get { return MaximizationParameter.Value; }
64    }
65    public DoubleValue BestKnownQuality {
66      get { return BestKnownQualityParameter.Value; }
67    }
68    ISingleObjectiveEvaluator ISingleObjectiveHeuristicOptimizationProblem.Evaluator {
69      get { return Evaluator; }
70    }
71    #endregion
72
73    [StorableConstructor]
74    protected GESymbolicDataAnalysisSingleObjectiveProblem(bool deserializing) : base(deserializing) { }
75    protected GESymbolicDataAnalysisSingleObjectiveProblem(GESymbolicDataAnalysisSingleObjectiveProblem<T, U, V> original, Cloner cloner)
76      : base(original, cloner) {
77      RegisterEventHandler();
78      MaximizationParameter.Hidden = true;
79    }
80
81    public GESymbolicDataAnalysisSingleObjectiveProblem(T problemData, U evaluator, V solutionCreator)
82      : base(problemData, evaluator, solutionCreator) {
83      Parameters.Add(new FixedValueParameter<BoolValue>(MaximizationParameterName, "Set to false if the problem should be minimized."));
84      Parameters.Add(new FixedValueParameter<DoubleValue>(BestKnownQualityParameterName, "The quality of the best known solution of this problem."));
85
86      MaximizationParameter.Hidden = true;
87      InitializeOperators();
88      RegisterEventHandler();
89    }
90
91    [StorableHook(HookType.AfterDeserialization)]
92    private void AfterDeserialization() {
93      RegisterEventHandler();
94    }
95
96    private void InitializeOperators() {
97      Operators.Add(new SymbolicDataAnalysisAlleleFrequencyAnalyzer());
98      ParameterizeOperators();
99    }
100
101    private void RegisterEventHandler() {
102      Evaluator.QualityParameter.ActualNameChanged += new EventHandler(QualityParameter_ActualNameChanged);
103    }
104
105    protected override void OnEvaluatorChanged() {
106      base.OnEvaluatorChanged();
107      Evaluator.QualityParameter.ActualNameChanged += new EventHandler(QualityParameter_ActualNameChanged);
108      Maximization.Value = base.Evaluator.Maximization;
109      ParameterizeOperators();
110    }
111
112    private void QualityParameter_ActualNameChanged(object sender, EventArgs e) {
113      ParameterizeOperators();
114    }
115
116    protected override void ParameterizeOperators() {
117      base.ParameterizeOperators();
118
119      foreach (var op in Operators.OfType<ISymbolicDataAnalysisSingleObjectiveAnalyzer>()) {
120        op.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
121        op.MaximizationParameter.ActualName = MaximizationParameterName;
122      }
123    }
124  }
125}
Note: See TracBrowser for help on using the repository browser.