Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisSingleObjectiveProblem.cs @ 10285

Last change on this file since 10285 was 10285, checked in by bburlacu, 11 years ago

#1772: Added SymbolicDataAnalysisGenealogyView, updated generic analyzer and operators.

File size: 5.7 KB
RevLine 
[5580]1#region License Information
2/* HeuristicLab
[9456]3 * Copyright (C) 2002-2013 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;
[10285]27using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
28using HeuristicLab.EvolutionTracking;
[5580]29using HeuristicLab.Optimization;
30using HeuristicLab.Parameters;
31using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
32
[10285]33using TGraph = HeuristicLab.EvolutionTracking.IGenealogyGraph<HeuristicLab.EvolutionTracking.GenealogyGraphNode<HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ISymbolicExpressionTree>,
34                                                              HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ISymbolicExpressionTree>;
35using TVertex = HeuristicLab.EvolutionTracking.GenealogyGraphNode<HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ISymbolicExpressionTree>;
36
[5580]37namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
38  [StorableClass]
[9049]39  public abstract class SymbolicDataAnalysisSingleObjectiveProblem<T, U, V> : SymbolicDataAnalysisProblem<T, U, V>, ISymbolicDataAnalysisSingleObjectiveProblem
[5580]40    where T : class,IDataAnalysisProblemData
[5618]41    where U : class, ISymbolicDataAnalysisSingleObjectiveEvaluator<T>
[5580]42    where V : class, ISymbolicDataAnalysisSolutionCreator {
43    private const string MaximizationParameterName = "Maximization";
44    private const string BestKnownQualityParameterName = "BestKnownQuality";
45
46    #region parameter properties
[5618]47    public IFixedValueParameter<BoolValue> MaximizationParameter {
48      get { return (IFixedValueParameter<BoolValue>)Parameters[MaximizationParameterName]; }
[5580]49    }
50    IParameter ISingleObjectiveHeuristicOptimizationProblem.MaximizationParameter {
51      get { return MaximizationParameter; }
52    }
[5618]53    public IFixedValueParameter<DoubleValue> BestKnownQualityParameter {
54      get { return (IFixedValueParameter<DoubleValue>)Parameters[BestKnownQualityParameterName]; }
[5580]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]
[5618]74    protected SymbolicDataAnalysisSingleObjectiveProblem(bool deserializing) : base(deserializing) { }
[5685]75    protected SymbolicDataAnalysisSingleObjectiveProblem(SymbolicDataAnalysisSingleObjectiveProblem<T, U, V> original, Cloner cloner)
76      : base(original, cloner) {
77      RegisterEventHandler();
[5835]78      MaximizationParameter.Hidden = true;
[5685]79    }
[5580]80
[5618]81    public SymbolicDataAnalysisSingleObjectiveProblem(T problemData, U evaluator, V solutionCreator)
82      : base(problemData, evaluator, solutionCreator) {
[5847]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."));
[5685]85
[5835]86      MaximizationParameter.Hidden = true;
[6533]87      InitializeOperators();
[5685]88      RegisterEventHandler();
[5580]89    }
[5618]90
[5685]91    [StorableHook(HookType.AfterDeserialization)]
92    private void AfterDeserialization() {
93      RegisterEventHandler();
94    }
95
[6533]96    private void InitializeOperators() {
97      Operators.Add(new SymbolicDataAnalysisAlleleFrequencyAnalyzer());
98      ParameterizeOperators();
99    }
100
[5685]101    private void RegisterEventHandler() {
102      Evaluator.QualityParameter.ActualNameChanged += new EventHandler(QualityParameter_ActualNameChanged);
103    }
104
[5618]105    protected override void OnEvaluatorChanged() {
106      base.OnEvaluatorChanged();
[5685]107      Evaluator.QualityParameter.ActualNameChanged += new EventHandler(QualityParameter_ActualNameChanged);
[5618]108      Maximization.Value = base.Evaluator.Maximization;
[5685]109      ParameterizeOperators();
[5618]110    }
[5685]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      }
[10285]123
124      foreach (var op in Operators.OfType<GenealogyAnalyzer<TGraph, TVertex, ISymbolicExpressionTree>>()) {
125        op.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
126        op.PopulationParameter.ActualName = Evaluator.SymbolicExpressionTreeParameter.ActualName;
127      }
[5685]128    }
[5580]129  }
130}
Note: See TracBrowser for help on using the repository browser.