Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/DataAnalysisSolution.cs @ 5624

Last change on this file since 5624 was 5624, checked in by gkronber, 13 years ago

#1418 renamed interface for interpreter, worked on solutions and models and implemented SVM regression.

File size: 5.8 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 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.Collections.Generic;
23using System.Linq;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Data;
27using HeuristicLab.Operators;
28using HeuristicLab.Parameters;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30using HeuristicLab.Optimization;
31using System;
32using System.Drawing;
33
34namespace HeuristicLab.Problems.DataAnalysis {
35  /// <summary>
36  /// Abstract base class for data analysis solutions
37  /// </summary>
38  [StorableClass]
39  public abstract class DataAnalysisSolution : ResultCollection, IDataAnalysisSolution {
40    private const string ModelResultName = "Model";
41    private const string ProblemDataResultName = "ProblemData";
42
43    public override Image ItemImage {
44      get { return HeuristicLab.Common.Resources.VSImageLibrary.Function; }
45    }
46
47    #region properties
48    public IDataAnalysisModel Model {
49      get { return (IDataAnalysisModel)this[ModelResultName].Value; }
50      //set {
51      //  if (this[ModelResultName].Value != value) {
52      //    if (value != null) {
53      //      this[ModelResultName].Value = value;
54      //      OnModelChanged(EventArgs.Empty);
55      //    }
56      //  }
57      //}
58    }
59
60    public IDataAnalysisProblemData ProblemData {
61      get { return (IDataAnalysisProblemData)this[ProblemDataResultName].Value; }
62      //set {
63      //  if (this[ProblemDataResultName].Value != value) {
64      //    if (value != null) {
65      //      ProblemData.Changed -= new EventHandler(ProblemData_Changed);
66      //      this[ProblemDataResultName].Value = value;
67      //      ProblemData.Changed += new EventHandler(ProblemData_Changed);
68      //      OnProblemDataChanged(EventArgs.Empty);
69      //    }
70      //  }
71      //}
72    }
73    #endregion
74
75    [StorableConstructor]
76    protected DataAnalysisSolution(bool deserializing) : base(deserializing) { }
77    protected DataAnalysisSolution(DataAnalysisSolution original, Cloner cloner)
78      : base(original, cloner) {
79      name = original.Name;
80      description = original.Description;
81    }
82    public DataAnalysisSolution(IDataAnalysisModel model, IDataAnalysisProblemData problemData)
83      : base() {
84      name = string.Empty;
85      description = string.Empty;
86      Add(new Result(ModelResultName, "The symbolic data analysis model.", model));
87      Add(new Result(ProblemDataResultName, "The symbolic data analysis problem data.", problemData));
88
89      problemData.Changed += new EventHandler(ProblemData_Changed);
90    }
91
92    private void ProblemData_Changed(object sender, EventArgs e) {
93      OnProblemDataChanged(e);
94    }
95
96    public event EventHandler ModelChanged;
97    protected virtual void OnModelChanged(EventArgs e) {
98      var listeners = ModelChanged;
99      if (listeners != null) listeners(this, e);
100    }
101
102    public event EventHandler ProblemDataChanged;
103    protected virtual void OnProblemDataChanged(EventArgs e) {
104      var listeners = ProblemDataChanged;
105      if (listeners != null) listeners(this, e);
106    }
107
108    #region INamedItem Members
109    [Storable]
110    protected string name;
111    public string Name {
112      get { return name; }
113      set {
114        if (!CanChangeName) throw new NotSupportedException("Name cannot be changed.");
115        if (!(name.Equals(value) || (value == null) && (name == string.Empty))) {
116          CancelEventArgs<string> e = value == null ? new CancelEventArgs<string>(string.Empty) : new CancelEventArgs<string>(value);
117          OnNameChanging(e);
118          if (!e.Cancel) {
119            name = value == null ? string.Empty : value;
120            OnNameChanged();
121          }
122        }
123      }
124    }
125    public virtual bool CanChangeName {
126      get { return true; }
127    }
128    [Storable]
129    protected string description;
130    public string Description {
131      get { return description; }
132      set {
133        if (!CanChangeDescription) throw new NotSupportedException("Description cannot be changed.");
134        if (!(description.Equals(value) || (value == null) && (description == string.Empty))) {
135          description = value == null ? string.Empty : value;
136          OnDescriptionChanged();
137        }
138      }
139    }
140    public virtual bool CanChangeDescription {
141      get { return true; }
142    }
143
144    public override string ToString() {
145      return Name;
146    }
147
148    public event EventHandler<CancelEventArgs<string>> NameChanging;
149    protected virtual void OnNameChanging(CancelEventArgs<string> e) {
150      var handler = NameChanging;
151      if (handler != null) handler(this, e);
152    }
153
154    public event EventHandler NameChanged;
155    protected virtual void OnNameChanged() {
156      var handler = NameChanged;
157      if (handler != null) handler(this, EventArgs.Empty);
158      OnToStringChanged();
159    }
160
161    public event EventHandler DescriptionChanged;
162    protected virtual void OnDescriptionChanged() {
163      var handler = DescriptionChanged;
164      if (handler != null) handler(this, EventArgs.Empty);
165    }
166    #endregion
167  }
168}
Note: See TracBrowser for help on using the repository browser.