Free cookie consent management tool by TermsFeed Policy Generator

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

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

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

File size: 5.7 KB
RevLine 
[3408]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;
[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]
[3979]35  public abstract class DataAnalysisSolution : NamedItem {
[3884]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() {
[3921]51      if (problemData != null)
52        RegisterProblemDataEvents();
[3884]53    }
54
[3408]55    [Storable]
56    private DataAnalysisProblemData problemData;
57    public DataAnalysisProblemData ProblemData {
58      get { return problemData; }
59      set {
60        if (problemData != value) {
[3442]61          if (value == null) throw new ArgumentNullException();
[3884]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
[3408]66          if (problemData != null) DeregisterProblemDataEvents();
67          problemData = value;
[3442]68          RegisterProblemDataEvents();
[3884]69          OnProblemDataChanged();
[3915]70          RecalculateEstimatedValues();
[3408]71        }
72      }
73    }
[3884]74
[3513]75    [Storable]
[3884]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();
[3915]84          RecalculateEstimatedValues();
[3884]85        }
86      }
87    }
88
89    [Storable]
[3513]90    private double lowerEstimationLimit;
91    public double LowerEstimationLimit {
92      get { return lowerEstimationLimit; }
93      set {
94        if (lowerEstimationLimit != value) {
95          lowerEstimationLimit = value;
[3884]96          RecalculateEstimatedValues();
[3513]97        }
98      }
99    }
[3442]100
[3513]101    [Storable]
102    private double upperEstimationLimit;
103    public double UpperEstimationLimit {
104      get { return upperEstimationLimit; }
105      set {
106        if (upperEstimationLimit != value) {
107          upperEstimationLimit = value;
[3884]108          RecalculateEstimatedValues();
[3513]109        }
110      }
111    }
112
[3462]113    public abstract IEnumerable<double> EstimatedValues { get; }
114    public abstract IEnumerable<double> EstimatedTrainingValues { get; }
115    public abstract IEnumerable<double> EstimatedTestValues { get; }
[3884]116    protected abstract void RecalculateEstimatedValues();
[3442]117
[3408]118    #region Events
[3462]119    protected virtual void RegisterProblemDataEvents() {
[3442]120      ProblemData.ProblemDataChanged += new EventHandler(ProblemData_Changed);
[3408]121    }
[3462]122    protected virtual void DeregisterProblemDataEvents() {
[3442]123      ProblemData.ProblemDataChanged += new EventHandler(ProblemData_Changed);
[3408]124    }
[3442]125    private void ProblemData_Changed(object sender, EventArgs e) {
[3884]126      OnProblemDataChanged();
[3408]127    }
[3462]128
129    public event EventHandler ProblemDataChanged;
[3884]130    protected virtual void OnProblemDataChanged() {
[3462]131      var listeners = ProblemDataChanged;
132      if (listeners != null)
[3884]133        listeners(this, EventArgs.Empty);
[3462]134    }
135
[3884]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
[3462]143    public event EventHandler EstimatedValuesChanged;
[3884]144    protected virtual void OnEstimatedValuesChanged() {
[3462]145      var listeners = EstimatedValuesChanged;
146      if (listeners != null)
[3884]147        listeners(this, EventArgs.Empty);
[3462]148    }
[3408]149    #endregion
[3884]150
151    public override IDeepCloneable Clone(Cloner cloner) {
152      DataAnalysisSolution clone = (DataAnalysisSolution)base.Clone(cloner);
[3933]153      clone.problemData = (DataAnalysisProblemData)cloner.Clone(problemData);
[3921]154      clone.model = (IDataAnalysisModel)cloner.Clone(model);
[3884]155      clone.lowerEstimationLimit = lowerEstimationLimit;
156      clone.upperEstimationLimit = upperEstimationLimit;
157      clone.Initialize();
[3921]158
[3884]159      return clone;
160    }
[3408]161  }
162}
Note: See TracBrowser for help on using the repository browser.