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

Last change on this file since 3661 was 3661, checked in by abeham, 12 years ago

#999

  • prepared TF visualization
  • removed obsolete TF solution analyzers
File size: 9.3 KB
Line 
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;
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 override Image ItemImage {
39      get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.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) DeregisterRealVectorEvents();
63          bestRealVector = value;
64          if (bestRealVector != null) RegisterRealVectorEvents();
65          OnRealVectorChanged();
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    private Image fitnessLandscape;
111    public Image FitnessLandscape {
112      get { return fitnessLandscape; }
113      set { fitnessLandscape = value; }
114    }
115
116    public SingleObjectiveTestFunctionSolution() : base() { }
117    public SingleObjectiveTestFunctionSolution(RealVector realVector, DoubleValue quality, ISingleObjectiveTestFunctionProblemEvaluator evaluator)
118      : base() {
119      this.bestRealVector = realVector;
120      this.bestQuality = quality;
121      this.evaluator = evaluator;
122      Initialize();
123    }
124    [StorableConstructor]
125    private SingleObjectiveTestFunctionSolution(bool deserializing) : base(deserializing) { }
126
127    [StorableHook(HookType.AfterDeserialization)]
128    private void Initialize() {
129      if (bestKnownRealVector != null) RegisterBestKnownRealVectorEvents();
130      if (bestRealVector != null) RegisterRealVectorEvents();
131      if (bestQuality != null) RegisterQualityEvents();
132      if (population != null) RegisterPopulationEvents();
133    }
134
135    public override IDeepCloneable Clone(Cloner cloner) {
136      SingleObjectiveTestFunctionSolution clone = new SingleObjectiveTestFunctionSolution();
137      cloner.RegisterClonedObject(this, clone);
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;
144      clone.Initialize();
145      return clone;
146    }
147
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
156    public event EventHandler RealVectorChanged;
157    private void OnRealVectorChanged() {
158      var changed = RealVectorChanged;
159      if (changed != null)
160        changed(this, EventArgs.Empty);
161    }
162
163    public event EventHandler QualityChanged;
164    private void OnQualityChanged() {
165      var changed = QualityChanged;
166      if (changed != null)
167        changed(this, EventArgs.Empty);
168    }
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    }
192    private void RegisterRealVectorEvents() {
193      BestRealVector.ItemChanged += new EventHandler<EventArgs<int>>(RealVector_ItemChanged);
194      BestRealVector.Reset += new EventHandler(RealVector_Reset);
195    }
196    private void DeregisterRealVectorEvents() {
197      BestRealVector.ItemChanged -= new EventHandler<EventArgs<int>>(RealVector_ItemChanged);
198      BestRealVector.Reset -= new EventHandler(RealVector_Reset);
199    }
200    private void RegisterQualityEvents() {
201      BestQuality.ValueChanged += new EventHandler(Quality_ValueChanged);
202    }
203    private void DeregisterQualityEvents() {
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    }
223    private void RealVector_ItemChanged(object sender, EventArgs<int> e) {
224      OnRealVectorChanged();
225    }
226    private void RealVector_Reset(object sender, EventArgs e) {
227      OnRealVectorChanged();
228    }
229    private void Quality_ValueChanged(object sender, EventArgs e) {
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();
240    }
241    #endregion
242  }
243}
Note: See TracBrowser for help on using the repository browser.