Free cookie consent management tool by TermsFeed Policy Generator

source: branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Symbolic/GESymbolicDataAnalysisSingleObjectiveProblem.cs @ 10226

Last change on this file since 10226 was 10226, checked in by sawinkle, 10 years ago

#2109:

  • Added file IGESymbolicDataAnalysisProblem.cs to determine, which parameters should be used. => Removed parameters MaximumSymbolicExpressionTreeDepthParameter, MaximumFunctionDefinitionsParameter and MaximumFunctionArgumentsParameter, which are unnecessary for Grammatical Evolution.
  • Adapted the other files to use the interfaces of the new file IGESymbolicDataAnalysisProblem.cs
File size: 5.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 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 HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Data;
27using HeuristicLab.Encodings.IntegerVectorEncoding;
28using HeuristicLab.Optimization;
29using HeuristicLab.Parameters;
30using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
31using HeuristicLab.Problems.DataAnalysis;
32using HeuristicLab.Problems.DataAnalysis.Symbolic;
33
34namespace HeuristicLab.Problems.GrammaticalEvolution {
35  [StorableClass]
36  public abstract class GESymbolicDataAnalysisSingleObjectiveProblem<T, U, V> : GESymbolicDataAnalysisProblem<T, U, V>,
37                                                                                IGESymbolicDataAnalysisSingleObjectiveProblem
38    where T : class, IDataAnalysisProblemData
39    where U : class, IGESymbolicDataAnalysisSingleObjectiveEvaluator<T>
40    where V : class, IIntegerVectorCreator {
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(bool deserializing) : base(deserializing) { }
73    protected GESymbolicDataAnalysisSingleObjectiveProblem(GESymbolicDataAnalysisSingleObjectiveProblem<T, U, V> original, Cloner cloner)
74      : base(original, cloner) {
75      RegisterEventHandler();
76      MaximizationParameter.Hidden = true;
77    }
78
79    public GESymbolicDataAnalysisSingleObjectiveProblem(T problemData, U evaluator, V solutionCreator)
80      : base(problemData, evaluator, solutionCreator) {
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.