Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1772: Cleaned up the design of the generic genealogy analyzer and related classes, created generic genealogy graph view. Added instrumentation code to TravelingSalesmapProblem.cs allowing genealogy tracking. Merged trunk changes (instrumentation for multi operators).

File size: 5.2 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
33namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
34  [StorableClass]
35  public abstract class SymbolicDataAnalysisSingleObjectiveProblem<T, U, V> : SymbolicDataAnalysisProblem<T, U, V>, ISymbolicDataAnalysisSingleObjectiveProblem
36    where T : class,IDataAnalysisProblemData
37    where U : class, ISymbolicDataAnalysisSingleObjectiveEvaluator<T>
38    where V : class, ISymbolicDataAnalysisSolutionCreator {
39    private const string MaximizationParameterName = "Maximization";
40    private const string BestKnownQualityParameterName = "BestKnownQuality";
41
42    #region parameter properties
43    public IFixedValueParameter<BoolValue> MaximizationParameter {
44      get { return (IFixedValueParameter<BoolValue>)Parameters[MaximizationParameterName]; }
45    }
46    IParameter ISingleObjectiveHeuristicOptimizationProblem.MaximizationParameter {
47      get { return MaximizationParameter; }
48    }
49    public IFixedValueParameter<DoubleValue> BestKnownQualityParameter {
50      get { return (IFixedValueParameter<DoubleValue>)Parameters[BestKnownQualityParameterName]; }
51    }
52    IParameter ISingleObjectiveHeuristicOptimizationProblem.BestKnownQualityParameter {
53      get { return BestKnownQualityParameter; }
54    }
55    #endregion
56
57    #region properties
58    public BoolValue Maximization {
59      get { return MaximizationParameter.Value; }
60    }
61    public DoubleValue BestKnownQuality {
62      get { return BestKnownQualityParameter.Value; }
63    }
64    ISingleObjectiveEvaluator ISingleObjectiveHeuristicOptimizationProblem.Evaluator {
65      get { return Evaluator; }
66    }
67    #endregion
68
69    [StorableConstructor]
70    protected SymbolicDataAnalysisSingleObjectiveProblem(bool deserializing) : base(deserializing) { }
71    protected SymbolicDataAnalysisSingleObjectiveProblem(SymbolicDataAnalysisSingleObjectiveProblem<T, U, V> original, Cloner cloner)
72      : base(original, cloner) {
73      RegisterEventHandler();
74      MaximizationParameter.Hidden = true;
75    }
76
77    public SymbolicDataAnalysisSingleObjectiveProblem(T problemData, U evaluator, V solutionCreator)
78      : base(problemData, evaluator, solutionCreator) {
79      Parameters.Add(new FixedValueParameter<BoolValue>(MaximizationParameterName, "Set to false if the problem should be minimized."));
80      Parameters.Add(new FixedValueParameter<DoubleValue>(BestKnownQualityParameterName, "The quality of the best known solution of this problem."));
81
82      MaximizationParameter.Hidden = true;
83      InitializeOperators();
84      RegisterEventHandler();
85    }
86
87    [StorableHook(HookType.AfterDeserialization)]
88    private void AfterDeserialization() {
89      RegisterEventHandler();
90    }
91
92    private void InitializeOperators() {
93      Operators.Add(new SymbolicDataAnalysisAlleleFrequencyAnalyzer());
94      ParameterizeOperators();
95    }
96
97    private void RegisterEventHandler() {
98      Evaluator.QualityParameter.ActualNameChanged += new EventHandler(QualityParameter_ActualNameChanged);
99    }
100
101    protected override void OnEvaluatorChanged() {
102      base.OnEvaluatorChanged();
103      Evaluator.QualityParameter.ActualNameChanged += new EventHandler(QualityParameter_ActualNameChanged);
104      Maximization.Value = base.Evaluator.Maximization;
105      ParameterizeOperators();
106    }
107
108    private void QualityParameter_ActualNameChanged(object sender, EventArgs e) {
109      ParameterizeOperators();
110    }
111
112    protected override void ParameterizeOperators() {
113      base.ParameterizeOperators();
114
115      foreach (var op in Operators.OfType<ISymbolicDataAnalysisSingleObjectiveAnalyzer>()) {
116        op.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
117        op.MaximizationParameter.ActualName = MaximizationParameterName;
118      }
119
120      foreach (var op in Operators.OfType<GenealogyAnalyzer<ISymbolicExpressionTree>>()) {
121        op.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
122        op.PopulationParameter.ActualName = Evaluator.SymbolicExpressionTreeParameter.ActualName;
123      }
124    }
125  }
126}
Note: See TracBrowser for help on using the repository browser.