Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisSingleObjectiveProblem.cs @ 12338

Last change on this file since 12338 was 12012, checked in by ascheibe, 10 years ago

#2212 merged r12008, r12009, r12010 back into trunk

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