Free cookie consent management tool by TermsFeed Policy Generator

source: branches/WebJobManager/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisSolution.cs @ 15301

Last change on this file since 15301 was 13656, checked in by ascheibe, 9 years ago

#2582 created branch for Hive Web Job Manager

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