Free cookie consent management tool by TermsFeed Policy Generator

Changeset 5209


Ignore:
Timestamp:
01/04/11 16:34:11 (14 years ago)
Author:
epitzer
Message:

Configurable ParticleUpdater, and topologies, different topology initializers and support for dynamic topology changes (#852)

Location:
branches/PSO/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3
Files:
9 added
3 edited
3 copied

Legend:

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

    r5033 r5209  
    1111    <RootNamespace>HeuristicLab.Algorithms.ParticleSwarmOptimization</RootNamespace>
    1212    <AssemblyName>HeuristicLab.Algorithms.ParticleSwarmOptimization-3.3</AssemblyName>
    13     <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
     13    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
    1414    <FileAlignment>512</FileAlignment>
    1515    <SignAssembly>true</SignAssembly>
     
    3434    <UseApplicationTrust>false</UseApplicationTrust>
    3535    <BootstrapperEnabled>true</BootstrapperEnabled>
     36    <TargetFrameworkProfile />
    3637  </PropertyGroup>
    3738  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
     
    9192  </PropertyGroup>
    9293  <ItemGroup>
     94    <Reference Include="HeuristicLab.Encodings.IntegerVectorEncoding-3.3">
     95      <HintPath>C:\Program Files\HeuristicLab 3.3\HeuristicLab.Encodings.IntegerVectorEncoding-3.3.dll</HintPath>
     96    </Reference>
    9397    <Reference Include="System" />
    9498    <Reference Include="System.Core">
     
    106110  <ItemGroup>
    107111    <Compile Include="BestPointInitializer.cs" />
     112    <Compile Include="RandomTopologyInitializer.cs" />
     113    <Compile Include="VonNeumannTopologyInitializer.cs" />
     114    <Compile Include="EmptyTopologyInitializer.cs" />
     115    <Compile Include="RingTopologyInitializer.cs" />
     116    <Compile Include="ITopologyUpdater.cs" />
     117    <Compile Include="IdentityTopologyUpdater.cs" />
     118    <Compile Include="NeighborUpdater.cs" />
     119    <Compile Include="TopologyInitializer.cs" />
     120    <Compile Include="ITopologyInitializer.cs" />
     121    <Compile Include="NeighborhoodParticleUpdater.cs" />
     122    <Compile Include="IParticleUpdater.cs" />
     123    <Compile Include="TotallyConnectedParticleUpdater.cs" />
    108124    <Compile Include="HeuristicLabAlgorithmsParticleSwarmOptimizationPlugin.cs" />
    109125    <Compile Include="ParticleSwarmOptimization.cs" />
  • branches/PSO/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/IParticleUpdater.cs

    r5208 r5209  
    2020#endregion
    2121
    22 using HeuristicLab.Common;
    2322using HeuristicLab.Core;
    2423using HeuristicLab.Data;
    2524using HeuristicLab.Encodings.RealVectorEncoding;
    26 using HeuristicLab.Operators;
    2725using HeuristicLab.Parameters;
    28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2926
    3027namespace HeuristicLab.Algorithms.ParticleSwarmOptimization {
    3128
    32   [StorableClass]
    33   public class ParticleUpdater : SingleSuccessorOperator {
     29  public interface IParticleUpdater : IItem {
     30    LookupParameter<RealVector> VelocityParameter { get; }
     31    LookupParameter<DoubleMatrix> VelocityBoundsParameter { get; }
    3432
    35     #region Parameter properties
    36     public LookupParameter<IRandom> RandomParameter {
    37       get { return (LookupParameter<IRandom>)Parameters["Random"]; }
    38     }
    39     public LookupParameter<RealVector> PointParameter {
    40       get { return (LookupParameter<RealVector>)Parameters["Point"]; }
    41     }
    42     public LookupParameter<RealVector> VelocityParameter {
    43       get { return (LookupParameter<RealVector>)Parameters["Velocity"]; }
    44     }
    45     public LookupParameter<RealVector> PersonalBestPointParameter {
    46       get { return (LookupParameter<RealVector>)Parameters["PersonalBestPoint"]; }
    47     }
    48     public LookupParameter<RealVector> BestPointParameter {
    49       get { return (LookupParameter<RealVector>)Parameters["BestPoint"]; }
    50     }
    51     public LookupParameter<DoubleMatrix> BoundsParameter {
    52       get { return (LookupParameter<DoubleMatrix>)Parameters["Bounds"]; }
    53     }
    54     public LookupParameter<DoubleMatrix> VelocityBoundsParameter {
    55       get { return (LookupParameter<DoubleMatrix>)Parameters["VelocityBounds"]; }
    56     }
    57     public LookupParameter<DoubleValue> OmegaParameter {
    58       get { return (LookupParameter<DoubleValue>)Parameters["Omega"]; }
    59     }
    60     public LookupParameter<DoubleValue> Phi_PParameter {
    61       get { return (LookupParameter<DoubleValue>)Parameters["Phi_P"]; }
    62     }
    63     public LookupParameter<DoubleValue> Phi_GParameter {
    64       get { return (LookupParameter<DoubleValue>)Parameters["Phi_G"]; }
    65     }
    66     #endregion
     33    LookupParameter<RealVector> PointParameter { get; }
     34    LookupParameter<DoubleMatrix> BoundsParameter { get; }
    6735
    68     #region Parameter Values
    69     public IRandom Random {
    70       get { return RandomParameter.ActualValue; }
    71     }
    72     public RealVector Point {
    73       get { return PointParameter.ActualValue; }
    74       set { PointParameter.ActualValue = value; }
    75     }
    76     public RealVector Velocity {
    77       get { return VelocityParameter.ActualValue; }
    78       set { VelocityParameter.ActualValue = value; }
    79     }
    80     public RealVector PersonalBestPoint {
    81       get { return PersonalBestPointParameter.ActualValue; }
    82     }
    83     public RealVector BestPoint {
    84       get { return BestPointParameter.ActualValue; }
    85     }
    86     public DoubleMatrix Bounds {
    87       get { return BoundsParameter.ActualValue; }
    88     }
    89     public DoubleMatrix VelocityBounds {
    90       get { return VelocityBoundsParameter.ActualValue; }
    91     }
    92     public double Omega {
    93       get { return OmegaParameter.ActualValue.Value; }
    94     }
    95     public double Phi_P {
    96       get { return Phi_PParameter.ActualValue.Value; }
    97     }
    98     public double Phi_G {
    99       get { return Phi_GParameter.ActualValue.Value; }
    100     }
    101     #endregion
     36    LookupParameter<RealVector> PersonalBestPointParameter { get; }
     37    LookupParameter<RealVector> BestNeighborPointParameter { get; }
     38    LookupParameter<RealVector> BestPointParameter { get; }
    10239
    103     #region Construction & Cloning
     40    LookupParameter<DoubleValue> OmegaParameter { get; }
     41    LookupParameter<DoubleValue> Phi_PParameter { get; }
     42    LookupParameter<DoubleValue> Phi_GParameter { get; }
     43  }
    10444
    105     [StorableConstructor]
    106     protected ParticleUpdater(bool deserializing) : base(deserializing) { }
    107     protected ParticleUpdater(ParticleUpdater original, Cloner cloner)
    108       : base(original, cloner) {
    109     }
    110 
    111     public ParticleUpdater()
    112       : base() {
    113       Parameters.Add(new LookupParameter<IRandom>("Random", "Random number generator."));
    114       Parameters.Add(new LookupParameter<RealVector>("Point", "Particle's current position"));
    115       Parameters.Add(new LookupParameter<RealVector>("Velocity", "Particle's current velocity."));
    116       Parameters.Add(new LookupParameter<RealVector>("PersonalBestPoint", "Particle's personal best position"));
    117       Parameters.Add(new LookupParameter<RealVector>("BestPoint", "Global best position"));
    118       Parameters.Add(new LookupParameter<DoubleMatrix>("Bounds", "The lower and upper bounds for each dimension of the position vector for the current problem."));
    119       Parameters.Add(new LookupParameter<DoubleMatrix>("VelocityBounds", "Upper and lower bounds for the particle's velocity vector."));
    120       Parameters.Add(new LookupParameter<DoubleValue>("Omega", "The weight for the particle's velocity vector."));
    121       Parameters.Add(new LookupParameter<DoubleValue>("Phi_P", "The weight for the particle's personal best position."));
    122       Parameters.Add(new LookupParameter<DoubleValue>("Phi_G", "The weight for the global best position."));
    123     }
    124 
    125     public override IDeepCloneable Clone(Cloner cloner) {
    126       return new ParticleUpdater(this, cloner);
    127     }
    128 
    129     #endregion
    130 
    131     public override IOperation Apply() {
    132       RealVector velocity = new RealVector(Velocity.Length);
    133       RealVector position = new RealVector(Point.Length);
    134       double r_p = Random.NextDouble();
    135       double r_g = Random.NextDouble();
    136       for (int i = 0; i < velocity.Length; i++) {
    137         velocity[i] =
    138           Velocity[i] * Omega +
    139           (PersonalBestPoint[i] - Point[i]) * Phi_P * r_p +
    140           (BestPoint[i] - Point[i]) * Phi_G * r_g;
    141       }
    142       BoundsChecker.Apply(velocity, VelocityBounds);
    143       for (int i = 0; i < velocity.Length; i++) {
    144         position[i] = Point[i] + velocity[i];
    145       }
    146       BoundsChecker.Apply(position, Bounds);
    147       Point = position;
    148       Velocity = velocity;
    149 
    150       return base.Apply();
    151     }
    152 
    153     public override bool CanChangeName {
    154       get { return false; }
    155     }
    156   }
    15745}
  • branches/PSO/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/NeighborhoodParticleUpdater.cs

    r5208 r5209  
    2222using HeuristicLab.Common;
    2323using HeuristicLab.Core;
    24 using HeuristicLab.Data;
    2524using HeuristicLab.Encodings.RealVectorEncoding;
    26 using HeuristicLab.Operators;
    27 using HeuristicLab.Parameters;
    2825using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2926
     
    3128
    3229  [StorableClass]
    33   public class ParticleUpdater : SingleSuccessorOperator {
    34 
    35     #region Parameter properties
    36     public LookupParameter<IRandom> RandomParameter {
    37       get { return (LookupParameter<IRandom>)Parameters["Random"]; }
    38     }
    39     public LookupParameter<RealVector> PointParameter {
    40       get { return (LookupParameter<RealVector>)Parameters["Point"]; }
    41     }
    42     public LookupParameter<RealVector> VelocityParameter {
    43       get { return (LookupParameter<RealVector>)Parameters["Velocity"]; }
    44     }
    45     public LookupParameter<RealVector> PersonalBestPointParameter {
    46       get { return (LookupParameter<RealVector>)Parameters["PersonalBestPoint"]; }
    47     }
    48     public LookupParameter<RealVector> BestPointParameter {
    49       get { return (LookupParameter<RealVector>)Parameters["BestPoint"]; }
    50     }
    51     public LookupParameter<DoubleMatrix> BoundsParameter {
    52       get { return (LookupParameter<DoubleMatrix>)Parameters["Bounds"]; }
    53     }
    54     public LookupParameter<DoubleMatrix> VelocityBoundsParameter {
    55       get { return (LookupParameter<DoubleMatrix>)Parameters["VelocityBounds"]; }
    56     }
    57     public LookupParameter<DoubleValue> OmegaParameter {
    58       get { return (LookupParameter<DoubleValue>)Parameters["Omega"]; }
    59     }
    60     public LookupParameter<DoubleValue> Phi_PParameter {
    61       get { return (LookupParameter<DoubleValue>)Parameters["Phi_P"]; }
    62     }
    63     public LookupParameter<DoubleValue> Phi_GParameter {
    64       get { return (LookupParameter<DoubleValue>)Parameters["Phi_G"]; }
    65     }
    66     #endregion
    67 
    68     #region Parameter Values
    69     public IRandom Random {
    70       get { return RandomParameter.ActualValue; }
    71     }
    72     public RealVector Point {
    73       get { return PointParameter.ActualValue; }
    74       set { PointParameter.ActualValue = value; }
    75     }
    76     public RealVector Velocity {
    77       get { return VelocityParameter.ActualValue; }
    78       set { VelocityParameter.ActualValue = value; }
    79     }
    80     public RealVector PersonalBestPoint {
    81       get { return PersonalBestPointParameter.ActualValue; }
    82     }
    83     public RealVector BestPoint {
    84       get { return BestPointParameter.ActualValue; }
    85     }
    86     public DoubleMatrix Bounds {
    87       get { return BoundsParameter.ActualValue; }
    88     }
    89     public DoubleMatrix VelocityBounds {
    90       get { return VelocityBoundsParameter.ActualValue; }
    91     }
    92     public double Omega {
    93       get { return OmegaParameter.ActualValue.Value; }
    94     }
    95     public double Phi_P {
    96       get { return Phi_PParameter.ActualValue.Value; }
    97     }
    98     public double Phi_G {
    99       get { return Phi_GParameter.ActualValue.Value; }
    100     }
    101     #endregion
     30  public class NeighborhoodParticleUpdater : ParticleUpdater {
    10231
    10332    #region Construction & Cloning
    10433
    10534    [StorableConstructor]
    106     protected ParticleUpdater(bool deserializing) : base(deserializing) { }
    107     protected ParticleUpdater(ParticleUpdater original, Cloner cloner)
    108       : base(original, cloner) {
    109     }
    110 
    111     public ParticleUpdater()
    112       : base() {
    113       Parameters.Add(new LookupParameter<IRandom>("Random", "Random number generator."));
    114       Parameters.Add(new LookupParameter<RealVector>("Point", "Particle's current position"));
    115       Parameters.Add(new LookupParameter<RealVector>("Velocity", "Particle's current velocity."));
    116       Parameters.Add(new LookupParameter<RealVector>("PersonalBestPoint", "Particle's personal best position"));
    117       Parameters.Add(new LookupParameter<RealVector>("BestPoint", "Global best position"));
    118       Parameters.Add(new LookupParameter<DoubleMatrix>("Bounds", "The lower and upper bounds for each dimension of the position vector for the current problem."));
    119       Parameters.Add(new LookupParameter<DoubleMatrix>("VelocityBounds", "Upper and lower bounds for the particle's velocity vector."));
    120       Parameters.Add(new LookupParameter<DoubleValue>("Omega", "The weight for the particle's velocity vector."));
    121       Parameters.Add(new LookupParameter<DoubleValue>("Phi_P", "The weight for the particle's personal best position."));
    122       Parameters.Add(new LookupParameter<DoubleValue>("Phi_G", "The weight for the global best position."));
    123     }
     35    protected NeighborhoodParticleUpdater(bool deserializing) : base(deserializing) { }
     36    protected NeighborhoodParticleUpdater(ParticleUpdater original, Cloner cloner) : base(original, cloner) { }
     37    public NeighborhoodParticleUpdater() : base() { }
    12438
    12539    public override IDeepCloneable Clone(Cloner cloner) {
    126       return new ParticleUpdater(this, cloner);
     40      return new NeighborhoodParticleUpdater(this, cloner);
    12741    }
    12842
     
    13852          Velocity[i] * Omega +
    13953          (PersonalBestPoint[i] - Point[i]) * Phi_P * r_p +
    140           (BestPoint[i] - Point[i]) * Phi_G * r_g;
     54          (BestNeighborPoint[i] - Point[i]) * Phi_G * r_g;
    14155      }
    14256      BoundsChecker.Apply(velocity, VelocityBounds);
     
    15064      return base.Apply();
    15165    }
    152 
    153     public override bool CanChangeName {
    154       get { return false; }
    155     }
    15666  }
    15767}
  • branches/PSO/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/ParticleSwarmOptimization.cs

    r5033 r5209  
    3232using HeuristicLab.Parameters;
    3333using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     34using HeuristicLab.PluginInfrastructure;
    3435using HeuristicLab.Random;
    3536
    3637namespace HeuristicLab.Algorithms.ParticleSwarmOptimization {
    3738
    38   [Item("Particle Swarm Optimization", "A particle swarm optimization algorithm.")]
     39  [Item("Particle Swarm Optimization", "A particle swarm optimization algorithm based on the description in Pedersen, M.E.H. (2010). PhD thesis. University of Southampton.")]
    3940  [Creatable("Algorithms")]
    4041  [StorableClass]
     
    8283    public ValueLookupParameter<DoubleMatrix> VelocityBoundsParameter {
    8384      get { return (ValueLookupParameter<DoubleMatrix>)Parameters["VelocityBounds"]; }
     85    }
     86    public ConstrainedValueParameter<IParticleUpdater> ParticleUpdaterParameter {
     87      get { return (ConstrainedValueParameter<IParticleUpdater>)Parameters["ParticleUpdater"]; }
     88    }
     89    public ConstrainedValueParameter<ITopologyInitializer> TopologyInitializerParameter {
     90      get { return (ConstrainedValueParameter<ITopologyInitializer>)Parameters["TopologyInitializer"]; }
     91    }
     92    public ConstrainedValueParameter<ITopologyUpdater> TopologyUpdaterParameter {
     93      get { return (ConstrainedValueParameter<ITopologyUpdater>)Parameters["TopologyUpdater"]; }
    8494    }
    8595    #endregion
     
    108118      Parameters.Add(new ValueParameter<DoubleValue>("Phi_G", "Weight for global best position.", new DoubleValue(3.7)));
    109119      Parameters.Add(new ValueLookupParameter<DoubleMatrix>("VelocityBounds", "Maximum Velocity in every dimension", new DoubleMatrix(new double[,] { { -1, 1 } })));
     120      Parameters.Add(new ConstrainedValueParameter<IParticleUpdater>("ParticleUpdater", "Operator that calculates new position and velocity of a particle",
     121        new ItemSet<IParticleUpdater>(ApplicationManager.Manager.GetInstances<IParticleUpdater>())));
     122      Parameters.Add(new ConstrainedValueParameter<ITopologyInitializer>("TopologyInitializer", "Creates neighborhood description vectors",
     123        new ItemSet<ITopologyInitializer>(ApplicationManager.Manager.GetInstances<ITopologyInitializer>())));
     124      Parameters.Add(new ConstrainedValueParameter<ITopologyUpdater>("TopologyUpdater", "Updates the neighborhood description vectors",
     125        new ItemSet<ITopologyUpdater>(ApplicationManager.Manager.GetInstances<ITopologyUpdater>())));
     126      ParticleUpdaterParameter.ActualValue = ParticleUpdaterParameter.ValidValues.SingleOrDefault(v => v.GetType() == typeof(TotallyConnectedParticleUpdater));
     127      TopologyInitializerParameter.ActualValue = TopologyInitializerParameter.ValidValues.SingleOrDefault(v => v.GetType() == typeof(EmptyTopologyInitializer));
     128      TopologyUpdaterParameter.ActualValue = TopologyUpdaterParameter.ValidValues.SingleOrDefault(v => v.GetType() == typeof(IdentityTopologyUpdater));
    110129
    111130      RandomCreator randomCreator = new RandomCreator();
     
    116135      Assigner bestPersonalQualityAssigner = new Assigner();
    117136      BestPointInitializer bestPositionInitializer = new BestPointInitializer();
     137      Placeholder topologyInitializerPlaceholder = new Placeholder();
     138      NeighborUpdater neighborUpdater = new NeighborUpdater();
    118139      Placeholder analyzerPlaceholder = new Placeholder();
    119140      UniformSubScopesProcessor uniformSubScopeProcessor = new UniformSubScopesProcessor();
    120       ParticleUpdater particleUpdater = new ParticleUpdater();
     141      Placeholder particleUpdaterPlaceholder = new Placeholder();
     142      Placeholder topologyUpdaterPlaceholder = new Placeholder();
     143      UniformSubScopesProcessor uniformSubscopesProcessor2 = new UniformSubScopesProcessor();
     144      NeighborUpdater neighborUpdater2 = new NeighborUpdater();
    121145      Placeholder evaluatorPlaceholder2 = new Placeholder();
    122146      SwarmUpdater swarmUpdater = new SwarmUpdater();
     
    149173      bestPersonalQualityAssigner.RightSideParameter.ActualName = "Quality";
    150174
    151       bestPositionInitializer.Successor = analyzerPlaceholder;
     175      bestPositionInitializer.Successor = topologyInitializerPlaceholder;
     176
     177      topologyInitializerPlaceholder.Name = "(TopologyInitializer)";
     178      topologyInitializerPlaceholder.OperatorParameter.ActualName = "TopologyInitializer";
     179      topologyInitializerPlaceholder.Successor = neighborUpdater;
     180
     181      neighborUpdater.Successor = analyzerPlaceholder;
    152182
    153183      analyzerPlaceholder.Name = "(Analyzer)";
     
    155185      analyzerPlaceholder.Successor = uniformSubScopeProcessor;
    156186
    157       uniformSubScopeProcessor.Operator = particleUpdater;
    158       uniformSubScopeProcessor.Successor = analyzerPlaceholder2;
    159 
    160       particleUpdater.Successor = evaluatorPlaceholder2;
     187      uniformSubScopeProcessor.Operator = particleUpdaterPlaceholder;
     188      uniformSubScopeProcessor.Successor = topologyUpdaterPlaceholder;
     189
     190      particleUpdaterPlaceholder.Name = "(ParticleUpdater)";
     191      particleUpdaterPlaceholder.OperatorParameter.ActualName = "ParticleUpdater";
     192      particleUpdaterPlaceholder.Successor = evaluatorPlaceholder2;
    161193
    162194      evaluatorPlaceholder2.Name = "(Evaluator)";
    163195      evaluatorPlaceholder2.OperatorParameter.ActualName = "Evaluator";
    164       evaluatorPlaceholder2.Successor = swarmUpdater;
     196
     197      topologyUpdaterPlaceholder.Name = "(TopologyUpdater)";
     198      topologyUpdaterPlaceholder.OperatorParameter.ActualName = "TopologyUpdater";
     199      topologyUpdaterPlaceholder.Successor = neighborUpdater2;
     200
     201      neighborUpdater2.Successor = uniformSubscopesProcessor2;
     202
     203      uniformSubscopesProcessor2.Operator = swarmUpdater;
     204      uniformSubscopesProcessor2.Successor = analyzerPlaceholder2;
    165205
    166206      analyzerPlaceholder2.Name = "(Analyzer)";
     
    226266
    227267    #region Helpers
     268    private void InitializeParticleUpdaters() {
     269    }
     270
    228271    private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
    229272    }
  • branches/PSO/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/ParticleUpdater.cs

    r5034 r5209  
    3131
    3232  [StorableClass]
    33   public class ParticleUpdater : SingleSuccessorOperator {
     33  public abstract class ParticleUpdater : SingleSuccessorOperator, IParticleUpdater {
    3434
    3535    #region Parameter properties
     
    4545    public LookupParameter<RealVector> PersonalBestPointParameter {
    4646      get { return (LookupParameter<RealVector>)Parameters["PersonalBestPoint"]; }
     47    }
     48    public LookupParameter<RealVector> BestNeighborPointParameter {
     49      get { return (LookupParameter<RealVector>)Parameters["BestNeighborPoint"]; }
    4750    }
    4851    public LookupParameter<RealVector> BestPointParameter {
     
    8487      get { return BestPointParameter.ActualValue; }
    8588    }
     89    public RealVector BestNeighborPoint {
     90      get { return BestNeighborPointParameter.ActualValue; }
     91    }
    8692    public DoubleMatrix Bounds {
    8793      get { return BoundsParameter.ActualValue; }
     
    101107    #endregion
    102108
     109    public override bool CanChangeName {
     110      get { return false; }
     111    }
     112
    103113    #region Construction & Cloning
    104114
     
    116126      Parameters.Add(new LookupParameter<RealVector>("PersonalBestPoint", "Particle's personal best position"));
    117127      Parameters.Add(new LookupParameter<RealVector>("BestPoint", "Global best position"));
     128      Parameters.Add(new LookupParameter<RealVector>("BestNeighborPoint", "Best neighboring position"));
    118129      Parameters.Add(new LookupParameter<DoubleMatrix>("Bounds", "The lower and upper bounds for each dimension of the position vector for the current problem."));
    119130      Parameters.Add(new LookupParameter<DoubleMatrix>("VelocityBounds", "Upper and lower bounds for the particle's velocity vector."));
     
    123134    }
    124135
    125     public override IDeepCloneable Clone(Cloner cloner) {
    126       return new ParticleUpdater(this, cloner);
    127     }
    128 
    129136    #endregion
    130137
    131     public override IOperation Apply() {
    132       RealVector velocity = new RealVector(Velocity.Length);
    133       RealVector position = new RealVector(Point.Length);
    134       double r_p = Random.NextDouble();
    135       double r_g = Random.NextDouble();
    136       for (int i = 0; i < velocity.Length; i++) {
    137         velocity[i] =
    138           Velocity[i] * Omega +
    139           (PersonalBestPoint[i] - Point[i]) * Phi_P * r_p +
    140           (BestPoint[i] - Point[i]) * Phi_G * r_g;
    141       }
    142       BoundsChecker.Apply(velocity, VelocityBounds);
    143       for (int i = 0; i < velocity.Length; i++) {
    144         position[i] = Point[i] + velocity[i];
    145       }
    146       BoundsChecker.Apply(position, Bounds);
    147       Point = position;
    148       Velocity = velocity;
    149 
    150       return base.Apply();
    151     }
    152 
    153     public override bool CanChangeName {
    154       get { return false; }
    155     }
    156138  }
    157139}
  • branches/PSO/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/TotallyConnectedParticleUpdater.cs

    r5208 r5209  
    2222using HeuristicLab.Common;
    2323using HeuristicLab.Core;
    24 using HeuristicLab.Data;
    2524using HeuristicLab.Encodings.RealVectorEncoding;
    26 using HeuristicLab.Operators;
    27 using HeuristicLab.Parameters;
    2825using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2926
     
    3128
    3229  [StorableClass]
    33   public class ParticleUpdater : SingleSuccessorOperator {
    34 
    35     #region Parameter properties
    36     public LookupParameter<IRandom> RandomParameter {
    37       get { return (LookupParameter<IRandom>)Parameters["Random"]; }
    38     }
    39     public LookupParameter<RealVector> PointParameter {
    40       get { return (LookupParameter<RealVector>)Parameters["Point"]; }
    41     }
    42     public LookupParameter<RealVector> VelocityParameter {
    43       get { return (LookupParameter<RealVector>)Parameters["Velocity"]; }
    44     }
    45     public LookupParameter<RealVector> PersonalBestPointParameter {
    46       get { return (LookupParameter<RealVector>)Parameters["PersonalBestPoint"]; }
    47     }
    48     public LookupParameter<RealVector> BestPointParameter {
    49       get { return (LookupParameter<RealVector>)Parameters["BestPoint"]; }
    50     }
    51     public LookupParameter<DoubleMatrix> BoundsParameter {
    52       get { return (LookupParameter<DoubleMatrix>)Parameters["Bounds"]; }
    53     }
    54     public LookupParameter<DoubleMatrix> VelocityBoundsParameter {
    55       get { return (LookupParameter<DoubleMatrix>)Parameters["VelocityBounds"]; }
    56     }
    57     public LookupParameter<DoubleValue> OmegaParameter {
    58       get { return (LookupParameter<DoubleValue>)Parameters["Omega"]; }
    59     }
    60     public LookupParameter<DoubleValue> Phi_PParameter {
    61       get { return (LookupParameter<DoubleValue>)Parameters["Phi_P"]; }
    62     }
    63     public LookupParameter<DoubleValue> Phi_GParameter {
    64       get { return (LookupParameter<DoubleValue>)Parameters["Phi_G"]; }
    65     }
    66     #endregion
    67 
    68     #region Parameter Values
    69     public IRandom Random {
    70       get { return RandomParameter.ActualValue; }
    71     }
    72     public RealVector Point {
    73       get { return PointParameter.ActualValue; }
    74       set { PointParameter.ActualValue = value; }
    75     }
    76     public RealVector Velocity {
    77       get { return VelocityParameter.ActualValue; }
    78       set { VelocityParameter.ActualValue = value; }
    79     }
    80     public RealVector PersonalBestPoint {
    81       get { return PersonalBestPointParameter.ActualValue; }
    82     }
    83     public RealVector BestPoint {
    84       get { return BestPointParameter.ActualValue; }
    85     }
    86     public DoubleMatrix Bounds {
    87       get { return BoundsParameter.ActualValue; }
    88     }
    89     public DoubleMatrix VelocityBounds {
    90       get { return VelocityBoundsParameter.ActualValue; }
    91     }
    92     public double Omega {
    93       get { return OmegaParameter.ActualValue.Value; }
    94     }
    95     public double Phi_P {
    96       get { return Phi_PParameter.ActualValue.Value; }
    97     }
    98     public double Phi_G {
    99       get { return Phi_GParameter.ActualValue.Value; }
    100     }
    101     #endregion
     30  public class TotallyConnectedParticleUpdater : ParticleUpdater {
    10231
    10332    #region Construction & Cloning
    10433
    10534    [StorableConstructor]
    106     protected ParticleUpdater(bool deserializing) : base(deserializing) { }
    107     protected ParticleUpdater(ParticleUpdater original, Cloner cloner)
    108       : base(original, cloner) {
    109     }
    110 
    111     public ParticleUpdater()
    112       : base() {
    113       Parameters.Add(new LookupParameter<IRandom>("Random", "Random number generator."));
    114       Parameters.Add(new LookupParameter<RealVector>("Point", "Particle's current position"));
    115       Parameters.Add(new LookupParameter<RealVector>("Velocity", "Particle's current velocity."));
    116       Parameters.Add(new LookupParameter<RealVector>("PersonalBestPoint", "Particle's personal best position"));
    117       Parameters.Add(new LookupParameter<RealVector>("BestPoint", "Global best position"));
    118       Parameters.Add(new LookupParameter<DoubleMatrix>("Bounds", "The lower and upper bounds for each dimension of the position vector for the current problem."));
    119       Parameters.Add(new LookupParameter<DoubleMatrix>("VelocityBounds", "Upper and lower bounds for the particle's velocity vector."));
    120       Parameters.Add(new LookupParameter<DoubleValue>("Omega", "The weight for the particle's velocity vector."));
    121       Parameters.Add(new LookupParameter<DoubleValue>("Phi_P", "The weight for the particle's personal best position."));
    122       Parameters.Add(new LookupParameter<DoubleValue>("Phi_G", "The weight for the global best position."));
    123     }
     35    protected TotallyConnectedParticleUpdater(bool deserializing) : base(deserializing) { }
     36    protected TotallyConnectedParticleUpdater(ParticleUpdater original, Cloner cloner) : base(original, cloner) { }
     37    public TotallyConnectedParticleUpdater() : base() { }
    12438
    12539    public override IDeepCloneable Clone(Cloner cloner) {
    126       return new ParticleUpdater(this, cloner);
     40      return new TotallyConnectedParticleUpdater(this, cloner);
    12741    }
    12842
     
    15064      return base.Apply();
    15165    }
    152 
    153     public override bool CanChangeName {
    154       get { return false; }
    155     }
    15666  }
    15767}
Note: See TracChangeset for help on using the changeset viewer.