Changeset 5209
- Timestamp:
- 01/04/11 16:34:11 (14 years ago)
- Location:
- branches/PSO/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3
- Files:
-
- 9 added
- 3 edited
- 3 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/PSO/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/HeuristicLab.Algorithms.ParticleSwarmOptimization-3.3.csproj
r5033 r5209 11 11 <RootNamespace>HeuristicLab.Algorithms.ParticleSwarmOptimization</RootNamespace> 12 12 <AssemblyName>HeuristicLab.Algorithms.ParticleSwarmOptimization-3.3</AssemblyName> 13 <TargetFrameworkVersion>v 3.5</TargetFrameworkVersion>13 <TargetFrameworkVersion>v4.0</TargetFrameworkVersion> 14 14 <FileAlignment>512</FileAlignment> 15 15 <SignAssembly>true</SignAssembly> … … 34 34 <UseApplicationTrust>false</UseApplicationTrust> 35 35 <BootstrapperEnabled>true</BootstrapperEnabled> 36 <TargetFrameworkProfile /> 36 37 </PropertyGroup> 37 38 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> … … 91 92 </PropertyGroup> 92 93 <ItemGroup> 94 <Reference Include="HeuristicLab.Encodings.IntegerVectorEncoding-3.3"> 95 <HintPath>C:\Program Files\HeuristicLab 3.3\HeuristicLab.Encodings.IntegerVectorEncoding-3.3.dll</HintPath> 96 </Reference> 93 97 <Reference Include="System" /> 94 98 <Reference Include="System.Core"> … … 106 110 <ItemGroup> 107 111 <Compile Include="BestPointInitializer.cs" /> 112 <Compile Include="RandomTopologyInitializer.cs" /> 113 <Compile Include="VonNeumannTopologyInitializer.cs" /> 114 <Compile Include="EmptyTopologyInitializer.cs" /> 115 <Compile Include="RingTopologyInitializer.cs" /> 116 <Compile Include="ITopologyUpdater.cs" /> 117 <Compile Include="IdentityTopologyUpdater.cs" /> 118 <Compile Include="NeighborUpdater.cs" /> 119 <Compile Include="TopologyInitializer.cs" /> 120 <Compile Include="ITopologyInitializer.cs" /> 121 <Compile Include="NeighborhoodParticleUpdater.cs" /> 122 <Compile Include="IParticleUpdater.cs" /> 123 <Compile Include="TotallyConnectedParticleUpdater.cs" /> 108 124 <Compile Include="HeuristicLabAlgorithmsParticleSwarmOptimizationPlugin.cs" /> 109 125 <Compile Include="ParticleSwarmOptimization.cs" /> -
branches/PSO/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/IParticleUpdater.cs
r5208 r5209 20 20 #endregion 21 21 22 using HeuristicLab.Common;23 22 using HeuristicLab.Core; 24 23 using HeuristicLab.Data; 25 24 using HeuristicLab.Encodings.RealVectorEncoding; 26 using HeuristicLab.Operators;27 25 using HeuristicLab.Parameters; 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;29 26 30 27 namespace HeuristicLab.Algorithms.ParticleSwarmOptimization { 31 28 32 [StorableClass] 33 public class ParticleUpdater : SingleSuccessorOperator { 29 public interface IParticleUpdater : IItem { 30 LookupParameter<RealVector> VelocityParameter { get; } 31 LookupParameter<DoubleMatrix> VelocityBoundsParameter { get; } 34 32 35 #region Parameter properties 36 public LookupParameter<IRandom> RandomParameter { 37 get { return (LookupParameter<IRandom>)Parameters["Random"]; } 38 } 39 public LookupParameter<RealVector> PointParameter { 40 get { return (LookupParameter<RealVector>)Parameters["Point"]; } 41 } 42 public LookupParameter<RealVector> VelocityParameter { 43 get { return (LookupParameter<RealVector>)Parameters["Velocity"]; } 44 } 45 public LookupParameter<RealVector> PersonalBestPointParameter { 46 get { return (LookupParameter<RealVector>)Parameters["PersonalBestPoint"]; } 47 } 48 public LookupParameter<RealVector> BestPointParameter { 49 get { return (LookupParameter<RealVector>)Parameters["BestPoint"]; } 50 } 51 public LookupParameter<DoubleMatrix> BoundsParameter { 52 get { return (LookupParameter<DoubleMatrix>)Parameters["Bounds"]; } 53 } 54 public LookupParameter<DoubleMatrix> VelocityBoundsParameter { 55 get { return (LookupParameter<DoubleMatrix>)Parameters["VelocityBounds"]; } 56 } 57 public LookupParameter<DoubleValue> OmegaParameter { 58 get { return (LookupParameter<DoubleValue>)Parameters["Omega"]; } 59 } 60 public LookupParameter<DoubleValue> Phi_PParameter { 61 get { return (LookupParameter<DoubleValue>)Parameters["Phi_P"]; } 62 } 63 public LookupParameter<DoubleValue> Phi_GParameter { 64 get { return (LookupParameter<DoubleValue>)Parameters["Phi_G"]; } 65 } 66 #endregion 33 LookupParameter<RealVector> PointParameter { get; } 34 LookupParameter<DoubleMatrix> BoundsParameter { get; } 67 35 68 #region Parameter Values 69 public IRandom Random { 70 get { return RandomParameter.ActualValue; } 71 } 72 public RealVector Point { 73 get { return PointParameter.ActualValue; } 74 set { PointParameter.ActualValue = value; } 75 } 76 public RealVector Velocity { 77 get { return VelocityParameter.ActualValue; } 78 set { VelocityParameter.ActualValue = value; } 79 } 80 public RealVector PersonalBestPoint { 81 get { return PersonalBestPointParameter.ActualValue; } 82 } 83 public RealVector BestPoint { 84 get { return BestPointParameter.ActualValue; } 85 } 86 public DoubleMatrix Bounds { 87 get { return BoundsParameter.ActualValue; } 88 } 89 public DoubleMatrix VelocityBounds { 90 get { return VelocityBoundsParameter.ActualValue; } 91 } 92 public double Omega { 93 get { return OmegaParameter.ActualValue.Value; } 94 } 95 public double Phi_P { 96 get { return Phi_PParameter.ActualValue.Value; } 97 } 98 public double Phi_G { 99 get { return Phi_GParameter.ActualValue.Value; } 100 } 101 #endregion 36 LookupParameter<RealVector> PersonalBestPointParameter { get; } 37 LookupParameter<RealVector> BestNeighborPointParameter { get; } 38 LookupParameter<RealVector> BestPointParameter { get; } 102 39 103 #region Construction & Cloning 40 LookupParameter<DoubleValue> OmegaParameter { get; } 41 LookupParameter<DoubleValue> Phi_PParameter { get; } 42 LookupParameter<DoubleValue> Phi_GParameter { get; } 43 } 104 44 105 [StorableConstructor]106 protected ParticleUpdater(bool deserializing) : base(deserializing) { }107 protected ParticleUpdater(ParticleUpdater original, Cloner cloner)108 : base(original, cloner) {109 }110 111 public ParticleUpdater()112 : base() {113 Parameters.Add(new LookupParameter<IRandom>("Random", "Random number generator."));114 Parameters.Add(new LookupParameter<RealVector>("Point", "Particle's current position"));115 Parameters.Add(new LookupParameter<RealVector>("Velocity", "Particle's current velocity."));116 Parameters.Add(new LookupParameter<RealVector>("PersonalBestPoint", "Particle's personal best position"));117 Parameters.Add(new LookupParameter<RealVector>("BestPoint", "Global best position"));118 Parameters.Add(new LookupParameter<DoubleMatrix>("Bounds", "The lower and upper bounds for each dimension of the position vector for the current problem."));119 Parameters.Add(new LookupParameter<DoubleMatrix>("VelocityBounds", "Upper and lower bounds for the particle's velocity vector."));120 Parameters.Add(new LookupParameter<DoubleValue>("Omega", "The weight for the particle's velocity vector."));121 Parameters.Add(new LookupParameter<DoubleValue>("Phi_P", "The weight for the particle's personal best position."));122 Parameters.Add(new LookupParameter<DoubleValue>("Phi_G", "The weight for the global best position."));123 }124 125 public override IDeepCloneable Clone(Cloner cloner) {126 return new ParticleUpdater(this, cloner);127 }128 129 #endregion130 131 public override IOperation Apply() {132 RealVector velocity = new RealVector(Velocity.Length);133 RealVector position = new RealVector(Point.Length);134 double r_p = Random.NextDouble();135 double r_g = Random.NextDouble();136 for (int i = 0; i < velocity.Length; i++) {137 velocity[i] =138 Velocity[i] * Omega +139 (PersonalBestPoint[i] - Point[i]) * Phi_P * r_p +140 (BestPoint[i] - Point[i]) * Phi_G * r_g;141 }142 BoundsChecker.Apply(velocity, VelocityBounds);143 for (int i = 0; i < velocity.Length; i++) {144 position[i] = Point[i] + velocity[i];145 }146 BoundsChecker.Apply(position, Bounds);147 Point = position;148 Velocity = velocity;149 150 return base.Apply();151 }152 153 public override bool CanChangeName {154 get { return false; }155 }156 }157 45 } -
branches/PSO/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/NeighborhoodParticleUpdater.cs
r5208 r5209 22 22 using HeuristicLab.Common; 23 23 using HeuristicLab.Core; 24 using HeuristicLab.Data;25 24 using HeuristicLab.Encodings.RealVectorEncoding; 26 using HeuristicLab.Operators;27 using HeuristicLab.Parameters;28 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 26 … … 31 28 32 29 [StorableClass] 33 public class ParticleUpdater : SingleSuccessorOperator { 34 35 #region Parameter properties 36 public LookupParameter<IRandom> RandomParameter { 37 get { return (LookupParameter<IRandom>)Parameters["Random"]; } 38 } 39 public LookupParameter<RealVector> PointParameter { 40 get { return (LookupParameter<RealVector>)Parameters["Point"]; } 41 } 42 public LookupParameter<RealVector> VelocityParameter { 43 get { return (LookupParameter<RealVector>)Parameters["Velocity"]; } 44 } 45 public LookupParameter<RealVector> PersonalBestPointParameter { 46 get { return (LookupParameter<RealVector>)Parameters["PersonalBestPoint"]; } 47 } 48 public LookupParameter<RealVector> BestPointParameter { 49 get { return (LookupParameter<RealVector>)Parameters["BestPoint"]; } 50 } 51 public LookupParameter<DoubleMatrix> BoundsParameter { 52 get { return (LookupParameter<DoubleMatrix>)Parameters["Bounds"]; } 53 } 54 public LookupParameter<DoubleMatrix> VelocityBoundsParameter { 55 get { return (LookupParameter<DoubleMatrix>)Parameters["VelocityBounds"]; } 56 } 57 public LookupParameter<DoubleValue> OmegaParameter { 58 get { return (LookupParameter<DoubleValue>)Parameters["Omega"]; } 59 } 60 public LookupParameter<DoubleValue> Phi_PParameter { 61 get { return (LookupParameter<DoubleValue>)Parameters["Phi_P"]; } 62 } 63 public LookupParameter<DoubleValue> Phi_GParameter { 64 get { return (LookupParameter<DoubleValue>)Parameters["Phi_G"]; } 65 } 66 #endregion 67 68 #region Parameter Values 69 public IRandom Random { 70 get { return RandomParameter.ActualValue; } 71 } 72 public RealVector Point { 73 get { return PointParameter.ActualValue; } 74 set { PointParameter.ActualValue = value; } 75 } 76 public RealVector Velocity { 77 get { return VelocityParameter.ActualValue; } 78 set { VelocityParameter.ActualValue = value; } 79 } 80 public RealVector PersonalBestPoint { 81 get { return PersonalBestPointParameter.ActualValue; } 82 } 83 public RealVector BestPoint { 84 get { return BestPointParameter.ActualValue; } 85 } 86 public DoubleMatrix Bounds { 87 get { return BoundsParameter.ActualValue; } 88 } 89 public DoubleMatrix VelocityBounds { 90 get { return VelocityBoundsParameter.ActualValue; } 91 } 92 public double Omega { 93 get { return OmegaParameter.ActualValue.Value; } 94 } 95 public double Phi_P { 96 get { return Phi_PParameter.ActualValue.Value; } 97 } 98 public double Phi_G { 99 get { return Phi_GParameter.ActualValue.Value; } 100 } 101 #endregion 30 public class NeighborhoodParticleUpdater : ParticleUpdater { 102 31 103 32 #region Construction & Cloning 104 33 105 34 [StorableConstructor] 106 protected ParticleUpdater(bool deserializing) : base(deserializing) { } 107 protected ParticleUpdater(ParticleUpdater original, Cloner cloner) 108 : base(original, cloner) { 109 } 110 111 public ParticleUpdater() 112 : base() { 113 Parameters.Add(new LookupParameter<IRandom>("Random", "Random number generator.")); 114 Parameters.Add(new LookupParameter<RealVector>("Point", "Particle's current position")); 115 Parameters.Add(new LookupParameter<RealVector>("Velocity", "Particle's current velocity.")); 116 Parameters.Add(new LookupParameter<RealVector>("PersonalBestPoint", "Particle's personal best position")); 117 Parameters.Add(new LookupParameter<RealVector>("BestPoint", "Global best position")); 118 Parameters.Add(new LookupParameter<DoubleMatrix>("Bounds", "The lower and upper bounds for each dimension of the position vector for the current problem.")); 119 Parameters.Add(new LookupParameter<DoubleMatrix>("VelocityBounds", "Upper and lower bounds for the particle's velocity vector.")); 120 Parameters.Add(new LookupParameter<DoubleValue>("Omega", "The weight for the particle's velocity vector.")); 121 Parameters.Add(new LookupParameter<DoubleValue>("Phi_P", "The weight for the particle's personal best position.")); 122 Parameters.Add(new LookupParameter<DoubleValue>("Phi_G", "The weight for the global best position.")); 123 } 35 protected NeighborhoodParticleUpdater(bool deserializing) : base(deserializing) { } 36 protected NeighborhoodParticleUpdater(ParticleUpdater original, Cloner cloner) : base(original, cloner) { } 37 public NeighborhoodParticleUpdater() : base() { } 124 38 125 39 public override IDeepCloneable Clone(Cloner cloner) { 126 return new ParticleUpdater(this, cloner);40 return new NeighborhoodParticleUpdater(this, cloner); 127 41 } 128 42 … … 138 52 Velocity[i] * Omega + 139 53 (PersonalBestPoint[i] - Point[i]) * Phi_P * r_p + 140 (Best Point[i] - Point[i]) * Phi_G * r_g;54 (BestNeighborPoint[i] - Point[i]) * Phi_G * r_g; 141 55 } 142 56 BoundsChecker.Apply(velocity, VelocityBounds); … … 150 64 return base.Apply(); 151 65 } 152 153 public override bool CanChangeName {154 get { return false; }155 }156 66 } 157 67 } -
branches/PSO/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/ParticleSwarmOptimization.cs
r5033 r5209 32 32 using HeuristicLab.Parameters; 33 33 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 34 using HeuristicLab.PluginInfrastructure; 34 35 using HeuristicLab.Random; 35 36 36 37 namespace HeuristicLab.Algorithms.ParticleSwarmOptimization { 37 38 38 [Item("Particle Swarm Optimization", "A particle swarm optimization algorithm .")]39 [Item("Particle Swarm Optimization", "A particle swarm optimization algorithm based on the description in Pedersen, M.E.H. (2010). PhD thesis. University of Southampton.")] 39 40 [Creatable("Algorithms")] 40 41 [StorableClass] … … 82 83 public ValueLookupParameter<DoubleMatrix> VelocityBoundsParameter { 83 84 get { return (ValueLookupParameter<DoubleMatrix>)Parameters["VelocityBounds"]; } 85 } 86 public ConstrainedValueParameter<IParticleUpdater> ParticleUpdaterParameter { 87 get { return (ConstrainedValueParameter<IParticleUpdater>)Parameters["ParticleUpdater"]; } 88 } 89 public ConstrainedValueParameter<ITopologyInitializer> TopologyInitializerParameter { 90 get { return (ConstrainedValueParameter<ITopologyInitializer>)Parameters["TopologyInitializer"]; } 91 } 92 public ConstrainedValueParameter<ITopologyUpdater> TopologyUpdaterParameter { 93 get { return (ConstrainedValueParameter<ITopologyUpdater>)Parameters["TopologyUpdater"]; } 84 94 } 85 95 #endregion … … 108 118 Parameters.Add(new ValueParameter<DoubleValue>("Phi_G", "Weight for global best position.", new DoubleValue(3.7))); 109 119 Parameters.Add(new ValueLookupParameter<DoubleMatrix>("VelocityBounds", "Maximum Velocity in every dimension", new DoubleMatrix(new double[,] { { -1, 1 } }))); 120 Parameters.Add(new ConstrainedValueParameter<IParticleUpdater>("ParticleUpdater", "Operator that calculates new position and velocity of a particle", 121 new ItemSet<IParticleUpdater>(ApplicationManager.Manager.GetInstances<IParticleUpdater>()))); 122 Parameters.Add(new ConstrainedValueParameter<ITopologyInitializer>("TopologyInitializer", "Creates neighborhood description vectors", 123 new ItemSet<ITopologyInitializer>(ApplicationManager.Manager.GetInstances<ITopologyInitializer>()))); 124 Parameters.Add(new ConstrainedValueParameter<ITopologyUpdater>("TopologyUpdater", "Updates the neighborhood description vectors", 125 new ItemSet<ITopologyUpdater>(ApplicationManager.Manager.GetInstances<ITopologyUpdater>()))); 126 ParticleUpdaterParameter.ActualValue = ParticleUpdaterParameter.ValidValues.SingleOrDefault(v => v.GetType() == typeof(TotallyConnectedParticleUpdater)); 127 TopologyInitializerParameter.ActualValue = TopologyInitializerParameter.ValidValues.SingleOrDefault(v => v.GetType() == typeof(EmptyTopologyInitializer)); 128 TopologyUpdaterParameter.ActualValue = TopologyUpdaterParameter.ValidValues.SingleOrDefault(v => v.GetType() == typeof(IdentityTopologyUpdater)); 110 129 111 130 RandomCreator randomCreator = new RandomCreator(); … … 116 135 Assigner bestPersonalQualityAssigner = new Assigner(); 117 136 BestPointInitializer bestPositionInitializer = new BestPointInitializer(); 137 Placeholder topologyInitializerPlaceholder = new Placeholder(); 138 NeighborUpdater neighborUpdater = new NeighborUpdater(); 118 139 Placeholder analyzerPlaceholder = new Placeholder(); 119 140 UniformSubScopesProcessor uniformSubScopeProcessor = new UniformSubScopesProcessor(); 120 ParticleUpdater particleUpdater = new ParticleUpdater(); 141 Placeholder particleUpdaterPlaceholder = new Placeholder(); 142 Placeholder topologyUpdaterPlaceholder = new Placeholder(); 143 UniformSubScopesProcessor uniformSubscopesProcessor2 = new UniformSubScopesProcessor(); 144 NeighborUpdater neighborUpdater2 = new NeighborUpdater(); 121 145 Placeholder evaluatorPlaceholder2 = new Placeholder(); 122 146 SwarmUpdater swarmUpdater = new SwarmUpdater(); … … 149 173 bestPersonalQualityAssigner.RightSideParameter.ActualName = "Quality"; 150 174 151 bestPositionInitializer.Successor = analyzerPlaceholder; 175 bestPositionInitializer.Successor = topologyInitializerPlaceholder; 176 177 topologyInitializerPlaceholder.Name = "(TopologyInitializer)"; 178 topologyInitializerPlaceholder.OperatorParameter.ActualName = "TopologyInitializer"; 179 topologyInitializerPlaceholder.Successor = neighborUpdater; 180 181 neighborUpdater.Successor = analyzerPlaceholder; 152 182 153 183 analyzerPlaceholder.Name = "(Analyzer)"; … … 155 185 analyzerPlaceholder.Successor = uniformSubScopeProcessor; 156 186 157 uniformSubScopeProcessor.Operator = particleUpdater; 158 uniformSubScopeProcessor.Successor = analyzerPlaceholder2; 159 160 particleUpdater.Successor = evaluatorPlaceholder2; 187 uniformSubScopeProcessor.Operator = particleUpdaterPlaceholder; 188 uniformSubScopeProcessor.Successor = topologyUpdaterPlaceholder; 189 190 particleUpdaterPlaceholder.Name = "(ParticleUpdater)"; 191 particleUpdaterPlaceholder.OperatorParameter.ActualName = "ParticleUpdater"; 192 particleUpdaterPlaceholder.Successor = evaluatorPlaceholder2; 161 193 162 194 evaluatorPlaceholder2.Name = "(Evaluator)"; 163 195 evaluatorPlaceholder2.OperatorParameter.ActualName = "Evaluator"; 164 evaluatorPlaceholder2.Successor = swarmUpdater; 196 197 topologyUpdaterPlaceholder.Name = "(TopologyUpdater)"; 198 topologyUpdaterPlaceholder.OperatorParameter.ActualName = "TopologyUpdater"; 199 topologyUpdaterPlaceholder.Successor = neighborUpdater2; 200 201 neighborUpdater2.Successor = uniformSubscopesProcessor2; 202 203 uniformSubscopesProcessor2.Operator = swarmUpdater; 204 uniformSubscopesProcessor2.Successor = analyzerPlaceholder2; 165 205 166 206 analyzerPlaceholder2.Name = "(Analyzer)"; … … 226 266 227 267 #region Helpers 268 private void InitializeParticleUpdaters() { 269 } 270 228 271 private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) { 229 272 } -
branches/PSO/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/ParticleUpdater.cs
r5034 r5209 31 31 32 32 [StorableClass] 33 public class ParticleUpdater : SingleSuccessorOperator {33 public abstract class ParticleUpdater : SingleSuccessorOperator, IParticleUpdater { 34 34 35 35 #region Parameter properties … … 45 45 public LookupParameter<RealVector> PersonalBestPointParameter { 46 46 get { return (LookupParameter<RealVector>)Parameters["PersonalBestPoint"]; } 47 } 48 public LookupParameter<RealVector> BestNeighborPointParameter { 49 get { return (LookupParameter<RealVector>)Parameters["BestNeighborPoint"]; } 47 50 } 48 51 public LookupParameter<RealVector> BestPointParameter { … … 84 87 get { return BestPointParameter.ActualValue; } 85 88 } 89 public RealVector BestNeighborPoint { 90 get { return BestNeighborPointParameter.ActualValue; } 91 } 86 92 public DoubleMatrix Bounds { 87 93 get { return BoundsParameter.ActualValue; } … … 101 107 #endregion 102 108 109 public override bool CanChangeName { 110 get { return false; } 111 } 112 103 113 #region Construction & Cloning 104 114 … … 116 126 Parameters.Add(new LookupParameter<RealVector>("PersonalBestPoint", "Particle's personal best position")); 117 127 Parameters.Add(new LookupParameter<RealVector>("BestPoint", "Global best position")); 128 Parameters.Add(new LookupParameter<RealVector>("BestNeighborPoint", "Best neighboring position")); 118 129 Parameters.Add(new LookupParameter<DoubleMatrix>("Bounds", "The lower and upper bounds for each dimension of the position vector for the current problem.")); 119 130 Parameters.Add(new LookupParameter<DoubleMatrix>("VelocityBounds", "Upper and lower bounds for the particle's velocity vector.")); … … 123 134 } 124 135 125 public override IDeepCloneable Clone(Cloner cloner) {126 return new ParticleUpdater(this, cloner);127 }128 129 136 #endregion 130 137 131 public override IOperation Apply() {132 RealVector velocity = new RealVector(Velocity.Length);133 RealVector position = new RealVector(Point.Length);134 double r_p = Random.NextDouble();135 double r_g = Random.NextDouble();136 for (int i = 0; i < velocity.Length; i++) {137 velocity[i] =138 Velocity[i] * Omega +139 (PersonalBestPoint[i] - Point[i]) * Phi_P * r_p +140 (BestPoint[i] - Point[i]) * Phi_G * r_g;141 }142 BoundsChecker.Apply(velocity, VelocityBounds);143 for (int i = 0; i < velocity.Length; i++) {144 position[i] = Point[i] + velocity[i];145 }146 BoundsChecker.Apply(position, Bounds);147 Point = position;148 Velocity = velocity;149 150 return base.Apply();151 }152 153 public override bool CanChangeName {154 get { return false; }155 }156 138 } 157 139 } -
branches/PSO/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/TotallyConnectedParticleUpdater.cs
r5208 r5209 22 22 using HeuristicLab.Common; 23 23 using HeuristicLab.Core; 24 using HeuristicLab.Data;25 24 using HeuristicLab.Encodings.RealVectorEncoding; 26 using HeuristicLab.Operators;27 using HeuristicLab.Parameters;28 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 26 … … 31 28 32 29 [StorableClass] 33 public class ParticleUpdater : SingleSuccessorOperator { 34 35 #region Parameter properties 36 public LookupParameter<IRandom> RandomParameter { 37 get { return (LookupParameter<IRandom>)Parameters["Random"]; } 38 } 39 public LookupParameter<RealVector> PointParameter { 40 get { return (LookupParameter<RealVector>)Parameters["Point"]; } 41 } 42 public LookupParameter<RealVector> VelocityParameter { 43 get { return (LookupParameter<RealVector>)Parameters["Velocity"]; } 44 } 45 public LookupParameter<RealVector> PersonalBestPointParameter { 46 get { return (LookupParameter<RealVector>)Parameters["PersonalBestPoint"]; } 47 } 48 public LookupParameter<RealVector> BestPointParameter { 49 get { return (LookupParameter<RealVector>)Parameters["BestPoint"]; } 50 } 51 public LookupParameter<DoubleMatrix> BoundsParameter { 52 get { return (LookupParameter<DoubleMatrix>)Parameters["Bounds"]; } 53 } 54 public LookupParameter<DoubleMatrix> VelocityBoundsParameter { 55 get { return (LookupParameter<DoubleMatrix>)Parameters["VelocityBounds"]; } 56 } 57 public LookupParameter<DoubleValue> OmegaParameter { 58 get { return (LookupParameter<DoubleValue>)Parameters["Omega"]; } 59 } 60 public LookupParameter<DoubleValue> Phi_PParameter { 61 get { return (LookupParameter<DoubleValue>)Parameters["Phi_P"]; } 62 } 63 public LookupParameter<DoubleValue> Phi_GParameter { 64 get { return (LookupParameter<DoubleValue>)Parameters["Phi_G"]; } 65 } 66 #endregion 67 68 #region Parameter Values 69 public IRandom Random { 70 get { return RandomParameter.ActualValue; } 71 } 72 public RealVector Point { 73 get { return PointParameter.ActualValue; } 74 set { PointParameter.ActualValue = value; } 75 } 76 public RealVector Velocity { 77 get { return VelocityParameter.ActualValue; } 78 set { VelocityParameter.ActualValue = value; } 79 } 80 public RealVector PersonalBestPoint { 81 get { return PersonalBestPointParameter.ActualValue; } 82 } 83 public RealVector BestPoint { 84 get { return BestPointParameter.ActualValue; } 85 } 86 public DoubleMatrix Bounds { 87 get { return BoundsParameter.ActualValue; } 88 } 89 public DoubleMatrix VelocityBounds { 90 get { return VelocityBoundsParameter.ActualValue; } 91 } 92 public double Omega { 93 get { return OmegaParameter.ActualValue.Value; } 94 } 95 public double Phi_P { 96 get { return Phi_PParameter.ActualValue.Value; } 97 } 98 public double Phi_G { 99 get { return Phi_GParameter.ActualValue.Value; } 100 } 101 #endregion 30 public class TotallyConnectedParticleUpdater : ParticleUpdater { 102 31 103 32 #region Construction & Cloning 104 33 105 34 [StorableConstructor] 106 protected ParticleUpdater(bool deserializing) : base(deserializing) { } 107 protected ParticleUpdater(ParticleUpdater original, Cloner cloner) 108 : base(original, cloner) { 109 } 110 111 public ParticleUpdater() 112 : base() { 113 Parameters.Add(new LookupParameter<IRandom>("Random", "Random number generator.")); 114 Parameters.Add(new LookupParameter<RealVector>("Point", "Particle's current position")); 115 Parameters.Add(new LookupParameter<RealVector>("Velocity", "Particle's current velocity.")); 116 Parameters.Add(new LookupParameter<RealVector>("PersonalBestPoint", "Particle's personal best position")); 117 Parameters.Add(new LookupParameter<RealVector>("BestPoint", "Global best position")); 118 Parameters.Add(new LookupParameter<DoubleMatrix>("Bounds", "The lower and upper bounds for each dimension of the position vector for the current problem.")); 119 Parameters.Add(new LookupParameter<DoubleMatrix>("VelocityBounds", "Upper and lower bounds for the particle's velocity vector.")); 120 Parameters.Add(new LookupParameter<DoubleValue>("Omega", "The weight for the particle's velocity vector.")); 121 Parameters.Add(new LookupParameter<DoubleValue>("Phi_P", "The weight for the particle's personal best position.")); 122 Parameters.Add(new LookupParameter<DoubleValue>("Phi_G", "The weight for the global best position.")); 123 } 35 protected TotallyConnectedParticleUpdater(bool deserializing) : base(deserializing) { } 36 protected TotallyConnectedParticleUpdater(ParticleUpdater original, Cloner cloner) : base(original, cloner) { } 37 public TotallyConnectedParticleUpdater() : base() { } 124 38 125 39 public override IDeepCloneable Clone(Cloner cloner) { 126 return new ParticleUpdater(this, cloner);40 return new TotallyConnectedParticleUpdater(this, cloner); 127 41 } 128 42 … … 150 64 return base.Apply(); 151 65 } 152 153 public override bool CanChangeName {154 get { return false; }155 }156 66 } 157 67 }
Note: See TracChangeset
for help on using the changeset viewer.