Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2521_ProblemRefactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisMultiObjectiveProblem.cs @ 17317

Last change on this file since 17317 was 17317, checked in by abeham, 5 years ago

#2521: refactored multi-objective problems' maximization

  • Add ForceValue method to IValueParameter to perform changes even when it is read-only
  • Add MaximizationChanged event handler
File size: 4.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 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 HEAL.Attic;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HeuristicLab.Data;
28using HeuristicLab.Optimization;
29using HeuristicLab.Parameters;
30
31namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
32  [StorableType("E9876DF8-ACFA-41C8-93B7-FA40C57CE459")]
33  public abstract class SymbolicDataAnalysisMultiObjectiveProblem<T, U, V> : SymbolicDataAnalysisProblem<T, U, V>, ISymbolicDataAnalysisMultiObjectiveProblem
34    where T : class,IDataAnalysisProblemData
35    where U : class, ISymbolicDataAnalysisMultiObjectiveEvaluator<T>
36    where V : class, ISymbolicDataAnalysisSolutionCreator {
37    private const string MaximizationParameterName = "Maximization";
38    private const string BestKnownQualityParameterName = "BestKnownQuality";
39
40    #region parameter properties
41    public IValueParameter<BoolArray> MaximizationParameter {
42      get { return (IValueParameter<BoolArray>)Parameters[MaximizationParameterName]; }
43    }
44    IParameter IMultiObjectiveHeuristicOptimizationProblem.MaximizationParameter {
45      get { return MaximizationParameter; }
46    }
47    #endregion
48
49    #region properties
50    public BoolArray Maximization {
51      get { return MaximizationParameter.Value; }
52      set { MaximizationParameter.Value = value; }
53    }
54    IMultiObjectiveEvaluator IMultiObjectiveHeuristicOptimizationProblem.Evaluator {
55      get { return Evaluator; }
56    }
57    #endregion
58
59    [StorableConstructor]
60    protected SymbolicDataAnalysisMultiObjectiveProblem(StorableConstructorFlag _) : base(_) { }
61    protected SymbolicDataAnalysisMultiObjectiveProblem(SymbolicDataAnalysisMultiObjectiveProblem<T, U, V> original, Cloner cloner)
62      : base(original, cloner) {
63      RegisterEventHandler();
64    }
65
66    public SymbolicDataAnalysisMultiObjectiveProblem(T problemData, U evaluator, V solutionCreator)
67      : base(problemData, evaluator, solutionCreator) {
68      Parameters.Add(new ValueParameter<BoolArray>(MaximizationParameterName, "Set to false if the problem should be minimized."));
69
70      ParameterizeOperators();
71      RegisterEventHandler();
72    }
73
74    [StorableHook(HookType.AfterDeserialization)]
75    private void AfterDeserialization() {
76      RegisterEventHandler();
77    }
78
79    private void RegisterEventHandler() {
80      Evaluator.QualitiesParameter.ActualNameChanged += new EventHandler(QualitiesParameter_ActualNameChanged);
81      MaximizationParameter.ValueChanged += MaximizationParameter_ValueChanged;
82    }
83
84    protected override void OnEvaluatorChanged() {
85      base.OnEvaluatorChanged();
86      Evaluator.QualitiesParameter.ActualNameChanged += new EventHandler(QualitiesParameter_ActualNameChanged);
87      Maximization = new BoolArray(Evaluator.Maximization.ToArray());
88      ParameterizeOperators();
89    }
90
91    private void QualitiesParameter_ActualNameChanged(object sender, EventArgs e) {
92      ParameterizeOperators();
93    }
94
95    private void MaximizationParameter_ValueChanged(object sender, EventArgs e) {
96      OnMaximizationChanged();
97    }
98
99    protected override void ParameterizeOperators() {
100      base.ParameterizeOperators();
101      foreach (var op in Operators.OfType<ISymbolicDataAnalysisMultiObjectiveAnalyzer>()) {
102        op.QualitiesParameter.ActualName = Evaluator.QualitiesParameter.ActualName;
103        op.MaximizationParameter.ActualName = MaximizationParameterName;
104      }
105    }
106
107    public event EventHandler MaximizationChanged;
108    protected void OnMaximizationChanged() {
109      MaximizationChanged?.Invoke(this, EventArgs.Empty);
110    }
111  }
112}
Note: See TracBrowser for help on using the repository browser.