[3647] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[12012] | 3 | * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[3647] | 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;
|
---|
[3661] | 23 | using HeuristicLab.Collections;
|
---|
| 24 | using HeuristicLab.Common;
|
---|
[3647] | 25 | using HeuristicLab.Core;
|
---|
| 26 | using HeuristicLab.Data;
|
---|
| 27 | using HeuristicLab.Encodings.RealVectorEncoding;
|
---|
[3661] | 28 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
[3647] | 29 |
|
---|
| 30 | namespace 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 |
|
---|
[13656] | 38 |
|
---|
[3647] | 39 | [Storable]
|
---|
[3661] | 40 | private RealVector bestKnownRealVector;
|
---|
[13656] | 41 | public RealVector BestKnownRealVector
|
---|
| 42 | {
|
---|
[3661] | 43 | get { return bestKnownRealVector; }
|
---|
[13656] | 44 | set
|
---|
| 45 | {
|
---|
[3661] | 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;
|
---|
[13656] | 57 | public RealVector BestRealVector
|
---|
| 58 | {
|
---|
[3661] | 59 | get { return bestRealVector; }
|
---|
[13656] | 60 | set
|
---|
| 61 | {
|
---|
[3661] | 62 | if (bestRealVector != value) {
|
---|
[3665] | 63 | if (bestRealVector != null) DeregisterBestRealVectorEvents();
|
---|
[3661] | 64 | bestRealVector = value;
|
---|
[3665] | 65 | if (bestRealVector != null) RegisterBestRealVectorEvents();
|
---|
| 66 | OnBestRealVectorChanged();
|
---|
[3647] | 67 | }
|
---|
| 68 | }
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | [Storable]
|
---|
[3661] | 72 | private DoubleValue bestQuality;
|
---|
[13656] | 73 | public DoubleValue BestQuality
|
---|
| 74 | {
|
---|
[3661] | 75 | get { return bestQuality; }
|
---|
[13656] | 76 | set
|
---|
| 77 | {
|
---|
[3661] | 78 | if (bestQuality != value) {
|
---|
| 79 | if (bestQuality != null) DeregisterQualityEvents();
|
---|
| 80 | bestQuality = value;
|
---|
| 81 | if (bestQuality != null) RegisterQualityEvents();
|
---|
[3647] | 82 | OnQualityChanged();
|
---|
| 83 | }
|
---|
| 84 | }
|
---|
| 85 | }
|
---|
| 86 |
|
---|
[3661] | 87 | [Storable]
|
---|
| 88 | private ItemArray<RealVector> population;
|
---|
[13656] | 89 | public ItemArray<RealVector> Population
|
---|
| 90 | {
|
---|
[3661] | 91 | get { return population; }
|
---|
[13656] | 92 | set
|
---|
| 93 | {
|
---|
[3661] | 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;
|
---|
[13656] | 105 | public ISingleObjectiveTestFunctionProblemEvaluator Evaluator
|
---|
| 106 | {
|
---|
[3661] | 107 | get { return evaluator; }
|
---|
[13656] | 108 | set
|
---|
| 109 | {
|
---|
[3661] | 110 | if (evaluator != value) {
|
---|
| 111 | evaluator = value;
|
---|
| 112 | OnEvaluatorChanged();
|
---|
| 113 | }
|
---|
| 114 | }
|
---|
| 115 | }
|
---|
| 116 |
|
---|
[3894] | 117 | [Storable]
|
---|
| 118 | private DoubleMatrix bounds;
|
---|
[13656] | 119 | public DoubleMatrix Bounds
|
---|
| 120 | {
|
---|
[3894] | 121 | get { return bounds; }
|
---|
[13656] | 122 | set
|
---|
| 123 | {
|
---|
[3894] | 124 | if (bounds != value) {
|
---|
| 125 | if (bounds != null) DeregisterBoundsEvents();
|
---|
| 126 | bounds = value;
|
---|
| 127 | if (bounds != null) RegisterBoundsEvents();
|
---|
| 128 | OnBoundsChanged();
|
---|
| 129 | }
|
---|
| 130 | }
|
---|
| 131 | }
|
---|
| 132 |
|
---|
[4722] | 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 | }
|
---|
[3647] | 145 | public SingleObjectiveTestFunctionSolution() : base() { }
|
---|
[3661] | 146 | public SingleObjectiveTestFunctionSolution(RealVector realVector, DoubleValue quality, ISingleObjectiveTestFunctionProblemEvaluator evaluator)
|
---|
[3647] | 147 | : base() {
|
---|
[3661] | 148 | this.bestRealVector = realVector;
|
---|
| 149 | this.bestQuality = quality;
|
---|
| 150 | this.evaluator = evaluator;
|
---|
[3647] | 151 | Initialize();
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 | [StorableHook(HookType.AfterDeserialization)]
|
---|
[4722] | 155 | private void AfterDeserialization() {
|
---|
| 156 | Initialize();
|
---|
| 157 | }
|
---|
| 158 |
|
---|
[3647] | 159 | private void Initialize() {
|
---|
[3661] | 160 | if (bestKnownRealVector != null) RegisterBestKnownRealVectorEvents();
|
---|
[3665] | 161 | if (bestRealVector != null) RegisterBestRealVectorEvents();
|
---|
[3661] | 162 | if (bestQuality != null) RegisterQualityEvents();
|
---|
| 163 | if (population != null) RegisterPopulationEvents();
|
---|
[3894] | 164 | if (bounds != null) RegisterBoundsEvents();
|
---|
[3647] | 165 | }
|
---|
| 166 |
|
---|
| 167 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
[4722] | 168 | return new SingleObjectiveTestFunctionSolution(this, cloner);
|
---|
[3647] | 169 | }
|
---|
| 170 |
|
---|
| 171 | #region Events
|
---|
[3661] | 172 | public event EventHandler BestKnownRealVectorChanged;
|
---|
| 173 | private void OnBestKnownRealVectorChanged() {
|
---|
| 174 | var changed = BestKnownRealVectorChanged;
|
---|
| 175 | if (changed != null)
|
---|
| 176 | changed(this, EventArgs.Empty);
|
---|
| 177 | }
|
---|
| 178 |
|
---|
[3665] | 179 | public event EventHandler BestRealVectorChanged;
|
---|
| 180 | private void OnBestRealVectorChanged() {
|
---|
| 181 | var changed = BestRealVectorChanged;
|
---|
[3647] | 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 |
|
---|
[3661] | 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 |
|
---|
[3894] | 207 | public event EventHandler BoundsChanged;
|
---|
| 208 | private void OnBoundsChanged() {
|
---|
| 209 | var changed = BoundsChanged;
|
---|
| 210 | if (changed != null)
|
---|
| 211 | changed(this, EventArgs.Empty);
|
---|
| 212 | }
|
---|
| 213 |
|
---|
[3661] | 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 | }
|
---|
[3665] | 222 | private void RegisterBestRealVectorEvents() {
|
---|
| 223 | BestRealVector.ItemChanged += new EventHandler<EventArgs<int>>(BestRealVector_ItemChanged);
|
---|
| 224 | BestRealVector.Reset += new EventHandler(BestRealVector_Reset);
|
---|
[3647] | 225 | }
|
---|
[3665] | 226 | private void DeregisterBestRealVectorEvents() {
|
---|
| 227 | BestRealVector.ItemChanged -= new EventHandler<EventArgs<int>>(BestRealVector_ItemChanged);
|
---|
| 228 | BestRealVector.Reset -= new EventHandler(BestRealVector_Reset);
|
---|
[3647] | 229 | }
|
---|
| 230 | private void RegisterQualityEvents() {
|
---|
[3661] | 231 | BestQuality.ValueChanged += new EventHandler(Quality_ValueChanged);
|
---|
[3647] | 232 | }
|
---|
| 233 | private void DeregisterQualityEvents() {
|
---|
[3661] | 234 | BestQuality.ValueChanged -= new EventHandler(Quality_ValueChanged);
|
---|
[3647] | 235 | }
|
---|
[3661] | 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 | }
|
---|
[3894] | 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 | }
|
---|
[3647] | 254 |
|
---|
[3661] | 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 | }
|
---|
[3665] | 261 | private void BestRealVector_ItemChanged(object sender, EventArgs<int> e) {
|
---|
| 262 | OnBestRealVectorChanged();
|
---|
[3647] | 263 | }
|
---|
[3665] | 264 | private void BestRealVector_Reset(object sender, EventArgs e) {
|
---|
| 265 | OnBestRealVectorChanged();
|
---|
[3647] | 266 | }
|
---|
| 267 | private void Quality_ValueChanged(object sender, EventArgs e) {
|
---|
| 268 | OnQualityChanged();
|
---|
| 269 | }
|
---|
[3661] | 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 | }
|
---|
[3894] | 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 | }
|
---|
[3647] | 285 | #endregion
|
---|
| 286 | }
|
---|
| 287 | }
|
---|