Free cookie consent management tool by TermsFeed Policy Generator

Changeset 15091 for trunk/sources


Ignore:
Timestamp:
06/29/17 15:26:16 (7 years ago)
Author:
abeham
Message:

#2797:

  • Updated PSO to make it more compatible with SPSO 2011
  • Removed truncation of velocity vector and instead rescaled it given the maximum velocity
  • Added non-zero initial velocity according to SPSO 2011
  • Removed complicated bouncing code due to box constraints and instead implemented as described in SPSO 2011
  • Calculating neighbor best has been changed to use personal best
  • Avoiding local and global particle update and instead relying on neighborbest
  • More randomization during velocity update by using a separate random numbers per dimension
  • Reusing problem specific solution creator in RealVectorParticleCreator instead of always using UniformRandomRealVectorCreator
Location:
trunk/sources
Files:
1 added
2 deleted
18 edited

Legend:

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

    r14185 r15091  
    2121
    2222using System;
     23using System.Collections.Generic;
    2324using System.Linq;
    2425using HeuristicLab.Analysis;
     
    179180      Parameters.Add(new ValueParameter<IntValue>("MaxIterations", "Maximal number of iterations.", new IntValue(1000)));
    180181      Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze each generation.", new MultiAnalyzer()));
    181       Parameters.Add(new ValueParameter<DoubleValue>("Inertia", "Inertia weight on a particle's movement (omega).", new DoubleValue(1)));
    182       Parameters.Add(new ValueParameter<DoubleValue>("PersonalBestAttraction", "Weight for particle's pull towards its personal best soution (phi_p).", new DoubleValue(-0.01)));
    183       Parameters.Add(new ValueParameter<DoubleValue>("NeighborBestAttraction", "Weight for pull towards the neighborhood best solution or global best solution in case of a totally connected topology (phi_g).", new DoubleValue(3.7)));
     182      Parameters.Add(new ValueParameter<DoubleValue>("Inertia", "Inertia weight on a particle's movement (omega).", new DoubleValue(0.9)));
     183      Parameters.Add(new ValueParameter<DoubleValue>("PersonalBestAttraction", "Weight for particle's pull towards its personal best soution (phi_p).", new DoubleValue(0.05)));
     184      Parameters.Add(new ValueParameter<DoubleValue>("NeighborBestAttraction", "Weight for pull towards the neighborhood best solution or global best solution in case of a totally connected topology (phi_g).", new DoubleValue(0.5)));
    184185      Parameters.Add(new ConstrainedValueParameter<IParticleCreator>("ParticleCreator", "Operator that creates a new particle."));
    185186      Parameters.Add(new ConstrainedValueParameter<IParticleUpdater>("ParticleUpdater", "Operator that updates a particle."));
     
    262263      UpdateAnalyzers();
    263264      ParameterizeAnalyzers();
     265      UpdateParticleUpdaterParameter();
    264266      UpdateTopologyParameters();
    265267      InitializeParticleCreator();
     
    280282
    281283    private void InitializeParticleCreator() {
     284      ParticleCreatorParameter.ValidValues.Clear();
    282285      if (Problem != null) {
    283286        IParticleCreator oldParticleCreator = ParticleCreator;
    284287        IParticleCreator defaultParticleCreator = Problem.Operators.OfType<IParticleCreator>().FirstOrDefault();
    285         ParticleCreatorParameter.ValidValues.Clear();
    286         foreach (IParticleCreator Creator in Problem.Operators.OfType<IParticleCreator>().OrderBy(x => x.Name)) {
    287           ParticleCreatorParameter.ValidValues.Add(Creator);
     288        foreach (var creator in Problem.Operators.OfType<IParticleCreator>().OrderBy(x => x.Name)) {
     289          ParticleCreatorParameter.ValidValues.Add(creator);
    288290        }
    289291        if (oldParticleCreator != null) {
    290           IParticleCreator creator = ParticleCreatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldParticleCreator.GetType());
     292          var creator = ParticleCreatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldParticleCreator.GetType());
    291293          if (creator != null) ParticleCreator = creator;
    292294          else oldParticleCreator = null;
     
    328330        updater.IndexParameter.ActualName = "Iterations";
    329331        updater.ValueParameter.ActualName = "CurrentInertia";
    330         updater.StartValueParameter.Value = new DoubleValue(1);
    331         updater.EndValueParameter.Value = new DoubleValue(1E-10);
     332        updater.StartValueParameter.ActualName = InertiaParameter.Name;
     333        updater.EndValueParameter.Value = new DoubleValue(0.70);
    332334      }
    333335    }
     
    346348
    347349    private void UpdateTopologyInitializer() {
    348       ITopologyInitializer oldTopologyInitializer = TopologyInitializer;
     350      var oldTopologyInitializer = TopologyInitializer;
    349351      TopologyInitializerParameter.ValidValues.Clear();
    350352      foreach (ITopologyInitializer topologyInitializer in ApplicationManager.Manager.GetInstances<ITopologyInitializer>().OrderBy(x => x.Name)) {
    351353        TopologyInitializerParameter.ValidValues.Add(topologyInitializer);
    352354      }
     355
    353356      if (oldTopologyInitializer != null && TopologyInitializerParameter.ValidValues.Any(x => x.GetType() == oldTopologyInitializer.GetType()))
    354357        TopologyInitializer = TopologyInitializerParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldTopologyInitializer.GetType());
     
    357360
    358361    private void ParameterizeTopologyUpdaters() {
    359       foreach (var updater in TopologyUpdaterParameter.ValidValues) {
    360         var multiPsoUpdater = updater as MultiPSOTopologyUpdater;
    361         if (multiPsoUpdater != null) {
    362           multiPsoUpdater.CurrentIterationParameter.ActualName = "Iterations";
    363         }
    364       }
    365     }
    366 
    367     private void UpdateTopologyParameters() {
    368       ITopologyUpdater oldTopologyUpdater = TopologyUpdater;
    369       IParticleUpdater oldParticleUpdater = ParticleUpdater;
    370       ClearTopologyParameters();
    371       if (Problem != null) {
    372         IParticleUpdater defaultParticleUpdater = null;
    373         if (TopologyInitializer != null) {
    374           foreach (ITopologyUpdater topologyUpdater in ApplicationManager.Manager.GetInstances<ITopologyUpdater>())
    375             TopologyUpdaterParameter.ValidValues.Add(topologyUpdater);
    376           defaultParticleUpdater = Problem.Operators.OfType<ILocalParticleUpdater>().FirstOrDefault();
    377           foreach (IParticleUpdater particleUpdater in Problem.Operators.OfType<ILocalParticleUpdater>().OrderBy(x => x.Name))
    378             ParticleUpdaterParameter.ValidValues.Add(particleUpdater);
    379         } else {
    380           defaultParticleUpdater = Problem.Operators.OfType<IGlobalParticleUpdater>().FirstOrDefault();
    381           foreach (IParticleUpdater particleUpdater in Problem.Operators.OfType<IGlobalParticleUpdater>().OrderBy(x => x.Name))
    382             ParticleUpdaterParameter.ValidValues.Add(particleUpdater);
    383         }
    384         if (oldTopologyUpdater != null) {
    385           ITopologyUpdater newTopologyUpdater = TopologyUpdaterParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldParticleUpdater.GetType());
    386           if (newTopologyUpdater != null) TopologyUpdater = newTopologyUpdater;
    387         }
     362      foreach (var updater in TopologyUpdaterParameter.ValidValues.OfType<MultiPSOTopologyUpdater>()) {
     363        updater.CurrentIterationParameter.ActualName = "Iterations";
     364      }
     365    }
     366
     367    private void UpdateParticleUpdaterParameter() {
     368      var oldParticleUpdater = ParticleUpdater;
     369      ParticleUpdaterParameter.ValidValues.Clear();
     370      if (Problem != null) {
     371        var defaultParticleUpdater = Problem.Operators.OfType<IParticleUpdater>().FirstOrDefault();
     372
     373        foreach (var particleUpdater in Problem.Operators.OfType<IParticleUpdater>().OrderBy(x => x.Name))
     374          ParticleUpdaterParameter.ValidValues.Add(particleUpdater);
     375
    388376        if (oldParticleUpdater != null) {
    389           IParticleUpdater newParticleUpdater = ParticleUpdaterParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldParticleUpdater.GetType());
     377          var newParticleUpdater = ParticleUpdaterParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldParticleUpdater.GetType());
    390378          if (newParticleUpdater != null) ParticleUpdater = newParticleUpdater;
    391379          else oldParticleUpdater = null;
     
    393381        if (oldParticleUpdater == null && defaultParticleUpdater != null)
    394382          ParticleUpdater = defaultParticleUpdater;
    395 
    396         ParameterizeTopologyUpdaters();
    397       }
    398     }
    399 
    400     private void ClearTopologyParameters() {
     383      }
     384    }
     385
     386    private void UpdateTopologyParameters() {
     387      ITopologyUpdater oldTopologyUpdater = TopologyUpdater;
    401388      TopologyUpdaterParameter.ValidValues.Clear();
    402       ParticleUpdaterParameter.ValidValues.Clear();
     389      if (Problem != null) {
     390        if (TopologyInitializerParameter.Value != null) {
     391          foreach (ITopologyUpdater topologyUpdater in ApplicationManager.Manager.GetInstances<ITopologyUpdater>())
     392            TopologyUpdaterParameter.ValidValues.Add(topologyUpdater);
     393
     394          if (oldTopologyUpdater != null) {
     395            ITopologyUpdater newTopologyUpdater = TopologyUpdaterParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldTopologyUpdater.GetType());
     396            if (newTopologyUpdater != null) TopologyUpdater = newTopologyUpdater;
     397          }
     398          ParameterizeTopologyUpdaters();
     399        }
     400      }
    403401    }
    404402
  • trunk/sources/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/RandomTopologyInitializer.cs

    r14185 r15091  
    2525using HeuristicLab.Core;
    2626using HeuristicLab.Data;
     27using HeuristicLab.Optimization;
    2728using HeuristicLab.Parameters;
    2829using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    3132  [Item("Random Topology Initializer", "Randomly connectes every particle with k other particles.")]
    3233  [StorableClass]
    33   public sealed class RandomTopologyInitializer : TopologyInitializer {
     34  public sealed class RandomTopologyInitializer : TopologyInitializer, IStochasticOperator {
    3435    #region Parameters
    3536    public ILookupParameter<IRandom> RandomParameter {
     
    4041    }
    4142    #endregion
    42 
    43     #region Parameter Values
    44     private IRandom Random {
    45       get { return RandomParameter.ActualValue; }
    46     }
    47     private int NrOfConnections {
    48       get { return NrOfConnectionsParameter.ActualValue.Value; }
    49     }
    50     #endregion
    51 
     43   
    5244    #region Construction & Cloning
    5345    [StorableConstructor]
     
    6557
    6658    public override IOperation Apply() {
    67       ItemArray<IntArray> neighbors = new ItemArray<IntArray>(SwarmSize);
    68       for (int i = 0; i < SwarmSize; i++) {
    69         var numbers = Enumerable.Range(0, SwarmSize).ToList();
     59      var random = RandomParameter.ActualValue;
     60      var swarmSize = SwarmSizeParameter.ActualValue.Value;
     61      var nrOfConnections = NrOfConnectionsParameter.ActualValue.Value;
     62
     63      ItemArray<IntArray> neighbors = new ItemArray<IntArray>(swarmSize);
     64      for (int i = 0; i < swarmSize; i++) {
     65        var numbers = Enumerable.Range(0, swarmSize).ToList();
    7066        numbers.RemoveAt(i);
    71         var selectedNumbers = new List<int>(NrOfConnections);
    72         for (int j = 0; j < NrOfConnections && numbers.Count > 0; j++) {
    73           int index = Random.Next(numbers.Count);
     67        var selectedNumbers = new List<int>(nrOfConnections);
     68        for (int j = 0; j < nrOfConnections && numbers.Count > 0; j++) {
     69          int index = random.Next(numbers.Count);
    7470          selectedNumbers.Add(numbers[index]);
    7571          numbers.RemoveAt(index);
     
    7773        neighbors[i] = new IntArray(selectedNumbers.ToArray());
    7874      }
    79       Neighbors = neighbors;
     75      NeighborsParameter.ActualValue = neighbors;
    8076      return base.Apply();
    8177    }
  • trunk/sources/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/RingTopologyInitializer.cs

    r14185 r15091  
    4343
    4444    public override IOperation Apply() {
    45       ItemArray<IntArray> neighbors = new ItemArray<IntArray>(SwarmSize);
    46       for (int i = 0; i < SwarmSize; i++) {
    47         neighbors[i] = new IntArray(new[] { (SwarmSize + i - 1) % SwarmSize, (i + 1) % SwarmSize });
     45      var swarmSize = SwarmSizeParameter.ActualValue.Value;
     46
     47      ItemArray<IntArray> neighbors = new ItemArray<IntArray>(swarmSize);
     48      for (int i = 0; i < swarmSize; i++) {
     49        neighbors[i] = new IntArray(new[] { (swarmSize + i - 1) % swarmSize, (i + 1) % swarmSize });
    4850      }
    49       Neighbors = neighbors;
     51      NeighborsParameter.ActualValue = neighbors;
    5052      return base.Apply();
    5153    }
  • trunk/sources/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/TopologyInitializer.cs

    r14185 r15091  
    4040      get { return (IScopeTreeLookupParameter<IntArray>)Parameters["Neighbors"]; }
    4141    }
    42 
    4342    public ILookupParameter<IntValue> SwarmSizeParameter {
    4443      get { return (ILookupParameter<IntValue>)Parameters["SwarmSize"]; }
    45     }
    46 
    47     #endregion
    48 
    49     #region Parameter Values
    50     protected ItemArray<IntArray> Neighbors {
    51       get { return NeighborsParameter.ActualValue; }
    52       set { NeighborsParameter.ActualValue = value; }
    53     }
    54     protected int SwarmSize {
    55       get { return SwarmSizeParameter.ActualValue.Value; }
    5644    }
    5745    #endregion
  • trunk/sources/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/VonNeumannTopologyInitializer.cs

    r14185 r15091  
    4444
    4545    public override IOperation Apply() {
    46       ItemArray<IntArray> neighbors = new ItemArray<IntArray>(SwarmSize);
    47       for (int i = 0; i < SwarmSize; i++) {
     46      var swarmSize = SwarmSizeParameter.ActualValue.Value;
     47
     48      ItemArray<IntArray> neighbors = new ItemArray<IntArray>(swarmSize);
     49      for (int i = 0; i < swarmSize; i++) {
    4850        neighbors[i] = new IntArray(new[] {
    49           (SwarmSize + i-2) % SwarmSize,
    50           (SwarmSize + i-1) % SwarmSize,
    51           (i+1) % SwarmSize,
    52           (i+2) % SwarmSize
     51          (swarmSize + i-2) % swarmSize,
     52          (swarmSize + i-1) % swarmSize,
     53          (i+1) % swarmSize,
     54          (i+2) % swarmSize
    5355        });
    5456      }
    55       Neighbors = neighbors;
     57      NeighborsParameter.ActualValue = neighbors;
    5658      return base.Apply();
    5759    }
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/HeuristicLab.Encodings.RealVectorEncoding-3.3.csproj

    r15067 r15091  
    132132    <Compile Include="ParticleOperators\RealVectorSwarmUpdater.cs" />
    133133    <Compile Include="ParticleOperators\RealVectorTotallyConnectedParticleUpdater.cs" />
     134    <Compile Include="ParticleOperators\RealVectorVelocityInitializer.cs" />
    134135    <Compile Include="Plugin.cs" />
    135136    <Compile Include="RealVectorCreator.cs" />
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Interfaces/IRealVectorParticleCreator.cs

    r14185 r15091  
    2626namespace HeuristicLab.Encodings.RealVectorEncoding {
    2727  public interface IRealVectorParticleCreator : IParticleCreator, IRealVectorOperator {
    28     ILookupParameter<IntValue> ProblemSizeParameter { get; }
    2928    ILookupParameter<RealVector> RealVectorParameter { get; }
    3029    ILookupParameter<RealVector> PersonalBestParameter { get; }
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Interfaces/IRealVectorParticleUpdater.cs

    r14185 r15091  
    2727  public interface IRealVectorParticleUpdater : IParticleUpdater, IRealVectorOperator {
    2828    ILookupParameter<RealVector> VelocityParameter { get; }
    29     ILookupParameter<DoubleMatrix> CurrentVelocityBoundsParameter { get; }
     29    ILookupParameter<DoubleValue> CurrentMaxVelocityParameter { get; }
    3030    ILookupParameter<RealVector> RealVectorParameter { get; }
    3131    ILookupParameter<DoubleMatrix> BoundsParameter { get; }
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/ParticleOperators/RealVectorNeighborhoodParticleUpdater.cs

    r14185 r15091  
    2222using HeuristicLab.Common;
    2323using HeuristicLab.Core;
    24 using HeuristicLab.Optimization;
    2524using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2625
     
    2827  [Item("Neighborhood Particle Updater", "Updates the particle's position using (among other things) the best neighbor's position. Point = Point + Velocity*Inertia + (PersonalBestPoint-Point)*Phi_P*r_p + (BestNeighborPoint-Point)*Phi_G*r_g.")]
    2928  [StorableClass]
    30   public sealed class RealVectorNeighborhoodParticleUpdater : RealVectorParticleUpdater, ILocalParticleUpdater {
     29  public sealed class RealVectorNeighborhoodParticleUpdater : RealVectorParticleUpdater {
    3130
    3231    #region Construction & Cloning
     
    4140
    4241    public override IOperation Apply() {
    43       double inertia = Inertia.Value;
    44       double personalBestAttraction = PersonalBestAttraction.Value;
    45       double neighborBestAttraction = NeighborBestAttraction.Value;
    46 
    47       RealVector velocity = new RealVector(Velocity.Length);
    48       RealVector position = new RealVector(RealVector.Length);
    49       double r_p = Random.NextDouble();
    50       double r_g = Random.NextDouble();
    51 
    52       for (int i = 0; i < velocity.Length; i++) {
    53         velocity[i] =
    54           Velocity[i] * inertia +
    55           (PersonalBest[i] - RealVector[i]) * personalBestAttraction * r_p +
    56           (BestPoint[i] - RealVector[i]) * neighborBestAttraction * r_g;
    57       }
    58 
    59       MoveParticle(velocity, position);
     42      UpdateVelocity();
     43      UpdatePosition();
    6044
    6145      return base.Apply();
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/ParticleOperators/RealVectorParticleCreator.cs

    r14185 r15091  
    2424using HeuristicLab.Data;
    2525using HeuristicLab.Operators;
     26using HeuristicLab.Optimization;
    2627using HeuristicLab.Parameters;
    2728using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    3031  [Item("RealVectorParticleCreator", "Creates a particle with position, zero velocity vector and personal best.")]
    3132  [StorableClass]
    32   public class RealVectorParticleCreator : AlgorithmOperator, IRealVectorParticleCreator {
     33  public class RealVectorParticleCreator : AlgorithmOperator, IRealVectorParticleCreator, IStochasticOperator {
    3334
    3435    #region Parameters
    35     public ILookupParameter<IntValue> ProblemSizeParameter {
    36       get { return (ILookupParameter<IntValue>)Parameters["ProblemSize"]; }
     36    public ILookupParameter<IRandom> RandomParameter {
     37      get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
    3738    }
    3839    public IValueLookupParameter<DoubleMatrix> BoundsParameter {
     
    4849      get { return (ILookupParameter<RealVector>)Parameters["Velocity"]; }
    4950    }
    50     #endregion
    51 
    52     #region Parameter Values
    53     protected int ProblemSize {
    54       get { return ProblemSizeParameter.ActualValue.Value; }
    55     }
    56     protected RealVector Velocity {
    57       set { VelocityParameter.ActualValue = value; }
     51    public ILookupParameter<ISolutionCreator> SolutionCreatorParameter {
     52      get { return (ILookupParameter<ISolutionCreator>)Parameters["SolutionCreator"]; }
    5853    }
    5954    #endregion
    60 
     55   
    6156    #region Construction & Cloning
    6257    [StorableConstructor]
     
    6560    public RealVectorParticleCreator()
    6661      : base() {
    67       Parameters.Add(new LookupParameter<IntValue>("ProblemSize", "The dimension of the problem."));
     62      Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator to use."));
    6863      Parameters.Add(new ValueLookupParameter<DoubleMatrix>("Bounds", "The lower and upper bounds in each dimension."));
    6964      Parameters.Add(new LookupParameter<RealVector>("RealVector", "Particle's current solution"));
    7065      Parameters.Add(new LookupParameter<RealVector>("PersonalBest", "Particle's personal best solution."));
    7166      Parameters.Add(new LookupParameter<RealVector>("Velocity", "Particle's current velocity."));
     67      Parameters.Add(new LookupParameter<ISolutionCreator>("SolutionCreator", "The operator that creates the initial position."));
    7268
    73       UniformRandomRealVectorCreator realVectorCreater = new UniformRandomRealVectorCreator();
     69      Placeholder realVectorCreater = new Placeholder();
    7470      Assigner personalBestPositionAssigner = new Assigner();
     71      RealVectorVelocityInitializer velocityInitializer = new RealVectorVelocityInitializer();
    7572
    7673      OperatorGraph.InitialOperator = realVectorCreater;
    7774
    78       realVectorCreater.RealVectorParameter.ActualName = RealVectorParameter.Name;
    79       realVectorCreater.LengthParameter.ActualName = ProblemSizeParameter.Name;
    80       realVectorCreater.BoundsParameter.ActualName = BoundsParameter.Name;
     75      realVectorCreater.OperatorParameter.ActualName = SolutionCreatorParameter.Name;
    8176      realVectorCreater.Successor = personalBestPositionAssigner;
    8277
    8378      personalBestPositionAssigner.LeftSideParameter.ActualName = PersonalBestParameter.Name;
    8479      personalBestPositionAssigner.RightSideParameter.ActualName = RealVectorParameter.Name;
    85       personalBestPositionAssigner.Successor = null;
     80      personalBestPositionAssigner.Successor = velocityInitializer;
     81
     82      velocityInitializer.BoundsParameter.ActualName = BoundsParameter.Name;
     83      velocityInitializer.RandomParameter.ActualName = RandomParameter.Name;
     84      velocityInitializer.RealVectorParameter.ActualName = RealVectorParameter.Name;
     85      velocityInitializer.VelocityParameter.ActualName = VelocityParameter.Name;
     86      velocityInitializer.Successor = null;
    8687    }
    8788    public override IDeepCloneable Clone(Cloner cloner) {
     
    8990    }
    9091    #endregion
    91 
    92     public override IOperation Apply() {
    93       Velocity = new RealVector(ProblemSize);
    94       return base.Apply();
    95     }
    96 
    97 
    9892  }
    9993}
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/ParticleOperators/RealVectorParticleUpdater.cs

    r14185 r15091  
    5151      get { return (ILookupParameter<RealVector>)Parameters["NeighborBest"]; }
    5252    }
    53     public LookupParameter<RealVector> BestRealVectorParameter {
    54       get { return (LookupParameter<RealVector>)Parameters["BestRealVector"]; }
    55     }
    5653    public ILookupParameter<RealVector> RealVectorParameter {
    5754      get { return (ILookupParameter<RealVector>)Parameters["RealVector"]; }
     
    6057      get { return (ILookupParameter<DoubleMatrix>)Parameters["Bounds"]; }
    6158    }
    62     public ILookupParameter<DoubleMatrix> CurrentVelocityBoundsParameter {
    63       get { return (ILookupParameter<DoubleMatrix>)Parameters["CurrentVelocityBounds"]; }
     59    public ILookupParameter<DoubleValue> CurrentMaxVelocityParameter {
     60      get { return (ILookupParameter<DoubleValue>)Parameters["CurrentMaxVelocity"]; }
    6461    }
    6562    public ILookupParameter<DoubleValue> InertiaParameter {
     
    7370    }
    7471    #endregion
    75 
    76     #region Parameter Values
    77     protected IRandom Random {
    78       get { return RandomParameter.ActualValue; }
    79     }
    80     protected RealVector Velocity {
    81       get { return VelocityParameter.ActualValue; }
    82       set { VelocityParameter.ActualValue = value; }
    83     }
    84     protected RealVector PersonalBest {
    85       get { return PersonalBestParameter.ActualValue; }
    86     }
    87     protected RealVector BestPoint {
    88       get { return BestRealVectorParameter.ActualValue; }
    89     }
    90     protected RealVector RealVector {
    91       get { return RealVectorParameter.ActualValue; }
    92       set { RealVectorParameter.ActualValue = value; }
    93     }
    94     protected RealVector NeighborBest {
    95       get { return NeighborBestParameter.ActualValue; }
    96     }
    97     protected DoubleMatrix Bounds {
    98       get { return BoundsParameter.ActualValue; }
    99     }
    100     protected DoubleMatrix CurrentVelocityBounds {
    101       get { return CurrentVelocityBoundsParameter.ActualValue; }
    102     }
    103     protected DoubleValue Inertia {
    104       get { return InertiaParameter.ActualValue; }
    105     }
    106     protected DoubleValue PersonalBestAttraction {
    107       get { return PersonalBestAttractionParameter.ActualValue; }
    108     }
    109     protected DoubleValue NeighborBestAttraction {
    110       get { return NeighborBestAttractionParameter.ActualValue; }
    111     }
    112     #endregion
    113 
     72   
    11473    #region Construction & Cloning
    11574    [StorableConstructor]
     
    12281      Parameters.Add(new LookupParameter<RealVector>("Velocity", "Particle's current velocity."));
    12382      Parameters.Add(new LookupParameter<RealVector>("PersonalBest", "Particle's personal best solution."));
    124       Parameters.Add(new LookupParameter<RealVector>("BestRealVector", "Global best position."));
    12583      Parameters.Add(new LookupParameter<RealVector>("NeighborBest", "Best neighboring solution."));
    12684      Parameters.Add(new LookupParameter<DoubleMatrix>("Bounds", "The lower and upper bounds for each dimension of the position vector for the current problem."));
    127       Parameters.Add(new LookupParameter<DoubleMatrix>("CurrentVelocityBounds", "Upper and lower bounds for the particle's velocity vector."));
     85      Parameters.Add(new LookupParameter<DoubleValue>("CurrentMaxVelocity", "Maximum for the particle's velocity vector."));
    12886      Parameters.Add(new LookupParameter<DoubleValue>("CurrentInertia", "The weight for the particle's velocity vector."));
    12987      Parameters.Add(new LookupParameter<DoubleValue>("PersonalBestAttraction", "The weight for the particle's personal best position."));
     
    13290    #endregion
    13391
    134     protected void MoveParticle(RealVector velocity, RealVector position) {
    135       BoundsChecker.Apply(velocity, CurrentVelocityBounds);
     92    protected void UpdateVelocity() {
     93      var velocity = VelocityParameter.ActualValue;
     94      var position = RealVectorParameter.ActualValue;
     95      var inertia = InertiaParameter.ActualValue.Value;
     96      var personalBest = PersonalBestParameter.ActualValue;
     97      var personalBestAttraction = PersonalBestAttractionParameter.ActualValue.Value;
     98      var neighborBest = NeighborBestParameter.ActualValue;
     99      var neighborBestAttraction = NeighborBestAttractionParameter.ActualValue.Value;
     100
     101      var random = RandomParameter.ActualValue;
     102
    136103      for (int i = 0; i < velocity.Length; i++) {
    137         position[i] = RealVector[i] + velocity[i];
     104        double r_p = random.NextDouble();
     105        double r_g = random.NextDouble();
     106        velocity[i] =
     107          velocity[i] * inertia +
     108          (personalBest[i] - position[i]) * personalBestAttraction * r_p +
     109          (neighborBest[i] - position[i]) * neighborBestAttraction * r_g;
    138110      }
     111
     112      var maxVelocity = CurrentMaxVelocityParameter.ActualValue.Value;
     113      var speed = Math.Sqrt(velocity.DotProduct(velocity));
     114      if (speed > maxVelocity) {
     115        for (var i = 0; i < velocity.Length; i++) {
     116          velocity[i] *= maxVelocity / speed;
     117        }
     118      }
     119    }
     120
     121    protected void UpdatePosition() {
     122      var velocity = VelocityParameter.ActualValue;
     123      var position = RealVectorParameter.ActualValue;
     124
     125      for (int i = 0; i < velocity.Length; i++) {
     126        position[i] += velocity[i];
     127      }
     128
     129      var bounds = BoundsParameter.ActualValue;
    139130      for (int i = 0; i < position.Length; i++) {
    140         double min = Bounds[i % Bounds.Rows, 0];
    141         double max = Bounds[i % Bounds.Rows, 1];
     131        double min = bounds[i % bounds.Rows, 0];
     132        double max = bounds[i % bounds.Rows, 1];
    142133        if (position[i] < min) {
    143           int reflectionCount = (int)Math.Truncate((min - position[i]) / (max - min)) + 1;
    144           double reflection = (min - position[i]) % (max - min);
    145           if (IsOdd(reflectionCount)) {
    146             position[i] = min + reflection;
    147             velocity[i] = -velocity[i];
    148 
    149           } else {
    150             position[i] = max - reflection;
    151           }
     134          position[i] = min;
     135          velocity[i] = -0.5 * velocity[i]; // SPSO 2011
    152136        }
    153137        if (position[i] > max) {
    154           int reflectionCount = (int)Math.Truncate((position[i] - max) / (max - min)) + 1;
    155           double reflection = (position[i] - max) % (max - min);
    156           if (IsOdd(reflectionCount)) {
    157             position[i] = max - reflection;
    158             velocity[i] = -velocity[i];
    159           } else {
    160             position[i] = min + reflection;
    161           }
     138          position[i] = max;
     139          velocity[i] = -0.5 * velocity[i]; // SPSO 2011
    162140        }
    163141      }
    164 
    165       RealVector = position;
    166       Velocity = velocity;
    167     }
    168 
    169     private static bool IsOdd(int number) {
    170       return number % 2 == 1;
    171142    }
    172143  }
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/ParticleOperators/RealVectorSwarmUpdater.cs

    r15071 r15091  
    7676      get { return (IScopeTreeLookupParameter<IntArray>)Parameters["Neighbors"]; }
    7777    }
    78     public IValueLookupParameter<DoubleMatrix> VelocityBoundsParameter {
    79       get { return (ValueLookupParameter<DoubleMatrix>)Parameters["VelocityBounds"]; }
    80     }
    81     public ILookupParameter<DoubleMatrix> CurrentVelocityBoundsParameter {
    82       get { return (ILookupParameter<DoubleMatrix>)Parameters["CurrentVelocityBounds"]; }
     78    public IValueLookupParameter<DoubleValue> MaxVelocityParameter {
     79      get { return (ValueLookupParameter<DoubleValue>)Parameters["MaxVelocity"]; }
     80    }
     81    public ILookupParameter<DoubleValue> CurrentMaxVelocityParameter {
     82      get { return (ILookupParameter<DoubleValue>)Parameters["CurrentMaxVelocity"]; }
    8383    }
    8484    public LookupParameter<ResultCollection> ResultsParameter {
     
    8686    }
    8787
    88     #region Velocity Bounds Updating
    89     public ILookupParameter<DoubleValue> VelocityBoundsScaleParameter {
    90       get { return (ILookupParameter<DoubleValue>)Parameters["VelocityBoundsScale"]; }
    91     }
    92     public IConstrainedValueParameter<IDiscreteDoubleValueModifier> VelocityBoundsScalingOperatorParameter {
    93       get { return (IConstrainedValueParameter<IDiscreteDoubleValueModifier>)Parameters["VelocityBoundsScalingOperator"]; }
    94     }
    95     public IValueLookupParameter<DoubleValue> VelocityBoundsStartValueParameter {
    96       get { return (IValueLookupParameter<DoubleValue>)Parameters["VelocityBoundsStartValue"]; }
    97     }
    98     public IValueLookupParameter<DoubleValue> VelocityBoundsEndValueParameter {
    99       get { return (IValueLookupParameter<DoubleValue>)Parameters["VelocityBoundsEndValue"]; }
    100     }
    101     public ILookupParameter<IntValue> VelocityBoundsIndexParameter {
    102       get { return (ILookupParameter<IntValue>)Parameters["VelocityBoundsIndex"]; }
    103     }
    104     public IValueLookupParameter<IntValue> VelocityBoundsStartIndexParameter {
    105       get { return (IValueLookupParameter<IntValue>)Parameters["VelocityBoundsStartIndex"]; }
    106     }
    107     public IValueLookupParameter<IntValue> VelocityBoundsEndIndexParameter {
    108       get { return (IValueLookupParameter<IntValue>)Parameters["VelocityBoundsEndIndex"]; }
     88    #region Max Velocity Updating
     89    public IConstrainedValueParameter<IDiscreteDoubleValueModifier> MaxVelocityScalingOperatorParameter {
     90      get { return (IConstrainedValueParameter<IDiscreteDoubleValueModifier>)Parameters["MaxVelocityScalingOperator"]; }
     91    }
     92    public IValueLookupParameter<DoubleValue> FinalMaxVelocityParameter {
     93      get { return (IValueLookupParameter<DoubleValue>)Parameters["FinalMaxVelocity"]; }
     94    }
     95    public ILookupParameter<IntValue> MaxVelocityIndexParameter {
     96      get { return (ILookupParameter<IntValue>)Parameters["MaxVelocityIndex"]; }
     97    }
     98    public IValueLookupParameter<IntValue> MaxVelocityStartIndexParameter {
     99      get { return (IValueLookupParameter<IntValue>)Parameters["MaxVelocityStartIndex"]; }
     100    }
     101    public IValueLookupParameter<IntValue> MaxVelocityEndIndexParameter {
     102      get { return (IValueLookupParameter<IntValue>)Parameters["MaxVelocityEndIndex"]; }
    109103    }
    110104    #endregion
     
    132126      Parameters.Add(new ScopeTreeLookupParameter<IntArray>("Neighbors", "The list of neighbors for each particle."));
    133127      Parameters.Add(new LookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
    134       Parameters.Add(new ValueLookupParameter<DoubleMatrix>("VelocityBounds", "Maximum velocity for each dimension.", new DoubleMatrix(new double[,] { { -1, 1 } })));
    135       Parameters.Add(new LookupParameter<DoubleMatrix>("CurrentVelocityBounds", "Current value of velocity bounds."));
     128      Parameters.Add(new ValueLookupParameter<DoubleValue>("MaxVelocity", "Speed limit for each particle.", new DoubleValue(1)));
     129      Parameters.Add(new LookupParameter<DoubleValue>("CurrentMaxVelocity", "Current value of the speed limit."));
    136130      Parameters.Add(new LookupParameter<ResultCollection>("Results", "Results"));
    137131
    138132      #region Velocity Bounds Updating
    139       Parameters.Add(new LookupParameter<DoubleValue>("VelocityBoundsScale", "Scale parameter."));
    140       Parameters.Add(new OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier>("VelocityBoundsScalingOperator", "Modifies the value"));
    141       Parameters.Add(new ValueLookupParameter<DoubleValue>("VelocityBoundsStartValue", "The start value of 'Value'.", new DoubleValue(1)));
    142       Parameters.Add(new ValueLookupParameter<DoubleValue>("VelocityBoundsEndValue", "The end value of 'Value'.", new DoubleValue(1E-10)));
    143       Parameters.Add(new LookupParameter<IntValue>("VelocityBoundsIndex", "The current index.", "Iterations"));
    144       Parameters.Add(new ValueLookupParameter<IntValue>("VelocityBoundsStartIndex", "The start index at which to start modifying 'Value'.", new IntValue(0)));
    145       Parameters.Add(new ValueLookupParameter<IntValue>("VelocityBoundsEndIndex", "The end index by which 'Value' should have reached 'EndValue'.", "MaxIterations"));
    146       VelocityBoundsStartIndexParameter.Hidden = true;
    147       VelocityBoundsEndIndexParameter.Hidden = true;
     133      Parameters.Add(new OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier>("MaxVelocityScalingOperator", "Modifies the value"));
     134      Parameters.Add(new ValueLookupParameter<DoubleValue>("FinalMaxVelocity", "The value of maximum velocity if PSO has reached maximum iterations.", new DoubleValue(1E-10)));
     135      Parameters.Add(new LookupParameter<IntValue>("MaxVelocityIndex", "The current index.", "Iterations"));
     136      Parameters.Add(new ValueLookupParameter<IntValue>("MaxVelocityStartIndex", "The start index at which to start modifying 'Value'.", new IntValue(0)));
     137      Parameters.Add(new ValueLookupParameter<IntValue>("MaxVelocityEndIndex", "The end index by which 'Value' should have reached 'EndValue'.", "MaxIterations"));
     138      MaxVelocityStartIndexParameter.Hidden = true;
     139      MaxVelocityEndIndexParameter.Hidden = true;
    148140      #endregion
    149141
    150142      Initialize();
    151       RegisterEvents();
    152143    }
    153144
     
    167158        Parameters.Remove("BestQuality");
    168159      }
    169       RegisterEvents();
    170     }
    171 
    172     private void RegisterEvents() {
    173       VelocityBoundsStartValueParameter.ValueChanged += new EventHandler(VelocityBoundsStartValueParameter_ValueChanged);
    174       VelocityBoundsStartValueParameter.Value.ValueChanged += new EventHandler(VelocityBoundsStartValueParameter_Value_ValueChanged);
    175     }
    176 
    177     void VelocityBoundsStartValueParameter_Value_ValueChanged(object sender, EventArgs e) {
    178       UpdateVelocityBoundsParamater();
    179     }
    180 
    181     void UpdateVelocityBoundsParamater() {
    182       if (VelocityBoundsParameter.Value == null) {
    183         VelocityBoundsParameter.Value = new DoubleMatrix(1, 2);
    184       } else if (VelocityBoundsParameter.Value.Columns != 2) {
    185         VelocityBoundsParameter.Value = new DoubleMatrix(VelocityBoundsParameter.Value.Rows, 2);
    186       }
    187       if (VelocityBoundsStartValueParameter.Value != null) {
    188         DoubleMatrix matrix = VelocityBoundsParameter.Value;
    189         for (int i = 0; i < matrix.Rows; i++) {
    190           matrix[i, 0] = (-1) * VelocityBoundsStartValueParameter.Value.Value;
    191           matrix[i, 1] = VelocityBoundsStartValueParameter.Value.Value;
    192         }
    193       }
    194     }
    195 
    196     void VelocityBoundsStartValueParameter_ValueChanged(object sender, EventArgs e) {
    197       if (VelocityBoundsStartValueParameter.Value != null) {
    198         VelocityBoundsStartValueParameter.Value.ValueChanged += new EventHandler(VelocityBoundsStartValueParameter_Value_ValueChanged);
    199       }
    200       UpdateVelocityBoundsParamater();
    201     }
    202 
     160    }
    203161    private void Initialize() {
    204162      ResultsCollector = new ResultsCollector();
    205       ResultsCollector.CollectedValues.Add(CurrentVelocityBoundsParameter);
    206       ResultsCollector.CollectedValues.Add(VelocityBoundsParameter);
     163      ResultsCollector.CollectedValues.Add(CurrentMaxVelocityParameter);
     164      ResultsCollector.CollectedValues.Add(MaxVelocityParameter);
    207165
    208166      foreach (IDiscreteDoubleValueModifier op in ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>()) {
    209         VelocityBoundsScalingOperatorParameter.ValidValues.Add(op);
    210         op.ValueParameter.ActualName = VelocityBoundsScaleParameter.Name;
    211         op.StartValueParameter.ActualName = VelocityBoundsStartValueParameter.Name;
    212         op.EndValueParameter.ActualName = VelocityBoundsEndValueParameter.Name;
    213         op.IndexParameter.ActualName = VelocityBoundsIndexParameter.Name;
    214         op.StartIndexParameter.ActualName = VelocityBoundsStartIndexParameter.Name;
    215         op.EndIndexParameter.ActualName = VelocityBoundsEndIndexParameter.Name;
    216       }
    217       VelocityBoundsScalingOperatorParameter.Value = null;
     167        MaxVelocityScalingOperatorParameter.ValidValues.Add(op);
     168        op.ValueParameter.ActualName = CurrentMaxVelocityParameter.Name;
     169        op.StartValueParameter.ActualName = MaxVelocityParameter.Name;
     170        op.EndValueParameter.ActualName = FinalMaxVelocityParameter.Name;
     171        op.IndexParameter.ActualName = MaxVelocityIndexParameter.Name;
     172        op.StartIndexParameter.ActualName = MaxVelocityStartIndexParameter.Name;
     173        op.EndIndexParameter.ActualName = MaxVelocityEndIndexParameter.Name;
     174      }
     175      MaxVelocityScalingOperatorParameter.Value = null;
    218176    }
    219177
    220178    public override IOperation Apply() {
    221179      var max = MaximizationParameter.ActualValue.Value;
     180      // Update of the personal bests
    222181      var points = RealVectorParameter.ActualValue;
    223182      var qualities = QualityParameter.ActualValue;
    224183      var particles = points.Select((p, i) => new { Particle = p, Index = i })
    225184        .Zip(qualities, (p, q) => Tuple.Create(p.Index, p.Particle, q.Value)).ToList();
    226       UpdateGlobalBest(max, particles);
     185      UpdatePersonalBest(max, particles);
     186
     187      // SPSO: update of the neighbor bests from the personal bests
     188      var personalBestPoints = PersonalBestParameter.ActualValue;
     189      var personalBestQualities = PersonalBestQualityParameter.ActualValue;
     190      particles = personalBestPoints.Select((p, i) => new { Particle = p, Index = i })
     191        .Zip(personalBestQualities, (p, q) => Tuple.Create(p.Index, p.Particle, q.Value)).ToList();
    227192      UpdateNeighborBest(max, particles);
    228       UpdatePersonalBest(max, particles);
    229       return UpdateVelocityBounds();
    230     }
    231 
    232     private void UpdateGlobalBest(bool maximization, IList<Tuple<int, RealVector, double>> particles) {
    233       var best = maximization ? particles.MaxItems(x => x.Item3).First() : particles.MinItems(x => x.Item3).First();
    234       var bestQuality = SwarmBestQualityParameter.ActualValue;
    235       if (bestQuality == null) {
    236         SwarmBestQualityParameter.ActualValue = new DoubleValue(best.Item3);
    237       } else bestQuality.Value = best.Item3;
    238       BestRealVectorParameter.ActualValue = (RealVector)best.Item2.Clone();
     193
     194      var next = new OperationCollection() { base.Apply() };
     195      next.Insert(0, ExecutionContext.CreateChildOperation(ResultsCollector));
     196      if (MaxVelocityScalingOperatorParameter.Value != null) {
     197        next.Insert(0, ExecutionContext.CreateChildOperation(MaxVelocityScalingOperatorParameter.Value));
     198      } else CurrentMaxVelocityParameter.ActualValue = new DoubleValue(MaxVelocityParameter.ActualValue.Value);
     199      return next;
    239200    }
    240201
     
    253214        NeighborBestParameter.ActualValue = neighborBest;
    254215        NeighborBestQualityParameter.ActualValue = neighborBestQuality;
     216      } else {
     217        // Neighbor best = Global best
     218        var best = maximization ? particles.MaxItems(x => x.Item3).First() : particles.MinItems(x => x.Item3).First();
     219        NeighborBestParameter.ActualValue = new ItemArray<RealVector>(particles.Select(x => best.Item2));
     220        NeighborBestQualityParameter.ActualValue = new ItemArray<DoubleValue>(particles.Select(x => new DoubleValue(best.Item3)));
    255221      }
    256222    }
     
    268234          !maximization && p.Item3 < personalBestQuality[p.Item1].Value) {
    269235          personalBestQuality[p.Item1].Value = p.Item3;
    270           personalBest[p.Item1] = p.Item2;
     236          personalBest[p.Item1] = (RealVector)p.Item2.Clone();
    271237        }
    272238      }
    273239      PersonalBestParameter.ActualValue = personalBest;
    274     }
    275 
    276     private IOperation UpdateVelocityBounds() {
    277       var currentVelocityBounds = CurrentVelocityBoundsParameter.ActualValue;
    278 
    279       if (currentVelocityBounds == null) {
    280         currentVelocityBounds = (DoubleMatrix)VelocityBoundsParameter.ActualValue.Clone();
    281         CurrentVelocityBoundsParameter.ActualValue = currentVelocityBounds;
    282       }
    283       if (VelocityBoundsScalingOperatorParameter.Value == null)
    284         return new OperationCollection() {
    285           ExecutionContext.CreateChildOperation(ResultsCollector),       
    286           base.Apply()
    287         };
    288 
    289       var velocityBoundsScale = VelocityBoundsScaleParameter.ActualValue;
    290       var velocityBoundsStartValue = VelocityBoundsStartValueParameter.ActualValue;
    291 
    292       if (velocityBoundsScale == null && velocityBoundsStartValue != null) {
    293         velocityBoundsScale = new DoubleValue(velocityBoundsStartValue.Value);
    294         VelocityBoundsScaleParameter.ActualValue = velocityBoundsScale;
    295       }
    296       for (int i = 0; i < currentVelocityBounds.Rows; i++) {
    297         for (int j = 0; j < currentVelocityBounds.Columns; j++) {
    298           if (currentVelocityBounds[i, j] >= 0) {
    299             currentVelocityBounds[i, j] = velocityBoundsScale.Value;
    300           } else {
    301             currentVelocityBounds[i, j] = (-1) * velocityBoundsScale.Value;
    302           }
    303         }
    304       }
    305 
    306       return new OperationCollection() {
    307         ExecutionContext.CreateChildOperation(ResultsCollector),
    308         ExecutionContext.CreateChildOperation(VelocityBoundsScalingOperatorParameter.Value),
    309         base.Apply()
    310       };
    311240    }
    312241  }
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/ParticleOperators/RealVectorTotallyConnectedParticleUpdater.cs

    r14185 r15091  
    2020#endregion
    2121
     22using System;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Core;
    2425using HeuristicLab.Optimization;
    2526using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     27using HeuristicLab.PluginInfrastructure;
    2628
    2729namespace HeuristicLab.Encodings.RealVectorEncoding {
    2830  [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*Inertia + (PersonalBestPoint-Point)*Phi_P*r_p + (BestPoint-Point)*Phi_G*r_g")]
    2931  [StorableClass]
    30   public sealed class RealVectorTotallyConnectedParticleUpdater : RealVectorParticleUpdater, IGlobalParticleUpdater {
     32  [NonDiscoverableType]
     33  [Obsolete("Same as the RealVectorNeighborhoodParticleUpdate")]
     34  internal sealed class RealVectorTotallyConnectedParticleUpdater : RealVectorParticleUpdater {
    3135
    3236    #region Construction & Cloning
     
    4145
    4246    public override IOperation Apply() {
    43       double inertia = Inertia.Value;
    44       double personalBestAttraction = PersonalBestAttraction.Value;
    45       double neighborBestAttraction = NeighborBestAttraction.Value;
    46 
    47       RealVector velocity = new RealVector(Velocity.Length);
    48       RealVector position = new RealVector(RealVector.Length);
    49       double r_p = Random.NextDouble();
    50       double r_g = Random.NextDouble();
    51 
    52       for (int i = 0; i < velocity.Length; i++) {
    53         velocity[i] =
    54           Velocity[i] * inertia +
    55           (PersonalBest[i] - RealVector[i]) * personalBestAttraction * r_p +
    56           (BestPoint[i] - RealVector[i]) * neighborBestAttraction * r_g;
    57       }
    58 
    59       MoveParticle(velocity, position);
     47      UpdateVelocity();
     48      UpdatePosition();
    6049
    6150      return base.Apply();
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/RealVector.cs

    r14185 r15091  
    2020#endregion
    2121
     22using System;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Core;
     
    7778    }
    7879
     80    public double DotProduct(RealVector other) {
     81      if (other.Length != Length) throw new ArgumentException("Vectors are of unequal length.");
     82      var dotProd = 0.0;
     83      for (var i = 0; i < Length; i++)
     84        dotProd += this[i] * other[i];
     85      return dotProd;
     86    }
    7987  }
    8088}
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/RealVectorEncoding.cs

    r14185 r15091  
    280280        particleCreator.RealVectorParameter.ActualName = Name;
    281281        particleCreator.BoundsParameter.ActualName = BoundsParameter.Name;
    282         particleCreator.ProblemSizeParameter.ActualName = LengthParameter.Name;
    283282      }
    284283    }
  • trunk/sources/HeuristicLab.Optimization/3.3/HeuristicLab.Optimization-3.3.csproj

    r15080 r15091  
    191191    <Compile Include="Interfaces\IDiscreteDoubleMatrixModifier.cs" />
    192192    <Compile Include="Algorithms\HeuristicOptimizationEngineAlgorithm.cs" />
    193     <Compile Include="Interfaces\IGlobalParticleUpdater.cs" />
    194193    <Compile Include="Interfaces\ILocalImprovementOperator.cs" />
    195     <Compile Include="Interfaces\ILocalParticleUpdater.cs" />
    196194    <Compile Include="Algorithms\HeuristicOptimizationAlgorithm.cs" />
    197195    <Compile Include="Interfaces\IMultiNeighborhoodShakingOperator.cs" />
  • trunk/sources/HeuristicLab.Optimization/3.3/Interfaces/IParticleCreator.cs

    r14185 r15091  
    2727  /// </summary>
    2828  public interface IParticleCreator : ISolutionCreator {
     29    ILookupParameter<ISolutionCreator> SolutionCreatorParameter { get; }
    2930  }
    3031}
  • trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/SingleObjectiveTestFunctionProblem.cs

    r15069 r15091  
    359359        op.BoundsParameter.ActualName = BoundsParameter.Name;
    360360        op.BoundsParameter.Hidden = true;
    361         op.ProblemSizeParameter.ActualName = ProblemSizeParameter.Name;
    362         op.ProblemSizeParameter.Hidden = true;
    363361      }
    364362      foreach (var op in Operators.OfType<IRealVectorParticleUpdater>()) {
Note: See TracChangeset for help on using the changeset viewer.