Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/SingleObjectiveTestFunctionSolution.cs @ 4502

Last change on this file since 4502 was 3894, checked in by abeham, 15 years ago

#1029

  • Added Bounds to SingleObjectiveTestFunctionSolution
  • This would break persistence, so I added a CompatibilityMethod (which can be removed again once moving to 3.4)
File size: 10.4 KB
RevLine 
[3647]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
22using System;
[3661]23using System.Drawing;
24using HeuristicLab.Collections;
25using HeuristicLab.Common;
[3647]26using HeuristicLab.Core;
27using HeuristicLab.Data;
28using HeuristicLab.Encodings.RealVectorEncoding;
[3661]29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
[3647]30
31namespace HeuristicLab.Problems.TestFunctions {
32  /// <summary>
33  /// Represents a SingleObjectiveTestFunctionSolution solution.
34  /// </summary>
35  [Item("SingleObjectiveTestFunctionSolution", "Represents a SingleObjectiveTestFunction solution.")]
36  [StorableClass]
37  public class SingleObjectiveTestFunctionSolution : Item {
38    public override Image ItemImage {
39      get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.Image; }
40    }
41
42    [Storable]
[3661]43    private RealVector bestKnownRealVector;
44    public RealVector BestKnownRealVector {
45      get { return bestKnownRealVector; }
[3647]46      set {
[3661]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) {
[3665]62          if (bestRealVector != null) DeregisterBestRealVectorEvents();
[3661]63          bestRealVector = value;
[3665]64          if (bestRealVector != null) RegisterBestRealVectorEvents();
65          OnBestRealVectorChanged();
[3647]66        }
67      }
68    }
69
70    [Storable]
[3661]71    private DoubleValue bestQuality;
72    public DoubleValue BestQuality {
73      get { return bestQuality; }
[3647]74      set {
[3661]75        if (bestQuality != value) {
76          if (bestQuality != null) DeregisterQualityEvents();
77          bestQuality = value;
78          if (bestQuality != null) RegisterQualityEvents();
[3647]79          OnQualityChanged();
80        }
81      }
82    }
83
[3661]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
[3894]110    [Storable]
111    private DoubleMatrix bounds;
112    public DoubleMatrix Bounds {
113      get { return bounds; }
114      set {
115        if (bounds != value) {
116          if (bounds != null) DeregisterBoundsEvents();
117          bounds = value;
118          if (bounds != null) RegisterBoundsEvents();
119          OnBoundsChanged();
120        }
121      }
122    }
123
[3647]124    public SingleObjectiveTestFunctionSolution() : base() { }
[3661]125    public SingleObjectiveTestFunctionSolution(RealVector realVector, DoubleValue quality, ISingleObjectiveTestFunctionProblemEvaluator evaluator)
[3647]126      : base() {
[3661]127      this.bestRealVector = realVector;
128      this.bestQuality = quality;
129      this.evaluator = evaluator;
[3647]130      Initialize();
131    }
132    [StorableConstructor]
133    private SingleObjectiveTestFunctionSolution(bool deserializing) : base(deserializing) { }
134
135    [StorableHook(HookType.AfterDeserialization)]
136    private void Initialize() {
[3661]137      if (bestKnownRealVector != null) RegisterBestKnownRealVectorEvents();
[3665]138      if (bestRealVector != null) RegisterBestRealVectorEvents();
[3661]139      if (bestQuality != null) RegisterQualityEvents();
140      if (population != null) RegisterPopulationEvents();
[3894]141      if (bounds != null) RegisterBoundsEvents();
[3647]142    }
143
144    public override IDeepCloneable Clone(Cloner cloner) {
145      SingleObjectiveTestFunctionSolution clone = new SingleObjectiveTestFunctionSolution();
146      cloner.RegisterClonedObject(this, clone);
[3661]147      clone.bestKnownRealVector = (RealVector)cloner.Clone(bestKnownRealVector);
148      clone.bestRealVector = (RealVector)cloner.Clone(bestRealVector);
149      clone.bestQuality = (DoubleValue)cloner.Clone(bestQuality);
150      clone.population = (ItemArray<RealVector>)cloner.Clone(population);
151      clone.evaluator = (ISingleObjectiveTestFunctionProblemEvaluator)cloner.Clone(evaluator);
[3894]152      clone.bounds = (DoubleMatrix)cloner.Clone(bounds);
[3647]153      clone.Initialize();
154      return clone;
155    }
156
157    #region Events
[3661]158    public event EventHandler BestKnownRealVectorChanged;
159    private void OnBestKnownRealVectorChanged() {
160      var changed = BestKnownRealVectorChanged;
161      if (changed != null)
162        changed(this, EventArgs.Empty);
163    }
164
[3665]165    public event EventHandler BestRealVectorChanged;
166    private void OnBestRealVectorChanged() {
167      var changed = BestRealVectorChanged;
[3647]168      if (changed != null)
169        changed(this, EventArgs.Empty);
170    }
171
172    public event EventHandler QualityChanged;
173    private void OnQualityChanged() {
174      var changed = QualityChanged;
175      if (changed != null)
176        changed(this, EventArgs.Empty);
177    }
178
[3661]179    public event EventHandler PopulationChanged;
180    private void OnPopulationChanged() {
181      var changed = PopulationChanged;
182      if (changed != null)
183        changed(this, EventArgs.Empty);
184    }
185
186    public event EventHandler EvaluatorChanged;
187    private void OnEvaluatorChanged() {
188      var changed = EvaluatorChanged;
189      if (changed != null)
190        changed(this, EventArgs.Empty);
191    }
192
[3894]193    public event EventHandler BoundsChanged;
194    private void OnBoundsChanged() {
195      var changed = BoundsChanged;
196      if (changed != null)
197        changed(this, EventArgs.Empty);
198    }
199
[3661]200    private void RegisterBestKnownRealVectorEvents() {
201      BestKnownRealVector.ItemChanged += new EventHandler<EventArgs<int>>(BestKnownRealVector_ItemChanged);
202      BestKnownRealVector.Reset += new EventHandler(BestKnownRealVector_Reset);
203    }
204    private void DeregisterBestKnownRealVectorEvents() {
205      BestKnownRealVector.ItemChanged -= new EventHandler<EventArgs<int>>(BestKnownRealVector_ItemChanged);
206      BestKnownRealVector.Reset -= new EventHandler(BestKnownRealVector_Reset);
207    }
[3665]208    private void RegisterBestRealVectorEvents() {
209      BestRealVector.ItemChanged += new EventHandler<EventArgs<int>>(BestRealVector_ItemChanged);
210      BestRealVector.Reset += new EventHandler(BestRealVector_Reset);
[3647]211    }
[3665]212    private void DeregisterBestRealVectorEvents() {
213      BestRealVector.ItemChanged -= new EventHandler<EventArgs<int>>(BestRealVector_ItemChanged);
214      BestRealVector.Reset -= new EventHandler(BestRealVector_Reset);
[3647]215    }
216    private void RegisterQualityEvents() {
[3661]217      BestQuality.ValueChanged += new EventHandler(Quality_ValueChanged);
[3647]218    }
219    private void DeregisterQualityEvents() {
[3661]220      BestQuality.ValueChanged -= new EventHandler(Quality_ValueChanged);
[3647]221    }
[3661]222    private void RegisterPopulationEvents() {
223      Population.CollectionReset += new CollectionItemsChangedEventHandler<IndexedItem<RealVector>>(Population_CollectionReset);
224      Population.ItemsMoved += new CollectionItemsChangedEventHandler<IndexedItem<RealVector>>(Population_ItemsMoved);
225      Population.ItemsReplaced += new CollectionItemsChangedEventHandler<IndexedItem<RealVector>>(Population_ItemsReplaced);
226    }
227    private void DeregisterPopulationEvents() {
228      Population.CollectionReset -= new CollectionItemsChangedEventHandler<IndexedItem<RealVector>>(Population_CollectionReset);
229      Population.ItemsMoved -= new CollectionItemsChangedEventHandler<IndexedItem<RealVector>>(Population_ItemsMoved);
230      Population.ItemsReplaced -= new CollectionItemsChangedEventHandler<IndexedItem<RealVector>>(Population_ItemsReplaced);
231    }
[3894]232    private void RegisterBoundsEvents() {
233      Bounds.ItemChanged += new EventHandler<EventArgs<int, int>>(Bounds_ItemChanged);
234      Bounds.Reset += new EventHandler(Bounds_Reset);
235    }
236    private void DeregisterBoundsEvents() {
237      Bounds.ItemChanged -= new EventHandler<EventArgs<int, int>>(Bounds_ItemChanged);
238      Bounds.Reset -= new EventHandler(Bounds_Reset);
239    }
[3647]240
[3661]241    private void BestKnownRealVector_ItemChanged(object sender, EventArgs<int> e) {
242      OnBestKnownRealVectorChanged();
243    }
244    private void BestKnownRealVector_Reset(object sender, EventArgs e) {
245      OnBestKnownRealVectorChanged();
246    }
[3665]247    private void BestRealVector_ItemChanged(object sender, EventArgs<int> e) {
248      OnBestRealVectorChanged();
[3647]249    }
[3665]250    private void BestRealVector_Reset(object sender, EventArgs e) {
251      OnBestRealVectorChanged();
[3647]252    }
253    private void Quality_ValueChanged(object sender, EventArgs e) {
254      OnQualityChanged();
255    }
[3661]256    private void Population_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IndexedItem<RealVector>> e) {
257      OnPopulationChanged();
258    }
259    private void Population_ItemsMoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<RealVector>> e) {
260      OnPopulationChanged();
261    }
262    private void Population_CollectionReset(object sender, CollectionItemsChangedEventArgs<IndexedItem<RealVector>> e) {
263      OnPopulationChanged();
264    }
[3894]265    private void Bounds_ItemChanged(object sender, EventArgs<int, int> e) {
266      OnBoundsChanged();
267    }
268    private void Bounds_Reset(object sender, EventArgs e) {
269      OnBoundsChanged();
270    }
[3647]271    #endregion
272  }
273}
Note: See TracBrowser for help on using the repository browser.