Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/24/11 17:08:11 (13 years ago)
Author:
mkofler
Message:

#852: Code refactoring. Created new interfaces and moved operators to respective projects as suggested in A. Beham's review. Work in progress.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/MultiPSOTopologyUpdater.cs

    r5435 r5560  
    2525using HeuristicLab.Core;
    2626using HeuristicLab.Data;
    27 using HeuristicLab.Encodings.IntegerVectorEncoding;
    2827using HeuristicLab.Operators;
     28using HeuristicLab.Optimization;
    2929using HeuristicLab.Parameters;
    3030using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3131
    3232namespace 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.")]
    3434  [StorableClass]
    35   public sealed class MultiPSOTopologyUpdater : SingleSuccessorOperator, ITopologyUpdater, ITopologyInitializer {
     35  public sealed class MultiPSOTopologyUpdater : SingleSuccessorOperator, ITopologyUpdater {
    3636    public override bool CanChangeName {
    3737      get { return false; }
     
    4848      get { return (ILookupParameter<IntValue>)Parameters["SwarmSize"]; }
    4949    }
    50     public IScopeTreeLookupParameter<IntegerVector> NeighborsParameter {
    51       get { return (IScopeTreeLookupParameter<IntegerVector>)Parameters["Neighbors"]; }
     50    public IScopeTreeLookupParameter<IntArray> NeighborsParameter {
     51      get { return (IScopeTreeLookupParameter<IntArray>)Parameters["Neighbors"]; }
    5252    }
    5353    public ILookupParameter<IntValue> CurrentIterationParameter {
     
    6969      get { return SwarmSizeParameter.ActualValue.Value; }
    7070    }
    71     private ItemArray<IntegerVector> Neighbors {
     71    private ItemArray<IntArray> Neighbors {
    7272      get { return NeighborsParameter.ActualValue; }
    7373      set { NeighborsParameter.ActualValue = value; }
     
    8484    private MultiPSOTopologyUpdater(bool deserializing) : base(deserializing) { }
    8585    private MultiPSOTopologyUpdater(MultiPSOTopologyUpdater original, Cloner cloner) : base(original, cloner) { }
     86   
    8687    public MultiPSOTopologyUpdater()
    8788      : base() {
     
    8990      Parameters.Add(new ValueLookupParameter<IntValue>("NrOfConnections", "Nr of connected neighbors.", new IntValue(3)));
    9091      Parameters.Add(new LookupParameter<IntValue>("SwarmSize", "Number of particles in the swarm."));
    91       Parameters.Add(new ScopeTreeLookupParameter<IntegerVector>("Neighbors", "The list of neighbors for each particle."));
     92      Parameters.Add(new ScopeTreeLookupParameter<IntArray>("Neighbors", "The list of neighbors for each particle."));
    9293      Parameters.Add(new LookupParameter<IntValue>("CurrentIteration", "The current iteration of the algorithm."));
    9394      Parameters.Add(new ValueLookupParameter<IntValue>("RegroupingPeriod", "Update interval (=iterations) for regrouping of neighborhoods.", new IntValue(5)));
     
    100101    // Splits the swarm into non-overlapping sub swarms
    101102    public override IOperation Apply() {
    102       if (CurrentIteration % RegroupingPeriod == 0) {
    103         ItemArray<IntegerVector> neighbors = new ItemArray<IntegerVector>(SwarmSize);
     103      if (CurrentIteration > 0 && CurrentIteration % RegroupingPeriod == 0) {
     104        ItemArray<IntArray> neighbors = new ItemArray<IntArray>(SwarmSize);
    104105        Dictionary<int, List<int>> neighborsPerParticle = new Dictionary<int, List<int>>();
    105106        for (int i = 0; i < SwarmSize; i++) {
     
    135136
    136137        for (int particle = 0; particle < neighborsPerParticle.Count; particle++) {
    137           neighbors[particle] = new IntegerVector(neighborsPerParticle[particle].ToArray());
     138          neighbors[particle] = new IntArray(neighborsPerParticle[particle].ToArray());
    138139        }
    139140        Neighbors = neighbors;
Note: See TracChangeset for help on using the changeset viewer.