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 |
|
---|
22 | using System;
|
---|
23 | using System.Drawing;
|
---|
24 | using HeuristicLab.Common;
|
---|
25 | using HeuristicLab.Optimization;
|
---|
26 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
27 |
|
---|
28 | namespace 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();
|
---|
51 | }
|
---|
52 | }
|
---|
53 | }
|
---|
54 | }
|
---|
55 |
|
---|
56 | public IDataAnalysisProblemData ProblemData {
|
---|
57 | get { return (IDataAnalysisProblemData)this[ProblemDataResultName].Value; }
|
---|
58 | 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();
|
---|
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 data analysis model.", model));
|
---|
83 | Add(new Result(ProblemDataResultName, "The data analysis problem data.", problemData));
|
---|
84 |
|
---|
85 | problemData.Changed += new EventHandler(ProblemData_Changed);
|
---|
86 | }
|
---|
87 |
|
---|
88 | protected abstract void RecalculateResults();
|
---|
89 |
|
---|
90 | private void ProblemData_Changed(object sender, EventArgs e) {
|
---|
91 | OnProblemDataChanged();
|
---|
92 | }
|
---|
93 |
|
---|
94 | public event EventHandler ModelChanged;
|
---|
95 | protected virtual void OnModelChanged() {
|
---|
96 | RecalculateResults();
|
---|
97 | RecalculateResults();
|
---|
98 | var listeners = ModelChanged;
|
---|
99 | if (listeners != null) listeners(this, EventArgs.Empty);
|
---|
100 | }
|
---|
101 |
|
---|
102 | public event EventHandler ProblemDataChanged;
|
---|
103 | protected virtual void OnProblemDataChanged() {
|
---|
104 | RecalculateResults();
|
---|
105 | RecalculateResults();
|
---|
106 | var listeners = ProblemDataChanged;
|
---|
107 | if (listeners != null) listeners(this, EventArgs.Empty);
|
---|
108 | }
|
---|
109 |
|
---|
110 | #region INamedItem Members
|
---|
111 | [Storable]
|
---|
112 | protected string name;
|
---|
113 | public string Name {
|
---|
114 | get { return name; }
|
---|
115 | set {
|
---|
116 | if (!CanChangeName) throw new NotSupportedException("Name cannot be changed.");
|
---|
117 | if (!(name.Equals(value) || (value == null) && (name == string.Empty))) {
|
---|
118 | CancelEventArgs<string> e = value == null ? new CancelEventArgs<string>(string.Empty) : new CancelEventArgs<string>(value);
|
---|
119 | OnNameChanging(e);
|
---|
120 | if (!e.Cancel) {
|
---|
121 | name = value == null ? string.Empty : value;
|
---|
122 | OnNameChanged();
|
---|
123 | }
|
---|
124 | }
|
---|
125 | }
|
---|
126 | }
|
---|
127 | public virtual bool CanChangeName {
|
---|
128 | get { return true; }
|
---|
129 | }
|
---|
130 | [Storable]
|
---|
131 | protected string description;
|
---|
132 | public string Description {
|
---|
133 | get { return description; }
|
---|
134 | set {
|
---|
135 | if (!CanChangeDescription) throw new NotSupportedException("Description cannot be changed.");
|
---|
136 | if (!(description.Equals(value) || (value == null) && (description == string.Empty))) {
|
---|
137 | description = value == null ? string.Empty : value;
|
---|
138 | OnDescriptionChanged();
|
---|
139 | }
|
---|
140 | }
|
---|
141 | }
|
---|
142 | public virtual bool CanChangeDescription {
|
---|
143 | get { return true; }
|
---|
144 | }
|
---|
145 |
|
---|
146 | public override string ToString() {
|
---|
147 | return Name;
|
---|
148 | }
|
---|
149 |
|
---|
150 | public event EventHandler<CancelEventArgs<string>> NameChanging;
|
---|
151 | protected virtual void OnNameChanging(CancelEventArgs<string> e) {
|
---|
152 | var handler = NameChanging;
|
---|
153 | if (handler != null) handler(this, e);
|
---|
154 | }
|
---|
155 |
|
---|
156 | public event EventHandler NameChanged;
|
---|
157 | protected virtual void OnNameChanged() {
|
---|
158 | var handler = NameChanged;
|
---|
159 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
160 | OnToStringChanged();
|
---|
161 | }
|
---|
162 |
|
---|
163 | public event EventHandler DescriptionChanged;
|
---|
164 | protected virtual void OnDescriptionChanged() {
|
---|
165 | var handler = DescriptionChanged;
|
---|
166 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
167 | }
|
---|
168 | #endregion
|
---|
169 | }
|
---|
170 | }
|
---|