[3742] | 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 |
|
---|
[5034] | 22 | using HeuristicLab.Common;
|
---|
[3682] | 23 | using HeuristicLab.Core;
|
---|
| 24 | using HeuristicLab.Data;
|
---|
| 25 | using HeuristicLab.Encodings.RealVectorEncoding;
|
---|
[4068] | 26 | using HeuristicLab.Operators;
|
---|
[3682] | 27 | using HeuristicLab.Parameters;
|
---|
[5033] | 28 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
[3682] | 29 |
|
---|
| 30 | namespace HeuristicLab.Algorithms.ParticleSwarmOptimization {
|
---|
[5034] | 31 |
|
---|
[5316] | 32 | [Item("Swarm Updater", "Updates personal best point and quality as well as global best point and quality.")]
|
---|
[5034] | 33 | [StorableClass]
|
---|
[3682] | 34 | public class SwarmUpdater : SingleSuccessorOperator {
|
---|
[5033] | 35 |
|
---|
[3682] | 36 | #region Parameter properties
|
---|
[5410] | 37 | public ILookupParameter<DoubleValue> QualityParameter {
|
---|
| 38 | get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; }
|
---|
[3682] | 39 | }
|
---|
[5410] | 40 | public ILookupParameter<DoubleValue> PersonalBestQualityParameter {
|
---|
| 41 | get { return (ILookupParameter<DoubleValue>)Parameters["PersonalBestQuality"]; }
|
---|
[3682] | 42 | }
|
---|
[5410] | 43 | public ILookupParameter<DoubleValue> BestQualityParameter {
|
---|
| 44 | get { return (ILookupParameter<DoubleValue>)Parameters["BestQuality"]; }
|
---|
[3682] | 45 | }
|
---|
[5410] | 46 | public ILookupParameter<RealVector> PointParameter {
|
---|
| 47 | get { return (ILookupParameter<RealVector>)Parameters["Point"]; }
|
---|
[3682] | 48 | }
|
---|
[5410] | 49 | public ILookupParameter<RealVector> PersonalBestPointParameter {
|
---|
| 50 | get { return (ILookupParameter<RealVector>)Parameters["PersonalBestPoint"]; }
|
---|
[3682] | 51 | }
|
---|
[5410] | 52 | public ILookupParameter<RealVector> BestPointParameter {
|
---|
| 53 | get { return (ILookupParameter<RealVector>)Parameters["BestPoint"]; }
|
---|
[3682] | 54 | }
|
---|
[5410] | 55 | public IValueLookupParameter<BoolValue> MaximizationParameter {
|
---|
| 56 | get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
|
---|
[3682] | 57 | }
|
---|
| 58 | #endregion
|
---|
| 59 |
|
---|
[5033] | 60 | #region Parameter values
|
---|
| 61 | public double Quality {
|
---|
| 62 | get { return QualityParameter.ActualValue.Value; }
|
---|
| 63 | }
|
---|
| 64 | public double PersonalBestQuality {
|
---|
[5034] | 65 | get { return PersonalBestQualityParameter.ActualValue.Value; }
|
---|
| 66 | set { PersonalBestQualityParameter.ActualValue = new DoubleValue(value); }
|
---|
[5033] | 67 | }
|
---|
| 68 | public double BestQuality {
|
---|
| 69 | get { return BestQualityParameter.ActualValue.Value; }
|
---|
| 70 | set { BestQualityParameter.ActualValue = new DoubleValue(value); }
|
---|
| 71 | }
|
---|
| 72 | public RealVector Point {
|
---|
| 73 | get { return PointParameter.ActualValue; }
|
---|
| 74 | }
|
---|
| 75 | public RealVector PersonalBestPoint {
|
---|
| 76 | get { return PersonalBestPointParameter.ActualValue; }
|
---|
| 77 | set { PersonalBestPointParameter.ActualValue = value; }
|
---|
| 78 | }
|
---|
| 79 | public RealVector BestPoint {
|
---|
| 80 | get { return BestPointParameter.ActualValue; }
|
---|
| 81 | set { BestPointParameter.ActualValue = value; }
|
---|
| 82 | }
|
---|
| 83 | public bool Maximization {
|
---|
| 84 | get { return MaximizationParameter.ActualValue.Value; }
|
---|
| 85 | }
|
---|
| 86 | #endregion
|
---|
| 87 |
|
---|
| 88 | #region Construction & Cloning
|
---|
| 89 |
|
---|
| 90 | [StorableConstructor]
|
---|
| 91 | protected SwarmUpdater(bool deserializing) : base(deserializing) { }
|
---|
| 92 | protected SwarmUpdater(SwarmUpdater original, Cloner cloner)
|
---|
| 93 | : base(original, cloner) {
|
---|
| 94 | }
|
---|
| 95 |
|
---|
[3682] | 96 | public SwarmUpdater()
|
---|
| 97 | : base() {
|
---|
[5033] | 98 | Parameters.Add(new LookupParameter<DoubleValue>("Quality", "Particle's quality"));
|
---|
| 99 | Parameters.Add(new LookupParameter<DoubleValue>("PersonalBestQuality", "Particle's personal best quality"));
|
---|
| 100 | Parameters.Add(new LookupParameter<DoubleValue>("BestQuality", "Global best particle quality"));
|
---|
| 101 | Parameters.Add(new LookupParameter<RealVector>("Point", "Particle's position"));
|
---|
| 102 | Parameters.Add(new LookupParameter<RealVector>("PersonalBestPoint", "Particle's personal best position"));
|
---|
| 103 | Parameters.Add(new LookupParameter<RealVector>("BestPoint", "Globa best particle position"));
|
---|
[3682] | 104 | Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
|
---|
| 105 | }
|
---|
| 106 |
|
---|
[5033] | 107 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 108 | return new SwarmUpdater(this, cloner);
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 | #endregion
|
---|
| 112 |
|
---|
[3682] | 113 | public override IOperation Apply() {
|
---|
[5033] | 114 |
|
---|
| 115 | if (Maximization && Quality > PersonalBestQuality ||
|
---|
| 116 | !Maximization && Quality < PersonalBestQuality) {
|
---|
| 117 | PersonalBestQuality = Quality;
|
---|
| 118 | PersonalBestPoint = Point;
|
---|
| 119 | if (Maximization && PersonalBestQuality > BestQuality ||
|
---|
| 120 | !Maximization && PersonalBestQuality < BestQuality) {
|
---|
| 121 | BestQuality = PersonalBestQuality;
|
---|
| 122 | BestPoint = PersonalBestPoint;
|
---|
[3682] | 123 | }
|
---|
| 124 | }
|
---|
| 125 | return base.Apply();
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 | public override bool CanChangeName {
|
---|
| 129 | get { return false; }
|
---|
| 130 | }
|
---|
| 131 | }
|
---|
| 132 | }
|
---|