Free cookie consent management tool by TermsFeed Policy Generator

Changeset 7512 for trunk/sources


Ignore:
Timestamp:
02/24/12 09:40:40 (13 years ago)
Author:
mkommend
Message:

#1691: Updated PSO to use default operators.

File:
1 edited

Legend:

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

    r7259 r7512  
    288288      if (Problem != null) {
    289289        IParticleCreator oldParticleCreator = ParticleCreator;
     290        IParticleCreator defaultParticleCreator = Problem.Operators.OfType<IParticleCreator>().FirstOrDefault();
    290291        ParticleCreatorParameter.ValidValues.Clear();
    291292        foreach (IParticleCreator Creator in Problem.Operators.OfType<IParticleCreator>().OrderBy(x => x.Name)) {
     
    295296          IParticleCreator creator = ParticleCreatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldParticleCreator.GetType());
    296297          if (creator != null) ParticleCreator = creator;
    297         }
     298          else oldParticleCreator = null;
     299        }
     300        if (oldParticleCreator == null && defaultParticleCreator != null)
     301          ParticleCreator = defaultParticleCreator;
    298302      }
    299303    }
     
    372376      ClearTopologyParameters();
    373377      if (Problem != null) {
     378        IParticleUpdater defaultParticleUpdater = null;
    374379        if (TopologyInitializer != null) {
    375380          foreach (ITopologyUpdater topologyUpdater in ApplicationManager.Manager.GetInstances<ITopologyUpdater>())
    376381            TopologyUpdaterParameter.ValidValues.Add(topologyUpdater);
     382          defaultParticleUpdater = Problem.Operators.OfType<ILocalParticleUpdater>().FirstOrDefault();
    377383          foreach (IParticleUpdater particleUpdater in Problem.Operators.OfType<ILocalParticleUpdater>().OrderBy(x => x.Name))
    378384            ParticleUpdaterParameter.ValidValues.Add(particleUpdater);
    379385        } else {
     386          defaultParticleUpdater = Problem.Operators.OfType<IGlobalParticleUpdater>().FirstOrDefault();
    380387          foreach (IParticleUpdater particleUpdater in Problem.Operators.OfType<IGlobalParticleUpdater>().OrderBy(x => x.Name))
    381388            ParticleUpdaterParameter.ValidValues.Add(particleUpdater);
     
    388395          IParticleUpdater newParticleUpdater = ParticleUpdaterParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldParticleUpdater.GetType());
    389396          if (newParticleUpdater != null) ParticleUpdater = newParticleUpdater;
    390         }
     397          else oldParticleUpdater = null;
     398        }
     399        if (oldParticleUpdater == null && defaultParticleUpdater != null)
     400          ParticleUpdater = defaultParticleUpdater;
    391401
    392402        ParameterizeTopologyUpdaters();
Note: See TracChangeset for help on using the changeset viewer.