Changeset 15091 for trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/ParticleOperators/RealVectorParticleCreator.cs
- Timestamp:
- 06/29/17 15:26:16 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/ParticleOperators/RealVectorParticleCreator.cs
r14185 r15091 24 24 using HeuristicLab.Data; 25 25 using HeuristicLab.Operators; 26 using HeuristicLab.Optimization; 26 27 using HeuristicLab.Parameters; 27 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 30 31 [Item("RealVectorParticleCreator", "Creates a particle with position, zero velocity vector and personal best.")] 31 32 [StorableClass] 32 public class RealVectorParticleCreator : AlgorithmOperator, IRealVectorParticleCreator {33 public class RealVectorParticleCreator : AlgorithmOperator, IRealVectorParticleCreator, IStochasticOperator { 33 34 34 35 #region Parameters 35 public ILookupParameter<I ntValue> ProblemSizeParameter {36 get { return (ILookupParameter<I ntValue>)Parameters["ProblemSize"]; }36 public ILookupParameter<IRandom> RandomParameter { 37 get { return (ILookupParameter<IRandom>)Parameters["Random"]; } 37 38 } 38 39 public IValueLookupParameter<DoubleMatrix> BoundsParameter { … … 48 49 get { return (ILookupParameter<RealVector>)Parameters["Velocity"]; } 49 50 } 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"]; } 58 53 } 59 54 #endregion 60 55 61 56 #region Construction & Cloning 62 57 [StorableConstructor] … … 65 60 public RealVectorParticleCreator() 66 61 : base() { 67 Parameters.Add(new LookupParameter<I ntValue>("ProblemSize", "The dimension of the problem."));62 Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator to use.")); 68 63 Parameters.Add(new ValueLookupParameter<DoubleMatrix>("Bounds", "The lower and upper bounds in each dimension.")); 69 64 Parameters.Add(new LookupParameter<RealVector>("RealVector", "Particle's current solution")); 70 65 Parameters.Add(new LookupParameter<RealVector>("PersonalBest", "Particle's personal best solution.")); 71 66 Parameters.Add(new LookupParameter<RealVector>("Velocity", "Particle's current velocity.")); 67 Parameters.Add(new LookupParameter<ISolutionCreator>("SolutionCreator", "The operator that creates the initial position.")); 72 68 73 UniformRandomRealVectorCreator realVectorCreater = new UniformRandomRealVectorCreator();69 Placeholder realVectorCreater = new Placeholder(); 74 70 Assigner personalBestPositionAssigner = new Assigner(); 71 RealVectorVelocityInitializer velocityInitializer = new RealVectorVelocityInitializer(); 75 72 76 73 OperatorGraph.InitialOperator = realVectorCreater; 77 74 78 realVectorCreater.RealVectorParameter.ActualName = RealVectorParameter.Name; 79 realVectorCreater.LengthParameter.ActualName = ProblemSizeParameter.Name; 80 realVectorCreater.BoundsParameter.ActualName = BoundsParameter.Name; 75 realVectorCreater.OperatorParameter.ActualName = SolutionCreatorParameter.Name; 81 76 realVectorCreater.Successor = personalBestPositionAssigner; 82 77 83 78 personalBestPositionAssigner.LeftSideParameter.ActualName = PersonalBestParameter.Name; 84 79 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; 86 87 } 87 88 public override IDeepCloneable Clone(Cloner cloner) { … … 89 90 } 90 91 #endregion 91 92 public override IOperation Apply() {93 Velocity = new RealVector(ProblemSize);94 return base.Apply();95 }96 97 98 92 } 99 93 }
Note: See TracChangeset
for help on using the changeset viewer.