Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HiveHiveEngine/HeuristicLab.Problems.TestFunctions/3.3/SingleObjectiveTestFunctionSolution.cs @ 10187

Last change on this file since 10187 was 7259, checked in by swagner, 13 years ago

Updated year of copyrights to 2012 (#1716)

File size: 10.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 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;
23using System.Drawing;
24using HeuristicLab.Collections;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HeuristicLab.Data;
28using HeuristicLab.Encodings.RealVectorEncoding;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
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 static new Image StaticItemImage {
39      get { return HeuristicLab.Common.Resources.VSImageLibrary.Image; }
40    }
41
42    [Storable]
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) DeregisterBestRealVectorEvents();
63          bestRealVector = value;
64          if (bestRealVector != null) RegisterBestRealVectorEvents();
65          OnBestRealVectorChanged();
66        }
67      }
68    }
69
70    [Storable]
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();
79          OnQualityChanged();
80        }
81      }
82    }
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    [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
124    [StorableConstructor]
125    protected SingleObjectiveTestFunctionSolution(bool deserializing) : base(deserializing) { }
126    protected SingleObjectiveTestFunctionSolution(SingleObjectiveTestFunctionSolution original, Cloner cloner)
127      : base(original, cloner) {
128      bestKnownRealVector = cloner.Clone(original.bestKnownRealVector);
129      bestRealVector = cloner.Clone(original.bestRealVector);
130      bestQuality = cloner.Clone(original.bestQuality);
131      population = cloner.Clone(original.population);
132      evaluator = cloner.Clone(original.evaluator);
133      bounds = cloner.Clone(original.bounds);
134      Initialize();
135    }
136    public SingleObjectiveTestFunctionSolution() : base() { }
137    public SingleObjectiveTestFunctionSolution(RealVector realVector, DoubleValue quality, ISingleObjectiveTestFunctionProblemEvaluator evaluator)
138      : base() {
139      this.bestRealVector = realVector;
140      this.bestQuality = quality;
141      this.evaluator = evaluator;
142      Initialize();
143    }
144
145    [StorableHook(HookType.AfterDeserialization)]
146    private void AfterDeserialization() {
147      Initialize();
148    }
149
150    private void Initialize() {
151      if (bestKnownRealVector != null) RegisterBestKnownRealVectorEvents();
152      if (bestRealVector != null) RegisterBestRealVectorEvents();
153      if (bestQuality != null) RegisterQualityEvents();
154      if (population != null) RegisterPopulationEvents();
155      if (bounds != null) RegisterBoundsEvents();
156    }
157
158    public override IDeepCloneable Clone(Cloner cloner) {
159      return new SingleObjectiveTestFunctionSolution(this, cloner);
160    }
161
162    #region Events
163    public event EventHandler BestKnownRealVectorChanged;
164    private void OnBestKnownRealVectorChanged() {
165      var changed = BestKnownRealVectorChanged;
166      if (changed != null)
167        changed(this, EventArgs.Empty);
168    }
169
170    public event EventHandler BestRealVectorChanged;
171    private void OnBestRealVectorChanged() {
172      var changed = BestRealVectorChanged;
173      if (changed != null)
174        changed(this, EventArgs.Empty);
175    }
176
177    public event EventHandler QualityChanged;
178    private void OnQualityChanged() {
179      var changed = QualityChanged;
180      if (changed != null)
181        changed(this, EventArgs.Empty);
182    }
183
184    public event EventHandler PopulationChanged;
185    private void OnPopulationChanged() {
186      var changed = PopulationChanged;
187      if (changed != null)
188        changed(this, EventArgs.Empty);
189    }
190
191    public event EventHandler EvaluatorChanged;
192    private void OnEvaluatorChanged() {
193      var changed = EvaluatorChanged;
194      if (changed != null)
195        changed(this, EventArgs.Empty);
196    }
197
198    public event EventHandler BoundsChanged;
199    private void OnBoundsChanged() {
200      var changed = BoundsChanged;
201      if (changed != null)
202        changed(this, EventArgs.Empty);
203    }
204
205    private void RegisterBestKnownRealVectorEvents() {
206      BestKnownRealVector.ItemChanged += new EventHandler<EventArgs<int>>(BestKnownRealVector_ItemChanged);
207      BestKnownRealVector.Reset += new EventHandler(BestKnownRealVector_Reset);
208    }
209    private void DeregisterBestKnownRealVectorEvents() {
210      BestKnownRealVector.ItemChanged -= new EventHandler<EventArgs<int>>(BestKnownRealVector_ItemChanged);
211      BestKnownRealVector.Reset -= new EventHandler(BestKnownRealVector_Reset);
212    }
213    private void RegisterBestRealVectorEvents() {
214      BestRealVector.ItemChanged += new EventHandler<EventArgs<int>>(BestRealVector_ItemChanged);
215      BestRealVector.Reset += new EventHandler(BestRealVector_Reset);
216    }
217    private void DeregisterBestRealVectorEvents() {
218      BestRealVector.ItemChanged -= new EventHandler<EventArgs<int>>(BestRealVector_ItemChanged);
219      BestRealVector.Reset -= new EventHandler(BestRealVector_Reset);
220    }
221    private void RegisterQualityEvents() {
222      BestQuality.ValueChanged += new EventHandler(Quality_ValueChanged);
223    }
224    private void DeregisterQualityEvents() {
225      BestQuality.ValueChanged -= new EventHandler(Quality_ValueChanged);
226    }
227    private void RegisterPopulationEvents() {
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    }
232    private void DeregisterPopulationEvents() {
233      Population.CollectionReset -= new CollectionItemsChangedEventHandler<IndexedItem<RealVector>>(Population_CollectionReset);
234      Population.ItemsMoved -= new CollectionItemsChangedEventHandler<IndexedItem<RealVector>>(Population_ItemsMoved);
235      Population.ItemsReplaced -= new CollectionItemsChangedEventHandler<IndexedItem<RealVector>>(Population_ItemsReplaced);
236    }
237    private void RegisterBoundsEvents() {
238      Bounds.ItemChanged += new EventHandler<EventArgs<int, int>>(Bounds_ItemChanged);
239      Bounds.Reset += new EventHandler(Bounds_Reset);
240    }
241    private void DeregisterBoundsEvents() {
242      Bounds.ItemChanged -= new EventHandler<EventArgs<int, int>>(Bounds_ItemChanged);
243      Bounds.Reset -= new EventHandler(Bounds_Reset);
244    }
245
246    private void BestKnownRealVector_ItemChanged(object sender, EventArgs<int> e) {
247      OnBestKnownRealVectorChanged();
248    }
249    private void BestKnownRealVector_Reset(object sender, EventArgs e) {
250      OnBestKnownRealVectorChanged();
251    }
252    private void BestRealVector_ItemChanged(object sender, EventArgs<int> e) {
253      OnBestRealVectorChanged();
254    }
255    private void BestRealVector_Reset(object sender, EventArgs e) {
256      OnBestRealVectorChanged();
257    }
258    private void Quality_ValueChanged(object sender, EventArgs e) {
259      OnQualityChanged();
260    }
261    private void Population_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IndexedItem<RealVector>> e) {
262      OnPopulationChanged();
263    }
264    private void Population_ItemsMoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<RealVector>> e) {
265      OnPopulationChanged();
266    }
267    private void Population_CollectionReset(object sender, CollectionItemsChangedEventArgs<IndexedItem<RealVector>> e) {
268      OnPopulationChanged();
269    }
270    private void Bounds_ItemChanged(object sender, EventArgs<int, int> e) {
271      OnBoundsChanged();
272    }
273    private void Bounds_Reset(object sender, EventArgs e) {
274      OnBoundsChanged();
275    }
276    #endregion
277  }
278}
Note: See TracBrowser for help on using the repository browser.