[3348] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[7259] | 3 | * Copyright (C) 2002-2012 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;
|
---|
| 23 | using System.Linq;
|
---|
[4068] | 24 | using HeuristicLab.Analysis;
|
---|
[3376] | 25 | using HeuristicLab.Common;
|
---|
[3348] | 26 | using HeuristicLab.Core;
|
---|
| 27 | using HeuristicLab.Data;
|
---|
[4068] | 28 | using HeuristicLab.Operators;
|
---|
[3348] | 29 | using HeuristicLab.Optimization;
|
---|
| 30 | using HeuristicLab.Optimization.Operators;
|
---|
| 31 | using HeuristicLab.Parameters;
|
---|
| 32 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
[5209] | 33 | using HeuristicLab.PluginInfrastructure;
|
---|
[3368] | 34 | using HeuristicLab.Random;
|
---|
[3348] | 35 |
|
---|
| 36 | namespace HeuristicLab.Algorithms.ParticleSwarmOptimization {
|
---|
[5209] | 37 | [Item("Particle Swarm Optimization", "A particle swarm optimization algorithm based on the description in Pedersen, M.E.H. (2010). PhD thesis. University of Southampton.")]
|
---|
[3348] | 38 | [Creatable("Algorithms")]
|
---|
| 39 | [StorableClass]
|
---|
[5809] | 40 | public sealed class ParticleSwarmOptimization : HeuristicOptimizationEngineAlgorithm, IStorableContent {
|
---|
[3348] | 41 | #region Parameter Properties
|
---|
[5410] | 42 | public IValueParameter<IntValue> SeedParameter {
|
---|
| 43 | get { return (IValueParameter<IntValue>)Parameters["Seed"]; }
|
---|
[3348] | 44 | }
|
---|
[5410] | 45 | public IValueParameter<BoolValue> SetSeedRandomlyParameter {
|
---|
| 46 | get { return (IValueParameter<BoolValue>)Parameters["SetSeedRandomly"]; }
|
---|
[3348] | 47 | }
|
---|
[5410] | 48 | public IValueParameter<IntValue> SwarmSizeParameter {
|
---|
| 49 | get { return (IValueParameter<IntValue>)Parameters["SwarmSize"]; }
|
---|
[3348] | 50 | }
|
---|
[5410] | 51 | public IValueParameter<IntValue> MaxIterationsParameter {
|
---|
| 52 | get { return (IValueParameter<IntValue>)Parameters["MaxIterations"]; }
|
---|
[3348] | 53 | }
|
---|
[5560] | 54 | public IValueParameter<DoubleValue> InertiaParameter {
|
---|
| 55 | get { return (IValueParameter<DoubleValue>)Parameters["Inertia"]; }
|
---|
[3348] | 56 | }
|
---|
[5560] | 57 | public IValueParameter<DoubleValue> PersonalBestAttractionParameter {
|
---|
| 58 | get { return (IValueParameter<DoubleValue>)Parameters["PersonalBestAttraction"]; }
|
---|
[5033] | 59 | }
|
---|
[5568] | 60 | public IValueParameter<DoubleValue> NeighborBestAttractionParameter {
|
---|
| 61 | get { return (IValueParameter<DoubleValue>)Parameters["NeighborBestAttraction"]; }
|
---|
[5033] | 62 | }
|
---|
[5410] | 63 | public IValueParameter<MultiAnalyzer> AnalyzerParameter {
|
---|
| 64 | get { return (IValueParameter<MultiAnalyzer>)Parameters["Analyzer"]; }
|
---|
[3682] | 65 | }
|
---|
[8206] | 66 | public IConstrainedValueParameter<IParticleCreator> ParticleCreatorParameter {
|
---|
| 67 | get { return (IConstrainedValueParameter<IParticleCreator>)Parameters["ParticleCreator"]; }
|
---|
[5033] | 68 | }
|
---|
[8206] | 69 | public IConstrainedValueParameter<IParticleUpdater> ParticleUpdaterParameter {
|
---|
| 70 | get { return (IConstrainedValueParameter<IParticleUpdater>)Parameters["ParticleUpdater"]; }
|
---|
[5209] | 71 | }
|
---|
[8206] | 72 | public IConstrainedValueParameter<ITopologyInitializer> TopologyInitializerParameter {
|
---|
| 73 | get { return (IConstrainedValueParameter<ITopologyInitializer>)Parameters["TopologyInitializer"]; }
|
---|
[5209] | 74 | }
|
---|
[8206] | 75 | public IConstrainedValueParameter<ITopologyUpdater> TopologyUpdaterParameter {
|
---|
| 76 | get { return (IConstrainedValueParameter<ITopologyUpdater>)Parameters["TopologyUpdater"]; }
|
---|
[5209] | 77 | }
|
---|
[8206] | 78 | public IConstrainedValueParameter<IDiscreteDoubleValueModifier> InertiaUpdaterParameter {
|
---|
| 79 | get { return (IConstrainedValueParameter<IDiscreteDoubleValueModifier>)Parameters["InertiaUpdater"]; }
|
---|
[5225] | 80 | }
|
---|
[8206] | 81 | public IConstrainedValueParameter<ISwarmUpdater> SwarmUpdaterParameter {
|
---|
| 82 | get { return (IConstrainedValueParameter<ISwarmUpdater>)Parameters["SwarmUpdater"]; }
|
---|
[5568] | 83 |
|
---|
| 84 | }
|
---|
[3348] | 85 | #endregion
|
---|
| 86 |
|
---|
| 87 | #region Properties
|
---|
[5316] | 88 |
|
---|
| 89 | public string Filename { get; set; }
|
---|
| 90 |
|
---|
[3719] | 91 | [Storable]
|
---|
[3682] | 92 | private BestAverageWorstQualityAnalyzer qualityAnalyzer;
|
---|
[5342] | 93 |
|
---|
[5560] | 94 | [Storable]
|
---|
| 95 | private SolutionsCreator solutionsCreator;
|
---|
| 96 |
|
---|
| 97 | [Storable]
|
---|
| 98 | private ParticleSwarmOptimizationMainLoop mainLoop;
|
---|
[7172] | 99 |
|
---|
[6476] | 100 | public override Type ProblemType {
|
---|
| 101 | get { return typeof(ISingleObjectiveHeuristicOptimizationProblem); }
|
---|
[5342] | 102 | }
|
---|
[6476] | 103 | public new ISingleObjectiveHeuristicOptimizationProblem Problem {
|
---|
| 104 | get { return (ISingleObjectiveHeuristicOptimizationProblem)base.Problem; }
|
---|
| 105 | set { base.Problem = value; }
|
---|
[5342] | 106 | }
|
---|
[6476] | 107 | public IntValue Seed {
|
---|
| 108 | get { return SeedParameter.Value; }
|
---|
| 109 | set { SeedParameter.Value = value; }
|
---|
| 110 | }
|
---|
| 111 | public BoolValue SetSeedRandomly {
|
---|
| 112 | get { return SetSeedRandomlyParameter.Value; }
|
---|
| 113 | set { SetSeedRandomlyParameter.Value = value; }
|
---|
| 114 | }
|
---|
| 115 | public IntValue SwarmSize {
|
---|
| 116 | get { return SwarmSizeParameter.Value; }
|
---|
| 117 | set { SwarmSizeParameter.Value = value; }
|
---|
| 118 | }
|
---|
| 119 | public IntValue MaxIterations {
|
---|
| 120 | get { return MaxIterationsParameter.Value; }
|
---|
| 121 | set { MaxIterationsParameter.Value = value; }
|
---|
| 122 | }
|
---|
| 123 | public DoubleValue Inertia {
|
---|
| 124 | get { return InertiaParameter.Value; }
|
---|
| 125 | set { InertiaParameter.Value = value; }
|
---|
| 126 | }
|
---|
| 127 | public DoubleValue PersonalBestAttraction {
|
---|
| 128 | get { return PersonalBestAttractionParameter.Value; }
|
---|
| 129 | set { PersonalBestAttractionParameter.Value = value; }
|
---|
| 130 | }
|
---|
| 131 | public DoubleValue NeighborBestAttraction {
|
---|
| 132 | get { return NeighborBestAttractionParameter.Value; }
|
---|
| 133 | set { NeighborBestAttractionParameter.Value = value; }
|
---|
| 134 | }
|
---|
| 135 | public MultiAnalyzer Analyzer {
|
---|
| 136 | get { return AnalyzerParameter.Value; }
|
---|
| 137 | set { AnalyzerParameter.Value = value; }
|
---|
| 138 | }
|
---|
[5560] | 139 | public IParticleCreator ParticleCreator {
|
---|
| 140 | get { return ParticleCreatorParameter.Value; }
|
---|
| 141 | set { ParticleCreatorParameter.Value = value; }
|
---|
| 142 | }
|
---|
[5342] | 143 | public IParticleUpdater ParticleUpdater {
|
---|
| 144 | get { return ParticleUpdaterParameter.Value; }
|
---|
| 145 | set { ParticleUpdaterParameter.Value = value; }
|
---|
| 146 | }
|
---|
[6476] | 147 | public ITopologyInitializer TopologyInitializer {
|
---|
| 148 | get { return TopologyInitializerParameter.Value; }
|
---|
| 149 | set { TopologyInitializerParameter.Value = value; }
|
---|
| 150 | }
|
---|
| 151 | public ITopologyUpdater TopologyUpdater {
|
---|
| 152 | get { return TopologyUpdaterParameter.Value; }
|
---|
| 153 | set { TopologyUpdaterParameter.Value = value; }
|
---|
| 154 | }
|
---|
| 155 | public IDiscreteDoubleValueModifier InertiaUpdater {
|
---|
| 156 | get { return InertiaUpdaterParameter.Value; }
|
---|
| 157 | set { InertiaUpdaterParameter.Value = value; }
|
---|
| 158 | }
|
---|
| 159 | public ISwarmUpdater SwarmUpdater {
|
---|
| 160 | get { return SwarmUpdaterParameter.Value; }
|
---|
| 161 | set { SwarmUpdaterParameter.Value = value; }
|
---|
| 162 | }
|
---|
[3348] | 163 | #endregion
|
---|
| 164 |
|
---|
[5033] | 165 | [StorableConstructor]
|
---|
[5435] | 166 | private ParticleSwarmOptimization(bool deserializing) : base(deserializing) { }
|
---|
| 167 | private ParticleSwarmOptimization(ParticleSwarmOptimization original, Cloner cloner)
|
---|
[5033] | 168 | : base(original, cloner) {
|
---|
| 169 | qualityAnalyzer = cloner.Clone(original.qualityAnalyzer);
|
---|
[5560] | 170 | solutionsCreator = cloner.Clone(original.solutionsCreator);
|
---|
[5561] | 171 | mainLoop = cloner.Clone(original.mainLoop);
|
---|
[5342] | 172 | Initialize();
|
---|
[5033] | 173 | }
|
---|
[3348] | 174 | public ParticleSwarmOptimization()
|
---|
| 175 | : base() {
|
---|
| 176 | Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
|
---|
| 177 | Parameters.Add(new ValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
|
---|
[3724] | 178 | Parameters.Add(new ValueParameter<IntValue>("SwarmSize", "Size of the particle swarm.", new IntValue(10)));
|
---|
[3348] | 179 | Parameters.Add(new ValueParameter<IntValue>("MaxIterations", "Maximal number of iterations.", new IntValue(1000)));
|
---|
[3682] | 180 | Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze each generation.", new MultiAnalyzer()));
|
---|
[5941] | 181 | Parameters.Add(new ValueParameter<DoubleValue>("Inertia", "Inertia weight on a particle's movement (omega).", new DoubleValue(1)));
|
---|
[5560] | 182 | Parameters.Add(new ValueParameter<DoubleValue>("PersonalBestAttraction", "Weight for particle's pull towards its personal best soution (phi_p).", new DoubleValue(-0.01)));
|
---|
[5568] | 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)));
|
---|
[5844] | 184 | Parameters.Add(new ConstrainedValueParameter<IParticleCreator>("ParticleCreator", "Operator that creates a new particle."));
|
---|
[5560] | 185 | Parameters.Add(new ConstrainedValueParameter<IParticleUpdater>("ParticleUpdater", "Operator that updates a particle."));
|
---|
| 186 | Parameters.Add(new OptionalConstrainedValueParameter<ITopologyInitializer>("TopologyInitializer", "Creates neighborhood description vectors."));
|
---|
| 187 | Parameters.Add(new OptionalConstrainedValueParameter<ITopologyUpdater>("TopologyUpdater", "Updates the neighborhood description vectors."));
|
---|
| 188 | Parameters.Add(new OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier>("InertiaUpdater", "Updates the omega parameter."));
|
---|
[5568] | 189 | 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"));
|
---|
[5866] | 190 | ParticleUpdaterParameter.Hidden = true;
|
---|
[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();
|
---|
[5560] | 264 | UpdateTopologyParameters();
|
---|
| 265 | InitializeParticleCreator();
|
---|
[5561] | 266 | InitializeSwarmUpdater();
|
---|
[5568] | 267 | ParameterizeSolutionsCreator();
|
---|
[5410] | 268 | base.OnProblemChanged();
|
---|
[5342] | 269 | }
|
---|
| 270 |
|
---|
| 271 | void TopologyInitializerParameter_ValueChanged(object sender, EventArgs e) {
|
---|
[5410] | 272 | this.UpdateTopologyParameters();
|
---|
| 273 | }
|
---|
| 274 | #endregion
|
---|
[5342] | 275 |
|
---|
[5410] | 276 | #region Helpers
|
---|
| 277 | private void Initialize() {
|
---|
| 278 | TopologyInitializerParameter.ValueChanged += new EventHandler(TopologyInitializerParameter_ValueChanged);
|
---|
| 279 | }
|
---|
| 280 |
|
---|
[5560] | 281 | private void InitializeParticleCreator() {
|
---|
| 282 | if (Problem != null) {
|
---|
| 283 | IParticleCreator oldParticleCreator = ParticleCreator;
|
---|
[7512] | 284 | IParticleCreator defaultParticleCreator = Problem.Operators.OfType<IParticleCreator>().FirstOrDefault();
|
---|
[5560] | 285 | ParticleCreatorParameter.ValidValues.Clear();
|
---|
| 286 | foreach (IParticleCreator Creator in Problem.Operators.OfType<IParticleCreator>().OrderBy(x => x.Name)) {
|
---|
| 287 | ParticleCreatorParameter.ValidValues.Add(Creator);
|
---|
| 288 | }
|
---|
| 289 | if (oldParticleCreator != null) {
|
---|
| 290 | IParticleCreator creator = ParticleCreatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldParticleCreator.GetType());
|
---|
| 291 | if (creator != null) ParticleCreator = creator;
|
---|
[7512] | 292 | else oldParticleCreator = null;
|
---|
[5568] | 293 | }
|
---|
[7512] | 294 | if (oldParticleCreator == null && defaultParticleCreator != null)
|
---|
| 295 | ParticleCreator = defaultParticleCreator;
|
---|
[5560] | 296 | }
|
---|
[3348] | 297 | }
|
---|
| 298 |
|
---|
[5410] | 299 | private void InitializeAnalyzers() {
|
---|
| 300 | qualityAnalyzer = new BestAverageWorstQualityAnalyzer();
|
---|
[5581] | 301 | qualityAnalyzer.ResultsParameter.ActualName = "Results";
|
---|
[5410] | 302 | ParameterizeAnalyzers();
|
---|
[3348] | 303 | }
|
---|
| 304 |
|
---|
[5410] | 305 | private void ParameterizeAnalyzers() {
|
---|
[5312] | 306 | if (Problem != null) {
|
---|
[5410] | 307 | qualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
|
---|
| 308 | qualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
| 309 | qualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
|
---|
[5312] | 310 | }
|
---|
[3348] | 311 | }
|
---|
| 312 |
|
---|
[5410] | 313 | private void UpdateAnalyzers() {
|
---|
| 314 | Analyzer.Operators.Clear();
|
---|
| 315 | if (Problem != null) {
|
---|
| 316 | foreach (IAnalyzer analyzer in Problem.Operators.OfType<IAnalyzer>())
|
---|
[7172] | 317 | Analyzer.Operators.Add(analyzer, analyzer.EnabledByDefault);
|
---|
[5410] | 318 | }
|
---|
[7172] | 319 | Analyzer.Operators.Add(qualityAnalyzer, qualityAnalyzer.EnabledByDefault);
|
---|
[3348] | 320 | }
|
---|
[3415] | 321 |
|
---|
[5560] | 322 | private void InitInertiaUpdater() {
|
---|
| 323 | foreach (IDiscreteDoubleValueModifier updater in InertiaUpdaterParameter.ValidValues) {
|
---|
[5311] | 324 | updater.EndIndexParameter.ActualName = MaxIterationsParameter.Name;
|
---|
[5935] | 325 | updater.EndIndexParameter.Hidden = true;
|
---|
[5311] | 326 | updater.StartIndexParameter.Value = new IntValue(0);
|
---|
[5893] | 327 | updater.StartIndexParameter.Hidden = true;
|
---|
[5935] | 328 | updater.IndexParameter.ActualName = "Iterations";
|
---|
[5645] | 329 | updater.ValueParameter.ActualName = "CurrentInertia";
|
---|
[5311] | 330 | updater.StartValueParameter.Value = new DoubleValue(1);
|
---|
[5941] | 331 | updater.EndValueParameter.Value = new DoubleValue(1E-10);
|
---|
[5311] | 332 | }
|
---|
| 333 | }
|
---|
| 334 |
|
---|
[5560] | 335 | private void UpdateInertiaUpdater() {
|
---|
| 336 | IDiscreteDoubleValueModifier oldInertiaUpdater = InertiaUpdater;
|
---|
| 337 | InertiaUpdaterParameter.ValidValues.Clear();
|
---|
[5311] | 338 | foreach (IDiscreteDoubleValueModifier updater in ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>().OrderBy(x => x.Name)) {
|
---|
[5560] | 339 | InertiaUpdaterParameter.ValidValues.Add(updater);
|
---|
[5311] | 340 | }
|
---|
[5560] | 341 | if (oldInertiaUpdater != null) {
|
---|
| 342 | IDiscreteDoubleValueModifier updater = InertiaUpdaterParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldInertiaUpdater.GetType());
|
---|
| 343 | if (updater != null) InertiaUpdaterParameter.Value = updater;
|
---|
[5311] | 344 | }
|
---|
| 345 | }
|
---|
| 346 |
|
---|
[5410] | 347 | private void UpdateTopologyInitializer() {
|
---|
| 348 | ITopologyInitializer oldTopologyInitializer = TopologyInitializer;
|
---|
| 349 | TopologyInitializerParameter.ValidValues.Clear();
|
---|
| 350 | foreach (ITopologyInitializer topologyInitializer in ApplicationManager.Manager.GetInstances<ITopologyInitializer>().OrderBy(x => x.Name)) {
|
---|
| 351 | TopologyInitializerParameter.ValidValues.Add(topologyInitializer);
|
---|
[3348] | 352 | }
|
---|
[5410] | 353 | if (oldTopologyInitializer != null && TopologyInitializerParameter.ValidValues.Any(x => x.GetType() == oldTopologyInitializer.GetType()))
|
---|
| 354 | TopologyInitializer = TopologyInitializerParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldTopologyInitializer.GetType());
|
---|
| 355 | UpdateTopologyParameters();
|
---|
[3348] | 356 | }
|
---|
[3415] | 357 |
|
---|
[6476] | 358 | 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 |
|
---|
[5410] | 367 | private void UpdateTopologyParameters() {
|
---|
| 368 | ITopologyUpdater oldTopologyUpdater = TopologyUpdater;
|
---|
| 369 | IParticleUpdater oldParticleUpdater = ParticleUpdater;
|
---|
| 370 | ClearTopologyParameters();
|
---|
[5560] | 371 | if (Problem != null) {
|
---|
[7512] | 372 | IParticleUpdater defaultParticleUpdater = null;
|
---|
[5560] | 373 | if (TopologyInitializer != null) {
|
---|
| 374 | foreach (ITopologyUpdater topologyUpdater in ApplicationManager.Manager.GetInstances<ITopologyUpdater>())
|
---|
| 375 | TopologyUpdaterParameter.ValidValues.Add(topologyUpdater);
|
---|
[7512] | 376 | defaultParticleUpdater = Problem.Operators.OfType<ILocalParticleUpdater>().FirstOrDefault();
|
---|
[5560] | 377 | foreach (IParticleUpdater particleUpdater in Problem.Operators.OfType<ILocalParticleUpdater>().OrderBy(x => x.Name))
|
---|
| 378 | ParticleUpdaterParameter.ValidValues.Add(particleUpdater);
|
---|
| 379 | } else {
|
---|
[7512] | 380 | defaultParticleUpdater = Problem.Operators.OfType<IGlobalParticleUpdater>().FirstOrDefault();
|
---|
[5560] | 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 | }
|
---|
| 388 | if (oldParticleUpdater != null) {
|
---|
| 389 | IParticleUpdater newParticleUpdater = ParticleUpdaterParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldParticleUpdater.GetType());
|
---|
| 390 | if (newParticleUpdater != null) ParticleUpdater = newParticleUpdater;
|
---|
[7512] | 391 | else oldParticleUpdater = null;
|
---|
[5560] | 392 | }
|
---|
[7512] | 393 | if (oldParticleUpdater == null && defaultParticleUpdater != null)
|
---|
| 394 | ParticleUpdater = defaultParticleUpdater;
|
---|
[6476] | 395 |
|
---|
| 396 | ParameterizeTopologyUpdaters();
|
---|
[3682] | 397 | }
|
---|
| 398 | }
|
---|
| 399 |
|
---|
[5410] | 400 | private void ClearTopologyParameters() {
|
---|
| 401 | TopologyUpdaterParameter.ValidValues.Clear();
|
---|
| 402 | ParticleUpdaterParameter.ValidValues.Clear();
|
---|
| 403 | }
|
---|
[5560] | 404 |
|
---|
| 405 | private void ParameterizeSolutionsCreator() {
|
---|
| 406 | if (Problem != null) {
|
---|
| 407 | solutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
|
---|
[7781] | 408 | if (ParticleCreatorParameter.Value != null)
|
---|
| 409 | solutionsCreator.SolutionCreatorParameter.ActualName = ParticleCreatorParameter.Name;
|
---|
| 410 | else
|
---|
| 411 | solutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name;
|
---|
[5560] | 412 | }
|
---|
| 413 | }
|
---|
| 414 |
|
---|
| 415 | private void ParameterizeMainLoop() {
|
---|
[5568] | 416 | if (Problem != null) {
|
---|
[5561] | 417 | mainLoop.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
|
---|
| 418 | }
|
---|
[5560] | 419 | }
|
---|
[5561] | 420 |
|
---|
| 421 | private void InitializeSwarmUpdater() {
|
---|
| 422 | if (Problem != null) {
|
---|
| 423 | ISwarmUpdater updater = Problem.Operators.OfType<ISwarmUpdater>().FirstOrDefault();
|
---|
[5568] | 424 | SwarmUpdaterParameter.ValidValues.Clear();
|
---|
[5868] | 425 | if (updater != null) {
|
---|
| 426 | SwarmUpdaterParameter.ValidValues.Add(updater);
|
---|
| 427 | SwarmUpdaterParameter.Value = updater;
|
---|
| 428 | }
|
---|
[5561] | 429 | }
|
---|
| 430 | }
|
---|
[3348] | 431 | #endregion
|
---|
[5410] | 432 |
|
---|
[3348] | 433 | }
|
---|
| 434 | }
|
---|