Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.Problems.GrammaticalEvolution/3.3/Symbolic/GESymbolicDataAnalysisSingleObjectiveProblem.cs @ 13397

Last change on this file since 13397 was 12009, checked in by ascheibe, 10 years ago

#2212 updated copyright year

File size: 5.1 KB
RevLine 
[10072]1#region License Information
2/* HeuristicLab
[12009]3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[10072]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/>.
[10968]19 *
20 * Author: Sabine Winkler
[10072]21 */
22#endregion
23
24using System;
25using System.Linq;
26using HeuristicLab.Common;
27using HeuristicLab.Core;
28using HeuristicLab.Data;
[10073]29using HeuristicLab.Encodings.IntegerVectorEncoding;
[10072]30using HeuristicLab.Optimization;
31using HeuristicLab.Parameters;
32using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
[10073]33using HeuristicLab.Problems.DataAnalysis;
34using HeuristicLab.Problems.DataAnalysis.Symbolic;
[10072]35
[10073]36namespace HeuristicLab.Problems.GrammaticalEvolution {
[10072]37  [StorableClass]
[10075]38  public abstract class GESymbolicDataAnalysisSingleObjectiveProblem<T, U, V> : GESymbolicDataAnalysisProblem<T, U, V>,
[10226]39                                                                                IGESymbolicDataAnalysisSingleObjectiveProblem
[10075]40    where T : class, IDataAnalysisProblemData
[10073]41    where U : class, IGESymbolicDataAnalysisSingleObjectiveEvaluator<T>
42    where V : class, IIntegerVectorCreator {
[10072]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]
[10073]74    protected GESymbolicDataAnalysisSingleObjectiveProblem(bool deserializing) : base(deserializing) { }
75    protected GESymbolicDataAnalysisSingleObjectiveProblem(GESymbolicDataAnalysisSingleObjectiveProblem<T, U, V> original, Cloner cloner)
[10072]76      : base(original, cloner) {
77      RegisterEventHandler();
78      MaximizationParameter.Hidden = true;
79    }
80
[10073]81    public GESymbolicDataAnalysisSingleObjectiveProblem(T problemData, U evaluator, V solutionCreator)
[10072]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.