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