Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/SingleObjectiveTestFunctionSolution.cs @ 3647

Last change on this file since 3647 was 3647, checked in by svonolfe, 14 years ago

Added anaylzers for the SingleObjectiveTestFunction problem (#999)

File size: 4.7 KB
Line 
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
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using System.Text;
26using HeuristicLab.Core;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28using System.Drawing;
29using HeuristicLab.Data;
30using HeuristicLab.Encodings.RealVectorEncoding;
31using HeuristicLab.Common;
32
33namespace HeuristicLab.Problems.TestFunctions {
34  /// <summary>
35  /// Represents a SingleObjectiveTestFunctionSolution solution.
36  /// </summary>
37  [Item("SingleObjectiveTestFunctionSolution", "Represents a SingleObjectiveTestFunction solution.")]
38  [StorableClass]
39  public class SingleObjectiveTestFunctionSolution : Item {
40    public override Image ItemImage {
41      get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.Image; }
42    }
43
44    [Storable]
45    private RealVector realVector;
46    public RealVector RealVector {
47      get { return realVector; }
48      set {
49        if (realVector != value) {
50          if (realVector != null) DeregisterRealVectorEvents();
51          realVector = value;
52          if (realVector != null) RegisterRealVectorEvents();
53          OnRealVectorChanged();
54        }
55      }
56    }
57
58    [Storable]
59    private DoubleValue quality;
60    public DoubleValue Quality {
61      get { return quality; }
62      set {
63        if (quality != value) {
64          if (quality != null) DeregisterQualityEvents();
65          quality = value;
66          if (quality != null) RegisterQualityEvents();
67          OnQualityChanged();
68        }
69      }
70    }
71
72    public SingleObjectiveTestFunctionSolution() : base() { }
73    public SingleObjectiveTestFunctionSolution(RealVector realVector, DoubleValue quality)
74      : base() {
75      this.realVector = realVector;
76      this.quality = quality;
77      Initialize();
78    }
79    [StorableConstructor]
80    private SingleObjectiveTestFunctionSolution(bool deserializing) : base(deserializing) { }
81
82    [StorableHook(HookType.AfterDeserialization)]
83    private void Initialize() {
84      if (realVector != null) RegisterRealVectorEvents();
85      if (quality != null) RegisterQualityEvents();
86    }
87
88    public override IDeepCloneable Clone(Cloner cloner) {
89      SingleObjectiveTestFunctionSolution clone = new SingleObjectiveTestFunctionSolution();
90      cloner.RegisterClonedObject(this, clone);
91      clone.realVector = (RealVector)cloner.Clone(realVector);
92      clone.quality = (DoubleValue)cloner.Clone(quality);
93      clone.Initialize();
94      return clone;
95    }
96
97    #region Events
98    public event EventHandler RealVectorChanged;
99    private void OnRealVectorChanged() {
100      var changed = RealVectorChanged;
101      if (changed != null)
102        changed(this, EventArgs.Empty);
103    }
104
105    public event EventHandler QualityChanged;
106    private void OnQualityChanged() {
107      var changed = QualityChanged;
108      if (changed != null)
109        changed(this, EventArgs.Empty);
110    }
111
112    private void RegisterRealVectorEvents() {
113      RealVector.ItemChanged += new EventHandler<EventArgs<int>>(RealVector_ItemChanged);
114      RealVector.Reset += new EventHandler(RealVector_Reset);
115    }
116
117    private void DeregisterRealVectorEvents() {
118      RealVector.ItemChanged -= new EventHandler<EventArgs<int>>(RealVector_ItemChanged);
119      RealVector.Reset -= new EventHandler(RealVector_Reset);
120    }
121    private void RegisterQualityEvents() {
122      Quality.ValueChanged += new EventHandler(Quality_ValueChanged);
123    }
124    private void DeregisterQualityEvents() {
125      Quality.ValueChanged -= new EventHandler(Quality_ValueChanged);
126    }
127
128    private void RealVector_ItemChanged(object sender, EventArgs<int> e) {
129      OnRealVectorChanged();
130    }
131    private void RealVector_Reset(object sender, EventArgs e) {
132      OnRealVectorChanged();
133    }
134    private void Quality_ValueChanged(object sender, EventArgs e) {
135      OnQualityChanged();
136    }
137    #endregion
138  }
139}
Note: See TracBrowser for help on using the repository browser.