Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisProblem.cs @ 17803

Last change on this file since 17803 was 17181, checked in by swagner, 5 years ago

#2875: Merged r17180 from trunk to stable

File size: 3.7 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 HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Optimization;
26using HeuristicLab.Parameters;
27using HEAL.Attic;
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    IParameter IDataAnalysisProblem.ProblemDataParameter {
39      get { return ProblemDataParameter; }
40    }
41    public IValueParameter<T> ProblemDataParameter {
42      get { return (IValueParameter<T>)Parameters[ProblemDataParameterName]; }
43    }
44    #endregion
45    #region properties
46    IDataAnalysisProblemData IDataAnalysisProblem.ProblemData {
47      get { return ProblemData; }
48    }
49    public T ProblemData {
50      get { return ProblemDataParameter.Value; }
51      set { ProblemDataParameter.Value = value; }
52    }
53    #endregion
54    protected DataAnalysisProblem(DataAnalysisProblem<T> original, Cloner cloner)
55      : base(original, cloner) {
56      RegisterEventHandlers();
57    }
58    [StorableConstructor]
59    protected DataAnalysisProblem(StorableConstructorFlag _) : base(_) { }
60
61    protected DataAnalysisProblem(T problemData)
62      : base() {
63      Parameters.Add(new ValueParameter<T>(ProblemDataParameterName, ProblemDataParameterDescription, problemData));
64      RegisterEventHandlers();
65    }
66
67    [StorableHook(HookType.AfterDeserialization)]
68    private void AfterDeserialization() {
69      RegisterEventHandlers();
70    }
71
72    private void RegisterEventHandlers() {
73      ProblemDataParameter.ValueChanged += new EventHandler(ProblemDataParameter_ValueChanged);
74      if (ProblemDataParameter.Value != null) ProblemDataParameter.Value.Changed += new EventHandler(ProblemData_Changed);
75    }
76
77    private void ProblemDataParameter_ValueChanged(object sender, EventArgs e) {
78      ProblemDataParameter.Value.Changed += new EventHandler(ProblemData_Changed);
79      OnProblemDataChanged();
80      OnReset();
81    }
82
83    private void ProblemData_Changed(object sender, EventArgs e) {
84      OnReset();
85    }
86
87    public event EventHandler ProblemDataChanged;
88    protected virtual void OnProblemDataChanged() {
89      var handler = ProblemDataChanged;
90      if (handler != null) handler(this, EventArgs.Empty);
91    }
92
93    #region Import & Export
94    public void Load(T data) {
95      Name = data.Name;
96      Description = data.Description;
97      ProblemData = data;
98    }
99
100    public T Export() {
101      return ProblemData;
102    }
103    #endregion
104  }
105}
Note: See TracBrowser for help on using the repository browser.