[5620] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[14185] | 3 | * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[5620] | 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 |
|
---|
[5777] | 22 | using System;
|
---|
[11330] | 23 | using System.Collections.Generic;
|
---|
[5777] | 24 | using System.Drawing;
|
---|
[5620] | 25 | using HeuristicLab.Common;
|
---|
[5777] | 26 | using HeuristicLab.Optimization;
|
---|
[14927] | 27 | using HeuristicLab.Persistence;
|
---|
[5620] | 28 |
|
---|
| 29 | namespace HeuristicLab.Problems.DataAnalysis {
|
---|
| 30 | /// <summary>
|
---|
| 31 | /// Abstract base class for data analysis solutions
|
---|
| 32 | /// </summary>
|
---|
[14927] | 33 | [StorableType("20122af0-c1b5-4e82-8b18-b142ef7a8c56")]
|
---|
[5620] | 34 | public abstract class DataAnalysisSolution : ResultCollection, IDataAnalysisSolution {
|
---|
| 35 | private const string ModelResultName = "Model";
|
---|
| 36 | private const string ProblemDataResultName = "ProblemData";
|
---|
[5624] | 37 |
|
---|
[5909] | 38 | public string Filename { get; set; }
|
---|
| 39 |
|
---|
[7201] | 40 | public static new Image StaticItemImage {
|
---|
[5624] | 41 | get { return HeuristicLab.Common.Resources.VSImageLibrary.Function; }
|
---|
| 42 | }
|
---|
| 43 |
|
---|
[5620] | 44 | #region properties
|
---|
| 45 | public IDataAnalysisModel Model {
|
---|
| 46 | get { return (IDataAnalysisModel)this[ModelResultName].Value; }
|
---|
[5717] | 47 | protected set {
|
---|
| 48 | if (this[ModelResultName].Value != value) {
|
---|
| 49 | if (value != null) {
|
---|
| 50 | this[ModelResultName].Value = value;
|
---|
[6606] | 51 | OnModelChanged();
|
---|
[5717] | 52 | }
|
---|
| 53 | }
|
---|
| 54 | }
|
---|
[5620] | 55 | }
|
---|
| 56 |
|
---|
| 57 | public IDataAnalysisProblemData ProblemData {
|
---|
| 58 | get { return (IDataAnalysisProblemData)this[ProblemDataResultName].Value; }
|
---|
[6653] | 59 | set {
|
---|
[5717] | 60 | if (this[ProblemDataResultName].Value != value) {
|
---|
| 61 | if (value != null) {
|
---|
| 62 | ProblemData.Changed -= new EventHandler(ProblemData_Changed);
|
---|
| 63 | this[ProblemDataResultName].Value = value;
|
---|
| 64 | ProblemData.Changed += new EventHandler(ProblemData_Changed);
|
---|
[6606] | 65 | OnProblemDataChanged();
|
---|
[5717] | 66 | }
|
---|
| 67 | }
|
---|
| 68 | }
|
---|
[5620] | 69 | }
|
---|
| 70 | #endregion
|
---|
| 71 |
|
---|
| 72 | [StorableConstructor]
|
---|
| 73 | protected DataAnalysisSolution(bool deserializing) : base(deserializing) { }
|
---|
| 74 | protected DataAnalysisSolution(DataAnalysisSolution original, Cloner cloner)
|
---|
| 75 | : base(original, cloner) {
|
---|
| 76 | name = original.Name;
|
---|
| 77 | description = original.Description;
|
---|
| 78 | }
|
---|
[5624] | 79 | public DataAnalysisSolution(IDataAnalysisModel model, IDataAnalysisProblemData problemData)
|
---|
[5620] | 80 | : base() {
|
---|
[5649] | 81 | name = ItemName;
|
---|
| 82 | description = ItemDescription;
|
---|
[6588] | 83 | Add(new Result(ModelResultName, "The data analysis model.", model));
|
---|
| 84 | Add(new Result(ProblemDataResultName, "The data analysis problem data.", problemData));
|
---|
[5624] | 85 |
|
---|
[5914] | 86 | problemData.Changed += new EventHandler(ProblemData_Changed);
|
---|
[5620] | 87 | }
|
---|
| 88 |
|
---|
[6411] | 89 | protected abstract void RecalculateResults();
|
---|
| 90 |
|
---|
[5624] | 91 | private void ProblemData_Changed(object sender, EventArgs e) {
|
---|
[6606] | 92 | OnProblemDataChanged();
|
---|
[5624] | 93 | }
|
---|
| 94 |
|
---|
[5620] | 95 | public event EventHandler ModelChanged;
|
---|
[6606] | 96 | protected virtual void OnModelChanged() {
|
---|
[6411] | 97 | RecalculateResults();
|
---|
[5620] | 98 | var listeners = ModelChanged;
|
---|
[6606] | 99 | if (listeners != null) listeners(this, EventArgs.Empty);
|
---|
[5620] | 100 | }
|
---|
| 101 |
|
---|
| 102 | public event EventHandler ProblemDataChanged;
|
---|
[6606] | 103 | protected virtual void OnProblemDataChanged() {
|
---|
[6411] | 104 | RecalculateResults();
|
---|
[5620] | 105 | var listeners = ProblemDataChanged;
|
---|
[6606] | 106 | if (listeners != null) listeners(this, EventArgs.Empty);
|
---|
[5620] | 107 | }
|
---|
| 108 |
|
---|
[11330] | 109 | //mkommend avoid unnecessary event registration for result name changes
|
---|
| 110 | protected override void RegisterItemEvents(IEnumerable<IResult> items) { }
|
---|
| 111 | protected override void DeregisterItemEvents(IEnumerable<IResult> items) { }
|
---|
| 112 |
|
---|
[5620] | 113 | #region INamedItem Members
|
---|
| 114 | [Storable]
|
---|
| 115 | protected string name;
|
---|
| 116 | public string Name {
|
---|
| 117 | get { return name; }
|
---|
| 118 | set {
|
---|
| 119 | if (!CanChangeName) throw new NotSupportedException("Name cannot be changed.");
|
---|
| 120 | if (!(name.Equals(value) || (value == null) && (name == string.Empty))) {
|
---|
| 121 | CancelEventArgs<string> e = value == null ? new CancelEventArgs<string>(string.Empty) : new CancelEventArgs<string>(value);
|
---|
| 122 | OnNameChanging(e);
|
---|
| 123 | if (!e.Cancel) {
|
---|
| 124 | name = value == null ? string.Empty : value;
|
---|
| 125 | OnNameChanged();
|
---|
| 126 | }
|
---|
| 127 | }
|
---|
| 128 | }
|
---|
| 129 | }
|
---|
| 130 | public virtual bool CanChangeName {
|
---|
| 131 | get { return true; }
|
---|
| 132 | }
|
---|
| 133 | [Storable]
|
---|
| 134 | protected string description;
|
---|
| 135 | public string Description {
|
---|
| 136 | get { return description; }
|
---|
| 137 | set {
|
---|
| 138 | if (!CanChangeDescription) throw new NotSupportedException("Description cannot be changed.");
|
---|
| 139 | if (!(description.Equals(value) || (value == null) && (description == string.Empty))) {
|
---|
| 140 | description = value == null ? string.Empty : value;
|
---|
| 141 | OnDescriptionChanged();
|
---|
| 142 | }
|
---|
| 143 | }
|
---|
| 144 | }
|
---|
| 145 | public virtual bool CanChangeDescription {
|
---|
| 146 | get { return true; }
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 | public override string ToString() {
|
---|
| 150 | return Name;
|
---|
| 151 | }
|
---|
| 152 |
|
---|
| 153 | public event EventHandler<CancelEventArgs<string>> NameChanging;
|
---|
| 154 | protected virtual void OnNameChanging(CancelEventArgs<string> e) {
|
---|
| 155 | var handler = NameChanging;
|
---|
| 156 | if (handler != null) handler(this, e);
|
---|
| 157 | }
|
---|
| 158 |
|
---|
| 159 | public event EventHandler NameChanged;
|
---|
| 160 | protected virtual void OnNameChanged() {
|
---|
| 161 | var handler = NameChanged;
|
---|
| 162 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
| 163 | OnToStringChanged();
|
---|
| 164 | }
|
---|
| 165 |
|
---|
| 166 | public event EventHandler DescriptionChanged;
|
---|
| 167 | protected virtual void OnDescriptionChanged() {
|
---|
| 168 | var handler = DescriptionChanged;
|
---|
| 169 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
| 170 | }
|
---|
| 171 | #endregion
|
---|
| 172 | }
|
---|
| 173 | }
|
---|