[3647] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[15973] | 3 | * Copyright (C) 2002-2018 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 System.Drawing;
|
---|
| 24 | using HeuristicLab.Collections;
|
---|
| 25 | using HeuristicLab.Common;
|
---|
[3647] | 26 | using HeuristicLab.Core;
|
---|
| 27 | using HeuristicLab.Data;
|
---|
| 28 | using HeuristicLab.Encodings.RealVectorEncoding;
|
---|
[3661] | 29 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
[3647] | 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 {
|
---|
[7201] | 38 | public static new Image StaticItemImage {
|
---|
[5287] | 39 | get { return HeuristicLab.Common.Resources.VSImageLibrary.Image; }
|
---|
[3647] | 40 | }
|
---|
| 41 |
|
---|
| 42 | [Storable]
|
---|
[3661] | 43 | private RealVector bestKnownRealVector;
|
---|
| 44 | public RealVector BestKnownRealVector {
|
---|
| 45 | get { return bestKnownRealVector; }
|
---|
[3647] | 46 | set {
|
---|
[3661] | 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) {
|
---|
[3665] | 62 | if (bestRealVector != null) DeregisterBestRealVectorEvents();
|
---|
[3661] | 63 | bestRealVector = value;
|
---|
[3665] | 64 | if (bestRealVector != null) RegisterBestRealVectorEvents();
|
---|
| 65 | OnBestRealVectorChanged();
|
---|
[3647] | 66 | }
|
---|
| 67 | }
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | [Storable]
|
---|
[3661] | 71 | private DoubleValue bestQuality;
|
---|
| 72 | public DoubleValue BestQuality {
|
---|
| 73 | get { return bestQuality; }
|
---|
[3647] | 74 | set {
|
---|
[3661] | 75 | if (bestQuality != value) {
|
---|
| 76 | if (bestQuality != null) DeregisterQualityEvents();
|
---|
| 77 | bestQuality = value;
|
---|
| 78 | if (bestQuality != null) RegisterQualityEvents();
|
---|
[3647] | 79 | OnQualityChanged();
|
---|
| 80 | }
|
---|
| 81 | }
|
---|
| 82 | }
|
---|
| 83 |
|
---|
[3661] | 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 |
|
---|
[3894] | 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 |
|
---|
[4722] | 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 | }
|
---|
[3647] | 136 | public SingleObjectiveTestFunctionSolution() : base() { }
|
---|
[3661] | 137 | public SingleObjectiveTestFunctionSolution(RealVector realVector, DoubleValue quality, ISingleObjectiveTestFunctionProblemEvaluator evaluator)
|
---|
[3647] | 138 | : base() {
|
---|
[3661] | 139 | this.bestRealVector = realVector;
|
---|
| 140 | this.bestQuality = quality;
|
---|
| 141 | this.evaluator = evaluator;
|
---|
[3647] | 142 | Initialize();
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 | [StorableHook(HookType.AfterDeserialization)]
|
---|
[4722] | 146 | private void AfterDeserialization() {
|
---|
| 147 | Initialize();
|
---|
| 148 | }
|
---|
| 149 |
|
---|
[3647] | 150 | private void Initialize() {
|
---|
[3661] | 151 | if (bestKnownRealVector != null) RegisterBestKnownRealVectorEvents();
|
---|
[3665] | 152 | if (bestRealVector != null) RegisterBestRealVectorEvents();
|
---|
[3661] | 153 | if (bestQuality != null) RegisterQualityEvents();
|
---|
| 154 | if (population != null) RegisterPopulationEvents();
|
---|
[3894] | 155 | if (bounds != null) RegisterBoundsEvents();
|
---|
[3647] | 156 | }
|
---|
| 157 |
|
---|
| 158 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
[4722] | 159 | return new SingleObjectiveTestFunctionSolution(this, cloner);
|
---|
[3647] | 160 | }
|
---|
| 161 |
|
---|
| 162 | #region Events
|
---|
[3661] | 163 | public event EventHandler BestKnownRealVectorChanged;
|
---|
| 164 | private void OnBestKnownRealVectorChanged() {
|
---|
| 165 | var changed = BestKnownRealVectorChanged;
|
---|
| 166 | if (changed != null)
|
---|
| 167 | changed(this, EventArgs.Empty);
|
---|
| 168 | }
|
---|
| 169 |
|
---|
[3665] | 170 | public event EventHandler BestRealVectorChanged;
|
---|
| 171 | private void OnBestRealVectorChanged() {
|
---|
| 172 | var changed = BestRealVectorChanged;
|
---|
[3647] | 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 |
|
---|
[3661] | 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 |
|
---|
[3894] | 198 | public event EventHandler BoundsChanged;
|
---|
| 199 | private void OnBoundsChanged() {
|
---|
| 200 | var changed = BoundsChanged;
|
---|
| 201 | if (changed != null)
|
---|
| 202 | changed(this, EventArgs.Empty);
|
---|
| 203 | }
|
---|
| 204 |
|
---|
[3661] | 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 | }
|
---|
[3665] | 213 | private void RegisterBestRealVectorEvents() {
|
---|
| 214 | BestRealVector.ItemChanged += new EventHandler<EventArgs<int>>(BestRealVector_ItemChanged);
|
---|
| 215 | BestRealVector.Reset += new EventHandler(BestRealVector_Reset);
|
---|
[3647] | 216 | }
|
---|
[3665] | 217 | private void DeregisterBestRealVectorEvents() {
|
---|
| 218 | BestRealVector.ItemChanged -= new EventHandler<EventArgs<int>>(BestRealVector_ItemChanged);
|
---|
| 219 | BestRealVector.Reset -= new EventHandler(BestRealVector_Reset);
|
---|
[3647] | 220 | }
|
---|
| 221 | private void RegisterQualityEvents() {
|
---|
[3661] | 222 | BestQuality.ValueChanged += new EventHandler(Quality_ValueChanged);
|
---|
[3647] | 223 | }
|
---|
| 224 | private void DeregisterQualityEvents() {
|
---|
[3661] | 225 | BestQuality.ValueChanged -= new EventHandler(Quality_ValueChanged);
|
---|
[3647] | 226 | }
|
---|
[3661] | 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 | }
|
---|
[3894] | 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 | }
|
---|
[3647] | 245 |
|
---|
[3661] | 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 | }
|
---|
[3665] | 252 | private void BestRealVector_ItemChanged(object sender, EventArgs<int> e) {
|
---|
| 253 | OnBestRealVectorChanged();
|
---|
[3647] | 254 | }
|
---|
[3665] | 255 | private void BestRealVector_Reset(object sender, EventArgs e) {
|
---|
| 256 | OnBestRealVectorChanged();
|
---|
[3647] | 257 | }
|
---|
| 258 | private void Quality_ValueChanged(object sender, EventArgs e) {
|
---|
| 259 | OnQualityChanged();
|
---|
| 260 | }
|
---|
[3661] | 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 | }
|
---|
[3894] | 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 | }
|
---|
[3647] | 276 | #endregion
|
---|
| 277 | }
|
---|
| 278 | }
|
---|