Changeset 5209 for branches/PSO/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/ParticleUpdater.cs
- Timestamp:
- 01/04/11 16:34:11 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PSO/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/ParticleUpdater.cs
r5034 r5209 31 31 32 32 [StorableClass] 33 public class ParticleUpdater : SingleSuccessorOperator {33 public abstract class ParticleUpdater : SingleSuccessorOperator, IParticleUpdater { 34 34 35 35 #region Parameter properties … … 45 45 public LookupParameter<RealVector> PersonalBestPointParameter { 46 46 get { return (LookupParameter<RealVector>)Parameters["PersonalBestPoint"]; } 47 } 48 public LookupParameter<RealVector> BestNeighborPointParameter { 49 get { return (LookupParameter<RealVector>)Parameters["BestNeighborPoint"]; } 47 50 } 48 51 public LookupParameter<RealVector> BestPointParameter { … … 84 87 get { return BestPointParameter.ActualValue; } 85 88 } 89 public RealVector BestNeighborPoint { 90 get { return BestNeighborPointParameter.ActualValue; } 91 } 86 92 public DoubleMatrix Bounds { 87 93 get { return BoundsParameter.ActualValue; } … … 101 107 #endregion 102 108 109 public override bool CanChangeName { 110 get { return false; } 111 } 112 103 113 #region Construction & Cloning 104 114 … … 116 126 Parameters.Add(new LookupParameter<RealVector>("PersonalBestPoint", "Particle's personal best position")); 117 127 Parameters.Add(new LookupParameter<RealVector>("BestPoint", "Global best position")); 128 Parameters.Add(new LookupParameter<RealVector>("BestNeighborPoint", "Best neighboring position")); 118 129 Parameters.Add(new LookupParameter<DoubleMatrix>("Bounds", "The lower and upper bounds for each dimension of the position vector for the current problem.")); 119 130 Parameters.Add(new LookupParameter<DoubleMatrix>("VelocityBounds", "Upper and lower bounds for the particle's velocity vector.")); … … 123 134 } 124 135 125 public override IDeepCloneable Clone(Cloner cloner) {126 return new ParticleUpdater(this, cloner);127 }128 129 136 #endregion 130 137 131 public override IOperation Apply() {132 RealVector velocity = new RealVector(Velocity.Length);133 RealVector position = new RealVector(Point.Length);134 double r_p = Random.NextDouble();135 double r_g = Random.NextDouble();136 for (int i = 0; i < velocity.Length; i++) {137 velocity[i] =138 Velocity[i] * Omega +139 (PersonalBestPoint[i] - Point[i]) * Phi_P * r_p +140 (BestPoint[i] - Point[i]) * Phi_G * r_g;141 }142 BoundsChecker.Apply(velocity, VelocityBounds);143 for (int i = 0; i < velocity.Length; i++) {144 position[i] = Point[i] + velocity[i];145 }146 BoundsChecker.Apply(position, Bounds);147 Point = position;148 Velocity = velocity;149 150 return base.Apply();151 }152 153 public override bool CanChangeName {154 get { return false; }155 }156 138 } 157 139 }
Note: See TracChangeset
for help on using the changeset viewer.