[3408] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2010 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;
|
---|
[4068] | 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Linq;
|
---|
[3408] | 25 | using HeuristicLab.Common;
|
---|
| 26 | using HeuristicLab.Core;
|
---|
| 27 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 28 |
|
---|
| 29 | namespace HeuristicLab.Problems.DataAnalysis {
|
---|
| 30 | /// <summary>
|
---|
| 31 | /// Represents a solution for a data analysis problem which can be visualized in the GUI.
|
---|
| 32 | /// </summary>
|
---|
| 33 | [Item("DataAnalysisSolution", "Represents a solution for a data analysis problem which can be visualized in the GUI.")]
|
---|
| 34 | [StorableClass]
|
---|
[4451] | 35 | public abstract class DataAnalysisSolution : NamedItem, IStorableContent {
|
---|
| 36 | #region IStorableContent Members
|
---|
| 37 | public string Filename { get; set; }
|
---|
| 38 | #endregion
|
---|
| 39 |
|
---|
[3884] | 40 | protected DataAnalysisSolution()
|
---|
| 41 | : base() { }
|
---|
| 42 | protected DataAnalysisSolution(DataAnalysisProblemData problemData) : this(problemData, double.NegativeInfinity, double.PositiveInfinity) { }
|
---|
| 43 | protected DataAnalysisSolution(DataAnalysisProblemData problemData, double lowerEstimationLimit, double upperEstimationLimit)
|
---|
| 44 | : this() {
|
---|
| 45 | this.problemData = problemData;
|
---|
| 46 | this.lowerEstimationLimit = lowerEstimationLimit;
|
---|
| 47 | this.upperEstimationLimit = upperEstimationLimit;
|
---|
| 48 | Initialize();
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | [StorableConstructor]
|
---|
| 52 | private DataAnalysisSolution(bool deserializing) : base(deserializing) { }
|
---|
| 53 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 54 | private void Initialize() {
|
---|
[3921] | 55 | if (problemData != null)
|
---|
| 56 | RegisterProblemDataEvents();
|
---|
[3884] | 57 | }
|
---|
| 58 |
|
---|
[3408] | 59 | [Storable]
|
---|
| 60 | private DataAnalysisProblemData problemData;
|
---|
| 61 | public DataAnalysisProblemData ProblemData {
|
---|
| 62 | get { return problemData; }
|
---|
| 63 | set {
|
---|
| 64 | if (problemData != value) {
|
---|
[3442] | 65 | if (value == null) throw new ArgumentNullException();
|
---|
[3884] | 66 | if (model != null && problemData != null && !problemData.InputVariables.Select(c => c.Value).SequenceEqual(
|
---|
| 67 | value.InputVariables.Select(c => c.Value)))
|
---|
| 68 | throw new ArgumentException("Could not set new problem data with different structure");
|
---|
| 69 |
|
---|
[3408] | 70 | if (problemData != null) DeregisterProblemDataEvents();
|
---|
| 71 | problemData = value;
|
---|
[3442] | 72 | RegisterProblemDataEvents();
|
---|
[3884] | 73 | OnProblemDataChanged();
|
---|
[3915] | 74 | RecalculateEstimatedValues();
|
---|
[3408] | 75 | }
|
---|
| 76 | }
|
---|
| 77 | }
|
---|
[3884] | 78 |
|
---|
[3513] | 79 | [Storable]
|
---|
[3884] | 80 | private IDataAnalysisModel model;
|
---|
| 81 | public IDataAnalysisModel Model {
|
---|
| 82 | get { return model; }
|
---|
| 83 | set {
|
---|
| 84 | if (model != value) {
|
---|
| 85 | if (value == null) throw new ArgumentNullException();
|
---|
| 86 | model = value;
|
---|
| 87 | OnModelChanged();
|
---|
[3915] | 88 | RecalculateEstimatedValues();
|
---|
[3884] | 89 | }
|
---|
| 90 | }
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | [Storable]
|
---|
[3513] | 94 | private double lowerEstimationLimit;
|
---|
| 95 | public double LowerEstimationLimit {
|
---|
| 96 | get { return lowerEstimationLimit; }
|
---|
| 97 | set {
|
---|
| 98 | if (lowerEstimationLimit != value) {
|
---|
| 99 | lowerEstimationLimit = value;
|
---|
[3884] | 100 | RecalculateEstimatedValues();
|
---|
[3513] | 101 | }
|
---|
| 102 | }
|
---|
| 103 | }
|
---|
[3442] | 104 |
|
---|
[3513] | 105 | [Storable]
|
---|
| 106 | private double upperEstimationLimit;
|
---|
| 107 | public double UpperEstimationLimit {
|
---|
| 108 | get { return upperEstimationLimit; }
|
---|
| 109 | set {
|
---|
| 110 | if (upperEstimationLimit != value) {
|
---|
| 111 | upperEstimationLimit = value;
|
---|
[3884] | 112 | RecalculateEstimatedValues();
|
---|
[3513] | 113 | }
|
---|
| 114 | }
|
---|
| 115 | }
|
---|
| 116 |
|
---|
[3462] | 117 | public abstract IEnumerable<double> EstimatedValues { get; }
|
---|
| 118 | public abstract IEnumerable<double> EstimatedTrainingValues { get; }
|
---|
| 119 | public abstract IEnumerable<double> EstimatedTestValues { get; }
|
---|
[3884] | 120 | protected abstract void RecalculateEstimatedValues();
|
---|
[3442] | 121 |
|
---|
[3408] | 122 | #region Events
|
---|
[3462] | 123 | protected virtual void RegisterProblemDataEvents() {
|
---|
[3442] | 124 | ProblemData.ProblemDataChanged += new EventHandler(ProblemData_Changed);
|
---|
[3408] | 125 | }
|
---|
[3462] | 126 | protected virtual void DeregisterProblemDataEvents() {
|
---|
[3442] | 127 | ProblemData.ProblemDataChanged += new EventHandler(ProblemData_Changed);
|
---|
[3408] | 128 | }
|
---|
[3442] | 129 | private void ProblemData_Changed(object sender, EventArgs e) {
|
---|
[3884] | 130 | OnProblemDataChanged();
|
---|
[3408] | 131 | }
|
---|
[3462] | 132 |
|
---|
| 133 | public event EventHandler ProblemDataChanged;
|
---|
[3884] | 134 | protected virtual void OnProblemDataChanged() {
|
---|
[3462] | 135 | var listeners = ProblemDataChanged;
|
---|
| 136 | if (listeners != null)
|
---|
[3884] | 137 | listeners(this, EventArgs.Empty);
|
---|
[3462] | 138 | }
|
---|
| 139 |
|
---|
[3884] | 140 | public event EventHandler ModelChanged;
|
---|
| 141 | protected virtual void OnModelChanged() {
|
---|
| 142 | EventHandler handler = ModelChanged;
|
---|
| 143 | if (handler != null)
|
---|
| 144 | handler(this, EventArgs.Empty);
|
---|
| 145 | }
|
---|
| 146 |
|
---|
[3462] | 147 | public event EventHandler EstimatedValuesChanged;
|
---|
[3884] | 148 | protected virtual void OnEstimatedValuesChanged() {
|
---|
[3462] | 149 | var listeners = EstimatedValuesChanged;
|
---|
| 150 | if (listeners != null)
|
---|
[3884] | 151 | listeners(this, EventArgs.Empty);
|
---|
[3462] | 152 | }
|
---|
[3408] | 153 | #endregion
|
---|
[3884] | 154 |
|
---|
| 155 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 156 | DataAnalysisSolution clone = (DataAnalysisSolution)base.Clone(cloner);
|
---|
[3933] | 157 | clone.problemData = (DataAnalysisProblemData)cloner.Clone(problemData);
|
---|
[3921] | 158 | clone.model = (IDataAnalysisModel)cloner.Clone(model);
|
---|
[3884] | 159 | clone.lowerEstimationLimit = lowerEstimationLimit;
|
---|
| 160 | clone.upperEstimationLimit = upperEstimationLimit;
|
---|
| 161 | clone.Initialize();
|
---|
[3921] | 162 |
|
---|
[3884] | 163 | return clone;
|
---|
| 164 | }
|
---|
[3408] | 165 | }
|
---|
| 166 | }
|
---|