Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 6284 was 5445, checked in by swagner, 14 years ago

Updated year of copyrights (#1406)

File size: 5.8 KB
RevLine 
[3408]1#region License Information
2/* HeuristicLab
[5445]3 * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[3408]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;
[4068]23using System.Collections.Generic;
24using System.Linq;
[3408]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]
[4451]35  public abstract class DataAnalysisSolution : NamedItem, IStorableContent {
36    #region IStorableContent Members
37    public string Filename { get; set; }
38    #endregion
[4722]39
40    [StorableConstructor]
41    protected DataAnalysisSolution(bool deserializing) : base(deserializing) { }
42    protected DataAnalysisSolution(DataAnalysisSolution original, Cloner cloner)
43      : base(original, cloner) {
44      problemData = (DataAnalysisProblemData)cloner.Clone(original.problemData);
45      model = (IDataAnalysisModel)cloner.Clone(original.model);
46      lowerEstimationLimit = original.lowerEstimationLimit;
47      upperEstimationLimit = original.upperEstimationLimit;
48      AfterDeserialization();
49    }
[3884]50    protected DataAnalysisSolution()
51      : base() { }
52    protected DataAnalysisSolution(DataAnalysisProblemData problemData) : this(problemData, double.NegativeInfinity, double.PositiveInfinity) { }
53    protected DataAnalysisSolution(DataAnalysisProblemData problemData, double lowerEstimationLimit, double upperEstimationLimit)
54      : this() {
55      this.problemData = problemData;
56      this.lowerEstimationLimit = lowerEstimationLimit;
57      this.upperEstimationLimit = upperEstimationLimit;
[4722]58      AfterDeserialization();
[3884]59    }
60
61    [StorableHook(HookType.AfterDeserialization)]
[4722]62    private void AfterDeserialization() {
[3921]63      if (problemData != null)
64        RegisterProblemDataEvents();
[3884]65    }
66
[3408]67    [Storable]
68    private DataAnalysisProblemData problemData;
69    public DataAnalysisProblemData ProblemData {
70      get { return problemData; }
71      set {
72        if (problemData != value) {
[3442]73          if (value == null) throw new ArgumentNullException();
[3884]74          if (model != null && problemData != null && !problemData.InputVariables.Select(c => c.Value).SequenceEqual(
75            value.InputVariables.Select(c => c.Value)))
76            throw new ArgumentException("Could not set new problem data with different structure");
77
[3408]78          if (problemData != null) DeregisterProblemDataEvents();
79          problemData = value;
[3442]80          RegisterProblemDataEvents();
[3884]81          OnProblemDataChanged();
[3915]82          RecalculateEstimatedValues();
[3408]83        }
84      }
85    }
[3884]86
[3513]87    [Storable]
[3884]88    private IDataAnalysisModel model;
89    public IDataAnalysisModel Model {
90      get { return model; }
91      set {
92        if (model != value) {
93          if (value == null) throw new ArgumentNullException();
94          model = value;
95          OnModelChanged();
[3915]96          RecalculateEstimatedValues();
[3884]97        }
98      }
99    }
100
101    [Storable]
[3513]102    private double lowerEstimationLimit;
103    public double LowerEstimationLimit {
104      get { return lowerEstimationLimit; }
105      set {
106        if (lowerEstimationLimit != value) {
107          lowerEstimationLimit = value;
[3884]108          RecalculateEstimatedValues();
[3513]109        }
110      }
111    }
[3442]112
[3513]113    [Storable]
114    private double upperEstimationLimit;
115    public double UpperEstimationLimit {
116      get { return upperEstimationLimit; }
117      set {
118        if (upperEstimationLimit != value) {
119          upperEstimationLimit = value;
[3884]120          RecalculateEstimatedValues();
[3513]121        }
122      }
123    }
124
[3462]125    public abstract IEnumerable<double> EstimatedValues { get; }
126    public abstract IEnumerable<double> EstimatedTrainingValues { get; }
127    public abstract IEnumerable<double> EstimatedTestValues { get; }
[3884]128    protected abstract void RecalculateEstimatedValues();
[3442]129
[3408]130    #region Events
[3462]131    protected virtual void RegisterProblemDataEvents() {
[3442]132      ProblemData.ProblemDataChanged += new EventHandler(ProblemData_Changed);
[3408]133    }
[3462]134    protected virtual void DeregisterProblemDataEvents() {
[3442]135      ProblemData.ProblemDataChanged += new EventHandler(ProblemData_Changed);
[3408]136    }
[3442]137    private void ProblemData_Changed(object sender, EventArgs e) {
[3884]138      OnProblemDataChanged();
[3408]139    }
[3462]140
141    public event EventHandler ProblemDataChanged;
[3884]142    protected virtual void OnProblemDataChanged() {
[3462]143      var listeners = ProblemDataChanged;
144      if (listeners != null)
[3884]145        listeners(this, EventArgs.Empty);
[3462]146    }
147
[3884]148    public event EventHandler ModelChanged;
149    protected virtual void OnModelChanged() {
[4722]150      EventHandler listeners = ModelChanged;
151      if (listeners != null)
152        listeners(this, EventArgs.Empty);
[3884]153    }
154
[3462]155    public event EventHandler EstimatedValuesChanged;
[3884]156    protected virtual void OnEstimatedValuesChanged() {
[3462]157      var listeners = EstimatedValuesChanged;
158      if (listeners != null)
[3884]159        listeners(this, EventArgs.Empty);
[3462]160    }
[3408]161    #endregion
[3884]162
[3408]163  }
164}
Note: See TracBrowser for help on using the repository browser.