Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/ParticleOperators/RealVectorParticleUpdater.cs @ 5566

Last change on this file since 5566 was 5566, checked in by mkofler, 13 years ago

#852: PSO code refactoring. Worked on swarm updater and particle updater.

File size: 5.8 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 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 HeuristicLab.Common;
23using HeuristicLab.Core;
24using HeuristicLab.Data;
25using HeuristicLab.Operators;
26using HeuristicLab.Parameters;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28
29namespace HeuristicLab.Encodings.RealVectorEncoding {
30  [Item("RealVectorParticleUpdater", "Updates a certain particle taking the current position and velocity into account, as well as the best point and the best point in a local neighborhood.")]
31  [StorableClass]
32  public abstract class RealVectorParticleUpdater : SingleSuccessorOperator, IRealVectorParticleUpdater {
33    public override bool CanChangeName {
34      get { return false; }
35    }
36
37    #region Parameter properties
38    public ILookupParameter<IRandom> RandomParameter {
39      get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
40    }
41    public ILookupParameter<RealVector> VelocityParameter {
42      get { return (ILookupParameter<RealVector>)Parameters["Velocity"]; }
43    }
44    public ILookupParameter<RealVector> PersonalBestParameter {
45      get { return (ILookupParameter<RealVector>)Parameters["PersonalBest"]; }
46    }
47    public ILookupParameter<RealVector> NeighborsBestParameter {
48      get { return (ILookupParameter<RealVector>)Parameters["NeighborsBest"]; }
49    }
50    public ILookupParameter<RealVector> RealVectorParameter {
51      get { return (ILookupParameter<RealVector>)Parameters["RealVector"]; }
52    }
53    public ILookupParameter<DoubleMatrix> BoundsParameter {
54      get { return (ILookupParameter<DoubleMatrix>)Parameters["Bounds"]; }
55    }
56    public ILookupParameter<DoubleMatrix> VelocityBoundsParameter {
57      get { return (ILookupParameter<DoubleMatrix>)Parameters["VelocityBounds"]; }
58    }
59    public ILookupParameter<DoubleValue> InertiaParameter {
60      get { return (ILookupParameter<DoubleValue>)Parameters["Inertia"]; }
61    }
62    public ILookupParameter<DoubleValue> PersonalBestAttractionParameter {
63      get { return (ILookupParameter<DoubleValue>)Parameters["PersonalBestAttraction"]; }
64    }
65    public ILookupParameter<DoubleValue> NeighborsBestAttractionParameter {
66      get { return (ILookupParameter<DoubleValue>)Parameters["NeighborsBestAttraction"]; }
67    }
68    #endregion
69
70    #region Parameter Values
71    protected IRandom Random {
72      get { return RandomParameter.ActualValue; }
73    }
74    protected RealVector Velocity {
75      get { return VelocityParameter.ActualValue; }
76      set { VelocityParameter.ActualValue = value; }
77    }
78    protected RealVector PersonalBest {
79      get { return PersonalBestParameter.ActualValue; }
80    }
81    protected RealVector RealVector {
82      get { return RealVectorParameter.ActualValue; }
83      set { RealVectorParameter.ActualValue = value; }
84    }
85    protected RealVector NeighborsBest {
86      get { return NeighborsBestParameter.ActualValue; }
87    }
88    protected DoubleMatrix Bounds {
89      get { return BoundsParameter.ActualValue; }
90    }
91    protected DoubleMatrix VelocityBounds {
92      get { return VelocityBoundsParameter.ActualValue; }
93    }
94    protected DoubleValue Inertia {
95      get { return InertiaParameter.ActualValue; }
96    }
97    protected DoubleValue PersonalBestAttraction {
98      get { return PersonalBestAttractionParameter.ActualValue; }
99    }
100    protected DoubleValue NeighborsBestAttraction {
101      get { return NeighborsBestAttractionParameter.ActualValue; }
102    }
103    #endregion
104
105    #region Construction & Cloning
106
107    [StorableConstructor]
108    protected RealVectorParticleUpdater(bool deserializing) : base(deserializing) { }
109    protected RealVectorParticleUpdater(RealVectorParticleUpdater original, Cloner cloner) : base(original, cloner) { }
110   
111    public RealVectorParticleUpdater()
112      : base() {
113      Parameters.Add(new LookupParameter<IRandom>("Random", "Random number generator."));
114      Parameters.Add(new LookupParameter<RealVector>("RealVector", "Particle's current solution"));
115      Parameters.Add(new LookupParameter<RealVector>("Velocity", "Particle's current velocity."));
116      Parameters.Add(new LookupParameter<RealVector>("PersonalBest", "Particle's personal best solution."));
117      Parameters.Add(new LookupParameter<RealVector>("BestPoint", "Global best position."));
118      Parameters.Add(new LookupParameter<RealVector>("NeighborsBest", "Best neighboring solution."));
119      Parameters.Add(new LookupParameter<DoubleMatrix>("Bounds", "The lower and upper bounds for each dimension of the position vector for the current problem."));
120      Parameters.Add(new LookupParameter<DoubleMatrix>("VelocityBounds", "Upper and lower bounds for the particle's velocity vector."));
121      Parameters.Add(new LookupParameter<DoubleValue>("Inertia", "The weight for the particle's velocity vector."));
122      Parameters.Add(new LookupParameter<DoubleValue>("PersonalBestAttraction", "The weight for the particle's personal best position."));
123      Parameters.Add(new LookupParameter<DoubleValue>("NeighborsBestAttraction", "The weight for the global best position."));
124    }
125
126    #endregion
127  }
128}
Note: See TracBrowser for help on using the repository browser.