- Timestamp:
- 03/30/11 16:45:28 (14 years ago)
- Location:
- trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/ParticleOperators
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/ParticleOperators/RealVectorNeighborhoodParticleUpdater.cs
r5866 r5892 57 57 } 58 58 59 BoundsChecker.Apply(velocity, CurrentVelocityBounds); 60 for (int i = 0; i < velocity.Length; i++) { 61 position[i] = RealVector[i] + velocity[i]; 62 } 63 BoundsChecker.Apply(position, Bounds); 64 65 RealVector = position; 66 Velocity = velocity; 59 MoveParticle(velocity, position); 67 60 68 61 return base.Apply(); -
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/ParticleOperators/RealVectorParticleUpdater.cs
r5866 r5892 20 20 #endregion 21 21 22 using System; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; … … 130 131 } 131 132 #endregion 133 134 protected void MoveParticle(RealVector velocity, RealVector position) { 135 BoundsChecker.Apply(velocity, CurrentVelocityBounds); 136 for (int i = 0; i < velocity.Length; i++) { 137 position[i] = RealVector[i] + velocity[i]; 138 } 139 for (int i = 0; i < position.Length; i++) { 140 double min = Bounds[i % Bounds.Rows, 0]; 141 double max = Bounds[i % Bounds.Rows, 1]; 142 if (position[i] < min) { 143 int reflectionCount = (int)Math.Truncate((min - position[i]) / (max - min)) + 1; 144 double reflection = (min - position[i]) % (max - min); 145 if (IsOdd(reflectionCount)) { 146 position[i] = min + reflection; 147 velocity[i] = -velocity[i]; 148 149 } else { 150 position[i] = max - reflection; 151 } 152 } 153 if (position[i] > max) { 154 int reflectionCount = (int)Math.Truncate((position[i] - max) / (max - min)) + 1; 155 double reflection = (position[i] - max) % (max - min); 156 if (IsOdd(reflectionCount)) { 157 position[i] = max - reflection; 158 velocity[i] = -velocity[i]; 159 } else { 160 position[i] = min + reflection; 161 } 162 } 163 } 164 165 RealVector = position; 166 Velocity = velocity; 167 } 168 169 private static bool IsOdd(int number) { 170 return number % 2 == 1; 171 } 132 172 } 133 173 } -
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/ParticleOperators/RealVectorTotallyConnectedParticleUpdater.cs
r5866 r5892 57 57 } 58 58 59 BoundsChecker.Apply(velocity, CurrentVelocityBounds); 60 for (int i = 0; i < velocity.Length; i++) { 61 position[i] = RealVector[i] + velocity[i]; 62 } 63 BoundsChecker.Apply(position, Bounds); 64 65 RealVector = position; 66 Velocity = velocity; 59 MoveParticle(velocity, position); 67 60 68 61 return base.Apply();
Note: See TracChangeset
for help on using the changeset viewer.