Changeset 5435 for trunk/sources/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/RingTopologyInitializer.cs
- Timestamp:
- 02/04/11 21:34:45 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/RingTopologyInitializer.cs
r5316 r5435 24 24 using HeuristicLab.Encodings.IntegerVectorEncoding; 25 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 26 27 namespace HeuristicLab.Algorithms.ParticleSwarmOptimization { 27 28 28 [Item("Ring Topology Initializer", "Connected every particle with its preceeding and its following particle.")] 29 29 [StorableClass] 30 public class RingTopologyInitializer : TopologyInitializer { 30 public sealed class RingTopologyInitializer : TopologyInitializer { 31 #region Construction & Cloning 31 32 32 #region Construction & Cloning33 public RingTopologyInitializer() { }34 33 [StorableConstructor] 35 pr otectedRingTopologyInitializer(bool deserializing) : base(deserializing) { }36 pr otected RingTopologyInitializer(RingTopologyInitializer original, Cloner cloner)37 : base(original, cloner) {38 } 34 private RingTopologyInitializer(bool deserializing) : base(deserializing) { } 35 private RingTopologyInitializer(RingTopologyInitializer original, Cloner cloner) : base(original, cloner) { } 36 public RingTopologyInitializer() : base() { } 37 39 38 public override IDeepCloneable Clone(Cloner cloner) { 40 39 return new RingTopologyInitializer(this, cloner); 41 40 } 41 42 42 #endregion 43 43 44 44 public override IOperation Apply() { 45 45 ItemArray<IntegerVector> neighbors = new ItemArray<IntegerVector>(SwarmSize); 46 for (int i = 0; i <SwarmSize; i++) {47 neighbors[i] = new IntegerVector(new[] { (SwarmSize + i -1) % SwarmSize, (i+1) % SwarmSize });46 for (int i = 0; i < SwarmSize; i++) { 47 neighbors[i] = new IntegerVector(new[] { (SwarmSize + i - 1) % SwarmSize, (i + 1) % SwarmSize }); 48 48 } 49 49 Neighbors = neighbors; 50 50 return base.Apply(); 51 51 } 52 53 52 } 54 53 }
Note: See TracChangeset
for help on using the changeset viewer.