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