Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/20/11 18:22:43 (14 years ago)
Author:
mkofler
Message:

#852: Worked on parameter wiring to ensure that users may only select correct parameter combinations (e.g. NeighborhoodParticleUpdater + some topology).

Location:
branches/PSO/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • branches/PSO/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/HeuristicLab.Algorithms.ParticleSwarmOptimization-3.3.csproj

    r5339 r5342  
    111111    <Compile Include="BestPointInitializer.cs" />
    112112    <Compile Include="IDiscreteDoubleMatrixModifier.cs" />
     113    <Compile Include="IGlobalParticleUpdater.cs" />
     114    <Compile Include="ILocalParticleUpdater.cs" />
    113115    <Compile Include="MultiPSOTopologyUpdater.cs" />
    114116    <Compile Include="VelocityBoundsModifier.cs" />
  • branches/PSO/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/IParticleUpdater.cs

    r5316 r5342  
    2727namespace HeuristicLab.Algorithms.ParticleSwarmOptimization {
    2828
    29   public interface IParticleUpdater : IItem {
     29  public interface IParticleUpdater : INamedItem {
    3030
    3131    LookupParameter<RealVector> VelocityParameter { get; }
  • branches/PSO/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/NeighborhoodParticleUpdater.cs

    r5316 r5342  
    2929  [Item("Neighborhood Particle Updater", "Updates the particle's position using (among other things) the best neighbor's position. Point = Point + Velocity*Omega + (PersonalBestPoint-Point)*Phi_P*r_p + (BestNeighborPoint-Point)*Phi_G*r_g")]
    3030  [StorableClass]
    31   public class NeighborhoodParticleUpdater : ParticleUpdater {
     31  public class NeighborhoodParticleUpdater : ParticleUpdater, ILocalParticleUpdater {
    3232
    3333    #region Construction & Cloning
  • branches/PSO/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/ParticleSwarmOptimization.cs

    r5339 r5342  
    115115    [Storable]
    116116    private BestAverageWorstQualityAnalyzer qualityAnalyzer;
     117
     118    public ITopologyInitializer TopologyInitializer {
     119      get { return TopologyInitializerParameter.Value; }
     120      set { TopologyInitializerParameter.Value = value; }
     121    }
     122
     123    public ITopologyUpdater TopologyUpdater {
     124      get { return TopologyUpdaterParameter.Value; }
     125      set { TopologyUpdaterParameter.Value = value; }
     126    }
     127
     128    public IParticleUpdater ParticleUpdater {
     129      get { return ParticleUpdaterParameter.Value; }
     130      set { ParticleUpdaterParameter.Value = value; }
     131    }
     132
    117133    #endregion
    118134
    119135    [StorableConstructor]
    120     protected ParticleSwarmOptimization(bool deserializing) : base(deserializing) { }
     136    protected ParticleSwarmOptimization(bool deserializing) : base(deserializing) {
     137      Initialize();
     138    }
    121139    protected ParticleSwarmOptimization(ParticleSwarmOptimization original, Cloner cloner)
    122140      : base(original, cloner) {
    123141      qualityAnalyzer = cloner.Clone(original.qualityAnalyzer);
     142      Initialize();
    124143    }
    125144
     
    255274      UpdateOmegaUpdater();
    256275      InitOmegaUpdater();
     276      Initialize();
     277    }
     278
     279    private void Initialize() {
     280      TopologyInitializerParameter.ValueChanged += new EventHandler(TopologyInitializerParameter_ValueChanged);
     281      ParticleUpdaterParameter.ValueChanged += new EventHandler(ParticleUpdaterParameter_ValueChanged);
     282      TopologyUpdaterParameter.ValueChanged += new EventHandler(TopologyUpdaterParameter_ValueChanged);
     283    }
     284
     285    void TopologyUpdaterParameter_ValueChanged(object sender, EventArgs e) {
     286      if (TopologyInitializer is EmptyTopologyInitializer) { // no topology updater allowed
     287        if (TopologyUpdater != null) {
     288          TopologyUpdater = null;
     289        }
     290      }
     291    }
     292
     293    void ParticleUpdaterParameter_ValueChanged(object sender, EventArgs e) {
     294      if (TopologyInitializer is EmptyTopologyInitializer) { // only global particle updater allowed
     295        if (!(ParticleUpdater is IGlobalParticleUpdater)) {
     296          ParticleUpdater = ParticleUpdaterParameter.ValidValues.Where(x => x is IGlobalParticleUpdater).First();
     297        }
     298      } else {  // only local particle updater allowed
     299        if (!(ParticleUpdater is ILocalParticleUpdater)) {
     300          ParticleUpdater = ParticleUpdaterParameter.ValidValues.Where(x => x is ILocalParticleUpdater).First();
     301        }
     302      }
     303    }
     304
     305    void TopologyInitializerParameter_ValueChanged(object sender, EventArgs e) {
     306      if (TopologyInitializer is EmptyTopologyInitializer) {   // only allow global particle update and no topology update
     307        if (ParticleUpdaterParameter.ValidValues.Count > 0) {
     308          if (!(ParticleUpdater is IGlobalParticleUpdater)) {
     309            ParticleUpdater = ParticleUpdaterParameter.ValidValues.Where(x => x is IGlobalParticleUpdater).First();
     310          }
     311        }
     312        if (TopologyUpdaterParameter.ValidValues.Count > 0) {
     313          if (!(TopologyUpdater != null)) {
     314            TopologyUpdater = null;
     315          }
     316        }
     317      } else { // only allow local particle update; topology change possible
     318        if (ParticleUpdaterParameter.ValidValues.Count > 0) {
     319          if (!(ParticleUpdater is ILocalParticleUpdater)) {
     320            ParticleUpdater = ParticleUpdaterParameter.ValidValues.Where(x => x is ILocalParticleUpdater).First();
     321          }
     322        }
     323      }
    257324    }
    258325
  • branches/PSO/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/TotallyConnectedParticleUpdater.cs

    r5316 r5342  
    2929  [Item("Totally Connected Particle Updater", "Updates the particle's position using (among other things) the global best position. Use together with the empty topology initialzer. Point = Point + Velocity*Omega + (PersonalBestPoint-Point)*Phi_P*r_p + (BestPoint-Point)*Phi_G*r_g")]
    3030  [StorableClass]
    31   public class TotallyConnectedParticleUpdater : ParticleUpdater {
     31  public class TotallyConnectedParticleUpdater : ParticleUpdater, IGlobalParticleUpdater {
    3232
    3333    #region Construction & Cloning
Note: See TracChangeset for help on using the changeset viewer.