- Timestamp:
- 06/01/10 17:58:03 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/DataAnalysisSolution.cs
r3710 r3884 36 36 [StorableClass] 37 37 public abstract class DataAnalysisSolution : NamedItem { 38 protected DataAnalysisSolution() 39 : base() { } 40 protected DataAnalysisSolution(DataAnalysisProblemData problemData) : this(problemData, double.NegativeInfinity, double.PositiveInfinity) { } 41 protected DataAnalysisSolution(DataAnalysisProblemData problemData, double lowerEstimationLimit, double upperEstimationLimit) 42 : this() { 43 this.problemData = problemData; 44 this.lowerEstimationLimit = lowerEstimationLimit; 45 this.upperEstimationLimit = upperEstimationLimit; 46 Initialize(); 47 } 48 49 [StorableConstructor] 50 private DataAnalysisSolution(bool deserializing) : base(deserializing) { } 51 [StorableHook(HookType.AfterDeserialization)] 52 private void Initialize() { 53 if (problemData != null) RegisterProblemDataEvents(); 54 } 55 38 56 [Storable] 39 57 private DataAnalysisProblemData problemData; … … 43 61 if (problemData != value) { 44 62 if (value == null) throw new ArgumentNullException(); 63 if (model != null && problemData != null && !problemData.InputVariables.Select(c => c.Value).SequenceEqual( 64 value.InputVariables.Select(c => c.Value))) 65 throw new ArgumentException("Could not set new problem data with different structure"); 66 45 67 if (problemData != null) DeregisterProblemDataEvents(); 46 68 problemData = value; 47 69 RegisterProblemDataEvents(); 48 OnProblemDataChanged( EventArgs.Empty);70 OnProblemDataChanged(); 49 71 } 50 72 } 51 73 } 74 75 [Storable] 76 private IDataAnalysisModel model; 77 public IDataAnalysisModel Model { 78 get { return model; } 79 set { 80 if (model != value) { 81 if (value == null) throw new ArgumentNullException(); 82 model = value; 83 OnModelChanged(); 84 } 85 } 86 } 87 52 88 [Storable] 53 89 private double lowerEstimationLimit; … … 57 93 if (lowerEstimationLimit != value) { 58 94 lowerEstimationLimit = value; 59 OnEstimatedValuesChanged(EventArgs.Empty);95 RecalculateEstimatedValues(); 60 96 } 61 97 } … … 69 105 if (upperEstimationLimit != value) { 70 106 upperEstimationLimit = value; 71 OnEstimatedValuesChanged(EventArgs.Empty);107 RecalculateEstimatedValues(); 72 108 } 73 109 } … … 77 113 public abstract IEnumerable<double> EstimatedTrainingValues { get; } 78 114 public abstract IEnumerable<double> EstimatedTestValues { get; } 79 80 protected DataAnalysisSolution() : base() { 81 Name = ItemName; 82 Description = ItemDescription; 83 } 84 protected DataAnalysisSolution(DataAnalysisProblemData problemData) : this(problemData, double.NegativeInfinity, double.PositiveInfinity) { } 85 protected DataAnalysisSolution(DataAnalysisProblemData problemData, double lowerEstimationLimit, double upperEstimationLimit) 86 : this() { 87 this.problemData = problemData; 88 this.lowerEstimationLimit = lowerEstimationLimit; 89 this.upperEstimationLimit = upperEstimationLimit; 90 Initialize(); 91 } 92 93 [StorableConstructor] 94 private DataAnalysisSolution(bool deserializing) : base(deserializing) { } 95 96 [StorableHook(HookType.AfterDeserialization)] 97 private void Initialize() { 98 if (problemData != null) RegisterProblemDataEvents(); 99 } 100 101 public override IDeepCloneable Clone(Cloner cloner) { 102 DataAnalysisSolution clone = (DataAnalysisSolution)base.Clone(cloner); 103 // don't clone the problem data! 104 clone.problemData = problemData; 105 clone.lowerEstimationLimit = lowerEstimationLimit; 106 clone.upperEstimationLimit = upperEstimationLimit; 107 clone.Initialize(); 108 return clone; 109 } 115 protected abstract void RecalculateEstimatedValues(); 110 116 111 117 #region Events … … 116 122 ProblemData.ProblemDataChanged += new EventHandler(ProblemData_Changed); 117 123 } 118 119 124 private void ProblemData_Changed(object sender, EventArgs e) { 120 OnProblemDataChanged( EventArgs.Empty);125 OnProblemDataChanged(); 121 126 } 122 127 123 128 public event EventHandler ProblemDataChanged; 124 protected virtual void OnProblemDataChanged(EventArgs e) { 129 protected virtual void OnProblemDataChanged() { 130 RecalculateEstimatedValues(); 125 131 var listeners = ProblemDataChanged; 126 132 if (listeners != null) 127 listeners(this, e); 133 listeners(this, EventArgs.Empty); 134 } 135 136 public event EventHandler ModelChanged; 137 protected virtual void OnModelChanged() { 138 RecalculateEstimatedValues(); 139 EventHandler handler = ModelChanged; 140 if (handler != null) 141 handler(this, EventArgs.Empty); 128 142 } 129 143 130 144 public event EventHandler EstimatedValuesChanged; 131 protected virtual void OnEstimatedValuesChanged( EventArgs e) {145 protected virtual void OnEstimatedValuesChanged() { 132 146 var listeners = EstimatedValuesChanged; 133 147 if (listeners != null) 134 listeners(this, e);148 listeners(this, EventArgs.Empty); 135 149 } 136 150 #endregion 151 152 public override IDeepCloneable Clone(Cloner cloner) { 153 DataAnalysisSolution clone = (DataAnalysisSolution)base.Clone(cloner); 154 // don't clone the problem data! 155 clone.problemData = problemData; 156 clone.Model = (IDataAnalysisModel)cloner.Clone(model); 157 clone.lowerEstimationLimit = lowerEstimationLimit; 158 clone.upperEstimationLimit = upperEstimationLimit; 159 clone.Initialize(); 160 return clone; 161 } 137 162 } 138 163 }
Note: See TracChangeset
for help on using the changeset viewer.