Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PersistenceSpeedUp/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisSolution.cs @ 6459

Last change on this file since 6459 was 5914, checked in by mkommend, 14 years ago

#1418: Changed DataAnalysisSolutions and -Models and updated GenerateRowsToEvaluate method in SymbolicDataAnalysisEvaluator.

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