- Timestamp:
- 02/28/11 15:08:14 (14 years ago)
- Location:
- trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/ParticleOperators
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/ParticleOperators/RealVectorParticleUpdater.cs
r5560 r5566 43 43 } 44 44 public ILookupParameter<RealVector> PersonalBestParameter { 45 get { return (ILookupParameter<RealVector>)Parameters["PersonalBest Parameter"]; }45 get { return (ILookupParameter<RealVector>)Parameters["PersonalBest"]; } 46 46 } 47 47 public ILookupParameter<RealVector> NeighborsBestParameter { -
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/ParticleOperators/RealVectorSwarmUpdater.cs
r5561 r5566 132 132 public override IOperation Apply() { 133 133 InitializeBestPoint(); 134 UpdateSwarm(); 134 135 UpdateNeighbors(); 135 136 UpdateVelocityBounds(); 136 UpdateSwarm();137 137 return base.Apply(); 138 138 } … … 140 140 private void InitializeBestPoint() { 141 141 if (BestQuality == null) 142 BestQualityParameter.ActualValue = new DoubleValue(); 142 BestQualityParameter.ActualValue = new DoubleValue(); 143 143 BestQuality.Value = Maximization ? Quality.Max(v => v.Value) : Quality.Min(v => v.Value); 144 144 int bestIndex = Quality.FindIndex(v => v.Value == BestQuality.Value); … … 167 167 private void UpdateSwarm() { 168 168 if (PersonalBestQuality.Length == 0) { 169 PersonalBestQualityParameter.ActualValue= new ItemArray<DoubleValue>(RealVector.Length);169 ItemArray<DoubleValue> personalBestQualities = new ItemArray<DoubleValue>(RealVector.Length); 170 170 for (int i = 0; i < RealVector.Length; i++) { 171 171 if (Maximization) { 172 PersonalBestQuality[i] = new DoubleValue();172 personalBestQualities[i] = new DoubleValue(double.MinValue); 173 173 } else { 174 PersonalBestQuality[i] = new DoubleValue(double.MaxValue);174 personalBestQualities[i] = new DoubleValue(double.MaxValue); 175 175 } 176 176 } 177 PersonalBestQualityParameter.ActualValue = personalBestQualities; 177 178 } 178 179 if (NeighborsBestQuality.Length == 0) { 179 NeighborsBestQualityParameter.ActualValue = new ItemArray<DoubleValue>(RealVector.Length); 180 for (int i = 0; i < RealVector.Length; i++) { 181 if (Maximization) { 182 NeighborsBestQuality[i] = new DoubleValue(); 183 } else { 184 NeighborsBestQuality[i] = new DoubleValue(double.MaxValue); 180 if (NeighborsParameter != null && Neighbors.Length > 0) { 181 ItemArray<DoubleValue> neighborsBestQualities = new ItemArray<DoubleValue>(RealVector.Length); 182 for (int i = 0; i < RealVector.Length; i++) { 183 if (Maximization) { 184 neighborsBestQualities[i] = new DoubleValue(double.MinValue); 185 } else { 186 neighborsBestQualities[i] = new DoubleValue(double.MaxValue); 187 } 185 188 } 186 } 187 } 188 if (NeighborsBest.Length == 0) { 189 NeighborsBestParameter.ActualValue = new ItemArray<RealVector>(RealVector.Length); 190 } 189 NeighborsBestQualityParameter.ActualValue = neighborsBestQualities; 190 } 191 } 192 ItemArray<RealVector> neighborsBest = new ItemArray<RealVector>(RealVector.Length); 191 193 for (int i = 0; i < RealVector.Length; i++) { 192 194 if (Maximization && Quality[i].Value > PersonalBestQuality[i].Value || … … 197 199 !Maximization && PersonalBestQuality[i].Value < NeighborsBestQuality[i].Value) { 198 200 NeighborsBestQuality[i].Value = PersonalBestQuality[i].Value; 199 NeighborsBest[i] = PersonalBest[i];201 neighborsBest[i] = PersonalBest[i]; 200 202 } 201 203 } 204 } 205 if (NeighborsParameter != null && Neighbors.Length > 0) { 206 NeighborsBestParameter.ActualValue = neighborsBest; 202 207 } 203 208 }
Note: See TracChangeset
for help on using the changeset viewer.