Free cookie consent management tool by TermsFeed Policy Generator

source: branches/WebJobManager/HeuristicLab.Problems.TestFunctions/3.3/SingleObjectiveTestFunctionSolution.cs @ 14563

Last change on this file since 14563 was 13656, checked in by ascheibe, 9 years ago

#2582 created branch for Hive Web Job Manager

File size: 10.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 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 HeuristicLab.Collections;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Data;
27using HeuristicLab.Encodings.RealVectorEncoding;
28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
29
30namespace HeuristicLab.Problems.TestFunctions {
31  /// <summary>
32  /// Represents a SingleObjectiveTestFunctionSolution solution.
33  /// </summary>
34  [Item("SingleObjectiveTestFunctionSolution", "Represents a SingleObjectiveTestFunction solution.")]
35  [StorableClass]
36  public class SingleObjectiveTestFunctionSolution : Item {
37
38
39    [Storable]
40    private RealVector bestKnownRealVector;
41    public RealVector BestKnownRealVector
42    {
43      get { return bestKnownRealVector; }
44      set
45      {
46        if (bestKnownRealVector != value) {
47          if (bestKnownRealVector != null) DeregisterBestKnownRealVectorEvents();
48          bestKnownRealVector = value;
49          if (bestKnownRealVector != null) RegisterBestKnownRealVectorEvents();
50          OnBestKnownRealVectorChanged();
51        }
52      }
53    }
54
55    [Storable]
56    private RealVector bestRealVector;
57    public RealVector BestRealVector
58    {
59      get { return bestRealVector; }
60      set
61      {
62        if (bestRealVector != value) {
63          if (bestRealVector != null) DeregisterBestRealVectorEvents();
64          bestRealVector = value;
65          if (bestRealVector != null) RegisterBestRealVectorEvents();
66          OnBestRealVectorChanged();
67        }
68      }
69    }
70
71    [Storable]
72    private DoubleValue bestQuality;
73    public DoubleValue BestQuality
74    {
75      get { return bestQuality; }
76      set
77      {
78        if (bestQuality != value) {
79          if (bestQuality != null) DeregisterQualityEvents();
80          bestQuality = value;
81          if (bestQuality != null) RegisterQualityEvents();
82          OnQualityChanged();
83        }
84      }
85    }
86
87    [Storable]
88    private ItemArray<RealVector> population;
89    public ItemArray<RealVector> Population
90    {
91      get { return population; }
92      set
93      {
94        if (population != value) {
95          if (population != null) DeregisterPopulationEvents();
96          population = value;
97          if (population != null) RegisterPopulationEvents();
98          OnPopulationChanged();
99        }
100      }
101    }
102
103    [Storable]
104    private ISingleObjectiveTestFunctionProblemEvaluator evaluator;
105    public ISingleObjectiveTestFunctionProblemEvaluator Evaluator
106    {
107      get { return evaluator; }
108      set
109      {
110        if (evaluator != value) {
111          evaluator = value;
112          OnEvaluatorChanged();
113        }
114      }
115    }
116
117    [Storable]
118    private DoubleMatrix bounds;
119    public DoubleMatrix Bounds
120    {
121      get { return bounds; }
122      set
123      {
124        if (bounds != value) {
125          if (bounds != null) DeregisterBoundsEvents();
126          bounds = value;
127          if (bounds != null) RegisterBoundsEvents();
128          OnBoundsChanged();
129        }
130      }
131    }
132
133    [StorableConstructor]
134    protected SingleObjectiveTestFunctionSolution(bool deserializing) : base(deserializing) { }
135    protected SingleObjectiveTestFunctionSolution(SingleObjectiveTestFunctionSolution original, Cloner cloner)
136      : base(original, cloner) {
137      bestKnownRealVector = cloner.Clone(original.bestKnownRealVector);
138      bestRealVector = cloner.Clone(original.bestRealVector);
139      bestQuality = cloner.Clone(original.bestQuality);
140      population = cloner.Clone(original.population);
141      evaluator = cloner.Clone(original.evaluator);
142      bounds = cloner.Clone(original.bounds);
143      Initialize();
144    }
145    public SingleObjectiveTestFunctionSolution() : base() { }
146    public SingleObjectiveTestFunctionSolution(RealVector realVector, DoubleValue quality, ISingleObjectiveTestFunctionProblemEvaluator evaluator)
147      : base() {
148      this.bestRealVector = realVector;
149      this.bestQuality = quality;
150      this.evaluator = evaluator;
151      Initialize();
152    }
153
154    [StorableHook(HookType.AfterDeserialization)]
155    private void AfterDeserialization() {
156      Initialize();
157    }
158
159    private void Initialize() {
160      if (bestKnownRealVector != null) RegisterBestKnownRealVectorEvents();
161      if (bestRealVector != null) RegisterBestRealVectorEvents();
162      if (bestQuality != null) RegisterQualityEvents();
163      if (population != null) RegisterPopulationEvents();
164      if (bounds != null) RegisterBoundsEvents();
165    }
166
167    public override IDeepCloneable Clone(Cloner cloner) {
168      return new SingleObjectiveTestFunctionSolution(this, cloner);
169    }
170
171    #region Events
172    public event EventHandler BestKnownRealVectorChanged;
173    private void OnBestKnownRealVectorChanged() {
174      var changed = BestKnownRealVectorChanged;
175      if (changed != null)
176        changed(this, EventArgs.Empty);
177    }
178
179    public event EventHandler BestRealVectorChanged;
180    private void OnBestRealVectorChanged() {
181      var changed = BestRealVectorChanged;
182      if (changed != null)
183        changed(this, EventArgs.Empty);
184    }
185
186    public event EventHandler QualityChanged;
187    private void OnQualityChanged() {
188      var changed = QualityChanged;
189      if (changed != null)
190        changed(this, EventArgs.Empty);
191    }
192
193    public event EventHandler PopulationChanged;
194    private void OnPopulationChanged() {
195      var changed = PopulationChanged;
196      if (changed != null)
197        changed(this, EventArgs.Empty);
198    }
199
200    public event EventHandler EvaluatorChanged;
201    private void OnEvaluatorChanged() {
202      var changed = EvaluatorChanged;
203      if (changed != null)
204        changed(this, EventArgs.Empty);
205    }
206
207    public event EventHandler BoundsChanged;
208    private void OnBoundsChanged() {
209      var changed = BoundsChanged;
210      if (changed != null)
211        changed(this, EventArgs.Empty);
212    }
213
214    private void RegisterBestKnownRealVectorEvents() {
215      BestKnownRealVector.ItemChanged += new EventHandler<EventArgs<int>>(BestKnownRealVector_ItemChanged);
216      BestKnownRealVector.Reset += new EventHandler(BestKnownRealVector_Reset);
217    }
218    private void DeregisterBestKnownRealVectorEvents() {
219      BestKnownRealVector.ItemChanged -= new EventHandler<EventArgs<int>>(BestKnownRealVector_ItemChanged);
220      BestKnownRealVector.Reset -= new EventHandler(BestKnownRealVector_Reset);
221    }
222    private void RegisterBestRealVectorEvents() {
223      BestRealVector.ItemChanged += new EventHandler<EventArgs<int>>(BestRealVector_ItemChanged);
224      BestRealVector.Reset += new EventHandler(BestRealVector_Reset);
225    }
226    private void DeregisterBestRealVectorEvents() {
227      BestRealVector.ItemChanged -= new EventHandler<EventArgs<int>>(BestRealVector_ItemChanged);
228      BestRealVector.Reset -= new EventHandler(BestRealVector_Reset);
229    }
230    private void RegisterQualityEvents() {
231      BestQuality.ValueChanged += new EventHandler(Quality_ValueChanged);
232    }
233    private void DeregisterQualityEvents() {
234      BestQuality.ValueChanged -= new EventHandler(Quality_ValueChanged);
235    }
236    private void RegisterPopulationEvents() {
237      Population.CollectionReset += new CollectionItemsChangedEventHandler<IndexedItem<RealVector>>(Population_CollectionReset);
238      Population.ItemsMoved += new CollectionItemsChangedEventHandler<IndexedItem<RealVector>>(Population_ItemsMoved);
239      Population.ItemsReplaced += new CollectionItemsChangedEventHandler<IndexedItem<RealVector>>(Population_ItemsReplaced);
240    }
241    private void DeregisterPopulationEvents() {
242      Population.CollectionReset -= new CollectionItemsChangedEventHandler<IndexedItem<RealVector>>(Population_CollectionReset);
243      Population.ItemsMoved -= new CollectionItemsChangedEventHandler<IndexedItem<RealVector>>(Population_ItemsMoved);
244      Population.ItemsReplaced -= new CollectionItemsChangedEventHandler<IndexedItem<RealVector>>(Population_ItemsReplaced);
245    }
246    private void RegisterBoundsEvents() {
247      Bounds.ItemChanged += new EventHandler<EventArgs<int, int>>(Bounds_ItemChanged);
248      Bounds.Reset += new EventHandler(Bounds_Reset);
249    }
250    private void DeregisterBoundsEvents() {
251      Bounds.ItemChanged -= new EventHandler<EventArgs<int, int>>(Bounds_ItemChanged);
252      Bounds.Reset -= new EventHandler(Bounds_Reset);
253    }
254
255    private void BestKnownRealVector_ItemChanged(object sender, EventArgs<int> e) {
256      OnBestKnownRealVectorChanged();
257    }
258    private void BestKnownRealVector_Reset(object sender, EventArgs e) {
259      OnBestKnownRealVectorChanged();
260    }
261    private void BestRealVector_ItemChanged(object sender, EventArgs<int> e) {
262      OnBestRealVectorChanged();
263    }
264    private void BestRealVector_Reset(object sender, EventArgs e) {
265      OnBestRealVectorChanged();
266    }
267    private void Quality_ValueChanged(object sender, EventArgs e) {
268      OnQualityChanged();
269    }
270    private void Population_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IndexedItem<RealVector>> e) {
271      OnPopulationChanged();
272    }
273    private void Population_ItemsMoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<RealVector>> e) {
274      OnPopulationChanged();
275    }
276    private void Population_CollectionReset(object sender, CollectionItemsChangedEventArgs<IndexedItem<RealVector>> e) {
277      OnPopulationChanged();
278    }
279    private void Bounds_ItemChanged(object sender, EventArgs<int, int> e) {
280      OnBoundsChanged();
281    }
282    private void Bounds_Reset(object sender, EventArgs e) {
283      OnBoundsChanged();
284    }
285    #endregion
286  }
287}
Note: See TracBrowser for help on using the repository browser.