Changeset 15096 for trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/ParticleOperators/RealVectorTotallyConnectedParticleUpdater.cs
- Timestamp:
- 06/29/17 23:04:03 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/ParticleOperators/RealVectorTotallyConnectedParticleUpdater.cs
r15091 r15096 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Core; 25 using HeuristicLab.Optimization;26 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 26 using HeuristicLab.PluginInfrastructure; … … 31 30 [StorableClass] 32 31 [NonDiscoverableType] 33 [Obsolete(" Same as the RealVectorNeighborhoodParticleUpdate")]32 [Obsolete("Replaced by SPSO2007ParticleUpdater")] 34 33 internal sealed class RealVectorTotallyConnectedParticleUpdater : RealVectorParticleUpdater { 35 34 … … 44 43 #endregion 45 44 45 private void UpdateVelocity() { 46 var velocity = VelocityParameter.ActualValue; 47 var position = RealVectorParameter.ActualValue; 48 var inertia = CurrentInertiaParameter.ActualValue.Value; 49 var personalBest = PersonalBestParameter.ActualValue; 50 var personalBestAttraction = PersonalBestAttractionParameter.ActualValue.Value; 51 var neighborBest = NeighborBestParameter.ActualValue; 52 var neighborBestAttraction = NeighborBestAttractionParameter.ActualValue.Value; 53 54 var random = RandomParameter.ActualValue; 55 56 for (int i = 0; i < velocity.Length; i++) { 57 double r_p = random.NextDouble(); 58 double r_g = random.NextDouble(); 59 velocity[i] = 60 velocity[i] * inertia + 61 (personalBest[i] - position[i]) * personalBestAttraction * r_p + 62 (neighborBest[i] - position[i]) * neighborBestAttraction * r_g; 63 } 64 65 var maxVelocity = CurrentMaxVelocityParameter.ActualValue.Value; 66 var speed = Math.Sqrt(velocity.DotProduct(velocity)); 67 if (speed > maxVelocity) { 68 for (var i = 0; i < velocity.Length; i++) { 69 velocity[i] *= maxVelocity / speed; 70 } 71 } 72 } 73 74 private void UpdatePosition() { 75 var velocity = VelocityParameter.ActualValue; 76 var position = RealVectorParameter.ActualValue; 77 78 for (int i = 0; i < velocity.Length; i++) { 79 position[i] += velocity[i]; 80 } 81 82 var bounds = BoundsParameter.ActualValue; 83 for (int i = 0; i < position.Length; i++) { 84 double min = bounds[i % bounds.Rows, 0]; 85 double max = bounds[i % bounds.Rows, 1]; 86 if (position[i] < min) { 87 position[i] = min; 88 velocity[i] = -0.5 * velocity[i]; // SPSO 2011 89 } 90 if (position[i] > max) { 91 position[i] = max; 92 velocity[i] = -0.5 * velocity[i]; // SPSO 2011 93 } 94 } 95 } 96 46 97 public override IOperation Apply() { 47 98 UpdateVelocity();
Note: See TracChangeset
for help on using the changeset viewer.