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 |
|
---|
22 | using System;
|
---|
23 | using System.Drawing;
|
---|
24 | using HeuristicLab.Collections;
|
---|
25 | using HeuristicLab.Common;
|
---|
26 | using HeuristicLab.Core;
|
---|
27 | using HeuristicLab.Data;
|
---|
28 | using HeuristicLab.Encodings.RealVectorEncoding;
|
---|
29 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
30 |
|
---|
31 | namespace 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) 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 | public SingleObjectiveTestFunctionSolution() : base() { }
|
---|
111 | public SingleObjectiveTestFunctionSolution(RealVector realVector, DoubleValue quality, ISingleObjectiveTestFunctionProblemEvaluator evaluator)
|
---|
112 | : base() {
|
---|
113 | this.bestRealVector = realVector;
|
---|
114 | this.bestQuality = quality;
|
---|
115 | this.evaluator = evaluator;
|
---|
116 | Initialize();
|
---|
117 | }
|
---|
118 | [StorableConstructor]
|
---|
119 | private SingleObjectiveTestFunctionSolution(bool deserializing) : base(deserializing) { }
|
---|
120 |
|
---|
121 | [StorableHook(HookType.AfterDeserialization)]
|
---|
122 | private void Initialize() {
|
---|
123 | if (bestKnownRealVector != null) RegisterBestKnownRealVectorEvents();
|
---|
124 | if (bestRealVector != null) RegisterBestRealVectorEvents();
|
---|
125 | if (bestQuality != null) RegisterQualityEvents();
|
---|
126 | if (population != null) RegisterPopulationEvents();
|
---|
127 | }
|
---|
128 |
|
---|
129 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
130 | SingleObjectiveTestFunctionSolution clone = new SingleObjectiveTestFunctionSolution();
|
---|
131 | cloner.RegisterClonedObject(this, clone);
|
---|
132 | clone.bestKnownRealVector = (RealVector)cloner.Clone(bestKnownRealVector);
|
---|
133 | clone.bestRealVector = (RealVector)cloner.Clone(bestRealVector);
|
---|
134 | clone.bestQuality = (DoubleValue)cloner.Clone(bestQuality);
|
---|
135 | clone.population = (ItemArray<RealVector>)cloner.Clone(population);
|
---|
136 | clone.evaluator = (ISingleObjectiveTestFunctionProblemEvaluator)cloner.Clone(evaluator);
|
---|
137 | clone.Initialize();
|
---|
138 | return clone;
|
---|
139 | }
|
---|
140 |
|
---|
141 | #region Events
|
---|
142 | public event EventHandler BestKnownRealVectorChanged;
|
---|
143 | private void OnBestKnownRealVectorChanged() {
|
---|
144 | var changed = BestKnownRealVectorChanged;
|
---|
145 | if (changed != null)
|
---|
146 | changed(this, EventArgs.Empty);
|
---|
147 | }
|
---|
148 |
|
---|
149 | public event EventHandler BestRealVectorChanged;
|
---|
150 | private void OnBestRealVectorChanged() {
|
---|
151 | var changed = BestRealVectorChanged;
|
---|
152 | if (changed != null)
|
---|
153 | changed(this, EventArgs.Empty);
|
---|
154 | }
|
---|
155 |
|
---|
156 | public event EventHandler QualityChanged;
|
---|
157 | private void OnQualityChanged() {
|
---|
158 | var changed = QualityChanged;
|
---|
159 | if (changed != null)
|
---|
160 | changed(this, EventArgs.Empty);
|
---|
161 | }
|
---|
162 |
|
---|
163 | public event EventHandler PopulationChanged;
|
---|
164 | private void OnPopulationChanged() {
|
---|
165 | var changed = PopulationChanged;
|
---|
166 | if (changed != null)
|
---|
167 | changed(this, EventArgs.Empty);
|
---|
168 | }
|
---|
169 |
|
---|
170 | public event EventHandler EvaluatorChanged;
|
---|
171 | private void OnEvaluatorChanged() {
|
---|
172 | var changed = EvaluatorChanged;
|
---|
173 | if (changed != null)
|
---|
174 | changed(this, EventArgs.Empty);
|
---|
175 | }
|
---|
176 |
|
---|
177 | private void RegisterBestKnownRealVectorEvents() {
|
---|
178 | BestKnownRealVector.ItemChanged += new EventHandler<EventArgs<int>>(BestKnownRealVector_ItemChanged);
|
---|
179 | BestKnownRealVector.Reset += new EventHandler(BestKnownRealVector_Reset);
|
---|
180 | }
|
---|
181 | private void DeregisterBestKnownRealVectorEvents() {
|
---|
182 | BestKnownRealVector.ItemChanged -= new EventHandler<EventArgs<int>>(BestKnownRealVector_ItemChanged);
|
---|
183 | BestKnownRealVector.Reset -= new EventHandler(BestKnownRealVector_Reset);
|
---|
184 | }
|
---|
185 | private void RegisterBestRealVectorEvents() {
|
---|
186 | BestRealVector.ItemChanged += new EventHandler<EventArgs<int>>(BestRealVector_ItemChanged);
|
---|
187 | BestRealVector.Reset += new EventHandler(BestRealVector_Reset);
|
---|
188 | }
|
---|
189 | private void DeregisterBestRealVectorEvents() {
|
---|
190 | BestRealVector.ItemChanged -= new EventHandler<EventArgs<int>>(BestRealVector_ItemChanged);
|
---|
191 | BestRealVector.Reset -= new EventHandler(BestRealVector_Reset);
|
---|
192 | }
|
---|
193 | private void RegisterQualityEvents() {
|
---|
194 | BestQuality.ValueChanged += new EventHandler(Quality_ValueChanged);
|
---|
195 | }
|
---|
196 | private void DeregisterQualityEvents() {
|
---|
197 | BestQuality.ValueChanged -= new EventHandler(Quality_ValueChanged);
|
---|
198 | }
|
---|
199 | private void RegisterPopulationEvents() {
|
---|
200 | Population.CollectionReset += new CollectionItemsChangedEventHandler<IndexedItem<RealVector>>(Population_CollectionReset);
|
---|
201 | Population.ItemsMoved += new CollectionItemsChangedEventHandler<IndexedItem<RealVector>>(Population_ItemsMoved);
|
---|
202 | Population.ItemsReplaced += new CollectionItemsChangedEventHandler<IndexedItem<RealVector>>(Population_ItemsReplaced);
|
---|
203 | }
|
---|
204 | private void DeregisterPopulationEvents() {
|
---|
205 | Population.CollectionReset -= new CollectionItemsChangedEventHandler<IndexedItem<RealVector>>(Population_CollectionReset);
|
---|
206 | Population.ItemsMoved -= new CollectionItemsChangedEventHandler<IndexedItem<RealVector>>(Population_ItemsMoved);
|
---|
207 | Population.ItemsReplaced -= new CollectionItemsChangedEventHandler<IndexedItem<RealVector>>(Population_ItemsReplaced);
|
---|
208 | }
|
---|
209 |
|
---|
210 | private void BestKnownRealVector_ItemChanged(object sender, EventArgs<int> e) {
|
---|
211 | OnBestKnownRealVectorChanged();
|
---|
212 | }
|
---|
213 | private void BestKnownRealVector_Reset(object sender, EventArgs e) {
|
---|
214 | OnBestKnownRealVectorChanged();
|
---|
215 | }
|
---|
216 | private void BestRealVector_ItemChanged(object sender, EventArgs<int> e) {
|
---|
217 | OnBestRealVectorChanged();
|
---|
218 | }
|
---|
219 | private void BestRealVector_Reset(object sender, EventArgs e) {
|
---|
220 | OnBestRealVectorChanged();
|
---|
221 | }
|
---|
222 | private void Quality_ValueChanged(object sender, EventArgs e) {
|
---|
223 | OnQualityChanged();
|
---|
224 | }
|
---|
225 | private void Population_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IndexedItem<RealVector>> e) {
|
---|
226 | OnPopulationChanged();
|
---|
227 | }
|
---|
228 | private void Population_ItemsMoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<RealVector>> e) {
|
---|
229 | OnPopulationChanged();
|
---|
230 | }
|
---|
231 | private void Population_CollectionReset(object sender, CollectionItemsChangedEventArgs<IndexedItem<RealVector>> e) {
|
---|
232 | OnPopulationChanged();
|
---|
233 | }
|
---|
234 | #endregion
|
---|
235 | }
|
---|
236 | }
|
---|