Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2521_ProblemRefactoring/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisProblem.cs @ 17520

Last change on this file since 17520 was 17520, checked in by mkommend, 4 years ago

#2521: Removed parameter for problemData in IDataAnalysisProblem.

File size: 3.6 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 HEAL.Attic;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Optimization;
27using HeuristicLab.Parameters;
28using HeuristicLab.Problems.Instances;
29
30namespace HeuristicLab.Problems.DataAnalysis {
31  [StorableType("67267E9F-8A34-4CB6-9776-DD1483131987")]
32  public abstract class DataAnalysisProblem<T> : Problem, IDataAnalysisProblem<T>,
33    IProblemInstanceConsumer<T>, IProblemInstanceExporter<T>
34    where T : class, IDataAnalysisProblemData {
35    private const string ProblemDataParameterName = "ProblemData";
36    private const string ProblemDataParameterDescription = "The data set, target variable and input variables of the data analysis problem.";
37    #region parameter properties
38    public IValueParameter<T> ProblemDataParameter {
39      get { return (IValueParameter<T>)Parameters[ProblemDataParameterName]; }
40    }
41    #endregion
42    #region properties
43    IDataAnalysisProblemData IDataAnalysisProblem.ProblemData {
44      get { return ProblemData; }
45    }
46    public T ProblemData {
47      get { return ProblemDataParameter.Value; }
48      set { ProblemDataParameter.Value = value; }
49    }
50    #endregion
51    protected DataAnalysisProblem(DataAnalysisProblem<T> original, Cloner cloner)
52      : base(original, cloner) {
53      RegisterEventHandlers();
54    }
55    [StorableConstructor]
56    protected DataAnalysisProblem(StorableConstructorFlag _) : base(_) { }
57
58    protected DataAnalysisProblem(T problemData)
59      : base() {
60      Parameters.Add(new ValueParameter<T>(ProblemDataParameterName, ProblemDataParameterDescription, problemData));
61      RegisterEventHandlers();
62    }
63
64    [StorableHook(HookType.AfterDeserialization)]
65    private void AfterDeserialization() {
66      RegisterEventHandlers();
67    }
68
69    private void RegisterEventHandlers() {
70      ProblemDataParameter.ValueChanged += new EventHandler(ProblemDataParameter_ValueChanged);
71      if (ProblemDataParameter.Value != null) ProblemDataParameter.Value.Changed += new EventHandler(ProblemData_Changed);
72    }
73
74    private void ProblemDataParameter_ValueChanged(object sender, EventArgs e) {
75      ProblemDataParameter.Value.Changed += new EventHandler(ProblemData_Changed);
76      OnProblemDataChanged();
77      OnReset();
78    }
79
80    private void ProblemData_Changed(object sender, EventArgs e) {
81      OnReset();
82    }
83
84    public event EventHandler ProblemDataChanged;
85    protected virtual void OnProblemDataChanged() {
86      var handler = ProblemDataChanged;
87      if (handler != null) handler(this, EventArgs.Empty);
88    }
89
90    #region Import & Export
91    public void Load(T data) {
92      Name = data.Name;
93      Description = data.Description;
94      ProblemData = data;
95    }
96
97    public T Export() {
98      return ProblemData;
99    }
100    #endregion
101  }
102}
Note: See TracBrowser for help on using the repository browser.