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
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.SymbolicExpressionTreeEncoding;
28using HeuristicLab.EvolutionTracking;
29using HeuristicLab.Optimization;
30using HeuristicLab.Parameters;
31using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
32
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
37namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
38  [StorableClass]
39  public abstract class SymbolicDataAnalysisSingleObjectiveProblem<T, U, V> : SymbolicDataAnalysisProblem<T, U, V>, ISymbolicDataAnalysisSingleObjectiveProblem
40    where T : class,IDataAnalysisProblemData
41    where U : class, ISymbolicDataAnalysisSingleObjectiveEvaluator<T>
42    where V : class, ISymbolicDataAnalysisSolutionCreator {
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 SymbolicDataAnalysisSingleObjectiveProblem(bool deserializing) : base(deserializing) { }
75    protected SymbolicDataAnalysisSingleObjectiveProblem(SymbolicDataAnalysisSingleObjectiveProblem<T, U, V> original, Cloner cloner)
76      : base(original, cloner) {
77      RegisterEventHandler();
78      MaximizationParameter.Hidden = true;
79    }
80
81    public SymbolicDataAnalysisSingleObjectiveProblem(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      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      }
128    }
129  }
130}
Note: See TracBrowser for help on using the repository browser.