Changeset 15973 for branches/2522_RefactorPluginInfrastructure/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/ParticleSwarmOptimization.cs
- Timestamp:
- 06/28/18 11:13:37 (7 years ago)
- Location:
- branches/2522_RefactorPluginInfrastructure
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2522_RefactorPluginInfrastructure
- Property svn:ignore
-
old new 24 24 protoc.exe 25 25 obj 26 .vs
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/2522_RefactorPluginInfrastructure/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/ParticleSwarmOptimization.cs
r13173 r15973 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 21 21 22 22 using System; 23 using System.Collections.Generic; 23 24 using System.Linq; 24 25 using HeuristicLab.Analysis; … … 35 36 36 37 namespace HeuristicLab.Algorithms.ParticleSwarmOptimization { 37 [Item("Particle Swarm Optimization (PSO)", "A particle swarm optimization algorithm based on the description in Pedersen, M.E.H. (2010). PhD thesis. University of Southampton.")]38 [Item("Particle Swarm Optimization (PSO)", "A particle swarm optimization algorithm based on Standard PSO (SPSO) as described in Clerc, M. (2012). Standard particle swarm optimisation.")] 38 39 [Creatable(CreatableAttribute.Categories.PopulationBasedAlgorithms, Priority = 300)] 39 40 [StorableClass] … … 176 177 Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0))); 177 178 Parameters.Add(new ValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true))); 178 Parameters.Add(new ValueParameter<IntValue>("SwarmSize", "Size of the particle swarm.", new IntValue( 10)));179 Parameters.Add(new ValueParameter<IntValue>("SwarmSize", "Size of the particle swarm.", new IntValue(40))); 179 180 Parameters.Add(new ValueParameter<IntValue>("MaxIterations", "Maximal number of iterations.", new IntValue(1000))); 180 181 Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze each generation.", new MultiAnalyzer())); 181 Parameters.Add(new ValueParameter<DoubleValue>("Inertia", "Inertia weight on a particle's movement (omega).", new DoubleValue( 1)));182 Parameters.Add(new ValueParameter<DoubleValue>("PersonalBestAttraction", "Weight for particle's pull towards its personal best soution (phi_p).", new DoubleValue( -0.01)));183 Parameters.Add(new ValueParameter<DoubleValue>("NeighborBestAttraction", "Weight for pull towards the neighborhood best solution or global best solution in case of a totally connected topology (phi_g).", new DoubleValue( 3.7)));182 Parameters.Add(new ValueParameter<DoubleValue>("Inertia", "Inertia weight on a particle's movement (omega).", new DoubleValue(0.721))); 183 Parameters.Add(new ValueParameter<DoubleValue>("PersonalBestAttraction", "Weight for particle's pull towards its personal best soution (phi_p).", new DoubleValue(1.193))); 184 Parameters.Add(new ValueParameter<DoubleValue>("NeighborBestAttraction", "Weight for pull towards the neighborhood best solution or global best solution in case of a totally connected topology (phi_g).", new DoubleValue(1.193))); 184 185 Parameters.Add(new ConstrainedValueParameter<IParticleCreator>("ParticleCreator", "Operator that creates a new particle.")); 185 186 Parameters.Add(new ConstrainedValueParameter<IParticleUpdater>("ParticleUpdater", "Operator that updates a particle.")); … … 188 189 Parameters.Add(new OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier>("InertiaUpdater", "Updates the omega parameter.")); 189 190 Parameters.Add(new ConstrainedValueParameter<ISwarmUpdater>("SwarmUpdater", "Encoding-specific parameter which is provided by the problem. May provide additional encoding-specific parameters, such as velocity bounds for real valued problems")); 190 ParticleUpdaterParameter.Hidden = true;191 191 192 192 RandomCreator randomCreator = new RandomCreator(); … … 262 262 UpdateAnalyzers(); 263 263 ParameterizeAnalyzers(); 264 UpdateParticleUpdaterParameter(); 264 265 UpdateTopologyParameters(); 265 266 InitializeParticleCreator(); … … 280 281 281 282 private void InitializeParticleCreator() { 283 ParticleCreatorParameter.ValidValues.Clear(); 282 284 if (Problem != null) { 283 285 IParticleCreator oldParticleCreator = ParticleCreator; 284 286 IParticleCreator defaultParticleCreator = Problem.Operators.OfType<IParticleCreator>().FirstOrDefault(); 285 ParticleCreatorParameter.ValidValues.Clear(); 286 foreach (IParticleCreator Creator in Problem.Operators.OfType<IParticleCreator>().OrderBy(x => x.Name)) { 287 ParticleCreatorParameter.ValidValues.Add(Creator); 287 foreach (var creator in Problem.Operators.OfType<IParticleCreator>().OrderBy(x => x.Name)) { 288 ParticleCreatorParameter.ValidValues.Add(creator); 288 289 } 289 290 if (oldParticleCreator != null) { 290 IParticleCreator creator = ParticleCreatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldParticleCreator.GetType());291 var creator = ParticleCreatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldParticleCreator.GetType()); 291 292 if (creator != null) ParticleCreator = creator; 292 293 else oldParticleCreator = null; … … 328 329 updater.IndexParameter.ActualName = "Iterations"; 329 330 updater.ValueParameter.ActualName = "CurrentInertia"; 330 updater.StartValueParameter. Value = new DoubleValue(1);331 updater.EndValueParameter.Value = new DoubleValue( 1E-10);331 updater.StartValueParameter.ActualName = InertiaParameter.Name; 332 updater.EndValueParameter.Value = new DoubleValue(0.70); 332 333 } 333 334 } … … 346 347 347 348 private void UpdateTopologyInitializer() { 348 ITopologyInitializer oldTopologyInitializer = TopologyInitializer;349 var oldTopologyInitializer = TopologyInitializer; 349 350 TopologyInitializerParameter.ValidValues.Clear(); 350 351 foreach (ITopologyInitializer topologyInitializer in ApplicationManager.Manager.GetInstances<ITopologyInitializer>().OrderBy(x => x.Name)) { 351 352 TopologyInitializerParameter.ValidValues.Add(topologyInitializer); 352 353 } 354 353 355 if (oldTopologyInitializer != null && TopologyInitializerParameter.ValidValues.Any(x => x.GetType() == oldTopologyInitializer.GetType())) 354 356 TopologyInitializer = TopologyInitializerParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldTopologyInitializer.GetType()); … … 357 359 358 360 private void ParameterizeTopologyUpdaters() { 359 foreach (var updater in TopologyUpdaterParameter.ValidValues) { 360 var multiPsoUpdater = updater as MultiPSOTopologyUpdater; 361 if (multiPsoUpdater != null) { 362 multiPsoUpdater.CurrentIterationParameter.ActualName = "Iterations"; 363 } 364 } 365 } 366 367 private void UpdateTopologyParameters() { 368 ITopologyUpdater oldTopologyUpdater = TopologyUpdater; 369 IParticleUpdater oldParticleUpdater = ParticleUpdater; 370 ClearTopologyParameters(); 371 if (Problem != null) { 372 IParticleUpdater defaultParticleUpdater = null; 373 if (TopologyInitializer != null) { 374 foreach (ITopologyUpdater topologyUpdater in ApplicationManager.Manager.GetInstances<ITopologyUpdater>()) 375 TopologyUpdaterParameter.ValidValues.Add(topologyUpdater); 376 defaultParticleUpdater = Problem.Operators.OfType<ILocalParticleUpdater>().FirstOrDefault(); 377 foreach (IParticleUpdater particleUpdater in Problem.Operators.OfType<ILocalParticleUpdater>().OrderBy(x => x.Name)) 378 ParticleUpdaterParameter.ValidValues.Add(particleUpdater); 379 } else { 380 defaultParticleUpdater = Problem.Operators.OfType<IGlobalParticleUpdater>().FirstOrDefault(); 381 foreach (IParticleUpdater particleUpdater in Problem.Operators.OfType<IGlobalParticleUpdater>().OrderBy(x => x.Name)) 382 ParticleUpdaterParameter.ValidValues.Add(particleUpdater); 383 } 384 if (oldTopologyUpdater != null) { 385 ITopologyUpdater newTopologyUpdater = TopologyUpdaterParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldParticleUpdater.GetType()); 386 if (newTopologyUpdater != null) TopologyUpdater = newTopologyUpdater; 387 } 361 foreach (var updater in TopologyUpdaterParameter.ValidValues.OfType<MultiPSOTopologyUpdater>()) { 362 updater.CurrentIterationParameter.ActualName = "Iterations"; 363 } 364 } 365 366 private void UpdateParticleUpdaterParameter() { 367 var oldParticleUpdater = ParticleUpdater; 368 ParticleUpdaterParameter.ValidValues.Clear(); 369 if (Problem != null) { 370 var defaultParticleUpdater = Problem.Operators.OfType<IParticleUpdater>().FirstOrDefault(); 371 372 foreach (var particleUpdater in Problem.Operators.OfType<IParticleUpdater>().OrderBy(x => x.Name)) 373 ParticleUpdaterParameter.ValidValues.Add(particleUpdater); 374 388 375 if (oldParticleUpdater != null) { 389 IParticleUpdater newParticleUpdater = ParticleUpdaterParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldParticleUpdater.GetType());376 var newParticleUpdater = ParticleUpdaterParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldParticleUpdater.GetType()); 390 377 if (newParticleUpdater != null) ParticleUpdater = newParticleUpdater; 391 378 else oldParticleUpdater = null; … … 393 380 if (oldParticleUpdater == null && defaultParticleUpdater != null) 394 381 ParticleUpdater = defaultParticleUpdater; 395 396 ParameterizeTopologyUpdaters(); 397 } 398 } 399 400 private void ClearTopologyParameters() { 382 } 383 } 384 385 private void UpdateTopologyParameters() { 386 ITopologyUpdater oldTopologyUpdater = TopologyUpdater; 401 387 TopologyUpdaterParameter.ValidValues.Clear(); 402 ParticleUpdaterParameter.ValidValues.Clear(); 388 if (Problem != null) { 389 if (TopologyInitializerParameter.Value != null) { 390 foreach (ITopologyUpdater topologyUpdater in ApplicationManager.Manager.GetInstances<ITopologyUpdater>()) 391 TopologyUpdaterParameter.ValidValues.Add(topologyUpdater); 392 393 if (oldTopologyUpdater != null) { 394 ITopologyUpdater newTopologyUpdater = TopologyUpdaterParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldTopologyUpdater.GetType()); 395 if (newTopologyUpdater != null) TopologyUpdater = newTopologyUpdater; 396 } 397 ParameterizeTopologyUpdaters(); 398 } 399 } 403 400 } 404 401
Note: See TracChangeset
for help on using the changeset viewer.