Changeset 5592 for trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/ParticleOperators/RealVectorParticleCreator.cs
- Timestamp:
- 03/02/11 15:22:54 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/ParticleOperators/RealVectorParticleCreator.cs
r5560 r5592 20 20 #endregion 21 21 22 using System; 23 using HeuristicLab.Operators; 22 using HeuristicLab.Common; 24 23 using HeuristicLab.Core; 25 24 using HeuristicLab.Data; 25 using HeuristicLab.Operators; 26 26 using HeuristicLab.Parameters; 27 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 using HeuristicLab.Common;29 using HeuristicLab.Optimization;30 28 31 29 namespace HeuristicLab.Encodings.RealVectorEncoding { 32 30 [Item("RealVectorParticleCreator", "Creates a particle with position, zero velocity vector and personal best.")] 33 31 [StorableClass] 34 public class RealVectorParticleCreator : SingleSuccessorOperator, IRealVectorParticleCreator { 35 #region IRealVectorParticleCreator Members 32 public class RealVectorParticleCreator : AlgorithmOperator, IRealVectorParticleCreator { 33 34 #region Parameters 36 35 public ILookupParameter<IntValue> ProblemSizeParameter { 37 get { return (ILookupParameter<IntValue>)Parameters["ProblemSize"]; }36 get { return (ILookupParameter<IntValue>)Parameters["ProblemSize"]; } 38 37 } 39 38 public IValueLookupParameter<DoubleMatrix> BoundsParameter { 39 get { return (IValueLookupParameter<DoubleMatrix>)Parameters["Bounds"]; } 40 } 40 41 public ILookupParameter<RealVector> RealVectorParameter { 41 42 get { return (ILookupParameter<RealVector>)Parameters["RealVector"]; } 42 43 } 43 44 44 public ILookupParameter<RealVector> PersonalBestParameter { 45 45 get { return (ILookupParameter<RealVector>)Parameters["PersonalBest"]; } 46 46 } 47 48 public IValueLookupParameter<DoubleMatrix> BoundsParameter {49 get { return (IValueLookupParameter<DoubleMatrix>)Parameters["Bounds"]; }50 }51 52 47 public ILookupParameter<RealVector> VelocityParameter { 53 48 get { return (ILookupParameter<RealVector>)Parameters["Velocity"]; } 54 49 } 55 56 50 #endregion 57 51 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() { 59 67 Parameters.Add(new LookupParameter<IntValue>("ProblemSize", "The dimension of the problem.")); 60 68 Parameters.Add(new ValueLookupParameter<DoubleMatrix>("Bounds", "The lower and upper bounds in each dimension.")); 61 69 Parameters.Add(new LookupParameter<RealVector>("RealVector", "Particle's current solution")); 62 70 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.")); 65 72 66 public override IOperation Apply() { 67 VelocityParameter.ActualValue = new RealVector(ProblemSizeParameter.ActualValue.Value); 68 UniformRandomRealVectorCreator realVectorCreater = new UniformRandomRealVectorCreator(); 73 UniformRandomRealVectorCreator realVectorCreater = new UniformRandomRealVectorCreator(); 69 74 Assigner personalBestPositionAssigner = new Assigner(); 70 75 71 this.Name = "Particle Creator";76 OperatorGraph.InitialOperator = realVectorCreater; 72 77 73 //realVectorCreater.Name = "(SolutionCreator)"; 74 realVectorCreater.RealVectorParameter.ActualName = "RealVector"; 78 realVectorCreater.RealVectorParameter.ActualName = RealVectorParameter.Name; 75 79 realVectorCreater.LengthParameter.ActualName = ProblemSizeParameter.Name; 76 realVectorCreater.BoundsParameter.ActualName = BoundsParameter.Name; 80 realVectorCreater.BoundsParameter.ActualName = BoundsParameter.Name; 77 81 realVectorCreater.Successor = personalBestPositionAssigner; 78 82 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; 87 86 } 88 89 87 public override IDeepCloneable Clone(Cloner cloner) { 90 88 return new RealVectorParticleCreator(this, cloner); 91 89 } 90 #endregion 92 91 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(); 95 95 } 96 96 97 [StorableConstructor] 98 protected RealVectorParticleCreator(bool deserializing) : base(deserializing) { } 97 99 98 } 100 99 }
Note: See TracChangeset
for help on using the changeset viewer.