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