Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 3491 was 3462, checked in by gkronber, 14 years ago

Refactored symbolic expression tree encoding and problem classes for symbolic regression. #937 , #938

File size: 3.8 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 HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Data;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
28using System.Collections.Generic;
29using System.Linq;
30
31namespace HeuristicLab.Problems.DataAnalysis {
32  /// <summary>
33  /// Represents a solution for a data analysis problem which can be visualized in the GUI.
34  /// </summary>
35  [Item("DataAnalysisSolution", "Represents a solution for a data analysis problem which can be visualized in the GUI.")]
36  [StorableClass]
37  public abstract class DataAnalysisSolution : Item {
38    [Storable]
39    private DataAnalysisProblemData problemData;
40    public DataAnalysisProblemData ProblemData {
41      get { return problemData; }
42      set {
43        if (problemData != value) {
44          if (value == null) throw new ArgumentNullException();
45          if (problemData != null) DeregisterProblemDataEvents();
46          problemData = value;
47          RegisterProblemDataEvents();
48          OnProblemDataChanged(EventArgs.Empty);
49        }
50      }
51    }
52
53    public abstract IEnumerable<double> EstimatedValues { get; }
54    public abstract IEnumerable<double> EstimatedTrainingValues { get; }
55    public abstract IEnumerable<double> EstimatedTestValues { get; }
56
57    protected DataAnalysisSolution() : base() { }
58    protected DataAnalysisSolution(DataAnalysisProblemData problemData)
59      : this() {
60      this.problemData = problemData;
61      Initialize();
62    }
63
64    [StorableConstructor]
65    private DataAnalysisSolution(bool deserializing) : base(deserializing) { }
66
67    [StorableHook(HookType.AfterDeserialization)]
68    private void Initialize() {
69      if (problemData != null) RegisterProblemDataEvents();
70    }
71
72    public override IDeepCloneable Clone(Cloner cloner) {
73      DataAnalysisSolution clone = (DataAnalysisSolution)base.Clone(cloner);
74      // don't clone the problem data!
75      clone.problemData = problemData;
76      clone.Initialize();
77      return clone;
78    }
79
80    #region Events
81    protected virtual void RegisterProblemDataEvents() {
82      ProblemData.ProblemDataChanged += new EventHandler(ProblemData_Changed);
83    }
84    protected virtual void DeregisterProblemDataEvents() {
85      ProblemData.ProblemDataChanged += new EventHandler(ProblemData_Changed);
86    }
87
88    private void ProblemData_Changed(object sender, EventArgs e) {
89      OnProblemDataChanged(EventArgs.Empty);
90    }
91
92    public event EventHandler ProblemDataChanged;
93    protected virtual void OnProblemDataChanged(EventArgs e) {
94      var listeners = ProblemDataChanged;
95      if (listeners != null)
96        listeners(this, e);
97    }
98
99    public event EventHandler EstimatedValuesChanged;
100    protected virtual void OnEstimatedValuesChanged(EventArgs e) {
101      var listeners = EstimatedValuesChanged;
102      if (listeners != null)
103        listeners(this, e);
104    }
105    #endregion
106  }
107}
Note: See TracBrowser for help on using the repository browser.