#region License Information
/* HeuristicLab
* Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System;
using System.Drawing;
using HeuristicLab.Collections;
using HeuristicLab.Common;
using HeuristicLab.Core;
using HeuristicLab.Data;
using HeuristicLab.Encodings.RealVectorEncoding;
using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
namespace HeuristicLab.Problems.TestFunctions {
///
/// Represents a SingleObjectiveTestFunctionSolution solution.
///
[Item("SingleObjectiveTestFunctionSolution", "Represents a SingleObjectiveTestFunction solution.")]
[StorableClass]
public class SingleObjectiveTestFunctionSolution : Item {
public static new Image StaticItemImage {
get { return HeuristicLab.Common.Resources.VSImageLibrary.Image; }
}
[Storable]
private RealVector bestKnownRealVector;
public RealVector BestKnownRealVector {
get { return bestKnownRealVector; }
set {
if (bestKnownRealVector != value) {
if (bestKnownRealVector != null) DeregisterBestKnownRealVectorEvents();
bestKnownRealVector = value;
if (bestKnownRealVector != null) RegisterBestKnownRealVectorEvents();
OnBestKnownRealVectorChanged();
}
}
}
[Storable]
private RealVector bestRealVector;
public RealVector BestRealVector {
get { return bestRealVector; }
set {
if (bestRealVector != value) {
if (bestRealVector != null) DeregisterBestRealVectorEvents();
bestRealVector = value;
if (bestRealVector != null) RegisterBestRealVectorEvents();
OnBestRealVectorChanged();
}
}
}
[Storable]
private DoubleValue bestQuality;
public DoubleValue BestQuality {
get { return bestQuality; }
set {
if (bestQuality != value) {
if (bestQuality != null) DeregisterQualityEvents();
bestQuality = value;
if (bestQuality != null) RegisterQualityEvents();
OnQualityChanged();
}
}
}
[Storable]
private ItemArray population;
public ItemArray Population {
get { return population; }
set {
if (population != value) {
if (population != null) DeregisterPopulationEvents();
population = value;
if (population != null) RegisterPopulationEvents();
OnPopulationChanged();
}
}
}
[Storable]
private ISingleObjectiveTestFunctionProblemEvaluator evaluator;
public ISingleObjectiveTestFunctionProblemEvaluator Evaluator {
get { return evaluator; }
set {
if (evaluator != value) {
evaluator = value;
OnEvaluatorChanged();
}
}
}
[Storable]
private DoubleMatrix bounds;
public DoubleMatrix Bounds {
get { return bounds; }
set {
if (bounds != value) {
if (bounds != null) DeregisterBoundsEvents();
bounds = value;
if (bounds != null) RegisterBoundsEvents();
OnBoundsChanged();
}
}
}
[StorableConstructor]
protected SingleObjectiveTestFunctionSolution(bool deserializing) : base(deserializing) { }
protected SingleObjectiveTestFunctionSolution(SingleObjectiveTestFunctionSolution original, Cloner cloner)
: base(original, cloner) {
bestKnownRealVector = cloner.Clone(original.bestKnownRealVector);
bestRealVector = cloner.Clone(original.bestRealVector);
bestQuality = cloner.Clone(original.bestQuality);
population = cloner.Clone(original.population);
evaluator = cloner.Clone(original.evaluator);
bounds = cloner.Clone(original.bounds);
Initialize();
}
public SingleObjectiveTestFunctionSolution() : base() { }
public SingleObjectiveTestFunctionSolution(RealVector realVector, DoubleValue quality, ISingleObjectiveTestFunctionProblemEvaluator evaluator)
: base() {
this.bestRealVector = realVector;
this.bestQuality = quality;
this.evaluator = evaluator;
Initialize();
}
[StorableHook(HookType.AfterDeserialization)]
private void AfterDeserialization() {
Initialize();
}
private void Initialize() {
if (bestKnownRealVector != null) RegisterBestKnownRealVectorEvents();
if (bestRealVector != null) RegisterBestRealVectorEvents();
if (bestQuality != null) RegisterQualityEvents();
if (population != null) RegisterPopulationEvents();
if (bounds != null) RegisterBoundsEvents();
}
public override IDeepCloneable Clone(Cloner cloner) {
return new SingleObjectiveTestFunctionSolution(this, cloner);
}
#region Events
public event EventHandler BestKnownRealVectorChanged;
private void OnBestKnownRealVectorChanged() {
var changed = BestKnownRealVectorChanged;
if (changed != null)
changed(this, EventArgs.Empty);
}
public event EventHandler BestRealVectorChanged;
private void OnBestRealVectorChanged() {
var changed = BestRealVectorChanged;
if (changed != null)
changed(this, EventArgs.Empty);
}
public event EventHandler QualityChanged;
private void OnQualityChanged() {
var changed = QualityChanged;
if (changed != null)
changed(this, EventArgs.Empty);
}
public event EventHandler PopulationChanged;
private void OnPopulationChanged() {
var changed = PopulationChanged;
if (changed != null)
changed(this, EventArgs.Empty);
}
public event EventHandler EvaluatorChanged;
private void OnEvaluatorChanged() {
var changed = EvaluatorChanged;
if (changed != null)
changed(this, EventArgs.Empty);
}
public event EventHandler BoundsChanged;
private void OnBoundsChanged() {
var changed = BoundsChanged;
if (changed != null)
changed(this, EventArgs.Empty);
}
private void RegisterBestKnownRealVectorEvents() {
BestKnownRealVector.ItemChanged += new EventHandler>(BestKnownRealVector_ItemChanged);
BestKnownRealVector.Reset += new EventHandler(BestKnownRealVector_Reset);
}
private void DeregisterBestKnownRealVectorEvents() {
BestKnownRealVector.ItemChanged -= new EventHandler>(BestKnownRealVector_ItemChanged);
BestKnownRealVector.Reset -= new EventHandler(BestKnownRealVector_Reset);
}
private void RegisterBestRealVectorEvents() {
BestRealVector.ItemChanged += new EventHandler>(BestRealVector_ItemChanged);
BestRealVector.Reset += new EventHandler(BestRealVector_Reset);
}
private void DeregisterBestRealVectorEvents() {
BestRealVector.ItemChanged -= new EventHandler>(BestRealVector_ItemChanged);
BestRealVector.Reset -= new EventHandler(BestRealVector_Reset);
}
private void RegisterQualityEvents() {
BestQuality.ValueChanged += new EventHandler(Quality_ValueChanged);
}
private void DeregisterQualityEvents() {
BestQuality.ValueChanged -= new EventHandler(Quality_ValueChanged);
}
private void RegisterPopulationEvents() {
Population.CollectionReset += new CollectionItemsChangedEventHandler>(Population_CollectionReset);
Population.ItemsMoved += new CollectionItemsChangedEventHandler>(Population_ItemsMoved);
Population.ItemsReplaced += new CollectionItemsChangedEventHandler>(Population_ItemsReplaced);
}
private void DeregisterPopulationEvents() {
Population.CollectionReset -= new CollectionItemsChangedEventHandler>(Population_CollectionReset);
Population.ItemsMoved -= new CollectionItemsChangedEventHandler>(Population_ItemsMoved);
Population.ItemsReplaced -= new CollectionItemsChangedEventHandler>(Population_ItemsReplaced);
}
private void RegisterBoundsEvents() {
Bounds.ItemChanged += new EventHandler>(Bounds_ItemChanged);
Bounds.Reset += new EventHandler(Bounds_Reset);
}
private void DeregisterBoundsEvents() {
Bounds.ItemChanged -= new EventHandler>(Bounds_ItemChanged);
Bounds.Reset -= new EventHandler(Bounds_Reset);
}
private void BestKnownRealVector_ItemChanged(object sender, EventArgs e) {
OnBestKnownRealVectorChanged();
}
private void BestKnownRealVector_Reset(object sender, EventArgs e) {
OnBestKnownRealVectorChanged();
}
private void BestRealVector_ItemChanged(object sender, EventArgs e) {
OnBestRealVectorChanged();
}
private void BestRealVector_Reset(object sender, EventArgs e) {
OnBestRealVectorChanged();
}
private void Quality_ValueChanged(object sender, EventArgs e) {
OnQualityChanged();
}
private void Population_ItemsReplaced(object sender, CollectionItemsChangedEventArgs> e) {
OnPopulationChanged();
}
private void Population_ItemsMoved(object sender, CollectionItemsChangedEventArgs> e) {
OnPopulationChanged();
}
private void Population_CollectionReset(object sender, CollectionItemsChangedEventArgs> e) {
OnPopulationChanged();
}
private void Bounds_ItemChanged(object sender, EventArgs e) {
OnBoundsChanged();
}
private void Bounds_Reset(object sender, EventArgs e) {
OnBoundsChanged();
}
#endregion
}
}