Changeset 5560 for trunk/sources/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/MultiPSOTopologyUpdater.cs
- Timestamp:
- 02/24/11 17:08:11 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/MultiPSOTopologyUpdater.cs
r5435 r5560 25 25 using HeuristicLab.Core; 26 26 using HeuristicLab.Data; 27 using HeuristicLab.Encodings.IntegerVectorEncoding;28 27 using HeuristicLab.Operators; 28 using HeuristicLab.Optimization; 29 29 using HeuristicLab.Parameters; 30 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 31 31 32 32 namespace HeuristicLab.Algorithms.ParticleSwarmOptimization { 33 [Item("Multi PSO Topology Initializer/Updater", "Splits swarm into swarmsize / (nrOfConnections + 1) non-overlapping sub-swarms. Swarms are re-grouped every regroupingPeriod iteration. The operator is implemented as described in Liang, J.J. and Suganthan, P.N 2005. Dynamic multi-swarm particle swarm optimizer. IEEE Swarm Intelligence Symposium, pp. 124-129.")]33 [Item("Multi PSO Topology Updater", "Splits swarm into swarmsize / (nrOfConnections + 1) non-overlapping sub-swarms. Swarms are re-grouped every regroupingPeriod iteration. The operator is implemented as described in Liang, J.J. and Suganthan, P.N 2005. Dynamic multi-swarm particle swarm optimizer. IEEE Swarm Intelligence Symposium, pp. 124-129.")] 34 34 [StorableClass] 35 public sealed class MultiPSOTopologyUpdater : SingleSuccessorOperator, ITopologyUpdater , ITopologyInitializer{35 public sealed class MultiPSOTopologyUpdater : SingleSuccessorOperator, ITopologyUpdater { 36 36 public override bool CanChangeName { 37 37 get { return false; } … … 48 48 get { return (ILookupParameter<IntValue>)Parameters["SwarmSize"]; } 49 49 } 50 public IScopeTreeLookupParameter<Int egerVector> NeighborsParameter {51 get { return (IScopeTreeLookupParameter<Int egerVector>)Parameters["Neighbors"]; }50 public IScopeTreeLookupParameter<IntArray> NeighborsParameter { 51 get { return (IScopeTreeLookupParameter<IntArray>)Parameters["Neighbors"]; } 52 52 } 53 53 public ILookupParameter<IntValue> CurrentIterationParameter { … … 69 69 get { return SwarmSizeParameter.ActualValue.Value; } 70 70 } 71 private ItemArray<Int egerVector> Neighbors {71 private ItemArray<IntArray> Neighbors { 72 72 get { return NeighborsParameter.ActualValue; } 73 73 set { NeighborsParameter.ActualValue = value; } … … 84 84 private MultiPSOTopologyUpdater(bool deserializing) : base(deserializing) { } 85 85 private MultiPSOTopologyUpdater(MultiPSOTopologyUpdater original, Cloner cloner) : base(original, cloner) { } 86 86 87 public MultiPSOTopologyUpdater() 87 88 : base() { … … 89 90 Parameters.Add(new ValueLookupParameter<IntValue>("NrOfConnections", "Nr of connected neighbors.", new IntValue(3))); 90 91 Parameters.Add(new LookupParameter<IntValue>("SwarmSize", "Number of particles in the swarm.")); 91 Parameters.Add(new ScopeTreeLookupParameter<Int egerVector>("Neighbors", "The list of neighbors for each particle."));92 Parameters.Add(new ScopeTreeLookupParameter<IntArray>("Neighbors", "The list of neighbors for each particle.")); 92 93 Parameters.Add(new LookupParameter<IntValue>("CurrentIteration", "The current iteration of the algorithm.")); 93 94 Parameters.Add(new ValueLookupParameter<IntValue>("RegroupingPeriod", "Update interval (=iterations) for regrouping of neighborhoods.", new IntValue(5))); … … 100 101 // Splits the swarm into non-overlapping sub swarms 101 102 public override IOperation Apply() { 102 if (CurrentIteration % RegroupingPeriod == 0) {103 ItemArray<Int egerVector> neighbors = new ItemArray<IntegerVector>(SwarmSize);103 if (CurrentIteration > 0 && CurrentIteration % RegroupingPeriod == 0) { 104 ItemArray<IntArray> neighbors = new ItemArray<IntArray>(SwarmSize); 104 105 Dictionary<int, List<int>> neighborsPerParticle = new Dictionary<int, List<int>>(); 105 106 for (int i = 0; i < SwarmSize; i++) { … … 135 136 136 137 for (int particle = 0; particle < neighborsPerParticle.Count; particle++) { 137 neighbors[particle] = new Int egerVector(neighborsPerParticle[particle].ToArray());138 neighbors[particle] = new IntArray(neighborsPerParticle[particle].ToArray()); 138 139 } 139 140 Neighbors = neighbors;
Note: See TracChangeset
for help on using the changeset viewer.