1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2011 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 |
|
---|
22 | using System;
|
---|
23 | using HeuristicLab.Common;
|
---|
24 | using HeuristicLab.Core;
|
---|
25 | using HeuristicLab.Optimization;
|
---|
26 | using HeuristicLab.Parameters;
|
---|
27 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
28 |
|
---|
29 | namespace HeuristicLab.Problems.DataAnalysis {
|
---|
30 | [StorableClass]
|
---|
31 | public abstract class DataAnalysisProblem<T> : Problem,
|
---|
32 | IDataAnalysisProblem<T>
|
---|
33 | where T : class, IDataAnalysisProblemData {
|
---|
34 | private const string ProblemDataParameterName = "ProblemData";
|
---|
35 | private const string ProblemDataParameterDescription = "The data set, target variable and input variables of the data analysis problem.";
|
---|
36 | #region parameter properties
|
---|
37 | IParameter IDataAnalysisProblem.ProblemDataParameter {
|
---|
38 | get { return ProblemDataParameter; }
|
---|
39 | }
|
---|
40 | public IValueParameter<T> ProblemDataParameter {
|
---|
41 | get { return (IValueParameter<T>)Parameters[ProblemDataParameterName]; }
|
---|
42 | }
|
---|
43 | #endregion
|
---|
44 | #region properties
|
---|
45 | IDataAnalysisProblemData IDataAnalysisProblem.ProblemData {
|
---|
46 | get { return ProblemData; }
|
---|
47 | set { ProblemData = (T)value; }
|
---|
48 | }
|
---|
49 | public T ProblemData {
|
---|
50 | get { return ProblemDataParameter.Value; }
|
---|
51 | protected set {
|
---|
52 | ProblemDataParameter.Value = value;
|
---|
53 | }
|
---|
54 | }
|
---|
55 | #endregion
|
---|
56 | protected DataAnalysisProblem(DataAnalysisProblem<T> original, Cloner cloner)
|
---|
57 | : base(original, cloner) {
|
---|
58 | RegisterEventHandlers();
|
---|
59 | }
|
---|
60 | [StorableConstructor]
|
---|
61 | protected DataAnalysisProblem(bool deserializing) : base(deserializing) { }
|
---|
62 | public DataAnalysisProblem()
|
---|
63 | : base() {
|
---|
64 | Parameters.Add(new ValueParameter<T>(ProblemDataParameterName, ProblemDataParameterDescription));
|
---|
65 | RegisterEventHandlers();
|
---|
66 | }
|
---|
67 |
|
---|
68 | [StorableHook(HookType.AfterDeserialization)]
|
---|
69 | private void AfterDeserialization() {
|
---|
70 | RegisterEventHandlers();
|
---|
71 | }
|
---|
72 |
|
---|
73 | private void RegisterEventHandlers() {
|
---|
74 | ProblemDataParameter.ValueChanged += new EventHandler(ProblemDataParameter_ValueChanged);
|
---|
75 | if (ProblemDataParameter.Value != null) ProblemDataParameter.Value.Changed += new EventHandler(ProblemData_Changed);
|
---|
76 | }
|
---|
77 |
|
---|
78 | private void ProblemDataParameter_ValueChanged(object sender, EventArgs e) {
|
---|
79 | ProblemDataParameter.Value.Changed += new EventHandler(ProblemData_Changed);
|
---|
80 | OnProblemDataChanged();
|
---|
81 | OnReset();
|
---|
82 | }
|
---|
83 |
|
---|
84 | private void ProblemData_Changed(object sender, EventArgs e) {
|
---|
85 | OnReset();
|
---|
86 | }
|
---|
87 |
|
---|
88 | public event EventHandler ProblemDataChanged;
|
---|
89 | protected virtual void OnProblemDataChanged() {
|
---|
90 | var handler = ProblemDataChanged;
|
---|
91 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
92 | }
|
---|
93 |
|
---|
94 | public abstract void ImportProblemDataFromFile(string fileName);
|
---|
95 | }
|
---|
96 | }
|
---|