Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/DataAnalysisSolution.cs @ 4193

Last change on this file since 4193 was 4068, checked in by swagner, 14 years ago

Sorted usings and removed unused usings in entire solution (#1094)

File size: 5.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 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 System.Collections.Generic;
24using System.Linq;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28
29namespace HeuristicLab.Problems.DataAnalysis {
30  /// <summary>
31  /// Represents a solution for a data analysis problem which can be visualized in the GUI.
32  /// </summary>
33  [Item("DataAnalysisSolution", "Represents a solution for a data analysis problem which can be visualized in the GUI.")]
34  [StorableClass]
35  public abstract class DataAnalysisSolution : NamedItem {
36    protected DataAnalysisSolution()
37      : base() { }
38    protected DataAnalysisSolution(DataAnalysisProblemData problemData) : this(problemData, double.NegativeInfinity, double.PositiveInfinity) { }
39    protected DataAnalysisSolution(DataAnalysisProblemData problemData, double lowerEstimationLimit, double upperEstimationLimit)
40      : this() {
41      this.problemData = problemData;
42      this.lowerEstimationLimit = lowerEstimationLimit;
43      this.upperEstimationLimit = upperEstimationLimit;
44      Initialize();
45    }
46
47    [StorableConstructor]
48    private DataAnalysisSolution(bool deserializing) : base(deserializing) { }
49    [StorableHook(HookType.AfterDeserialization)]
50    private void Initialize() {
51      if (problemData != null)
52        RegisterProblemDataEvents();
53    }
54
55    [Storable]
56    private DataAnalysisProblemData problemData;
57    public DataAnalysisProblemData ProblemData {
58      get { return problemData; }
59      set {
60        if (problemData != value) {
61          if (value == null) throw new ArgumentNullException();
62          if (model != null && problemData != null && !problemData.InputVariables.Select(c => c.Value).SequenceEqual(
63            value.InputVariables.Select(c => c.Value)))
64            throw new ArgumentException("Could not set new problem data with different structure");
65
66          if (problemData != null) DeregisterProblemDataEvents();
67          problemData = value;
68          RegisterProblemDataEvents();
69          OnProblemDataChanged();
70          RecalculateEstimatedValues();
71        }
72      }
73    }
74
75    [Storable]
76    private IDataAnalysisModel model;
77    public IDataAnalysisModel Model {
78      get { return model; }
79      set {
80        if (model != value) {
81          if (value == null) throw new ArgumentNullException();
82          model = value;
83          OnModelChanged();
84          RecalculateEstimatedValues();
85        }
86      }
87    }
88
89    [Storable]
90    private double lowerEstimationLimit;
91    public double LowerEstimationLimit {
92      get { return lowerEstimationLimit; }
93      set {
94        if (lowerEstimationLimit != value) {
95          lowerEstimationLimit = value;
96          RecalculateEstimatedValues();
97        }
98      }
99    }
100
101    [Storable]
102    private double upperEstimationLimit;
103    public double UpperEstimationLimit {
104      get { return upperEstimationLimit; }
105      set {
106        if (upperEstimationLimit != value) {
107          upperEstimationLimit = value;
108          RecalculateEstimatedValues();
109        }
110      }
111    }
112
113    public abstract IEnumerable<double> EstimatedValues { get; }
114    public abstract IEnumerable<double> EstimatedTrainingValues { get; }
115    public abstract IEnumerable<double> EstimatedTestValues { get; }
116    protected abstract void RecalculateEstimatedValues();
117
118    #region Events
119    protected virtual void RegisterProblemDataEvents() {
120      ProblemData.ProblemDataChanged += new EventHandler(ProblemData_Changed);
121    }
122    protected virtual void DeregisterProblemDataEvents() {
123      ProblemData.ProblemDataChanged += new EventHandler(ProblemData_Changed);
124    }
125    private void ProblemData_Changed(object sender, EventArgs e) {
126      OnProblemDataChanged();
127    }
128
129    public event EventHandler ProblemDataChanged;
130    protected virtual void OnProblemDataChanged() {
131      var listeners = ProblemDataChanged;
132      if (listeners != null)
133        listeners(this, EventArgs.Empty);
134    }
135
136    public event EventHandler ModelChanged;
137    protected virtual void OnModelChanged() {
138      EventHandler handler = ModelChanged;
139      if (handler != null)
140        handler(this, EventArgs.Empty);
141    }
142
143    public event EventHandler EstimatedValuesChanged;
144    protected virtual void OnEstimatedValuesChanged() {
145      var listeners = EstimatedValuesChanged;
146      if (listeners != null)
147        listeners(this, EventArgs.Empty);
148    }
149    #endregion
150
151    public override IDeepCloneable Clone(Cloner cloner) {
152      DataAnalysisSolution clone = (DataAnalysisSolution)base.Clone(cloner);
153      clone.problemData = (DataAnalysisProblemData)cloner.Clone(problemData);
154      clone.model = (IDataAnalysisModel)cloner.Clone(model);
155      clone.lowerEstimationLimit = lowerEstimationLimit;
156      clone.upperEstimationLimit = upperEstimationLimit;
157      clone.Initialize();
158
159      return clone;
160    }
161  }
162}
Note: See TracBrowser for help on using the repository browser.