Changeset 5410 for branches/PSO
- Timestamp:
- 02/03/11 12:23:40 (14 years ago)
- Location:
- branches/PSO/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3
- Files:
-
- 2 deleted
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PSO/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/BestPointInitializer.cs
r5316 r5410 36 36 37 37 #region Parameter properties 38 public ScopeTreeLookupParameter<DoubleValue> QualityParameter {39 get { return ( ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }38 public IScopeTreeLookupParameter<DoubleValue> QualityParameter { 39 get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; } 40 40 } 41 public LookupParameter<DoubleValue> BestQualityParameter {42 get { return ( LookupParameter<DoubleValue>)Parameters["BestQuality"]; }41 public ILookupParameter<DoubleValue> BestQualityParameter { 42 get { return (ILookupParameter<DoubleValue>)Parameters["BestQuality"]; } 43 43 } 44 public ScopeTreeLookupParameter<RealVector> PointParameter {45 get { return ( ScopeTreeLookupParameter<RealVector>)Parameters["Point"]; }44 public IScopeTreeLookupParameter<RealVector> PointParameter { 45 get { return (IScopeTreeLookupParameter<RealVector>)Parameters["Point"]; } 46 46 } 47 public LookupParameter<RealVector> BestPointParameter {48 get { return ( LookupParameter<RealVector>)Parameters["BestPoint"]; }47 public ILookupParameter<RealVector> BestPointParameter { 48 get { return (ILookupParameter<RealVector>)Parameters["BestPoint"]; } 49 49 } 50 public ValueLookupParameter<BoolValue> MaximizationParameter {51 get { return ( ValueLookupParameter<BoolValue>)Parameters["Maximization"]; }50 public IValueLookupParameter<BoolValue> MaximizationParameter { 51 get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; } 52 52 } 53 53 #endregion -
branches/PSO/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/HeuristicLab.Algorithms.ParticleSwarmOptimization-3.3.csproj
r5342 r5410 117 117 <Compile Include="RandomTopologyInitializer.cs" /> 118 118 <Compile Include="VonNeumannTopologyInitializer.cs" /> 119 <Compile Include="EmptyTopologyInitializer.cs" />120 119 <Compile Include="RingTopologyInitializer.cs" /> 121 120 <Compile Include="ITopologyUpdater.cs" /> 122 <Compile Include="IdentityTopologyUpdater.cs" />123 121 <Compile Include="NeighborUpdater.cs" /> 124 122 <Compile Include="TopologyInitializer.cs" /> -
branches/PSO/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/IParticleUpdater.cs
r5342 r5410 27 27 namespace HeuristicLab.Algorithms.ParticleSwarmOptimization { 28 28 29 public interface IParticleUpdater : I NamedItem{29 public interface IParticleUpdater : IOperator { 30 30 31 LookupParameter<RealVector> VelocityParameter { get; }32 LookupParameter<DoubleMatrix> VelocityBoundsParameter { get; }31 ILookupParameter<RealVector> VelocityParameter { get; } 32 ILookupParameter<DoubleMatrix> VelocityBoundsParameter { get; } 33 33 34 LookupParameter<RealVector> PointParameter { get; }35 LookupParameter<DoubleMatrix> BoundsParameter { get; }34 ILookupParameter<RealVector> PointParameter { get; } 35 ILookupParameter<DoubleMatrix> BoundsParameter { get; } 36 36 37 LookupParameter<RealVector> PersonalBestPointParameter { get; }38 LookupParameter<RealVector> BestNeighborPointParameter { get; }39 LookupParameter<RealVector> BestPointParameter { get; }37 ILookupParameter<RealVector> PersonalBestPointParameter { get; } 38 ILookupParameter<RealVector> BestNeighborPointParameter { get; } 39 ILookupParameter<RealVector> BestPointParameter { get; } 40 40 41 LookupParameter<DoubleValue> OmegaParameter { get; }42 LookupParameter<DoubleValue> Phi_PParameter { get; }43 LookupParameter<DoubleValue> Phi_GParameter { get; }41 ILookupParameter<DoubleValue> OmegaParameter { get; } 42 ILookupParameter<DoubleValue> Phi_PParameter { get; } 43 ILookupParameter<DoubleValue> Phi_GParameter { get; } 44 44 } 45 45 -
branches/PSO/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/ITopologyInitializer.cs
r5209 r5410 26 26 namespace HeuristicLab.Algorithms.ParticleSwarmOptimization { 27 27 28 public interface ITopologyInitializer : I Item{29 ScopeTreeLookupParameter<IntegerVector> NeighborsParameter { get; }30 LookupParameter<IntValue> SwarmSizeParameter { get; }28 public interface ITopologyInitializer : IOperator { 29 IScopeTreeLookupParameter<IntegerVector> NeighborsParameter { get; } 30 ILookupParameter<IntValue> SwarmSizeParameter { get; } 31 31 } 32 32 -
branches/PSO/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/ITopologyUpdater.cs
r5209 r5410 26 26 27 27 public interface ITopologyUpdater : IItem { 28 ScopeTreeLookupParameter<IntegerVector> NeighborsParameter { get; }28 IScopeTreeLookupParameter<IntegerVector> NeighborsParameter { get; } 29 29 } 30 30 -
branches/PSO/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/MultiPSOTopologyUpdater.cs
r5339 r5410 16 16 public class MultiPSOTopologyUpdater : SingleSuccessorOperator, ITopologyUpdater, ITopologyInitializer { 17 17 #region Parameters 18 public LookupParameter<IRandom> RandomParameter {19 get { return ( LookupParameter<IRandom>)Parameters["Random"]; }18 public ILookupParameter<IRandom> RandomParameter { 19 get { return (ILookupParameter<IRandom>)Parameters["Random"]; } 20 20 } 21 public ValueLookupParameter<IntValue> NrOfConnectionsParameter {22 get { return ( ValueLookupParameter<IntValue>)Parameters["NrOfConnections"]; }21 public IValueLookupParameter<IntValue> NrOfConnectionsParameter { 22 get { return (IValueLookupParameter<IntValue>)Parameters["NrOfConnections"]; } 23 23 } 24 public LookupParameter<IntValue> SwarmSizeParameter {25 get { return ( LookupParameter<IntValue>)Parameters["SwarmSize"]; }24 public ILookupParameter<IntValue> SwarmSizeParameter { 25 get { return (ILookupParameter<IntValue>)Parameters["SwarmSize"]; } 26 26 } 27 public ScopeTreeLookupParameter<IntegerVector> NeighborsParameter {28 get { return ( ScopeTreeLookupParameter<IntegerVector>)Parameters["Neighbors"]; }27 public IScopeTreeLookupParameter<IntegerVector> NeighborsParameter { 28 get { return (IScopeTreeLookupParameter<IntegerVector>)Parameters["Neighbors"]; } 29 29 } 30 public LookupParameter<IntValue> CurrentIterationParameter {31 get { return ( LookupParameter<IntValue>)Parameters["CurrentIteration"]; }30 public ILookupParameter<IntValue> CurrentIterationParameter { 31 get { return (ILookupParameter<IntValue>)Parameters["CurrentIteration"]; } 32 32 } 33 public ValueLookupParameter<IntValue> RegroupingPeriodParameter {34 get { return ( ValueLookupParameter<IntValue>)Parameters["RegroupingPeriod"]; }33 public IValueLookupParameter<IntValue> RegroupingPeriodParameter { 34 get { return (IValueLookupParameter<IntValue>)Parameters["RegroupingPeriod"]; } 35 35 } 36 36 #endregion -
branches/PSO/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/NeighborUpdater.cs
r5316 r5410 36 36 37 37 #region Parameters 38 public ScopeTreeLookupParameter<RealVector> PointsParameter {39 get { return ( ScopeTreeLookupParameter<RealVector>)Parameters["Point"]; }38 public IScopeTreeLookupParameter<RealVector> PointsParameter { 39 get { return (IScopeTreeLookupParameter<RealVector>)Parameters["Point"]; } 40 40 } 41 public ScopeTreeLookupParameter<IntegerVector> NeighborsParameter {42 get { return ( ScopeTreeLookupParameter<IntegerVector>)Parameters["Neighbors"]; }41 public IScopeTreeLookupParameter<IntegerVector> NeighborsParameter { 42 get { return (IScopeTreeLookupParameter<IntegerVector>)Parameters["Neighbors"]; } 43 43 } 44 public ScopeTreeLookupParameter<RealVector> BestNeighborPointParameter {45 get { return ( ScopeTreeLookupParameter<RealVector>)Parameters["BestNeighborPoint"]; }44 public IScopeTreeLookupParameter<RealVector> BestNeighborPointParameter { 45 get { return (IScopeTreeLookupParameter<RealVector>)Parameters["BestNeighborPoint"]; } 46 46 } 47 public ScopeTreeLookupParameter<DoubleValue> QualityParameter {48 get { return ( ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }47 public IScopeTreeLookupParameter<DoubleValue> QualityParameter { 48 get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; } 49 49 } 50 public LookupParameter<BoolValue> MaximizationParameter {51 get { return ( LookupParameter<BoolValue>)Parameters["Maximization"]; }50 public ILookupParameter<BoolValue> MaximizationParameter { 51 get { return (ILookupParameter<BoolValue>)Parameters["Maximization"]; } 52 52 } 53 53 #endregion -
branches/PSO/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/NeighborhoodParticleUpdater.cs
r5342 r5410 49 49 double r_p = Random.NextDouble(); 50 50 double r_g = Random.NextDouble(); 51 double omega = Omega.Value; 52 double phi_p = Phi_P.Value; 53 double phi_g = Phi_G.Value; 51 54 for (int i = 0; i < velocity.Length; i++) { 52 55 velocity[i] = 53 Velocity[i] * Omega +54 (PersonalBestPoint[i] - Point[i]) * Phi_P* r_p +55 (BestNeighborPoint[i] - Point[i]) * Phi_G* r_g;56 Velocity[i] * omega + 57 (PersonalBestPoint[i] - Point[i]) * phi_p * r_p + 58 (BestNeighborPoint[i] - Point[i]) * phi_g * r_g; 56 59 } 57 60 BoundsChecker.Apply(velocity, VelocityBounds); -
branches/PSO/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/ParticleSwarmOptimization.cs
r5342 r5410 34 34 using HeuristicLab.PluginInfrastructure; 35 35 using HeuristicLab.Random; 36 using System.Collections.Generic; 36 37 37 38 namespace HeuristicLab.Algorithms.ParticleSwarmOptimization { … … 65 66 66 67 #region Parameter Properties 67 public ValueParameter<IntValue> SeedParameter {68 get { return ( ValueParameter<IntValue>)Parameters["Seed"]; }69 } 70 public ValueParameter<BoolValue> SetSeedRandomlyParameter {71 get { return ( ValueParameter<BoolValue>)Parameters["SetSeedRandomly"]; }72 } 73 public ValueParameter<IntValue> SwarmSizeParameter {74 get { return ( ValueParameter<IntValue>)Parameters["SwarmSize"]; }75 } 76 public ValueParameter<IntValue> MaxIterationsParameter {77 get { return ( ValueParameter<IntValue>)Parameters["MaxIterations"]; }78 } 79 public ValueParameter<DoubleValue> OmegaParameter {80 get { return ( ValueParameter<DoubleValue>)Parameters["Omega"]; }81 } 82 public ValueParameter<DoubleValue> Phi_PParameter {83 get { return ( ValueParameter<DoubleValue>)Parameters["Phi_P"]; }84 } 85 public ValueParameter<DoubleValue> Phi_GParameter {86 get { return ( ValueParameter<DoubleValue>)Parameters["Phi_G"]; }87 } 88 public ValueParameter<MultiAnalyzer> AnalyzerParameter {89 get { return ( ValueParameter<MultiAnalyzer>)Parameters["Analyzer"]; }90 } 91 public ValueLookupParameter<DoubleMatrix> VelocityBoundsParameter {92 get { return ( ValueLookupParameter<DoubleMatrix>)Parameters["VelocityBounds"]; }68 public IValueParameter<IntValue> SeedParameter { 69 get { return (IValueParameter<IntValue>)Parameters["Seed"]; } 70 } 71 public IValueParameter<BoolValue> SetSeedRandomlyParameter { 72 get { return (IValueParameter<BoolValue>)Parameters["SetSeedRandomly"]; } 73 } 74 public IValueParameter<IntValue> SwarmSizeParameter { 75 get { return (IValueParameter<IntValue>)Parameters["SwarmSize"]; } 76 } 77 public IValueParameter<IntValue> MaxIterationsParameter { 78 get { return (IValueParameter<IntValue>)Parameters["MaxIterations"]; } 79 } 80 public IValueParameter<DoubleValue> OmegaParameter { 81 get { return (IValueParameter<DoubleValue>)Parameters["Omega"]; } 82 } 83 public IValueParameter<DoubleValue> Phi_PParameter { 84 get { return (IValueParameter<DoubleValue>)Parameters["Phi_P"]; } 85 } 86 public IValueParameter<DoubleValue> Phi_GParameter { 87 get { return (IValueParameter<DoubleValue>)Parameters["Phi_G"]; } 88 } 89 public IValueParameter<MultiAnalyzer> AnalyzerParameter { 90 get { return (IValueParameter<MultiAnalyzer>)Parameters["Analyzer"]; } 91 } 92 public IValueLookupParameter<DoubleMatrix> VelocityBoundsParameter { 93 get { return (IValueLookupParameter<DoubleMatrix>)Parameters["VelocityBounds"]; } 93 94 } 94 95 public ConstrainedValueParameter<IParticleUpdater> ParticleUpdaterParameter { 95 96 get { return (ConstrainedValueParameter<IParticleUpdater>)Parameters["ParticleUpdater"]; } 96 97 } 97 public ConstrainedValueParameter<ITopologyInitializer> TopologyInitializerParameter {98 get { return ( ConstrainedValueParameter<ITopologyInitializer>)Parameters["TopologyInitializer"]; }99 } 100 public ConstrainedValueParameter<ITopologyUpdater> TopologyUpdaterParameter {101 get { return ( ConstrainedValueParameter<ITopologyUpdater>)Parameters["TopologyUpdater"]; }98 public OptionalConstrainedValueParameter<ITopologyInitializer> TopologyInitializerParameter { 99 get { return (OptionalConstrainedValueParameter<ITopologyInitializer>)Parameters["TopologyInitializer"]; } 100 } 101 public OptionalConstrainedValueParameter<ITopologyUpdater> TopologyUpdaterParameter { 102 get { return (OptionalConstrainedValueParameter<ITopologyUpdater>)Parameters["TopologyUpdater"]; } 102 103 } 103 104 public OptionalConstrainedValueParameter<IDiscreteDoubleMatrixModifier> VelocityBoundsUpdaterParameter { … … 134 135 135 136 [StorableConstructor] 136 protected ParticleSwarmOptimization(bool deserializing) : base(deserializing) {137 Initialize();137 protected ParticleSwarmOptimization(bool deserializing) 138 : base(deserializing) { 138 139 } 139 140 protected ParticleSwarmOptimization(ParticleSwarmOptimization original, Cloner cloner) 140 141 : base(original, cloner) { 141 142 qualityAnalyzer = cloner.Clone(original.qualityAnalyzer); 143 Initialize(); 144 } 145 146 [StorableHook(HookType.AfterDeserialization)] 147 private void AfterDeserialization() { 142 148 Initialize(); 143 149 } … … 154 160 Parameters.Add(new ValueParameter<DoubleValue>("Phi_G", "Weight for global best position.", new DoubleValue(3.7))); 155 161 Parameters.Add(new ValueLookupParameter<DoubleMatrix>("VelocityBounds", "Maximum Velocity in every dimension", new DoubleMatrix(new double[,] { { -1, 1 } }))); 156 Parameters.Add(new ConstrainedValueParameter<IParticleUpdater>("ParticleUpdater", "Operator that calculates new position and velocity of a particle", 157 new ItemSet<IParticleUpdater>(ApplicationManager.Manager.GetInstances<IParticleUpdater>()))); 158 Parameters.Add(new ConstrainedValueParameter<ITopologyInitializer>("TopologyInitializer", "Creates neighborhood description vectors", 159 new ItemSet<ITopologyInitializer>(ApplicationManager.Manager.GetInstances<ITopologyInitializer>()))); 160 Parameters.Add(new ConstrainedValueParameter<ITopologyUpdater>("TopologyUpdater", "Updates the neighborhood description vectors", 161 new ItemSet<ITopologyUpdater>(ApplicationManager.Manager.GetInstances<ITopologyUpdater>()))); 162 Parameters.Add(new ConstrainedValueParameter<IParticleUpdater>("ParticleUpdater", "Operator that calculates new position and velocity of a particle")); 163 Parameters.Add(new OptionalConstrainedValueParameter<ITopologyInitializer>("TopologyInitializer", "Creates neighborhood description vectors")); 164 Parameters.Add(new OptionalConstrainedValueParameter<ITopologyUpdater>("TopologyUpdater", "Updates the neighborhood description vectors")); 162 165 Parameters.Add(new OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier>("OmegaUpdater", "Updates the omega parameter")); 163 166 Parameters.Add(new OptionalConstrainedValueParameter<IDiscreteDoubleMatrixModifier>("VelocityBoundsUpdater", "Adjusts the velocity bounds.")); 164 167 ParticleUpdaterParameter.ActualValue = ParticleUpdaterParameter.ValidValues.SingleOrDefault(v => v.GetType() == typeof(TotallyConnectedParticleUpdater)); 165 TopologyInitializerParameter.ActualValue = TopologyInitializerParameter.ValidValues.SingleOrDefault(v => v.GetType() == typeof(EmptyTopologyInitializer));166 168 167 169 RandomCreator randomCreator = new RandomCreator(); … … 274 276 UpdateOmegaUpdater(); 275 277 InitOmegaUpdater(); 278 UpdateTopologyInitializer(); 276 279 Initialize(); 277 }278 279 private void Initialize() {280 TopologyInitializerParameter.ValueChanged += new EventHandler(TopologyInitializerParameter_ValueChanged);281 ParticleUpdaterParameter.ValueChanged += new EventHandler(ParticleUpdaterParameter_ValueChanged);282 TopologyUpdaterParameter.ValueChanged += new EventHandler(TopologyUpdaterParameter_ValueChanged);283 }284 285 void TopologyUpdaterParameter_ValueChanged(object sender, EventArgs e) {286 if (TopologyInitializer is EmptyTopologyInitializer) { // no topology updater allowed287 if (TopologyUpdater != null) {288 TopologyUpdater = null;289 }290 }291 }292 293 void ParticleUpdaterParameter_ValueChanged(object sender, EventArgs e) {294 if (TopologyInitializer is EmptyTopologyInitializer) { // only global particle updater allowed295 if (!(ParticleUpdater is IGlobalParticleUpdater)) {296 ParticleUpdater = ParticleUpdaterParameter.ValidValues.Where(x => x is IGlobalParticleUpdater).First();297 }298 } else { // only local particle updater allowed299 if (!(ParticleUpdater is ILocalParticleUpdater)) {300 ParticleUpdater = ParticleUpdaterParameter.ValidValues.Where(x => x is ILocalParticleUpdater).First();301 }302 }303 }304 305 void TopologyInitializerParameter_ValueChanged(object sender, EventArgs e) {306 if (TopologyInitializer is EmptyTopologyInitializer) { // only allow global particle update and no topology update307 if (ParticleUpdaterParameter.ValidValues.Count > 0) {308 if (!(ParticleUpdater is IGlobalParticleUpdater)) {309 ParticleUpdater = ParticleUpdaterParameter.ValidValues.Where(x => x is IGlobalParticleUpdater).First();310 }311 }312 if (TopologyUpdaterParameter.ValidValues.Count > 0) {313 if (!(TopologyUpdater != null)) {314 TopologyUpdater = null;315 }316 }317 } else { // only allow local particle update; topology change possible318 if (ParticleUpdaterParameter.ValidValues.Count > 0) {319 if (!(ParticleUpdater is ILocalParticleUpdater)) {320 ParticleUpdater = ParticleUpdaterParameter.ValidValues.Where(x => x is ILocalParticleUpdater).First();321 }322 }323 }324 }325 326 private static void InitializeParticleCreator(CombinedOperator particleCreator) {327 Placeholder positionCreator = new Placeholder();328 Assigner personalBestPositionAssigner = new Assigner();329 UniformRandomRealVectorCreator velocityCreator = new UniformRandomRealVectorCreator();330 331 particleCreator.Name = "Particle Creator";332 particleCreator.OperatorGraph.InitialOperator = positionCreator;333 334 positionCreator.Name = "(SolutionCreator)";335 positionCreator.OperatorParameter.ActualName = "SolutionCreator";336 positionCreator.Successor = personalBestPositionAssigner;337 338 personalBestPositionAssigner.LeftSideParameter.ActualName = "PersonalBestPoint";339 personalBestPositionAssigner.RightSideParameter.ActualName = "Point";340 personalBestPositionAssigner.Successor = velocityCreator;341 342 velocityCreator.LengthParameter.ActualName = "ProblemSize";343 velocityCreator.BoundsParameter.ActualName = "VelocityBounds";344 velocityCreator.RealVectorParameter.ActualName = "Velocity";345 280 } 346 281 … … 369 304 UpdateAnalyzers(); 370 305 ParameterizeAnalyzers(); 371 Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);372 306 base.OnProblemChanged(); 373 307 } 374 308 309 void TopologyInitializerParameter_ValueChanged(object sender, EventArgs e) { 310 this.UpdateTopologyParameters(); 311 } 312 313 void VelocityBoundsUpdaterParameter_ValueChanged(object sender, EventArgs e) { 314 if (VelocityBoundsParameter.Value != null) { 315 foreach (IDiscreteDoubleMatrixModifier matrixOp in VelocityBoundsUpdaterParameter.Value.ScalingOperatorParameter.ValidValues) { 316 matrixOp.ValueParameter.ActualName = VelocityBoundsUpdater.ScaleParameter.Name; 317 matrixOp.StartValueParameter.Value = new DoubleValue(VelocityBoundsUpdater.ScaleParameter.ActualValue.Value); 318 } 319 } 320 } 375 321 #endregion 376 322 377 323 #region Helpers 378 private void InitializeParticleUpdaters() { 379 } 380 381 private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) { 324 private void Initialize() { 325 TopologyInitializerParameter.ValueChanged += new EventHandler(TopologyInitializerParameter_ValueChanged); 326 } 327 328 private static void InitializeParticleCreator(CombinedOperator particleCreator) { 329 Placeholder positionCreator = new Placeholder(); 330 Assigner personalBestPositionAssigner = new Assigner(); 331 UniformRandomRealVectorCreator velocityCreator = new UniformRandomRealVectorCreator(); 332 333 particleCreator.Name = "Particle Creator"; 334 particleCreator.OperatorGraph.InitialOperator = positionCreator; 335 336 positionCreator.Name = "(SolutionCreator)"; 337 positionCreator.OperatorParameter.ActualName = "SolutionCreator"; 338 positionCreator.Successor = personalBestPositionAssigner; 339 340 personalBestPositionAssigner.LeftSideParameter.ActualName = "PersonalBestPoint"; 341 personalBestPositionAssigner.RightSideParameter.ActualName = "Point"; 342 personalBestPositionAssigner.Successor = velocityCreator; 343 344 velocityCreator.LengthParameter.ActualName = "ProblemSize"; 345 velocityCreator.BoundsParameter.ActualName = "VelocityBounds"; 346 velocityCreator.RealVectorParameter.ActualName = "Velocity"; 382 347 } 383 348 … … 385 350 qualityAnalyzer = new BestAverageWorstQualityAnalyzer(); 386 351 ParameterizeAnalyzers(); 352 } 353 354 private void ParameterizeAnalyzers() { 355 if (Problem != null) { 356 qualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name; 357 qualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName; 358 qualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name; 359 } 360 } 361 362 private void UpdateAnalyzers() { 363 Analyzer.Operators.Clear(); 364 if (Problem != null) { 365 foreach (IAnalyzer analyzer in Problem.Operators.OfType<IAnalyzer>()) 366 Analyzer.Operators.Add(analyzer); 367 } 368 Analyzer.Operators.Add(qualityAnalyzer); 387 369 } 388 370 … … 399 381 } 400 382 401 void VelocityBoundsUpdaterParameter_ValueChanged(object sender, EventArgs e) {402 if (VelocityBoundsParameter.Value != null) {403 foreach (IDiscreteDoubleMatrixModifier matrixOp in VelocityBoundsUpdaterParameter.Value.ScalingOperatorParameter.ValidValues) {404 matrixOp.ValueParameter.ActualName = VelocityBoundsUpdater.ScaleParameter.Name;405 matrixOp.StartValueParameter.Value = new DoubleValue(VelocityBoundsUpdater.ScaleParameter.ActualValue.Value);406 }407 }408 }409 410 383 private void InitOmegaUpdater() { 411 384 foreach (IDiscreteDoubleValueModifier updater in OmegaUpdaterParameter.ValidValues) { … … 431 404 } 432 405 433 private void ParameterizeAnalyzers() { 434 if (Problem != null) { 435 qualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name; 436 qualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName; 437 qualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name; 438 } 439 } 440 441 private void UpdateAnalyzers() { 442 Analyzer.Operators.Clear(); 443 if (Problem != null) { 444 foreach (IAnalyzer analyzer in Problem.Operators.OfType<IAnalyzer>()) 445 Analyzer.Operators.Add(analyzer); 446 } 447 Analyzer.Operators.Add(qualityAnalyzer); 448 } 449 406 private void UpdateTopologyInitializer() { 407 ITopologyInitializer oldTopologyInitializer = TopologyInitializer; 408 TopologyInitializerParameter.ValidValues.Clear(); 409 foreach (ITopologyInitializer topologyInitializer in ApplicationManager.Manager.GetInstances<ITopologyInitializer>().OrderBy(x => x.Name)) { 410 TopologyInitializerParameter.ValidValues.Add(topologyInitializer); 411 } 412 if (oldTopologyInitializer != null && TopologyInitializerParameter.ValidValues.Any(x => x.GetType() == oldTopologyInitializer.GetType())) 413 TopologyInitializer = TopologyInitializerParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldTopologyInitializer.GetType()); 414 UpdateTopologyParameters(); 415 } 416 417 private void UpdateTopologyParameters() { 418 ITopologyUpdater oldTopologyUpdater = TopologyUpdater; 419 IParticleUpdater oldParticleUpdater = ParticleUpdater; 420 ClearTopologyParameters(); 421 if (TopologyInitializer != null) { 422 foreach (ITopologyUpdater topologyUpdater in ApplicationManager.Manager.GetInstances<ITopologyUpdater>()) 423 TopologyUpdaterParameter.ValidValues.Add(topologyUpdater); 424 foreach (IParticleUpdater particleUpdater in ApplicationManager.Manager.GetInstances<ILocalParticleUpdater>()) 425 ParticleUpdaterParameter.ValidValues.Add(particleUpdater); 426 } else { 427 foreach (IParticleUpdater particleUpdater in ApplicationManager.Manager.GetInstances<IGlobalParticleUpdater>()) 428 ParticleUpdaterParameter.ValidValues.Add(particleUpdater); 429 } 430 if (oldTopologyUpdater != null) { 431 ITopologyUpdater newTopologyUpdater = TopologyUpdaterParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldParticleUpdater.GetType()); 432 if (newTopologyUpdater != null) TopologyUpdater = newTopologyUpdater; 433 } 434 if (oldParticleUpdater != null) { 435 IParticleUpdater newParticleUpdater = ParticleUpdaterParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldParticleUpdater.GetType()); 436 if (newParticleUpdater != null) ParticleUpdater = newParticleUpdater; 437 } 438 } 439 440 private void ClearTopologyParameters() { 441 TopologyUpdaterParameter.ValidValues.Clear(); 442 ParticleUpdaterParameter.ValidValues.Clear(); 443 } 450 444 #endregion 451 445 452 446 } 453 447 } -
branches/PSO/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/ParticleUpdater.cs
r5209 r5410 34 34 35 35 #region Parameter properties 36 public LookupParameter<IRandom> RandomParameter {37 get { return ( LookupParameter<IRandom>)Parameters["Random"]; }36 public ILookupParameter<IRandom> RandomParameter { 37 get { return (ILookupParameter<IRandom>)Parameters["Random"]; } 38 38 } 39 public LookupParameter<RealVector> PointParameter {40 get { return ( LookupParameter<RealVector>)Parameters["Point"]; }39 public ILookupParameter<RealVector> PointParameter { 40 get { return (ILookupParameter<RealVector>)Parameters["Point"]; } 41 41 } 42 public LookupParameter<RealVector> VelocityParameter {43 get { return ( LookupParameter<RealVector>)Parameters["Velocity"]; }42 public ILookupParameter<RealVector> VelocityParameter { 43 get { return (ILookupParameter<RealVector>)Parameters["Velocity"]; } 44 44 } 45 public LookupParameter<RealVector> PersonalBestPointParameter {46 get { return ( LookupParameter<RealVector>)Parameters["PersonalBestPoint"]; }45 public ILookupParameter<RealVector> PersonalBestPointParameter { 46 get { return (ILookupParameter<RealVector>)Parameters["PersonalBestPoint"]; } 47 47 } 48 public LookupParameter<RealVector> BestNeighborPointParameter {49 get { return ( LookupParameter<RealVector>)Parameters["BestNeighborPoint"]; }48 public ILookupParameter<RealVector> BestNeighborPointParameter { 49 get { return (ILookupParameter<RealVector>)Parameters["BestNeighborPoint"]; } 50 50 } 51 public LookupParameter<RealVector> BestPointParameter {52 get { return ( LookupParameter<RealVector>)Parameters["BestPoint"]; }51 public ILookupParameter<RealVector> BestPointParameter { 52 get { return (ILookupParameter<RealVector>)Parameters["BestPoint"]; } 53 53 } 54 public LookupParameter<DoubleMatrix> BoundsParameter {55 get { return ( LookupParameter<DoubleMatrix>)Parameters["Bounds"]; }54 public ILookupParameter<DoubleMatrix> BoundsParameter { 55 get { return (ILookupParameter<DoubleMatrix>)Parameters["Bounds"]; } 56 56 } 57 public LookupParameter<DoubleMatrix> VelocityBoundsParameter {58 get { return ( LookupParameter<DoubleMatrix>)Parameters["VelocityBounds"]; }57 public ILookupParameter<DoubleMatrix> VelocityBoundsParameter { 58 get { return (ILookupParameter<DoubleMatrix>)Parameters["VelocityBounds"]; } 59 59 } 60 public LookupParameter<DoubleValue> OmegaParameter {61 get { return ( LookupParameter<DoubleValue>)Parameters["Omega"]; }60 public ILookupParameter<DoubleValue> OmegaParameter { 61 get { return (ILookupParameter<DoubleValue>)Parameters["Omega"]; } 62 62 } 63 public LookupParameter<DoubleValue> Phi_PParameter {64 get { return ( LookupParameter<DoubleValue>)Parameters["Phi_P"]; }63 public ILookupParameter<DoubleValue> Phi_PParameter { 64 get { return (ILookupParameter<DoubleValue>)Parameters["Phi_P"]; } 65 65 } 66 public LookupParameter<DoubleValue> Phi_GParameter {67 get { return ( LookupParameter<DoubleValue>)Parameters["Phi_G"]; }66 public ILookupParameter<DoubleValue> Phi_GParameter { 67 get { return (ILookupParameter<DoubleValue>)Parameters["Phi_G"]; } 68 68 } 69 69 #endregion … … 96 96 get { return VelocityBoundsParameter.ActualValue; } 97 97 } 98 public double Omega { 99 get { return OmegaParameter.ActualValue.Value; } 98 99 public DoubleValue Omega { 100 get { return OmegaParameter.ActualValue; } 100 101 } 101 public double Phi_P {102 get { return Phi_PParameter.ActualValue .Value; }102 public DoubleValue Phi_P { 103 get { return Phi_PParameter.ActualValue; } 103 104 } 104 public double Phi_G {105 get { return Phi_GParameter.ActualValue .Value; }105 public DoubleValue Phi_G { 106 get { return Phi_GParameter.ActualValue; } 106 107 } 107 108 #endregion … … 135 136 136 137 #endregion 137 138 138 } 139 139 } -
branches/PSO/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/RandomTopologyInitializer.cs
r5316 r5410 35 35 36 36 #region Parameters 37 public LookupParameter<IRandom> RandomParameter {38 get { return ( LookupParameter<IRandom>)Parameters["Random"]; }37 public ILookupParameter<IRandom> RandomParameter { 38 get { return (ILookupParameter<IRandom>)Parameters["Random"]; } 39 39 } 40 public ValueLookupParameter<IntValue> NrOfConnectionsParameter {41 get { return ( ValueLookupParameter<IntValue>)Parameters["NrOfConnections"]; }40 public IValueLookupParameter<IntValue> NrOfConnectionsParameter { 41 get { return (IValueLookupParameter<IntValue>)Parameters["NrOfConnections"]; } 42 42 } 43 43 #endregion -
branches/PSO/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/SwarmUpdater.cs
r5316 r5410 35 35 36 36 #region Parameter properties 37 public LookupParameter<DoubleValue> QualityParameter {38 get { return ( LookupParameter<DoubleValue>)Parameters["Quality"]; }37 public ILookupParameter<DoubleValue> QualityParameter { 38 get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; } 39 39 } 40 public LookupParameter<DoubleValue> PersonalBestQualityParameter {41 get { return ( LookupParameter<DoubleValue>)Parameters["PersonalBestQuality"]; }40 public ILookupParameter<DoubleValue> PersonalBestQualityParameter { 41 get { return (ILookupParameter<DoubleValue>)Parameters["PersonalBestQuality"]; } 42 42 } 43 public LookupParameter<DoubleValue> BestQualityParameter {44 get { return ( LookupParameter<DoubleValue>)Parameters["BestQuality"]; }43 public ILookupParameter<DoubleValue> BestQualityParameter { 44 get { return (ILookupParameter<DoubleValue>)Parameters["BestQuality"]; } 45 45 } 46 public LookupParameter<RealVector> PointParameter {47 get { return ( LookupParameter<RealVector>)Parameters["Point"]; }46 public ILookupParameter<RealVector> PointParameter { 47 get { return (ILookupParameter<RealVector>)Parameters["Point"]; } 48 48 } 49 public LookupParameter<RealVector> PersonalBestPointParameter {50 get { return ( LookupParameter<RealVector>)Parameters["PersonalBestPoint"]; }49 public ILookupParameter<RealVector> PersonalBestPointParameter { 50 get { return (ILookupParameter<RealVector>)Parameters["PersonalBestPoint"]; } 51 51 } 52 public LookupParameter<RealVector> BestPointParameter {53 get { return ( LookupParameter<RealVector>)Parameters["BestPoint"]; }52 public ILookupParameter<RealVector> BestPointParameter { 53 get { return (ILookupParameter<RealVector>)Parameters["BestPoint"]; } 54 54 } 55 public ValueLookupParameter<BoolValue> MaximizationParameter {56 get { return ( ValueLookupParameter<BoolValue>)Parameters["Maximization"]; }55 public IValueLookupParameter<BoolValue> MaximizationParameter { 56 get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; } 57 57 } 58 58 #endregion -
branches/PSO/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/TopologyInitializer.cs
r5209 r5410 33 33 34 34 #region Parameters 35 public ScopeTreeLookupParameter<IntegerVector> NeighborsParameter {36 get { return ( ScopeTreeLookupParameter<IntegerVector>)Parameters["Neighbors"]; }35 public IScopeTreeLookupParameter<IntegerVector> NeighborsParameter { 36 get { return (IScopeTreeLookupParameter<IntegerVector>)Parameters["Neighbors"]; } 37 37 } 38 public LookupParameter<IntValue> SwarmSizeParameter {39 get { return ( LookupParameter<IntValue>)Parameters["SwarmSize"]; }38 public ILookupParameter<IntValue> SwarmSizeParameter { 39 get { return (ILookupParameter<IntValue>)Parameters["SwarmSize"]; } 40 40 } 41 41 -
branches/PSO/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/TotallyConnectedParticleUpdater.cs
r5342 r5410 45 45 46 46 public override IOperation Apply() { 47 base.Apply(); 47 48 RealVector velocity = new RealVector(Velocity.Length); 48 49 RealVector position = new RealVector(Point.Length); 49 50 double r_p = Random.NextDouble(); 50 51 double r_g = Random.NextDouble(); 52 double omega = Omega.Value; 53 double phi_p = Phi_P.Value; 54 double phi_g = Phi_G.Value; 51 55 for (int i = 0; i < velocity.Length; i++) { 52 56 velocity[i] = 53 Velocity[i] * Omega +54 (PersonalBestPoint[i] - Point[i]) * Phi_P* r_p +55 (BestPoint[i] - Point[i]) * Phi_G* r_g;57 Velocity[i] * omega + 58 (PersonalBestPoint[i] - Point[i]) * phi_p * r_p + 59 (BestPoint[i] - Point[i]) * phi_g * r_g; 56 60 } 57 61 BoundsChecker.Apply(velocity, VelocityBounds);
Note: See TracChangeset
for help on using the changeset viewer.