Changeset 3661 for trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/SingleObjectiveTestFunctionSolution.cs
- Timestamp:
- 05/06/10 02:00:55 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/SingleObjectiveTestFunctionSolution.cs
r3647 r3661 21 21 22 22 using System; 23 using System. Collections.Generic;24 using System.Linq;25 using System.Text;23 using System.Drawing; 24 using HeuristicLab.Collections; 25 using HeuristicLab.Common; 26 26 using HeuristicLab.Core; 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;28 using System.Drawing;29 27 using HeuristicLab.Data; 30 28 using HeuristicLab.Encodings.RealVectorEncoding; 31 using HeuristicLab. Common;29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 32 30 33 31 namespace HeuristicLab.Problems.TestFunctions { … … 43 41 44 42 [Storable] 45 private RealVector realVector; 46 public RealVector RealVector { 47 get { return realVector; } 48 set { 49 if (realVector != value) { 50 if (realVector != null) DeregisterRealVectorEvents(); 51 realVector = value; 52 if (realVector != null) RegisterRealVectorEvents(); 43 private RealVector bestKnownRealVector; 44 public RealVector BestKnownRealVector { 45 get { return bestKnownRealVector; } 46 set { 47 if (bestKnownRealVector != value) { 48 if (bestKnownRealVector != null) DeregisterBestKnownRealVectorEvents(); 49 bestKnownRealVector = value; 50 if (bestKnownRealVector != null) RegisterBestKnownRealVectorEvents(); 51 OnBestKnownRealVectorChanged(); 52 } 53 } 54 } 55 56 [Storable] 57 private RealVector bestRealVector; 58 public RealVector BestRealVector { 59 get { return bestRealVector; } 60 set { 61 if (bestRealVector != value) { 62 if (bestRealVector != null) DeregisterRealVectorEvents(); 63 bestRealVector = value; 64 if (bestRealVector != null) RegisterRealVectorEvents(); 53 65 OnRealVectorChanged(); 54 66 } … … 57 69 58 70 [Storable] 59 private DoubleValue quality;60 public DoubleValue Quality {61 get { return quality; }62 set { 63 if ( quality != value) {64 if ( quality != null) DeregisterQualityEvents();65 quality = value;66 if ( quality != null) RegisterQualityEvents();71 private DoubleValue bestQuality; 72 public DoubleValue BestQuality { 73 get { return bestQuality; } 74 set { 75 if (bestQuality != value) { 76 if (bestQuality != null) DeregisterQualityEvents(); 77 bestQuality = value; 78 if (bestQuality != null) RegisterQualityEvents(); 67 79 OnQualityChanged(); 68 80 } … … 70 82 } 71 83 84 [Storable] 85 private ItemArray<RealVector> population; 86 public ItemArray<RealVector> Population { 87 get { return population; } 88 set { 89 if (population != value) { 90 if (population != null) DeregisterPopulationEvents(); 91 population = value; 92 if (population != null) RegisterPopulationEvents(); 93 OnPopulationChanged(); 94 } 95 } 96 } 97 98 [Storable] 99 private ISingleObjectiveTestFunctionProblemEvaluator evaluator; 100 public ISingleObjectiveTestFunctionProblemEvaluator Evaluator { 101 get { return evaluator; } 102 set { 103 if (evaluator != value) { 104 evaluator = value; 105 OnEvaluatorChanged(); 106 } 107 } 108 } 109 110 private Image fitnessLandscape; 111 public Image FitnessLandscape { 112 get { return fitnessLandscape; } 113 set { fitnessLandscape = value; } 114 } 115 72 116 public SingleObjectiveTestFunctionSolution() : base() { } 73 public SingleObjectiveTestFunctionSolution(RealVector realVector, DoubleValue quality )117 public SingleObjectiveTestFunctionSolution(RealVector realVector, DoubleValue quality, ISingleObjectiveTestFunctionProblemEvaluator evaluator) 74 118 : base() { 75 this.realVector = realVector; 76 this.quality = quality; 119 this.bestRealVector = realVector; 120 this.bestQuality = quality; 121 this.evaluator = evaluator; 77 122 Initialize(); 78 123 } … … 82 127 [StorableHook(HookType.AfterDeserialization)] 83 128 private void Initialize() { 84 if (realVector != null) RegisterRealVectorEvents(); 85 if (quality != null) RegisterQualityEvents(); 129 if (bestKnownRealVector != null) RegisterBestKnownRealVectorEvents(); 130 if (bestRealVector != null) RegisterRealVectorEvents(); 131 if (bestQuality != null) RegisterQualityEvents(); 132 if (population != null) RegisterPopulationEvents(); 86 133 } 87 134 … … 89 136 SingleObjectiveTestFunctionSolution clone = new SingleObjectiveTestFunctionSolution(); 90 137 cloner.RegisterClonedObject(this, clone); 91 clone.realVector = (RealVector)cloner.Clone(realVector); 92 clone.quality = (DoubleValue)cloner.Clone(quality); 138 clone.bestKnownRealVector = (RealVector)cloner.Clone(bestKnownRealVector); 139 clone.bestRealVector = (RealVector)cloner.Clone(bestRealVector); 140 clone.bestQuality = (DoubleValue)cloner.Clone(bestQuality); 141 clone.population = (ItemArray<RealVector>)cloner.Clone(population); 142 clone.evaluator = (ISingleObjectiveTestFunctionProblemEvaluator)cloner.Clone(evaluator); 143 clone.fitnessLandscape = null; 93 144 clone.Initialize(); 94 145 return clone; … … 96 147 97 148 #region Events 149 public event EventHandler BestKnownRealVectorChanged; 150 private void OnBestKnownRealVectorChanged() { 151 var changed = BestKnownRealVectorChanged; 152 if (changed != null) 153 changed(this, EventArgs.Empty); 154 } 155 98 156 public event EventHandler RealVectorChanged; 99 157 private void OnRealVectorChanged() { … … 110 168 } 111 169 170 public event EventHandler PopulationChanged; 171 private void OnPopulationChanged() { 172 var changed = PopulationChanged; 173 if (changed != null) 174 changed(this, EventArgs.Empty); 175 } 176 177 public event EventHandler EvaluatorChanged; 178 private void OnEvaluatorChanged() { 179 var changed = EvaluatorChanged; 180 if (changed != null) 181 changed(this, EventArgs.Empty); 182 } 183 184 private void RegisterBestKnownRealVectorEvents() { 185 BestKnownRealVector.ItemChanged += new EventHandler<EventArgs<int>>(BestKnownRealVector_ItemChanged); 186 BestKnownRealVector.Reset += new EventHandler(BestKnownRealVector_Reset); 187 } 188 private void DeregisterBestKnownRealVectorEvents() { 189 BestKnownRealVector.ItemChanged -= new EventHandler<EventArgs<int>>(BestKnownRealVector_ItemChanged); 190 BestKnownRealVector.Reset -= new EventHandler(BestKnownRealVector_Reset); 191 } 112 192 private void RegisterRealVectorEvents() { 113 RealVector.ItemChanged += new EventHandler<EventArgs<int>>(RealVector_ItemChanged); 114 RealVector.Reset += new EventHandler(RealVector_Reset); 115 } 116 193 BestRealVector.ItemChanged += new EventHandler<EventArgs<int>>(RealVector_ItemChanged); 194 BestRealVector.Reset += new EventHandler(RealVector_Reset); 195 } 117 196 private void DeregisterRealVectorEvents() { 118 RealVector.ItemChanged -= new EventHandler<EventArgs<int>>(RealVector_ItemChanged);119 RealVector.Reset -= new EventHandler(RealVector_Reset);197 BestRealVector.ItemChanged -= new EventHandler<EventArgs<int>>(RealVector_ItemChanged); 198 BestRealVector.Reset -= new EventHandler(RealVector_Reset); 120 199 } 121 200 private void RegisterQualityEvents() { 122 Quality.ValueChanged += new EventHandler(Quality_ValueChanged);201 BestQuality.ValueChanged += new EventHandler(Quality_ValueChanged); 123 202 } 124 203 private void DeregisterQualityEvents() { 125 Quality.ValueChanged -= new EventHandler(Quality_ValueChanged); 126 } 127 204 BestQuality.ValueChanged -= new EventHandler(Quality_ValueChanged); 205 } 206 private void RegisterPopulationEvents() { 207 Population.CollectionReset += new CollectionItemsChangedEventHandler<IndexedItem<RealVector>>(Population_CollectionReset); 208 Population.ItemsMoved += new CollectionItemsChangedEventHandler<IndexedItem<RealVector>>(Population_ItemsMoved); 209 Population.ItemsReplaced += new CollectionItemsChangedEventHandler<IndexedItem<RealVector>>(Population_ItemsReplaced); 210 } 211 private void DeregisterPopulationEvents() { 212 Population.CollectionReset -= new CollectionItemsChangedEventHandler<IndexedItem<RealVector>>(Population_CollectionReset); 213 Population.ItemsMoved -= new CollectionItemsChangedEventHandler<IndexedItem<RealVector>>(Population_ItemsMoved); 214 Population.ItemsReplaced -= new CollectionItemsChangedEventHandler<IndexedItem<RealVector>>(Population_ItemsReplaced); 215 } 216 217 private void BestKnownRealVector_ItemChanged(object sender, EventArgs<int> e) { 218 OnBestKnownRealVectorChanged(); 219 } 220 private void BestKnownRealVector_Reset(object sender, EventArgs e) { 221 OnBestKnownRealVectorChanged(); 222 } 128 223 private void RealVector_ItemChanged(object sender, EventArgs<int> e) { 129 224 OnRealVectorChanged(); … … 134 229 private void Quality_ValueChanged(object sender, EventArgs e) { 135 230 OnQualityChanged(); 231 } 232 private void Population_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IndexedItem<RealVector>> e) { 233 OnPopulationChanged(); 234 } 235 private void Population_ItemsMoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<RealVector>> e) { 236 OnPopulationChanged(); 237 } 238 private void Population_CollectionReset(object sender, CollectionItemsChangedEventArgs<IndexedItem<RealVector>> e) { 239 OnPopulationChanged(); 136 240 } 137 241 #endregion
Note: See TracChangeset
for help on using the changeset viewer.