[3348] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[15583] | 3 | * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[3348] | 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
[15091] | 23 | using System.Collections.Generic;
|
---|
[3348] | 24 | using System.Linq;
|
---|
[4068] | 25 | using HeuristicLab.Analysis;
|
---|
[3376] | 26 | using HeuristicLab.Common;
|
---|
[3348] | 27 | using HeuristicLab.Core;
|
---|
| 28 | using HeuristicLab.Data;
|
---|
[4068] | 29 | using HeuristicLab.Operators;
|
---|
[3348] | 30 | using HeuristicLab.Optimization;
|
---|
| 31 | using HeuristicLab.Optimization.Operators;
|
---|
| 32 | using HeuristicLab.Parameters;
|
---|
| 33 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
[5209] | 34 | using HeuristicLab.PluginInfrastructure;
|
---|
[3368] | 35 | using HeuristicLab.Random;
|
---|
[3348] | 36 |
|
---|
| 37 | namespace HeuristicLab.Algorithms.ParticleSwarmOptimization {
|
---|
[15102] | 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.")]
|
---|
[12504] | 39 | [Creatable(CreatableAttribute.Categories.PopulationBasedAlgorithms, Priority = 300)]
|
---|
[3348] | 40 | [StorableClass]
|
---|
[5809] | 41 | public sealed class ParticleSwarmOptimization : HeuristicOptimizationEngineAlgorithm, IStorableContent {
|
---|
[3348] | 42 | #region Parameter Properties
|
---|
[5410] | 43 | public IValueParameter<IntValue> SeedParameter {
|
---|
| 44 | get { return (IValueParameter<IntValue>)Parameters["Seed"]; }
|
---|
[3348] | 45 | }
|
---|
[5410] | 46 | public IValueParameter<BoolValue> SetSeedRandomlyParameter {
|
---|
| 47 | get { return (IValueParameter<BoolValue>)Parameters["SetSeedRandomly"]; }
|
---|
[3348] | 48 | }
|
---|
[5410] | 49 | public IValueParameter<IntValue> SwarmSizeParameter {
|
---|
| 50 | get { return (IValueParameter<IntValue>)Parameters["SwarmSize"]; }
|
---|
[3348] | 51 | }
|
---|
[5410] | 52 | public IValueParameter<IntValue> MaxIterationsParameter {
|
---|
| 53 | get { return (IValueParameter<IntValue>)Parameters["MaxIterations"]; }
|
---|
[3348] | 54 | }
|
---|
[5560] | 55 | public IValueParameter<DoubleValue> InertiaParameter {
|
---|
| 56 | get { return (IValueParameter<DoubleValue>)Parameters["Inertia"]; }
|
---|
[3348] | 57 | }
|
---|
[5560] | 58 | public IValueParameter<DoubleValue> PersonalBestAttractionParameter {
|
---|
| 59 | get { return (IValueParameter<DoubleValue>)Parameters["PersonalBestAttraction"]; }
|
---|
[5033] | 60 | }
|
---|
[5568] | 61 | public IValueParameter<DoubleValue> NeighborBestAttractionParameter {
|
---|
| 62 | get { return (IValueParameter<DoubleValue>)Parameters["NeighborBestAttraction"]; }
|
---|
[5033] | 63 | }
|
---|
[5410] | 64 | public IValueParameter<MultiAnalyzer> AnalyzerParameter {
|
---|
| 65 | get { return (IValueParameter<MultiAnalyzer>)Parameters["Analyzer"]; }
|
---|
[3682] | 66 | }
|
---|
[8121] | 67 | public IConstrainedValueParameter<IParticleCreator> ParticleCreatorParameter {
|
---|
| 68 | get { return (IConstrainedValueParameter<IParticleCreator>)Parameters["ParticleCreator"]; }
|
---|
[5033] | 69 | }
|
---|
[8121] | 70 | public IConstrainedValueParameter<IParticleUpdater> ParticleUpdaterParameter {
|
---|
| 71 | get { return (IConstrainedValueParameter<IParticleUpdater>)Parameters["ParticleUpdater"]; }
|
---|
[5209] | 72 | }
|
---|
[8121] | 73 | public IConstrainedValueParameter<ITopologyInitializer> TopologyInitializerParameter {
|
---|
| 74 | get { return (IConstrainedValueParameter<ITopologyInitializer>)Parameters["TopologyInitializer"]; }
|
---|
[5209] | 75 | }
|
---|
[8121] | 76 | public IConstrainedValueParameter<ITopologyUpdater> TopologyUpdaterParameter {
|
---|
| 77 | get { return (IConstrainedValueParameter<ITopologyUpdater>)Parameters["TopologyUpdater"]; }
|
---|
[5209] | 78 | }
|
---|
[8121] | 79 | public IConstrainedValueParameter<IDiscreteDoubleValueModifier> InertiaUpdaterParameter {
|
---|
| 80 | get { return (IConstrainedValueParameter<IDiscreteDoubleValueModifier>)Parameters["InertiaUpdater"]; }
|
---|
[5225] | 81 | }
|
---|
[8121] | 82 | public IConstrainedValueParameter<ISwarmUpdater> SwarmUpdaterParameter {
|
---|
| 83 | get { return (IConstrainedValueParameter<ISwarmUpdater>)Parameters["SwarmUpdater"]; }
|
---|
[5568] | 84 |
|
---|
| 85 | }
|
---|
[3348] | 86 | #endregion
|
---|
| 87 |
|
---|
| 88 | #region Properties
|
---|
[5316] | 89 |
|
---|
| 90 | public string Filename { get; set; }
|
---|
| 91 |
|
---|
[3719] | 92 | [Storable]
|
---|
[3682] | 93 | private BestAverageWorstQualityAnalyzer qualityAnalyzer;
|
---|
[5342] | 94 |
|
---|
[5560] | 95 | [Storable]
|
---|
| 96 | private SolutionsCreator solutionsCreator;
|
---|
| 97 |
|
---|
| 98 | [Storable]
|
---|
| 99 | private ParticleSwarmOptimizationMainLoop mainLoop;
|
---|
[7172] | 100 |
|
---|
[6476] | 101 | public override Type ProblemType {
|
---|
| 102 | get { return typeof(ISingleObjectiveHeuristicOptimizationProblem); }
|
---|
[5342] | 103 | }
|
---|
[6476] | 104 | public new ISingleObjectiveHeuristicOptimizationProblem Problem {
|
---|
| 105 | get { return (ISingleObjectiveHeuristicOptimizationProblem)base.Problem; }
|
---|
| 106 | set { base.Problem = value; }
|
---|
[5342] | 107 | }
|
---|
[6476] | 108 | public IntValue Seed {
|
---|
| 109 | get { return SeedParameter.Value; }
|
---|
| 110 | set { SeedParameter.Value = value; }
|
---|
| 111 | }
|
---|
| 112 | public BoolValue SetSeedRandomly {
|
---|
| 113 | get { return SetSeedRandomlyParameter.Value; }
|
---|
| 114 | set { SetSeedRandomlyParameter.Value = value; }
|
---|
| 115 | }
|
---|
| 116 | public IntValue SwarmSize {
|
---|
| 117 | get { return SwarmSizeParameter.Value; }
|
---|
| 118 | set { SwarmSizeParameter.Value = value; }
|
---|
| 119 | }
|
---|
| 120 | public IntValue MaxIterations {
|
---|
| 121 | get { return MaxIterationsParameter.Value; }
|
---|
| 122 | set { MaxIterationsParameter.Value = value; }
|
---|
| 123 | }
|
---|
| 124 | public DoubleValue Inertia {
|
---|
| 125 | get { return InertiaParameter.Value; }
|
---|
| 126 | set { InertiaParameter.Value = value; }
|
---|
| 127 | }
|
---|
| 128 | public DoubleValue PersonalBestAttraction {
|
---|
| 129 | get { return PersonalBestAttractionParameter.Value; }
|
---|
| 130 | set { PersonalBestAttractionParameter.Value = value; }
|
---|
| 131 | }
|
---|
| 132 | public DoubleValue NeighborBestAttraction {
|
---|
| 133 | get { return NeighborBestAttractionParameter.Value; }
|
---|
| 134 | set { NeighborBestAttractionParameter.Value = value; }
|
---|
| 135 | }
|
---|
| 136 | public MultiAnalyzer Analyzer {
|
---|
| 137 | get { return AnalyzerParameter.Value; }
|
---|
| 138 | set { AnalyzerParameter.Value = value; }
|
---|
| 139 | }
|
---|
[5560] | 140 | public IParticleCreator ParticleCreator {
|
---|
| 141 | get { return ParticleCreatorParameter.Value; }
|
---|
| 142 | set { ParticleCreatorParameter.Value = value; }
|
---|
| 143 | }
|
---|
[5342] | 144 | public IParticleUpdater ParticleUpdater {
|
---|
| 145 | get { return ParticleUpdaterParameter.Value; }
|
---|
| 146 | set { ParticleUpdaterParameter.Value = value; }
|
---|
| 147 | }
|
---|
[6476] | 148 | public ITopologyInitializer TopologyInitializer {
|
---|
| 149 | get { return TopologyInitializerParameter.Value; }
|
---|
| 150 | set { TopologyInitializerParameter.Value = value; }
|
---|
| 151 | }
|
---|
| 152 | public ITopologyUpdater TopologyUpdater {
|
---|
| 153 | get { return TopologyUpdaterParameter.Value; }
|
---|
| 154 | set { TopologyUpdaterParameter.Value = value; }
|
---|
| 155 | }
|
---|
| 156 | public IDiscreteDoubleValueModifier InertiaUpdater {
|
---|
| 157 | get { return InertiaUpdaterParameter.Value; }
|
---|
| 158 | set { InertiaUpdaterParameter.Value = value; }
|
---|
| 159 | }
|
---|
| 160 | public ISwarmUpdater SwarmUpdater {
|
---|
| 161 | get { return SwarmUpdaterParameter.Value; }
|
---|
| 162 | set { SwarmUpdaterParameter.Value = value; }
|
---|
| 163 | }
|
---|
[3348] | 164 | #endregion
|
---|
| 165 |
|
---|
[5033] | 166 | [StorableConstructor]
|
---|
[5435] | 167 | private ParticleSwarmOptimization(bool deserializing) : base(deserializing) { }
|
---|
| 168 | private ParticleSwarmOptimization(ParticleSwarmOptimization original, Cloner cloner)
|
---|
[5033] | 169 | : base(original, cloner) {
|
---|
| 170 | qualityAnalyzer = cloner.Clone(original.qualityAnalyzer);
|
---|
[5560] | 171 | solutionsCreator = cloner.Clone(original.solutionsCreator);
|
---|
[5561] | 172 | mainLoop = cloner.Clone(original.mainLoop);
|
---|
[5342] | 173 | Initialize();
|
---|
[5033] | 174 | }
|
---|
[3348] | 175 | public ParticleSwarmOptimization()
|
---|
| 176 | : base() {
|
---|
| 177 | Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
|
---|
| 178 | Parameters.Add(new ValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
|
---|
[15181] | 179 | Parameters.Add(new ValueParameter<IntValue>("SwarmSize", "Size of the particle swarm.", new IntValue(40)));
|
---|
[3348] | 180 | Parameters.Add(new ValueParameter<IntValue>("MaxIterations", "Maximal number of iterations.", new IntValue(1000)));
|
---|
[3682] | 181 | Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze each generation.", new MultiAnalyzer()));
|
---|
[15181] | 182 | Parameters.Add(new ValueParameter<DoubleValue>("Inertia", "Inertia weight on a particle's movement (omega).", new DoubleValue(0.721)));
|
---|
[15214] | 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)));
|
---|
[5844] | 185 | Parameters.Add(new ConstrainedValueParameter<IParticleCreator>("ParticleCreator", "Operator that creates a new particle."));
|
---|
[5560] | 186 | Parameters.Add(new ConstrainedValueParameter<IParticleUpdater>("ParticleUpdater", "Operator that updates a particle."));
|
---|
| 187 | Parameters.Add(new OptionalConstrainedValueParameter<ITopologyInitializer>("TopologyInitializer", "Creates neighborhood description vectors."));
|
---|
| 188 | Parameters.Add(new OptionalConstrainedValueParameter<ITopologyUpdater>("TopologyUpdater", "Updates the neighborhood description vectors."));
|
---|
| 189 | Parameters.Add(new OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier>("InertiaUpdater", "Updates the omega parameter."));
|
---|
[5568] | 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"));
|
---|
[5033] | 191 |
|
---|
[3348] | 192 | RandomCreator randomCreator = new RandomCreator();
|
---|
[5033] | 193 | VariableCreator variableCreator = new VariableCreator();
|
---|
[5866] | 194 | Assigner currentInertiaAssigner = new Assigner();
|
---|
[5560] | 195 | solutionsCreator = new SolutionsCreator();
|
---|
[5643] | 196 | SubScopesCounter subScopesCounter = new SubScopesCounter();
|
---|
[5209] | 197 | Placeholder topologyInitializerPlaceholder = new Placeholder();
|
---|
[5560] | 198 | mainLoop = new ParticleSwarmOptimizationMainLoop();
|
---|
[3348] | 199 |
|
---|
[5033] | 200 | OperatorGraph.InitialOperator = randomCreator;
|
---|
[3682] | 201 |
|
---|
[5033] | 202 | randomCreator.SetSeedRandomlyParameter.Value = null;
|
---|
[3348] | 203 | randomCreator.SeedParameter.Value = null;
|
---|
[5033] | 204 | randomCreator.Successor = variableCreator;
|
---|
[4068] | 205 |
|
---|
[5935] | 206 | variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Iterations", new IntValue(0)));
|
---|
[5866] | 207 | variableCreator.Successor = currentInertiaAssigner;
|
---|
[4068] | 208 |
|
---|
[5866] | 209 | currentInertiaAssigner.Name = "CurrentInertia := Inertia";
|
---|
| 210 | currentInertiaAssigner.LeftSideParameter.ActualName = "CurrentInertia";
|
---|
| 211 | currentInertiaAssigner.RightSideParameter.ActualName = "Inertia";
|
---|
| 212 | currentInertiaAssigner.Successor = solutionsCreator;
|
---|
[5645] | 213 |
|
---|
[5033] | 214 | solutionsCreator.NumberOfSolutionsParameter.ActualName = "SwarmSize";
|
---|
[5568] | 215 | ParameterizeSolutionsCreator();
|
---|
[5643] | 216 | solutionsCreator.Successor = subScopesCounter;
|
---|
[4068] | 217 |
|
---|
[5643] | 218 | subScopesCounter.Name = "Initialize EvaluatedSolutions";
|
---|
| 219 | subScopesCounter.ValueParameter.ActualName = "EvaluatedSolutions";
|
---|
| 220 | subScopesCounter.Successor = topologyInitializerPlaceholder;
|
---|
| 221 |
|
---|
[5209] | 222 | topologyInitializerPlaceholder.Name = "(TopologyInitializer)";
|
---|
| 223 | topologyInitializerPlaceholder.OperatorParameter.ActualName = "TopologyInitializer";
|
---|
[5568] | 224 | topologyInitializerPlaceholder.Successor = mainLoop;
|
---|
[5209] | 225 |
|
---|
[5560] | 226 | mainLoop.AnalyzerParameter.ActualName = AnalyzerParameter.Name;
|
---|
[5645] | 227 | mainLoop.InertiaParameter.ActualName = "CurrentInertia";
|
---|
[5560] | 228 | mainLoop.MaxIterationsParameter.ActualName = MaxIterationsParameter.Name;
|
---|
[5568] | 229 | mainLoop.NeighborBestAttractionParameter.ActualName = NeighborBestAttractionParameter.Name;
|
---|
[5560] | 230 | mainLoop.InertiaUpdaterParameter.ActualName = InertiaUpdaterParameter.Name;
|
---|
| 231 | mainLoop.ParticleUpdaterParameter.ActualName = ParticleUpdaterParameter.Name;
|
---|
| 232 | mainLoop.PersonalBestAttractionParameter.ActualName = PersonalBestAttractionParameter.Name;
|
---|
| 233 | mainLoop.RandomParameter.ActualName = randomCreator.RandomParameter.ActualName;
|
---|
[5568] | 234 | mainLoop.SwarmSizeParameter.ActualName = SwarmSizeParameter.Name;
|
---|
| 235 | mainLoop.TopologyUpdaterParameter.ActualName = TopologyUpdaterParameter.Name;
|
---|
[5560] | 236 | mainLoop.RandomParameter.ActualName = randomCreator.RandomParameter.ActualName;
|
---|
| 237 | mainLoop.ResultsParameter.ActualName = "Results";
|
---|
[3682] | 238 |
|
---|
[3719] | 239 | InitializeAnalyzers();
|
---|
[5560] | 240 | InitializeParticleCreator();
|
---|
[5561] | 241 | InitializeSwarmUpdater();
|
---|
[5568] | 242 | ParameterizeSolutionsCreator();
|
---|
[3719] | 243 | UpdateAnalyzers();
|
---|
[5560] | 244 | UpdateInertiaUpdater();
|
---|
| 245 | InitInertiaUpdater();
|
---|
[5410] | 246 | UpdateTopologyInitializer();
|
---|
[5342] | 247 | Initialize();
|
---|
[5568] | 248 | ParameterizeMainLoop();
|
---|
[3348] | 249 | }
|
---|
| 250 |
|
---|
[5410] | 251 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 252 | return new ParticleSwarmOptimization(this, cloner);
|
---|
[5342] | 253 | }
|
---|
| 254 |
|
---|
[5435] | 255 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 256 | private void AfterDeserialization() {
|
---|
| 257 | Initialize();
|
---|
| 258 | }
|
---|
| 259 |
|
---|
[5410] | 260 | #region Events
|
---|
| 261 | protected override void OnProblemChanged() {
|
---|
| 262 | UpdateAnalyzers();
|
---|
| 263 | ParameterizeAnalyzers();
|
---|
[15091] | 264 | UpdateParticleUpdaterParameter();
|
---|
[5560] | 265 | UpdateTopologyParameters();
|
---|
| 266 | InitializeParticleCreator();
|
---|
[5561] | 267 | InitializeSwarmUpdater();
|
---|
[5568] | 268 | ParameterizeSolutionsCreator();
|
---|
[5410] | 269 | base.OnProblemChanged();
|
---|
[5342] | 270 | }
|
---|
| 271 |
|
---|
| 272 | void TopologyInitializerParameter_ValueChanged(object sender, EventArgs e) {
|
---|
[5410] | 273 | this.UpdateTopologyParameters();
|
---|
| 274 | }
|
---|
| 275 | #endregion
|
---|
[5342] | 276 |
|
---|
[5410] | 277 | #region Helpers
|
---|
| 278 | private void Initialize() {
|
---|
| 279 | TopologyInitializerParameter.ValueChanged += new EventHandler(TopologyInitializerParameter_ValueChanged);
|
---|
| 280 | }
|
---|
| 281 |
|
---|
[5560] | 282 | private void InitializeParticleCreator() {
|
---|
[15091] | 283 | ParticleCreatorParameter.ValidValues.Clear();
|
---|
[5560] | 284 | if (Problem != null) {
|
---|
| 285 | IParticleCreator oldParticleCreator = ParticleCreator;
|
---|
[7512] | 286 | IParticleCreator defaultParticleCreator = Problem.Operators.OfType<IParticleCreator>().FirstOrDefault();
|
---|
[15091] | 287 | foreach (var creator in Problem.Operators.OfType<IParticleCreator>().OrderBy(x => x.Name)) {
|
---|
| 288 | ParticleCreatorParameter.ValidValues.Add(creator);
|
---|
[5560] | 289 | }
|
---|
| 290 | if (oldParticleCreator != null) {
|
---|
[15091] | 291 | var creator = ParticleCreatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldParticleCreator.GetType());
|
---|
[5560] | 292 | if (creator != null) ParticleCreator = creator;
|
---|
[7512] | 293 | else oldParticleCreator = null;
|
---|
[5568] | 294 | }
|
---|
[7512] | 295 | if (oldParticleCreator == null && defaultParticleCreator != null)
|
---|
| 296 | ParticleCreator = defaultParticleCreator;
|
---|
[5560] | 297 | }
|
---|
[3348] | 298 | }
|
---|
| 299 |
|
---|
[5410] | 300 | private void InitializeAnalyzers() {
|
---|
| 301 | qualityAnalyzer = new BestAverageWorstQualityAnalyzer();
|
---|
[5581] | 302 | qualityAnalyzer.ResultsParameter.ActualName = "Results";
|
---|
[5410] | 303 | ParameterizeAnalyzers();
|
---|
[3348] | 304 | }
|
---|
| 305 |
|
---|
[5410] | 306 | private void ParameterizeAnalyzers() {
|
---|
[5312] | 307 | if (Problem != null) {
|
---|
[5410] | 308 | qualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
|
---|
| 309 | qualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
| 310 | qualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
|
---|
[5312] | 311 | }
|
---|
[3348] | 312 | }
|
---|
| 313 |
|
---|
[5410] | 314 | private void UpdateAnalyzers() {
|
---|
| 315 | Analyzer.Operators.Clear();
|
---|
| 316 | if (Problem != null) {
|
---|
| 317 | foreach (IAnalyzer analyzer in Problem.Operators.OfType<IAnalyzer>())
|
---|
[7172] | 318 | Analyzer.Operators.Add(analyzer, analyzer.EnabledByDefault);
|
---|
[5410] | 319 | }
|
---|
[7172] | 320 | Analyzer.Operators.Add(qualityAnalyzer, qualityAnalyzer.EnabledByDefault);
|
---|
[3348] | 321 | }
|
---|
[3415] | 322 |
|
---|
[5560] | 323 | private void InitInertiaUpdater() {
|
---|
| 324 | foreach (IDiscreteDoubleValueModifier updater in InertiaUpdaterParameter.ValidValues) {
|
---|
[5311] | 325 | updater.EndIndexParameter.ActualName = MaxIterationsParameter.Name;
|
---|
[5935] | 326 | updater.EndIndexParameter.Hidden = true;
|
---|
[5311] | 327 | updater.StartIndexParameter.Value = new IntValue(0);
|
---|
[5893] | 328 | updater.StartIndexParameter.Hidden = true;
|
---|
[5935] | 329 | updater.IndexParameter.ActualName = "Iterations";
|
---|
[5645] | 330 | updater.ValueParameter.ActualName = "CurrentInertia";
|
---|
[15091] | 331 | updater.StartValueParameter.ActualName = InertiaParameter.Name;
|
---|
| 332 | updater.EndValueParameter.Value = new DoubleValue(0.70);
|
---|
[5311] | 333 | }
|
---|
| 334 | }
|
---|
| 335 |
|
---|
[5560] | 336 | private void UpdateInertiaUpdater() {
|
---|
| 337 | IDiscreteDoubleValueModifier oldInertiaUpdater = InertiaUpdater;
|
---|
| 338 | InertiaUpdaterParameter.ValidValues.Clear();
|
---|
[5311] | 339 | foreach (IDiscreteDoubleValueModifier updater in ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>().OrderBy(x => x.Name)) {
|
---|
[5560] | 340 | InertiaUpdaterParameter.ValidValues.Add(updater);
|
---|
[5311] | 341 | }
|
---|
[5560] | 342 | if (oldInertiaUpdater != null) {
|
---|
| 343 | IDiscreteDoubleValueModifier updater = InertiaUpdaterParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldInertiaUpdater.GetType());
|
---|
| 344 | if (updater != null) InertiaUpdaterParameter.Value = updater;
|
---|
[5311] | 345 | }
|
---|
| 346 | }
|
---|
| 347 |
|
---|
[5410] | 348 | private void UpdateTopologyInitializer() {
|
---|
[15091] | 349 | var oldTopologyInitializer = TopologyInitializer;
|
---|
[5410] | 350 | TopologyInitializerParameter.ValidValues.Clear();
|
---|
| 351 | foreach (ITopologyInitializer topologyInitializer in ApplicationManager.Manager.GetInstances<ITopologyInitializer>().OrderBy(x => x.Name)) {
|
---|
| 352 | TopologyInitializerParameter.ValidValues.Add(topologyInitializer);
|
---|
[3348] | 353 | }
|
---|
[15091] | 354 |
|
---|
[5410] | 355 | if (oldTopologyInitializer != null && TopologyInitializerParameter.ValidValues.Any(x => x.GetType() == oldTopologyInitializer.GetType()))
|
---|
| 356 | TopologyInitializer = TopologyInitializerParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldTopologyInitializer.GetType());
|
---|
| 357 | UpdateTopologyParameters();
|
---|
[3348] | 358 | }
|
---|
[3415] | 359 |
|
---|
[6476] | 360 | private void ParameterizeTopologyUpdaters() {
|
---|
[15091] | 361 | foreach (var updater in TopologyUpdaterParameter.ValidValues.OfType<MultiPSOTopologyUpdater>()) {
|
---|
| 362 | updater.CurrentIterationParameter.ActualName = "Iterations";
|
---|
[6476] | 363 | }
|
---|
| 364 | }
|
---|
| 365 |
|
---|
[15091] | 366 | private void UpdateParticleUpdaterParameter() {
|
---|
| 367 | var oldParticleUpdater = ParticleUpdater;
|
---|
| 368 | ParticleUpdaterParameter.ValidValues.Clear();
|
---|
[5560] | 369 | if (Problem != null) {
|
---|
[15091] | 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 |
|
---|
[5560] | 375 | if (oldParticleUpdater != null) {
|
---|
[15091] | 376 | var newParticleUpdater = ParticleUpdaterParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldParticleUpdater.GetType());
|
---|
[5560] | 377 | if (newParticleUpdater != null) ParticleUpdater = newParticleUpdater;
|
---|
[7512] | 378 | else oldParticleUpdater = null;
|
---|
[5560] | 379 | }
|
---|
[7512] | 380 | if (oldParticleUpdater == null && defaultParticleUpdater != null)
|
---|
| 381 | ParticleUpdater = defaultParticleUpdater;
|
---|
[3682] | 382 | }
|
---|
| 383 | }
|
---|
| 384 |
|
---|
[15091] | 385 | private void UpdateTopologyParameters() {
|
---|
| 386 | ITopologyUpdater oldTopologyUpdater = TopologyUpdater;
|
---|
[5410] | 387 | TopologyUpdaterParameter.ValidValues.Clear();
|
---|
[15091] | 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 | }
|
---|
[5410] | 400 | }
|
---|
[5560] | 401 |
|
---|
| 402 | private void ParameterizeSolutionsCreator() {
|
---|
| 403 | if (Problem != null) {
|
---|
| 404 | solutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
|
---|
[7781] | 405 | if (ParticleCreatorParameter.Value != null)
|
---|
| 406 | solutionsCreator.SolutionCreatorParameter.ActualName = ParticleCreatorParameter.Name;
|
---|
| 407 | else
|
---|
| 408 | solutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name;
|
---|
[5560] | 409 | }
|
---|
| 410 | }
|
---|
| 411 |
|
---|
| 412 | private void ParameterizeMainLoop() {
|
---|
[5568] | 413 | if (Problem != null) {
|
---|
[5561] | 414 | mainLoop.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
|
---|
| 415 | }
|
---|
[5560] | 416 | }
|
---|
[5561] | 417 |
|
---|
| 418 | private void InitializeSwarmUpdater() {
|
---|
| 419 | if (Problem != null) {
|
---|
| 420 | ISwarmUpdater updater = Problem.Operators.OfType<ISwarmUpdater>().FirstOrDefault();
|
---|
[5568] | 421 | SwarmUpdaterParameter.ValidValues.Clear();
|
---|
[5868] | 422 | if (updater != null) {
|
---|
| 423 | SwarmUpdaterParameter.ValidValues.Add(updater);
|
---|
| 424 | SwarmUpdaterParameter.Value = updater;
|
---|
| 425 | }
|
---|
[5561] | 426 | }
|
---|
| 427 | }
|
---|
[3348] | 428 | #endregion
|
---|
[5410] | 429 |
|
---|
[3348] | 430 | }
|
---|
| 431 | }
|
---|