Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/30/17 21:57:38 (7 years ago)
Author:
abeham
Message:

#2797:

  • Recreated backwards compatibility by readding old operators and renaming new operators to SPSO*
    • If a previously configured algorithm is run again, the same results should be obtained
  • Set all old operators to internal, NonDiscoverableType, and Obsolete (they are also not fixed, e.g. PersonalBest update remains flawed)
  • Added SPSO 2007 velocity initializer and let users choose in SPSOParticleCreator
  • Changed description of PSO
  • Updated sample
File:
1 edited

Legend:

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

    r15091 r15102  
    2020#endregion
    2121
     22using System;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Core;
     
    2728using HeuristicLab.Parameters;
    2829using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     30using HeuristicLab.PluginInfrastructure;
    2931
    3032namespace HeuristicLab.Encodings.RealVectorEncoding {
    3133  [Item("RealVectorParticleCreator", "Creates a particle with position, zero velocity vector and personal best.")]
    3234  [StorableClass]
    33   public class RealVectorParticleCreator : AlgorithmOperator, IRealVectorParticleCreator, IStochasticOperator {
     35  [NonDiscoverableType]
     36  [Obsolete("Use SPSOParticleCreator")]
     37  internal class RealVectorParticleCreator : AlgorithmOperator, IRealVectorParticleCreator {
    3438
    3539    #region Parameters
    36     public ILookupParameter<IRandom> RandomParameter {
    37       get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
     40    public ILookupParameter<IntValue> ProblemSizeParameter {
     41      get { return (ILookupParameter<IntValue>)Parameters["ProblemSize"]; }
    3842    }
    3943    public IValueLookupParameter<DoubleMatrix> BoundsParameter {
     
    5357    }
    5458    #endregion
    55    
     59
     60    #region Parameter Values
     61    protected int ProblemSize {
     62      get { return ProblemSizeParameter.ActualValue.Value; }
     63    }
     64    protected RealVector Velocity {
     65      set { VelocityParameter.ActualValue = value; }
     66    }
     67    #endregion
     68
    5669    #region Construction & Cloning
    5770    [StorableConstructor]
     
    6073    public RealVectorParticleCreator()
    6174      : base() {
    62       Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator to use."));
     75      Parameters.Add(new LookupParameter<IntValue>("ProblemSize", "The dimension of the problem."));
    6376      Parameters.Add(new ValueLookupParameter<DoubleMatrix>("Bounds", "The lower and upper bounds in each dimension."));
    6477      Parameters.Add(new LookupParameter<RealVector>("RealVector", "Particle's current solution"));
     
    6780      Parameters.Add(new LookupParameter<ISolutionCreator>("SolutionCreator", "The operator that creates the initial position."));
    6881
    69       Placeholder realVectorCreater = new Placeholder();
     82      UniformRandomRealVectorCreator realVectorCreater = new UniformRandomRealVectorCreator();
    7083      Assigner personalBestPositionAssigner = new Assigner();
    71       RealVectorVelocityInitializer velocityInitializer = new RealVectorVelocityInitializer();
    7284
    7385      OperatorGraph.InitialOperator = realVectorCreater;
    7486
    75       realVectorCreater.OperatorParameter.ActualName = SolutionCreatorParameter.Name;
     87      realVectorCreater.RealVectorParameter.ActualName = RealVectorParameter.Name;
     88      realVectorCreater.LengthParameter.ActualName = ProblemSizeParameter.Name;
     89      realVectorCreater.BoundsParameter.ActualName = BoundsParameter.Name;
    7690      realVectorCreater.Successor = personalBestPositionAssigner;
    7791
    7892      personalBestPositionAssigner.LeftSideParameter.ActualName = PersonalBestParameter.Name;
    7993      personalBestPositionAssigner.RightSideParameter.ActualName = RealVectorParameter.Name;
    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;
     94      personalBestPositionAssigner.Successor = null;
    8795    }
    8896    public override IDeepCloneable Clone(Cloner cloner) {
     
    9098    }
    9199    #endregion
     100
     101    public override IOperation Apply() {
     102      Velocity = new RealVector(ProblemSize);
     103      return base.Apply();
     104    }
     105   
     106    [StorableHook(HookType.AfterDeserialization)]
     107    private void AfterDeserialization() {
     108      if (!Parameters.ContainsKey("SolutionCreator"))
     109        Parameters.Add(new LookupParameter<ISolutionCreator>("SolutionCreator", "The operator that creates the initial position."));
     110    }
    92111  }
    93112}
Note: See TracChangeset for help on using the changeset viewer.