[3647] | 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;
|
---|
[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 {
|
---|
| 38 | public override Image ItemImage {
|
---|
| 39 | get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.Image; }
|
---|
| 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 |
|
---|
[3647] | 110 | public SingleObjectiveTestFunctionSolution() : base() { }
|
---|
[3661] | 111 | public SingleObjectiveTestFunctionSolution(RealVector realVector, DoubleValue quality, ISingleObjectiveTestFunctionProblemEvaluator evaluator)
|
---|
[3647] | 112 | : base() {
|
---|
[3661] | 113 | this.bestRealVector = realVector;
|
---|
| 114 | this.bestQuality = quality;
|
---|
| 115 | this.evaluator = evaluator;
|
---|
[3647] | 116 | Initialize();
|
---|
| 117 | }
|
---|
| 118 | [StorableConstructor]
|
---|
| 119 | private SingleObjectiveTestFunctionSolution(bool deserializing) : base(deserializing) { }
|
---|
| 120 |
|
---|
| 121 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 122 | private void Initialize() {
|
---|
[3661] | 123 | if (bestKnownRealVector != null) RegisterBestKnownRealVectorEvents();
|
---|
[3665] | 124 | if (bestRealVector != null) RegisterBestRealVectorEvents();
|
---|
[3661] | 125 | if (bestQuality != null) RegisterQualityEvents();
|
---|
| 126 | if (population != null) RegisterPopulationEvents();
|
---|
[3647] | 127 | }
|
---|
| 128 |
|
---|
| 129 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 130 | SingleObjectiveTestFunctionSolution clone = new SingleObjectiveTestFunctionSolution();
|
---|
| 131 | cloner.RegisterClonedObject(this, clone);
|
---|
[3661] | 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);
|
---|
[3647] | 137 | clone.Initialize();
|
---|
| 138 | return clone;
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 | #region Events
|
---|
[3661] | 142 | public event EventHandler BestKnownRealVectorChanged;
|
---|
| 143 | private void OnBestKnownRealVectorChanged() {
|
---|
| 144 | var changed = BestKnownRealVectorChanged;
|
---|
| 145 | if (changed != null)
|
---|
| 146 | changed(this, EventArgs.Empty);
|
---|
| 147 | }
|
---|
| 148 |
|
---|
[3665] | 149 | public event EventHandler BestRealVectorChanged;
|
---|
| 150 | private void OnBestRealVectorChanged() {
|
---|
| 151 | var changed = BestRealVectorChanged;
|
---|
[3647] | 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 |
|
---|
[3661] | 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 | }
|
---|
[3665] | 185 | private void RegisterBestRealVectorEvents() {
|
---|
| 186 | BestRealVector.ItemChanged += new EventHandler<EventArgs<int>>(BestRealVector_ItemChanged);
|
---|
| 187 | BestRealVector.Reset += new EventHandler(BestRealVector_Reset);
|
---|
[3647] | 188 | }
|
---|
[3665] | 189 | private void DeregisterBestRealVectorEvents() {
|
---|
| 190 | BestRealVector.ItemChanged -= new EventHandler<EventArgs<int>>(BestRealVector_ItemChanged);
|
---|
| 191 | BestRealVector.Reset -= new EventHandler(BestRealVector_Reset);
|
---|
[3647] | 192 | }
|
---|
| 193 | private void RegisterQualityEvents() {
|
---|
[3661] | 194 | BestQuality.ValueChanged += new EventHandler(Quality_ValueChanged);
|
---|
[3647] | 195 | }
|
---|
| 196 | private void DeregisterQualityEvents() {
|
---|
[3661] | 197 | BestQuality.ValueChanged -= new EventHandler(Quality_ValueChanged);
|
---|
[3647] | 198 | }
|
---|
[3661] | 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 | }
|
---|
[3647] | 209 |
|
---|
[3661] | 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 | }
|
---|
[3665] | 216 | private void BestRealVector_ItemChanged(object sender, EventArgs<int> e) {
|
---|
| 217 | OnBestRealVectorChanged();
|
---|
[3647] | 218 | }
|
---|
[3665] | 219 | private void BestRealVector_Reset(object sender, EventArgs e) {
|
---|
| 220 | OnBestRealVectorChanged();
|
---|
[3647] | 221 | }
|
---|
| 222 | private void Quality_ValueChanged(object sender, EventArgs e) {
|
---|
| 223 | OnQualityChanged();
|
---|
| 224 | }
|
---|
[3661] | 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 | }
|
---|
[3647] | 234 | #endregion
|
---|
| 235 | }
|
---|
| 236 | }
|
---|