Free cookie consent management tool by TermsFeed Policy Generator

source: branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Symbolic/GESymbolicDataAnalysisSingleObjectiveProblem.cs @ 10075

Last change on this file since 10075 was 10075, checked in by sawinkle, 10 years ago

#2109:

  • For each newly created node, ResetLocalParameters() has to be called, if possible. Otherwise 'Variable' symbols won't be initialized correctly. (E.g. internal ValueName is null and causes exceptions.)
  • Method MapDepthFirstRecursively() of DepthFirstMapper.cs checks subtree boundaries by using the MinimumArity instead of the MaximumArity. Otherwise e.g. adding the 'Addition' symbol will cause very short trees, because this symbol has got a MaximumArity of 255! This would cause, that the tree is immediately full, after insertion of one 'Addition' symbol, if the genotype length is e.g. just 100.
  • Several bug fixes.
  • Unresolved issues:
    • Changes in the selected grammar are not taken into account during a run (e.g. 'Addition' symbols will be inserted into the tree, although its checkbox was unchecked previously).
    • Exception, if a division by zero is tried.
    • Wrapping mechanism.
File size: 5.0 KB
RevLine 
[10072]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;
[10073]27using HeuristicLab.Encodings.IntegerVectorEncoding;
[10072]28using HeuristicLab.Optimization;
29using HeuristicLab.Parameters;
30using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
[10073]31using HeuristicLab.Problems.DataAnalysis;
32using HeuristicLab.Problems.DataAnalysis.Symbolic;
[10072]33
[10073]34namespace HeuristicLab.Problems.GrammaticalEvolution {
[10072]35  [StorableClass]
[10075]36  public abstract class GESymbolicDataAnalysisSingleObjectiveProblem<T, U, V> : GESymbolicDataAnalysisProblem<T, U, V>,
37                                                                                ISymbolicDataAnalysisSingleObjectiveProblem
38    where T : class, IDataAnalysisProblemData
[10073]39    where U : class, IGESymbolicDataAnalysisSingleObjectiveEvaluator<T>
40    where V : class, IIntegerVectorCreator {
[10072]41    private const string MaximizationParameterName = "Maximization";
42    private const string BestKnownQualityParameterName = "BestKnownQuality";
43
44    #region parameter properties
45    public IFixedValueParameter<BoolValue> MaximizationParameter {
46      get { return (IFixedValueParameter<BoolValue>)Parameters[MaximizationParameterName]; }
47    }
48    IParameter ISingleObjectiveHeuristicOptimizationProblem.MaximizationParameter {
49      get { return MaximizationParameter; }
50    }
51    public IFixedValueParameter<DoubleValue> BestKnownQualityParameter {
52      get { return (IFixedValueParameter<DoubleValue>)Parameters[BestKnownQualityParameterName]; }
53    }
54    IParameter ISingleObjectiveHeuristicOptimizationProblem.BestKnownQualityParameter {
55      get { return BestKnownQualityParameter; }
56    }
57    #endregion
58
59    #region properties
60    public BoolValue Maximization {
61      get { return MaximizationParameter.Value; }
62    }
63    public DoubleValue BestKnownQuality {
64      get { return BestKnownQualityParameter.Value; }
65    }
66    ISingleObjectiveEvaluator ISingleObjectiveHeuristicOptimizationProblem.Evaluator {
67      get { return Evaluator; }
68    }
69    #endregion
70
71    [StorableConstructor]
[10073]72    protected GESymbolicDataAnalysisSingleObjectiveProblem(bool deserializing) : base(deserializing) { }
73    protected GESymbolicDataAnalysisSingleObjectiveProblem(GESymbolicDataAnalysisSingleObjectiveProblem<T, U, V> original, Cloner cloner)
[10072]74      : base(original, cloner) {
75      RegisterEventHandler();
76      MaximizationParameter.Hidden = true;
77    }
78
[10073]79    public GESymbolicDataAnalysisSingleObjectiveProblem(T problemData, U evaluator, V solutionCreator)
[10072]80      : base(problemData, evaluator, solutionCreator) {
81      Parameters.Add(new FixedValueParameter<BoolValue>(MaximizationParameterName, "Set to false if the problem should be minimized."));
82      Parameters.Add(new FixedValueParameter<DoubleValue>(BestKnownQualityParameterName, "The quality of the best known solution of this problem."));
83
84      MaximizationParameter.Hidden = true;
85      InitializeOperators();
86      RegisterEventHandler();
87    }
88
89    [StorableHook(HookType.AfterDeserialization)]
90    private void AfterDeserialization() {
91      RegisterEventHandler();
92    }
93
94    private void InitializeOperators() {
95      Operators.Add(new SymbolicDataAnalysisAlleleFrequencyAnalyzer());
96      ParameterizeOperators();
97    }
98
99    private void RegisterEventHandler() {
100      Evaluator.QualityParameter.ActualNameChanged += new EventHandler(QualityParameter_ActualNameChanged);
101    }
102
103    protected override void OnEvaluatorChanged() {
104      base.OnEvaluatorChanged();
105      Evaluator.QualityParameter.ActualNameChanged += new EventHandler(QualityParameter_ActualNameChanged);
106      Maximization.Value = base.Evaluator.Maximization;
107      ParameterizeOperators();
108    }
109
110    private void QualityParameter_ActualNameChanged(object sender, EventArgs e) {
111      ParameterizeOperators();
112    }
113
114    protected override void ParameterizeOperators() {
115      base.ParameterizeOperators();
116
117      foreach (var op in Operators.OfType<ISymbolicDataAnalysisSingleObjectiveAnalyzer>()) {
118        op.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
119        op.MaximizationParameter.ActualName = MaximizationParameterName;
120      }
121    }
122  }
123}
Note: See TracBrowser for help on using the repository browser.