Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/02/11 15:22:54 (14 years ago)
Author:
epitzer
Message:

Additional improvements to PSO (#852)

  • simplify and clean up RealVectorSwarmUpdater
  • make the RealVectorParticleCreator an AlgorithmOperator
  • standardize naming of local variables in ParticleUpdaters
  • remove default parameter values from main loop
  • new implementation of MultiPSOTopologyUpdater (using shuffling)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/ParticleOperators/RealVectorParticleCreator.cs

    r5560 r5592  
    2020#endregion
    2121
    22 using System;
    23 using HeuristicLab.Operators;
     22using HeuristicLab.Common;
    2423using HeuristicLab.Core;
    2524using HeuristicLab.Data;
     25using HeuristicLab.Operators;
    2626using HeuristicLab.Parameters;
    2727using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    28 using HeuristicLab.Common;
    29 using HeuristicLab.Optimization;
    3028
    3129namespace HeuristicLab.Encodings.RealVectorEncoding {
    3230  [Item("RealVectorParticleCreator", "Creates a particle with position, zero velocity vector and personal best.")]
    3331  [StorableClass]
    34   public class RealVectorParticleCreator : SingleSuccessorOperator, IRealVectorParticleCreator {
    35     #region IRealVectorParticleCreator Members
     32  public class RealVectorParticleCreator : AlgorithmOperator, IRealVectorParticleCreator {
     33
     34    #region Parameters
    3635    public ILookupParameter<IntValue> ProblemSizeParameter {
    37      get { return (ILookupParameter<IntValue>)Parameters["ProblemSize"]; }
     36      get { return (ILookupParameter<IntValue>)Parameters["ProblemSize"]; }
    3837    }
    39 
     38    public IValueLookupParameter<DoubleMatrix> BoundsParameter {
     39      get { return (IValueLookupParameter<DoubleMatrix>)Parameters["Bounds"]; }
     40    }
    4041    public ILookupParameter<RealVector> RealVectorParameter {
    4142      get { return (ILookupParameter<RealVector>)Parameters["RealVector"]; }
    4243    }
    43 
    4444    public ILookupParameter<RealVector> PersonalBestParameter {
    4545      get { return (ILookupParameter<RealVector>)Parameters["PersonalBest"]; }
    4646    }
    47 
    48     public IValueLookupParameter<DoubleMatrix> BoundsParameter {
    49       get { return (IValueLookupParameter<DoubleMatrix>)Parameters["Bounds"]; }
    50     }
    51 
    5247    public ILookupParameter<RealVector> VelocityParameter {
    5348      get { return (ILookupParameter<RealVector>)Parameters["Velocity"]; }
    5449    }
    55 
    5650    #endregion
    5751
    58     public RealVectorParticleCreator() : base() {
     52    #region Parameter Values
     53    protected int ProblemSize {
     54      get { return ProblemSizeParameter.ActualValue.Value; }
     55    }
     56    protected RealVector Velocity {
     57      set { VelocityParameter.ActualValue = value; }
     58    }
     59    #endregion
     60
     61    #region Construction & Cloning
     62    [StorableConstructor]
     63    protected RealVectorParticleCreator(bool deserializing) : base(deserializing) { }
     64    protected RealVectorParticleCreator(RealVectorParticleCreator original, Cloner cloner) : base(original, cloner) { }
     65    public RealVectorParticleCreator()
     66      : base() {
    5967      Parameters.Add(new LookupParameter<IntValue>("ProblemSize", "The dimension of the problem."));
    6068      Parameters.Add(new ValueLookupParameter<DoubleMatrix>("Bounds", "The lower and upper bounds in each dimension."));
    6169      Parameters.Add(new LookupParameter<RealVector>("RealVector", "Particle's current solution"));
    6270      Parameters.Add(new LookupParameter<RealVector>("PersonalBest", "Particle's personal best solution."));
    63       Parameters.Add(new LookupParameter<RealVector>("Velocity", "Particle's current velocity."));   
    64     }
     71      Parameters.Add(new LookupParameter<RealVector>("Velocity", "Particle's current velocity."));
    6572
    66     public override IOperation Apply() {
    67       VelocityParameter.ActualValue = new RealVector(ProblemSizeParameter.ActualValue.Value);
    68       UniformRandomRealVectorCreator realVectorCreater = new UniformRandomRealVectorCreator();
     73      UniformRandomRealVectorCreator realVectorCreater = new UniformRandomRealVectorCreator();
    6974      Assigner personalBestPositionAssigner = new Assigner();
    7075
    71       this.Name = "Particle Creator";
     76      OperatorGraph.InitialOperator = realVectorCreater;
    7277
    73       //realVectorCreater.Name = "(SolutionCreator)";
    74       realVectorCreater.RealVectorParameter.ActualName = "RealVector";
     78      realVectorCreater.RealVectorParameter.ActualName = RealVectorParameter.Name;
    7579      realVectorCreater.LengthParameter.ActualName = ProblemSizeParameter.Name;
    76       realVectorCreater.BoundsParameter.ActualName = BoundsParameter.Name; 
     80      realVectorCreater.BoundsParameter.ActualName = BoundsParameter.Name;
    7781      realVectorCreater.Successor = personalBestPositionAssigner;
    7882
    79       personalBestPositionAssigner.LeftSideParameter.ActualName = "PersonalBest";
    80       personalBestPositionAssigner.RightSideParameter.ActualName = "RealVector";
    81       personalBestPositionAssigner.Successor = null;
    82 
    83       OperationCollection next = new OperationCollection();
    84       next.Add(ExecutionContext.CreateChildOperation(realVectorCreater));
    85       next.Add(base.Apply());
    86       return next;
     83      personalBestPositionAssigner.LeftSideParameter.ActualName = PersonalBestParameter.Name;
     84      personalBestPositionAssigner.RightSideParameter.ActualName = RealVectorParameter.Name;
     85      personalBestPositionAssigner.Successor = null;
    8786    }
    88 
    8987    public override IDeepCloneable Clone(Cloner cloner) {
    9088      return new RealVectorParticleCreator(this, cloner);
    9189    }
     90    #endregion
    9291
    93     protected RealVectorParticleCreator(RealVectorParticleCreator original, Cloner cloner)
    94       : base(original, cloner) {
     92    public override IOperation Apply() {
     93      Velocity = new RealVector(ProblemSize);
     94      return base.Apply();
    9595    }
    9696
    97     [StorableConstructor]
    98     protected RealVectorParticleCreator(bool deserializing) : base(deserializing) { }
     97
    9998  }
    10099}
Note: See TracChangeset for help on using the changeset viewer.