Free cookie consent management tool by TermsFeed Policy Generator

Changeset 5410 for branches/PSO


Ignore:
Timestamp:
02/03/11 12:23:40 (13 years ago)
Author:
mkofler
Message:

#852: Realized code cleanup as described in the reviewer comments by Andreas Beham.

Location:
branches/PSO/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3
Files:
2 deleted
14 edited

Legend:

Unmodified
Added
Removed
  • branches/PSO/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/BestPointInitializer.cs

    r5316 r5410  
    3636
    3737    #region Parameter properties
    38     public ScopeTreeLookupParameter<DoubleValue> QualityParameter {
    39       get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
     38    public IScopeTreeLookupParameter<DoubleValue> QualityParameter {
     39      get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
    4040    }
    41     public LookupParameter<DoubleValue> BestQualityParameter {
    42       get { return (LookupParameter<DoubleValue>)Parameters["BestQuality"]; }
     41    public ILookupParameter<DoubleValue> BestQualityParameter {
     42      get { return (ILookupParameter<DoubleValue>)Parameters["BestQuality"]; }
    4343    }
    44     public ScopeTreeLookupParameter<RealVector> PointParameter {
    45       get { return (ScopeTreeLookupParameter<RealVector>)Parameters["Point"]; }
     44    public IScopeTreeLookupParameter<RealVector> PointParameter {
     45      get { return (IScopeTreeLookupParameter<RealVector>)Parameters["Point"]; }
    4646    }
    47     public LookupParameter<RealVector> BestPointParameter {
    48       get { return (LookupParameter<RealVector>)Parameters["BestPoint"]; }
     47    public ILookupParameter<RealVector> BestPointParameter {
     48      get { return (ILookupParameter<RealVector>)Parameters["BestPoint"]; }
    4949    }
    50     public ValueLookupParameter<BoolValue> MaximizationParameter {
    51       get { return (ValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
     50    public IValueLookupParameter<BoolValue> MaximizationParameter {
     51      get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
    5252    }
    5353    #endregion
  • branches/PSO/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/HeuristicLab.Algorithms.ParticleSwarmOptimization-3.3.csproj

    r5342 r5410  
    117117    <Compile Include="RandomTopologyInitializer.cs" />
    118118    <Compile Include="VonNeumannTopologyInitializer.cs" />
    119     <Compile Include="EmptyTopologyInitializer.cs" />
    120119    <Compile Include="RingTopologyInitializer.cs" />
    121120    <Compile Include="ITopologyUpdater.cs" />
    122     <Compile Include="IdentityTopologyUpdater.cs" />
    123121    <Compile Include="NeighborUpdater.cs" />
    124122    <Compile Include="TopologyInitializer.cs" />
  • branches/PSO/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/IParticleUpdater.cs

    r5342 r5410  
    2727namespace HeuristicLab.Algorithms.ParticleSwarmOptimization {
    2828
    29   public interface IParticleUpdater : INamedItem {
     29  public interface IParticleUpdater : IOperator {
    3030
    31     LookupParameter<RealVector> VelocityParameter { get; }
    32     LookupParameter<DoubleMatrix> VelocityBoundsParameter { get; }
     31    ILookupParameter<RealVector> VelocityParameter { get; }
     32    ILookupParameter<DoubleMatrix> VelocityBoundsParameter { get; }
    3333
    34     LookupParameter<RealVector> PointParameter { get; }
    35     LookupParameter<DoubleMatrix> BoundsParameter { get; }
     34    ILookupParameter<RealVector> PointParameter { get; }
     35    ILookupParameter<DoubleMatrix> BoundsParameter { get; }
    3636
    37     LookupParameter<RealVector> PersonalBestPointParameter { get; }
    38     LookupParameter<RealVector> BestNeighborPointParameter { get; }
    39     LookupParameter<RealVector> BestPointParameter { get; }
     37    ILookupParameter<RealVector> PersonalBestPointParameter { get; }
     38    ILookupParameter<RealVector> BestNeighborPointParameter { get; }
     39    ILookupParameter<RealVector> BestPointParameter { get; }
    4040
    41     LookupParameter<DoubleValue> OmegaParameter { get; }
    42     LookupParameter<DoubleValue> Phi_PParameter { get; }
    43     LookupParameter<DoubleValue> Phi_GParameter { get; }
     41    ILookupParameter<DoubleValue> OmegaParameter { get; }
     42    ILookupParameter<DoubleValue> Phi_PParameter { get; }
     43    ILookupParameter<DoubleValue> Phi_GParameter { get; }
    4444  }
    4545
  • branches/PSO/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/ITopologyInitializer.cs

    r5209 r5410  
    2626namespace HeuristicLab.Algorithms.ParticleSwarmOptimization {
    2727
    28   public interface ITopologyInitializer : IItem {
    29     ScopeTreeLookupParameter<IntegerVector> NeighborsParameter { get; }
    30     LookupParameter<IntValue> SwarmSizeParameter { get; }
     28  public interface ITopologyInitializer : IOperator {
     29    IScopeTreeLookupParameter<IntegerVector> NeighborsParameter { get; }
     30    ILookupParameter<IntValue> SwarmSizeParameter { get; }
    3131  }
    3232
  • branches/PSO/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/ITopologyUpdater.cs

    r5209 r5410  
    2626
    2727  public interface ITopologyUpdater : IItem {
    28     ScopeTreeLookupParameter<IntegerVector> NeighborsParameter { get; }
     28    IScopeTreeLookupParameter<IntegerVector> NeighborsParameter { get; }
    2929  }
    3030
  • branches/PSO/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/MultiPSOTopologyUpdater.cs

    r5339 r5410  
    1616  public class MultiPSOTopologyUpdater : SingleSuccessorOperator, ITopologyUpdater, ITopologyInitializer {
    1717    #region Parameters
    18     public LookupParameter<IRandom> RandomParameter {
    19       get { return (LookupParameter<IRandom>)Parameters["Random"]; }
     18    public ILookupParameter<IRandom> RandomParameter {
     19      get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
    2020    }
    21     public ValueLookupParameter<IntValue> NrOfConnectionsParameter {
    22       get { return (ValueLookupParameter<IntValue>)Parameters["NrOfConnections"]; }
     21    public IValueLookupParameter<IntValue> NrOfConnectionsParameter {
     22      get { return (IValueLookupParameter<IntValue>)Parameters["NrOfConnections"]; }
    2323    }
    24     public LookupParameter<IntValue> SwarmSizeParameter {
    25       get { return (LookupParameter<IntValue>)Parameters["SwarmSize"]; }
     24    public ILookupParameter<IntValue> SwarmSizeParameter {
     25      get { return (ILookupParameter<IntValue>)Parameters["SwarmSize"]; }
    2626    }
    27     public ScopeTreeLookupParameter<IntegerVector> NeighborsParameter {
    28       get { return (ScopeTreeLookupParameter<IntegerVector>)Parameters["Neighbors"]; }
     27    public IScopeTreeLookupParameter<IntegerVector> NeighborsParameter {
     28      get { return (IScopeTreeLookupParameter<IntegerVector>)Parameters["Neighbors"]; }
    2929    }
    30     public LookupParameter<IntValue> CurrentIterationParameter {
    31       get { return (LookupParameter<IntValue>)Parameters["CurrentIteration"]; }
     30    public ILookupParameter<IntValue> CurrentIterationParameter {
     31      get { return (ILookupParameter<IntValue>)Parameters["CurrentIteration"]; }
    3232    }
    33     public ValueLookupParameter<IntValue> RegroupingPeriodParameter {
    34       get { return (ValueLookupParameter<IntValue>)Parameters["RegroupingPeriod"]; }
     33    public IValueLookupParameter<IntValue> RegroupingPeriodParameter {
     34      get { return (IValueLookupParameter<IntValue>)Parameters["RegroupingPeriod"]; }
    3535    }
    3636    #endregion
  • branches/PSO/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/NeighborUpdater.cs

    r5316 r5410  
    3636
    3737    #region Parameters
    38     public ScopeTreeLookupParameter<RealVector> PointsParameter {
    39       get { return (ScopeTreeLookupParameter<RealVector>)Parameters["Point"]; }
     38    public IScopeTreeLookupParameter<RealVector> PointsParameter {
     39      get { return (IScopeTreeLookupParameter<RealVector>)Parameters["Point"]; }
    4040    }
    41     public ScopeTreeLookupParameter<IntegerVector> NeighborsParameter {
    42       get { return (ScopeTreeLookupParameter<IntegerVector>)Parameters["Neighbors"]; }
     41    public IScopeTreeLookupParameter<IntegerVector> NeighborsParameter {
     42      get { return (IScopeTreeLookupParameter<IntegerVector>)Parameters["Neighbors"]; }
    4343    }
    44     public ScopeTreeLookupParameter<RealVector> BestNeighborPointParameter {
    45       get { return (ScopeTreeLookupParameter<RealVector>)Parameters["BestNeighborPoint"]; }
     44    public IScopeTreeLookupParameter<RealVector> BestNeighborPointParameter {
     45      get { return (IScopeTreeLookupParameter<RealVector>)Parameters["BestNeighborPoint"]; }
    4646    }
    47     public ScopeTreeLookupParameter<DoubleValue> QualityParameter {
    48       get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
     47    public IScopeTreeLookupParameter<DoubleValue> QualityParameter {
     48      get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
    4949    }
    50     public LookupParameter<BoolValue> MaximizationParameter {
    51       get { return (LookupParameter<BoolValue>)Parameters["Maximization"]; }
     50    public ILookupParameter<BoolValue> MaximizationParameter {
     51      get { return (ILookupParameter<BoolValue>)Parameters["Maximization"]; }
    5252    }
    5353    #endregion
  • branches/PSO/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/NeighborhoodParticleUpdater.cs

    r5342 r5410  
    4949      double r_p = Random.NextDouble();
    5050      double r_g = Random.NextDouble();
     51      double omega = Omega.Value;
     52      double phi_p = Phi_P.Value;
     53      double phi_g = Phi_G.Value;
    5154      for (int i = 0; i < velocity.Length; i++) {
    5255        velocity[i] =
    53           Velocity[i] * Omega +
    54           (PersonalBestPoint[i] - Point[i]) * Phi_P * r_p +
    55           (BestNeighborPoint[i] - Point[i]) * Phi_G * r_g;
     56          Velocity[i] * omega +
     57          (PersonalBestPoint[i] - Point[i]) * phi_p * r_p +
     58          (BestNeighborPoint[i] - Point[i]) * phi_g * r_g;
    5659      }
    5760      BoundsChecker.Apply(velocity, VelocityBounds);
  • branches/PSO/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/ParticleSwarmOptimization.cs

    r5342 r5410  
    3434using HeuristicLab.PluginInfrastructure;
    3535using HeuristicLab.Random;
     36using System.Collections.Generic;
    3637
    3738namespace HeuristicLab.Algorithms.ParticleSwarmOptimization {
     
    6566
    6667    #region Parameter Properties
    67     public ValueParameter<IntValue> SeedParameter {
    68       get { return (ValueParameter<IntValue>)Parameters["Seed"]; }
    69     }
    70     public ValueParameter<BoolValue> SetSeedRandomlyParameter {
    71       get { return (ValueParameter<BoolValue>)Parameters["SetSeedRandomly"]; }
    72     }
    73     public ValueParameter<IntValue> SwarmSizeParameter {
    74       get { return (ValueParameter<IntValue>)Parameters["SwarmSize"]; }
    75     }
    76     public ValueParameter<IntValue> MaxIterationsParameter {
    77       get { return (ValueParameter<IntValue>)Parameters["MaxIterations"]; }
    78     }
    79     public ValueParameter<DoubleValue> OmegaParameter {
    80       get { return (ValueParameter<DoubleValue>)Parameters["Omega"]; }
    81     }
    82     public ValueParameter<DoubleValue> Phi_PParameter {
    83       get { return (ValueParameter<DoubleValue>)Parameters["Phi_P"]; }
    84     }
    85     public ValueParameter<DoubleValue> Phi_GParameter {
    86       get { return (ValueParameter<DoubleValue>)Parameters["Phi_G"]; }
    87     }
    88     public ValueParameter<MultiAnalyzer> AnalyzerParameter {
    89       get { return (ValueParameter<MultiAnalyzer>)Parameters["Analyzer"]; }
    90     }
    91     public ValueLookupParameter<DoubleMatrix> VelocityBoundsParameter {
    92       get { return (ValueLookupParameter<DoubleMatrix>)Parameters["VelocityBounds"]; }
     68    public IValueParameter<IntValue> SeedParameter {
     69      get { return (IValueParameter<IntValue>)Parameters["Seed"]; }
     70    }
     71    public IValueParameter<BoolValue> SetSeedRandomlyParameter {
     72      get { return (IValueParameter<BoolValue>)Parameters["SetSeedRandomly"]; }
     73    }
     74    public IValueParameter<IntValue> SwarmSizeParameter {
     75      get { return (IValueParameter<IntValue>)Parameters["SwarmSize"]; }
     76    }
     77    public IValueParameter<IntValue> MaxIterationsParameter {
     78      get { return (IValueParameter<IntValue>)Parameters["MaxIterations"]; }
     79    }
     80    public IValueParameter<DoubleValue> OmegaParameter {
     81      get { return (IValueParameter<DoubleValue>)Parameters["Omega"]; }
     82    }
     83    public IValueParameter<DoubleValue> Phi_PParameter {
     84      get { return (IValueParameter<DoubleValue>)Parameters["Phi_P"]; }
     85    }
     86    public IValueParameter<DoubleValue> Phi_GParameter {
     87      get { return (IValueParameter<DoubleValue>)Parameters["Phi_G"]; }
     88    }
     89    public IValueParameter<MultiAnalyzer> AnalyzerParameter {
     90      get { return (IValueParameter<MultiAnalyzer>)Parameters["Analyzer"]; }
     91    }
     92    public IValueLookupParameter<DoubleMatrix> VelocityBoundsParameter {
     93      get { return (IValueLookupParameter<DoubleMatrix>)Parameters["VelocityBounds"]; }
    9394    }
    9495    public ConstrainedValueParameter<IParticleUpdater> ParticleUpdaterParameter {
    9596      get { return (ConstrainedValueParameter<IParticleUpdater>)Parameters["ParticleUpdater"]; }
    9697    }
    97     public ConstrainedValueParameter<ITopologyInitializer> TopologyInitializerParameter {
    98       get { return (ConstrainedValueParameter<ITopologyInitializer>)Parameters["TopologyInitializer"]; }
    99     }
    100     public ConstrainedValueParameter<ITopologyUpdater> TopologyUpdaterParameter {
    101       get { return (ConstrainedValueParameter<ITopologyUpdater>)Parameters["TopologyUpdater"]; }
     98    public OptionalConstrainedValueParameter<ITopologyInitializer> TopologyInitializerParameter {
     99      get { return (OptionalConstrainedValueParameter<ITopologyInitializer>)Parameters["TopologyInitializer"]; }
     100    }
     101    public OptionalConstrainedValueParameter<ITopologyUpdater> TopologyUpdaterParameter {
     102      get { return (OptionalConstrainedValueParameter<ITopologyUpdater>)Parameters["TopologyUpdater"]; }
    102103    }
    103104    public OptionalConstrainedValueParameter<IDiscreteDoubleMatrixModifier> VelocityBoundsUpdaterParameter {
     
    134135
    135136    [StorableConstructor]
    136     protected ParticleSwarmOptimization(bool deserializing) : base(deserializing) {
    137       Initialize();
     137    protected ParticleSwarmOptimization(bool deserializing)
     138      : base(deserializing) {
    138139    }
    139140    protected ParticleSwarmOptimization(ParticleSwarmOptimization original, Cloner cloner)
    140141      : base(original, cloner) {
    141142      qualityAnalyzer = cloner.Clone(original.qualityAnalyzer);
     143      Initialize();
     144    }
     145
     146    [StorableHook(HookType.AfterDeserialization)]
     147    private void AfterDeserialization() {
    142148      Initialize();
    143149    }
     
    154160      Parameters.Add(new ValueParameter<DoubleValue>("Phi_G", "Weight for global best position.", new DoubleValue(3.7)));
    155161      Parameters.Add(new ValueLookupParameter<DoubleMatrix>("VelocityBounds", "Maximum Velocity in every dimension", new DoubleMatrix(new double[,] { { -1, 1 } })));
    156       Parameters.Add(new ConstrainedValueParameter<IParticleUpdater>("ParticleUpdater", "Operator that calculates new position and velocity of a particle",
    157         new ItemSet<IParticleUpdater>(ApplicationManager.Manager.GetInstances<IParticleUpdater>())));
    158       Parameters.Add(new ConstrainedValueParameter<ITopologyInitializer>("TopologyInitializer", "Creates neighborhood description vectors",
    159         new ItemSet<ITopologyInitializer>(ApplicationManager.Manager.GetInstances<ITopologyInitializer>())));
    160       Parameters.Add(new ConstrainedValueParameter<ITopologyUpdater>("TopologyUpdater", "Updates the neighborhood description vectors",
    161         new ItemSet<ITopologyUpdater>(ApplicationManager.Manager.GetInstances<ITopologyUpdater>())));
     162      Parameters.Add(new ConstrainedValueParameter<IParticleUpdater>("ParticleUpdater", "Operator that calculates new position and velocity of a particle"));
     163      Parameters.Add(new OptionalConstrainedValueParameter<ITopologyInitializer>("TopologyInitializer", "Creates neighborhood description vectors"));
     164      Parameters.Add(new OptionalConstrainedValueParameter<ITopologyUpdater>("TopologyUpdater", "Updates the neighborhood description vectors"));
    162165      Parameters.Add(new OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier>("OmegaUpdater", "Updates the omega parameter"));
    163166      Parameters.Add(new OptionalConstrainedValueParameter<IDiscreteDoubleMatrixModifier>("VelocityBoundsUpdater", "Adjusts the velocity bounds."));
    164167      ParticleUpdaterParameter.ActualValue = ParticleUpdaterParameter.ValidValues.SingleOrDefault(v => v.GetType() == typeof(TotallyConnectedParticleUpdater));
    165       TopologyInitializerParameter.ActualValue = TopologyInitializerParameter.ValidValues.SingleOrDefault(v => v.GetType() == typeof(EmptyTopologyInitializer));
    166168
    167169      RandomCreator randomCreator = new RandomCreator();
     
    274276      UpdateOmegaUpdater();
    275277      InitOmegaUpdater();
     278      UpdateTopologyInitializer();
    276279      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       }
    324     }
    325 
    326     private static void InitializeParticleCreator(CombinedOperator particleCreator) {
    327       Placeholder positionCreator = new Placeholder();
    328       Assigner personalBestPositionAssigner = new Assigner();
    329       UniformRandomRealVectorCreator velocityCreator = new UniformRandomRealVectorCreator();
    330 
    331       particleCreator.Name = "Particle Creator";
    332       particleCreator.OperatorGraph.InitialOperator = positionCreator;
    333 
    334       positionCreator.Name = "(SolutionCreator)";
    335       positionCreator.OperatorParameter.ActualName = "SolutionCreator";
    336       positionCreator.Successor = personalBestPositionAssigner;
    337 
    338       personalBestPositionAssigner.LeftSideParameter.ActualName = "PersonalBestPoint";
    339       personalBestPositionAssigner.RightSideParameter.ActualName = "Point";
    340       personalBestPositionAssigner.Successor = velocityCreator;
    341 
    342       velocityCreator.LengthParameter.ActualName = "ProblemSize";
    343       velocityCreator.BoundsParameter.ActualName = "VelocityBounds";
    344       velocityCreator.RealVectorParameter.ActualName = "Velocity";
    345280    }
    346281
     
    369304      UpdateAnalyzers();
    370305      ParameterizeAnalyzers();
    371       Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
    372306      base.OnProblemChanged();
    373307    }
    374308
     309    void TopologyInitializerParameter_ValueChanged(object sender, EventArgs e) {
     310      this.UpdateTopologyParameters();
     311    }
     312
     313    void VelocityBoundsUpdaterParameter_ValueChanged(object sender, EventArgs e) {
     314      if (VelocityBoundsParameter.Value != null) {
     315        foreach (IDiscreteDoubleMatrixModifier matrixOp in VelocityBoundsUpdaterParameter.Value.ScalingOperatorParameter.ValidValues) {
     316          matrixOp.ValueParameter.ActualName = VelocityBoundsUpdater.ScaleParameter.Name;
     317          matrixOp.StartValueParameter.Value = new DoubleValue(VelocityBoundsUpdater.ScaleParameter.ActualValue.Value);
     318        }
     319      }
     320    }
    375321    #endregion
    376322
    377323    #region Helpers
    378     private void InitializeParticleUpdaters() {
    379     }
    380 
    381     private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
     324    private void Initialize() {
     325      TopologyInitializerParameter.ValueChanged += new EventHandler(TopologyInitializerParameter_ValueChanged);
     326    }
     327
     328    private static void InitializeParticleCreator(CombinedOperator particleCreator) {
     329      Placeholder positionCreator = new Placeholder();
     330      Assigner personalBestPositionAssigner = new Assigner();
     331      UniformRandomRealVectorCreator velocityCreator = new UniformRandomRealVectorCreator();
     332
     333      particleCreator.Name = "Particle Creator";
     334      particleCreator.OperatorGraph.InitialOperator = positionCreator;
     335
     336      positionCreator.Name = "(SolutionCreator)";
     337      positionCreator.OperatorParameter.ActualName = "SolutionCreator";
     338      positionCreator.Successor = personalBestPositionAssigner;
     339
     340      personalBestPositionAssigner.LeftSideParameter.ActualName = "PersonalBestPoint";
     341      personalBestPositionAssigner.RightSideParameter.ActualName = "Point";
     342      personalBestPositionAssigner.Successor = velocityCreator;
     343
     344      velocityCreator.LengthParameter.ActualName = "ProblemSize";
     345      velocityCreator.BoundsParameter.ActualName = "VelocityBounds";
     346      velocityCreator.RealVectorParameter.ActualName = "Velocity";
    382347    }
    383348
     
    385350      qualityAnalyzer = new BestAverageWorstQualityAnalyzer();
    386351      ParameterizeAnalyzers();
     352    }
     353
     354    private void ParameterizeAnalyzers() {
     355      if (Problem != null) {
     356        qualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
     357        qualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
     358        qualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
     359      }
     360    }
     361
     362    private void UpdateAnalyzers() {
     363      Analyzer.Operators.Clear();
     364      if (Problem != null) {
     365        foreach (IAnalyzer analyzer in Problem.Operators.OfType<IAnalyzer>())
     366          Analyzer.Operators.Add(analyzer);
     367      }
     368      Analyzer.Operators.Add(qualityAnalyzer);
    387369    }
    388370
     
    399381    }
    400382
    401     void VelocityBoundsUpdaterParameter_ValueChanged(object sender, EventArgs e) {
    402       if (VelocityBoundsParameter.Value != null) {
    403         foreach (IDiscreteDoubleMatrixModifier matrixOp in VelocityBoundsUpdaterParameter.Value.ScalingOperatorParameter.ValidValues) {
    404             matrixOp.ValueParameter.ActualName = VelocityBoundsUpdater.ScaleParameter.Name;
    405             matrixOp.StartValueParameter.Value = new DoubleValue(VelocityBoundsUpdater.ScaleParameter.ActualValue.Value);
    406         }
    407       }
    408     }
    409 
    410383    private void InitOmegaUpdater() {
    411384      foreach (IDiscreteDoubleValueModifier updater in OmegaUpdaterParameter.ValidValues) {
     
    431404    }
    432405
    433     private void ParameterizeAnalyzers() {
    434       if (Problem != null) {
    435         qualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
    436         qualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
    437         qualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
    438       }
    439     }
    440 
    441     private void UpdateAnalyzers() {
    442       Analyzer.Operators.Clear();
    443       if (Problem != null) {
    444         foreach (IAnalyzer analyzer in Problem.Operators.OfType<IAnalyzer>())
    445           Analyzer.Operators.Add(analyzer);
    446       }
    447       Analyzer.Operators.Add(qualityAnalyzer);
    448     }
    449 
     406    private void UpdateTopologyInitializer() {
     407      ITopologyInitializer oldTopologyInitializer = TopologyInitializer;
     408      TopologyInitializerParameter.ValidValues.Clear();
     409      foreach (ITopologyInitializer topologyInitializer in ApplicationManager.Manager.GetInstances<ITopologyInitializer>().OrderBy(x => x.Name)) {
     410        TopologyInitializerParameter.ValidValues.Add(topologyInitializer);
     411      }
     412      if (oldTopologyInitializer != null && TopologyInitializerParameter.ValidValues.Any(x => x.GetType() == oldTopologyInitializer.GetType()))
     413        TopologyInitializer = TopologyInitializerParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldTopologyInitializer.GetType());
     414      UpdateTopologyParameters();
     415    }
     416
     417    private void UpdateTopologyParameters() {
     418      ITopologyUpdater oldTopologyUpdater = TopologyUpdater;
     419      IParticleUpdater oldParticleUpdater = ParticleUpdater;
     420      ClearTopologyParameters();
     421      if (TopologyInitializer != null) {
     422        foreach (ITopologyUpdater topologyUpdater in ApplicationManager.Manager.GetInstances<ITopologyUpdater>())
     423          TopologyUpdaterParameter.ValidValues.Add(topologyUpdater);
     424        foreach (IParticleUpdater particleUpdater in ApplicationManager.Manager.GetInstances<ILocalParticleUpdater>())
     425          ParticleUpdaterParameter.ValidValues.Add(particleUpdater);
     426      } else {
     427        foreach (IParticleUpdater particleUpdater in ApplicationManager.Manager.GetInstances<IGlobalParticleUpdater>())
     428          ParticleUpdaterParameter.ValidValues.Add(particleUpdater);
     429      }
     430      if (oldTopologyUpdater != null) {
     431        ITopologyUpdater newTopologyUpdater = TopologyUpdaterParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldParticleUpdater.GetType());
     432        if (newTopologyUpdater != null) TopologyUpdater = newTopologyUpdater;
     433      }
     434      if (oldParticleUpdater != null) {
     435        IParticleUpdater newParticleUpdater = ParticleUpdaterParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldParticleUpdater.GetType());
     436        if (newParticleUpdater != null) ParticleUpdater = newParticleUpdater;
     437      }
     438    }
     439
     440    private void ClearTopologyParameters() {
     441      TopologyUpdaterParameter.ValidValues.Clear();
     442      ParticleUpdaterParameter.ValidValues.Clear();
     443    }
    450444    #endregion
    451      
     445
    452446  }
    453447}
  • branches/PSO/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/ParticleUpdater.cs

    r5209 r5410  
    3434
    3535    #region Parameter properties
    36     public LookupParameter<IRandom> RandomParameter {
    37       get { return (LookupParameter<IRandom>)Parameters["Random"]; }
     36    public ILookupParameter<IRandom> RandomParameter {
     37      get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
    3838    }
    39     public LookupParameter<RealVector> PointParameter {
    40       get { return (LookupParameter<RealVector>)Parameters["Point"]; }
     39    public ILookupParameter<RealVector> PointParameter {
     40      get { return (ILookupParameter<RealVector>)Parameters["Point"]; }
    4141    }
    42     public LookupParameter<RealVector> VelocityParameter {
    43       get { return (LookupParameter<RealVector>)Parameters["Velocity"]; }
     42    public ILookupParameter<RealVector> VelocityParameter {
     43      get { return (ILookupParameter<RealVector>)Parameters["Velocity"]; }
    4444    }
    45     public LookupParameter<RealVector> PersonalBestPointParameter {
    46       get { return (LookupParameter<RealVector>)Parameters["PersonalBestPoint"]; }
     45    public ILookupParameter<RealVector> PersonalBestPointParameter {
     46      get { return (ILookupParameter<RealVector>)Parameters["PersonalBestPoint"]; }
    4747    }
    48     public LookupParameter<RealVector> BestNeighborPointParameter {
    49       get { return (LookupParameter<RealVector>)Parameters["BestNeighborPoint"]; }
     48    public ILookupParameter<RealVector> BestNeighborPointParameter {
     49      get { return (ILookupParameter<RealVector>)Parameters["BestNeighborPoint"]; }
    5050    }
    51     public LookupParameter<RealVector> BestPointParameter {
    52       get { return (LookupParameter<RealVector>)Parameters["BestPoint"]; }
     51    public ILookupParameter<RealVector> BestPointParameter {
     52      get { return (ILookupParameter<RealVector>)Parameters["BestPoint"]; }
    5353    }
    54     public LookupParameter<DoubleMatrix> BoundsParameter {
    55       get { return (LookupParameter<DoubleMatrix>)Parameters["Bounds"]; }
     54    public ILookupParameter<DoubleMatrix> BoundsParameter {
     55      get { return (ILookupParameter<DoubleMatrix>)Parameters["Bounds"]; }
    5656    }
    57     public LookupParameter<DoubleMatrix> VelocityBoundsParameter {
    58       get { return (LookupParameter<DoubleMatrix>)Parameters["VelocityBounds"]; }
     57    public ILookupParameter<DoubleMatrix> VelocityBoundsParameter {
     58      get { return (ILookupParameter<DoubleMatrix>)Parameters["VelocityBounds"]; }
    5959    }
    60     public LookupParameter<DoubleValue> OmegaParameter {
    61       get { return (LookupParameter<DoubleValue>)Parameters["Omega"]; }
     60    public ILookupParameter<DoubleValue> OmegaParameter {
     61      get { return (ILookupParameter<DoubleValue>)Parameters["Omega"]; }
    6262    }
    63     public LookupParameter<DoubleValue> Phi_PParameter {
    64       get { return (LookupParameter<DoubleValue>)Parameters["Phi_P"]; }
     63    public ILookupParameter<DoubleValue> Phi_PParameter {
     64      get { return (ILookupParameter<DoubleValue>)Parameters["Phi_P"]; }
    6565    }
    66     public LookupParameter<DoubleValue> Phi_GParameter {
    67       get { return (LookupParameter<DoubleValue>)Parameters["Phi_G"]; }
     66    public ILookupParameter<DoubleValue> Phi_GParameter {
     67      get { return (ILookupParameter<DoubleValue>)Parameters["Phi_G"]; }
    6868    }
    6969    #endregion
     
    9696      get { return VelocityBoundsParameter.ActualValue; }
    9797    }
    98     public double Omega {
    99       get { return OmegaParameter.ActualValue.Value; }
     98
     99    public DoubleValue Omega {
     100      get { return OmegaParameter.ActualValue; }
    100101    }
    101     public double Phi_P {
    102       get { return Phi_PParameter.ActualValue.Value; }
     102    public DoubleValue Phi_P {
     103      get { return Phi_PParameter.ActualValue; }
    103104    }
    104     public double Phi_G {
    105       get { return Phi_GParameter.ActualValue.Value; }
     105    public DoubleValue Phi_G {
     106      get { return Phi_GParameter.ActualValue; }
    106107    }
    107108    #endregion
     
    135136
    136137    #endregion
    137 
    138138  }
    139139}
  • branches/PSO/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/RandomTopologyInitializer.cs

    r5316 r5410  
    3535
    3636    #region Parameters
    37     public LookupParameter<IRandom> RandomParameter {
    38       get { return (LookupParameter<IRandom>)Parameters["Random"]; }
     37    public ILookupParameter<IRandom> RandomParameter {
     38      get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
    3939    }
    40     public ValueLookupParameter<IntValue> NrOfConnectionsParameter {
    41       get { return (ValueLookupParameter<IntValue>)Parameters["NrOfConnections"]; }
     40    public IValueLookupParameter<IntValue> NrOfConnectionsParameter {
     41      get { return (IValueLookupParameter<IntValue>)Parameters["NrOfConnections"]; }
    4242    }
    4343    #endregion
  • branches/PSO/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/SwarmUpdater.cs

    r5316 r5410  
    3535
    3636    #region Parameter properties
    37     public LookupParameter<DoubleValue> QualityParameter {
    38       get { return (LookupParameter<DoubleValue>)Parameters["Quality"]; }
     37    public ILookupParameter<DoubleValue> QualityParameter {
     38      get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; }
    3939    }
    40     public LookupParameter<DoubleValue> PersonalBestQualityParameter {
    41       get { return (LookupParameter<DoubleValue>)Parameters["PersonalBestQuality"]; }
     40    public ILookupParameter<DoubleValue> PersonalBestQualityParameter {
     41      get { return (ILookupParameter<DoubleValue>)Parameters["PersonalBestQuality"]; }
    4242    }
    43     public LookupParameter<DoubleValue> BestQualityParameter {
    44       get { return (LookupParameter<DoubleValue>)Parameters["BestQuality"]; }
     43    public ILookupParameter<DoubleValue> BestQualityParameter {
     44      get { return (ILookupParameter<DoubleValue>)Parameters["BestQuality"]; }
    4545    }
    46     public LookupParameter<RealVector> PointParameter {
    47       get { return (LookupParameter<RealVector>)Parameters["Point"]; }
     46    public ILookupParameter<RealVector> PointParameter {
     47      get { return (ILookupParameter<RealVector>)Parameters["Point"]; }
    4848    }
    49     public LookupParameter<RealVector> PersonalBestPointParameter {
    50       get { return (LookupParameter<RealVector>)Parameters["PersonalBestPoint"]; }
     49    public ILookupParameter<RealVector> PersonalBestPointParameter {
     50      get { return (ILookupParameter<RealVector>)Parameters["PersonalBestPoint"]; }
    5151    }
    52     public LookupParameter<RealVector> BestPointParameter {
    53       get { return (LookupParameter<RealVector>)Parameters["BestPoint"]; }
     52    public ILookupParameter<RealVector> BestPointParameter {
     53      get { return (ILookupParameter<RealVector>)Parameters["BestPoint"]; }
    5454    }
    55     public ValueLookupParameter<BoolValue> MaximizationParameter {
    56       get { return (ValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
     55    public IValueLookupParameter<BoolValue> MaximizationParameter {
     56      get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
    5757    }
    5858    #endregion
  • branches/PSO/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/TopologyInitializer.cs

    r5209 r5410  
    3333
    3434    #region Parameters
    35     public ScopeTreeLookupParameter<IntegerVector> NeighborsParameter {
    36       get { return (ScopeTreeLookupParameter<IntegerVector>)Parameters["Neighbors"]; }
     35    public IScopeTreeLookupParameter<IntegerVector> NeighborsParameter {
     36      get { return (IScopeTreeLookupParameter<IntegerVector>)Parameters["Neighbors"]; }
    3737    }
    38     public LookupParameter<IntValue> SwarmSizeParameter {
    39       get { return (LookupParameter<IntValue>)Parameters["SwarmSize"]; }
     38    public ILookupParameter<IntValue> SwarmSizeParameter {
     39      get { return (ILookupParameter<IntValue>)Parameters["SwarmSize"]; }
    4040    }
    4141
  • branches/PSO/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/TotallyConnectedParticleUpdater.cs

    r5342 r5410  
    4545
    4646    public override IOperation Apply() {
     47      base.Apply();
    4748      RealVector velocity = new RealVector(Velocity.Length);
    4849      RealVector position = new RealVector(Point.Length);
    4950      double r_p = Random.NextDouble();
    5051      double r_g = Random.NextDouble();
     52      double omega = Omega.Value;
     53      double phi_p = Phi_P.Value;
     54      double phi_g = Phi_G.Value;
    5155      for (int i = 0; i < velocity.Length; i++) {
    5256        velocity[i] =
    53           Velocity[i] * Omega +
    54           (PersonalBestPoint[i] - Point[i]) * Phi_P * r_p +
    55           (BestPoint[i] - Point[i]) * Phi_G * r_g;
     57          Velocity[i] * omega +
     58          (PersonalBestPoint[i] - Point[i]) * phi_p * r_p +
     59          (BestPoint[i] - Point[i]) * phi_g * r_g;
    5660      }
    5761      BoundsChecker.Apply(velocity, VelocityBounds);
Note: See TracChangeset for help on using the changeset viewer.