Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/BestPointInitializer.cs @ 5444

Last change on this file since 5444 was 5435, checked in by abeham, 14 years ago

#852

  • Made public properties that redirect to ActualValue.Value private or protected
  • Sealed all of the specific operators
  • Removed files that are present in the repository, but are not included in the project
  • Removed .sln file (is this still needed?)
  • Added license headers to some files
  • Unified the pattern for writing the constructors similar to other files in the trunk
  • Corrected assembly and plugin version from 3.3.0.x to 3.3.2.x
  • Fixed the wiring in the VelocityBoundsModifier
File size: 4.2 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.Linq;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Data;
26using HeuristicLab.Encodings.RealVectorEncoding;
27using HeuristicLab.Operators;
28using HeuristicLab.Parameters;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30
31namespace HeuristicLab.Algorithms.ParticleSwarmOptimization {
32  [Item("Best Point Initializer", "Determines the best quality and point of the current particle population.")]
33  [StorableClass]
34  public sealed class BestPointInitializer : SingleSuccessorOperator {
35    public override bool CanChangeName {
36      get { return false; }
37    }
38
39    #region Parameter properties
40    public IScopeTreeLookupParameter<DoubleValue> QualityParameter {
41      get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
42    }
43    public ILookupParameter<DoubleValue> BestQualityParameter {
44      get { return (ILookupParameter<DoubleValue>)Parameters["BestQuality"]; }
45    }
46    public IScopeTreeLookupParameter<RealVector> PointParameter {
47      get { return (IScopeTreeLookupParameter<RealVector>)Parameters["Point"]; }
48    }
49    public ILookupParameter<RealVector> BestPointParameter {
50      get { return (ILookupParameter<RealVector>)Parameters["BestPoint"]; }
51    }
52    public IValueLookupParameter<BoolValue> MaximizationParameter {
53      get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
54    }
55    #endregion
56
57    #region Parameter values
58    private ItemArray<DoubleValue> Quality {
59      get { return QualityParameter.ActualValue; }
60    }
61    private double BestQuality {
62      get { return BestQualityParameter.ActualValue.Value; }
63      set { BestQualityParameter.ActualValue = new DoubleValue(value); }
64    }
65    private ItemArray<RealVector> Point {
66      get { return PointParameter.ActualValue; }
67    }
68    private RealVector BestPoint {
69      get { return BestPointParameter.ActualValue; }
70      set { BestPointParameter.ActualValue = value; }
71    }
72    private bool Maximization {
73      get { return MaximizationParameter.ActualValue.Value; }
74    }
75    #endregion
76
77    #region Construction & Cloning
78
79    [StorableConstructor]
80    private BestPointInitializer(bool deserializing) : base(deserializing) { }
81    private BestPointInitializer(BestPointInitializer original, Cloner cloner) : base(original, cloner) { }
82    public BestPointInitializer()
83      : base() {
84      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "Particle's quality"));
85      Parameters.Add(new LookupParameter<DoubleValue>("BestQuality", "Global best particle quality"));
86      Parameters.Add(new ScopeTreeLookupParameter<RealVector>("Point", "Particle's position"));
87      Parameters.Add(new LookupParameter<RealVector>("BestPoint", "Globa best particle position"));
88      Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
89    }
90
91    public override IDeepCloneable Clone(Cloner cloner) {
92      return new BestPointInitializer(this, cloner);
93    }
94
95    #endregion
96
97    public override IOperation Apply() {
98      BestQuality = Maximization ? Quality.Max(v => v.Value) : Quality.Min(v => v.Value);
99      int bestIndex = Quality.FindIndex(v => v.Value == BestQuality);
100      BestPoint = (RealVector)Point[bestIndex].Clone();
101      return base.Apply();
102    }
103  }
104}
Note: See TracBrowser for help on using the repository browser.