Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/ParticleSwarmOptimization.cs @ 5440

Last change on this file since 5440 was 5435, checked in by abeham, 14 years ago

#852

  • Made public properties that redirect to ActualValue.Value private or protected
  • Sealed all of the specific operators
  • Removed files that are present in the repository, but are not included in the project
  • Removed .sln file (is this still needed?)
  • Added license headers to some files
  • Unified the pattern for writing the constructors similar to other files in the trunk
  • Corrected assembly and plugin version from 3.3.0.x to 3.3.2.x
  • Fixed the wiring in the VelocityBoundsModifier
File size: 21.8 KB
RevLine 
[3348]1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
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
22using System;
23using System.Linq;
[4068]24using HeuristicLab.Analysis;
[3376]25using HeuristicLab.Common;
[3348]26using HeuristicLab.Core;
27using HeuristicLab.Data;
28using HeuristicLab.Encodings.RealVectorEncoding;
[4068]29using HeuristicLab.Operators;
[3348]30using HeuristicLab.Optimization;
31using HeuristicLab.Optimization.Operators;
32using HeuristicLab.Parameters;
33using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
[5209]34using HeuristicLab.PluginInfrastructure;
[3368]35using HeuristicLab.Random;
[3348]36
37namespace HeuristicLab.Algorithms.ParticleSwarmOptimization {
[5209]38  [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]39  [Creatable("Algorithms")]
40  [StorableClass]
[5435]41  public sealed class ParticleSwarmOptimization : EngineAlgorithm, IStorableContent {
[5033]42
[3348]43    #region Problem Properties
44    public override Type ProblemType {
45      get { return typeof(ISingleObjectiveProblem); }
46    }
47    public new ISingleObjectiveProblem Problem {
48      get { return (ISingleObjectiveProblem)base.Problem; }
49      set { base.Problem = value; }
50    }
[3682]51    public MultiAnalyzer Analyzer {
52      get { return AnalyzerParameter.Value; }
53      set { AnalyzerParameter.Value = value; }
54    }
[5311]55    public IDiscreteDoubleValueModifier OmegaUpdater {
[5225]56      get { return OmegaUpdaterParameter.Value; }
57      set { OmegaUpdaterParameter.Value = value; }
58    }
[5311]59    public IDiscreteDoubleMatrixModifier VelocityBoundsUpdater {
[5225]60      get { return VelocityBoundsUpdaterParameter.Value; }
61      set { VelocityBoundsUpdaterParameter.Value = value; }
62    }
[4068]63    #endregion
[3348]64
65    #region Parameter Properties
[5410]66    public IValueParameter<IntValue> SeedParameter {
67      get { return (IValueParameter<IntValue>)Parameters["Seed"]; }
[3348]68    }
[5410]69    public IValueParameter<BoolValue> SetSeedRandomlyParameter {
70      get { return (IValueParameter<BoolValue>)Parameters["SetSeedRandomly"]; }
[3348]71    }
[5410]72    public IValueParameter<IntValue> SwarmSizeParameter {
73      get { return (IValueParameter<IntValue>)Parameters["SwarmSize"]; }
[3348]74    }
[5410]75    public IValueParameter<IntValue> MaxIterationsParameter {
76      get { return (IValueParameter<IntValue>)Parameters["MaxIterations"]; }
[3348]77    }
[5410]78    public IValueParameter<DoubleValue> OmegaParameter {
79      get { return (IValueParameter<DoubleValue>)Parameters["Omega"]; }
[3348]80    }
[5410]81    public IValueParameter<DoubleValue> Phi_PParameter {
82      get { return (IValueParameter<DoubleValue>)Parameters["Phi_P"]; }
[5033]83    }
[5410]84    public IValueParameter<DoubleValue> Phi_GParameter {
85      get { return (IValueParameter<DoubleValue>)Parameters["Phi_G"]; }
[5033]86    }
[5410]87    public IValueParameter<MultiAnalyzer> AnalyzerParameter {
88      get { return (IValueParameter<MultiAnalyzer>)Parameters["Analyzer"]; }
[3682]89    }
[5410]90    public IValueLookupParameter<DoubleMatrix> VelocityBoundsParameter {
91      get { return (IValueLookupParameter<DoubleMatrix>)Parameters["VelocityBounds"]; }
[5033]92    }
[5209]93    public ConstrainedValueParameter<IParticleUpdater> ParticleUpdaterParameter {
94      get { return (ConstrainedValueParameter<IParticleUpdater>)Parameters["ParticleUpdater"]; }
95    }
[5410]96    public OptionalConstrainedValueParameter<ITopologyInitializer> TopologyInitializerParameter {
97      get { return (OptionalConstrainedValueParameter<ITopologyInitializer>)Parameters["TopologyInitializer"]; }
[5209]98    }
[5410]99    public OptionalConstrainedValueParameter<ITopologyUpdater> TopologyUpdaterParameter {
100      get { return (OptionalConstrainedValueParameter<ITopologyUpdater>)Parameters["TopologyUpdater"]; }
[5209]101    }
[5311]102    public OptionalConstrainedValueParameter<IDiscreteDoubleMatrixModifier> VelocityBoundsUpdaterParameter {
103      get { return (OptionalConstrainedValueParameter<IDiscreteDoubleMatrixModifier>)Parameters["VelocityBoundsUpdater"]; }
[5225]104    }
[5311]105    public OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier> OmegaUpdaterParameter {
106      get { return (OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier>)Parameters["OmegaUpdater"]; }
[5225]107    }
[3348]108    #endregion
109
110    #region Properties
[5316]111
112    public string Filename { get; set; }
113
[3719]114    [Storable]
[3682]115    private BestAverageWorstQualityAnalyzer qualityAnalyzer;
[5342]116
117    public ITopologyInitializer TopologyInitializer {
118      get { return TopologyInitializerParameter.Value; }
119      set { TopologyInitializerParameter.Value = value; }
120    }
121
122    public ITopologyUpdater TopologyUpdater {
123      get { return TopologyUpdaterParameter.Value; }
124      set { TopologyUpdaterParameter.Value = value; }
125    }
126
127    public IParticleUpdater ParticleUpdater {
128      get { return ParticleUpdaterParameter.Value; }
129      set { ParticleUpdaterParameter.Value = value; }
130    }
131
[3348]132    #endregion
133
[5033]134    [StorableConstructor]
[5435]135    private ParticleSwarmOptimization(bool deserializing) : base(deserializing) { }
136    private ParticleSwarmOptimization(ParticleSwarmOptimization original, Cloner cloner)
[5033]137      : base(original, cloner) {
138      qualityAnalyzer = cloner.Clone(original.qualityAnalyzer);
[5342]139      Initialize();
[5033]140    }
[3348]141    public ParticleSwarmOptimization()
142      : base() {
143      Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
144      Parameters.Add(new ValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
[3724]145      Parameters.Add(new ValueParameter<IntValue>("SwarmSize", "Size of the particle swarm.", new IntValue(10)));
[3348]146      Parameters.Add(new ValueParameter<IntValue>("MaxIterations", "Maximal number of iterations.", new IntValue(1000)));
[3682]147      Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze each generation.", new MultiAnalyzer()));
[5033]148      Parameters.Add(new ValueParameter<DoubleValue>("Omega", "Weight for particle's velocity vector.", new DoubleValue(-0.2)));
149      Parameters.Add(new ValueParameter<DoubleValue>("Phi_P", "Weight for particle's personal best position.", new DoubleValue(-0.01)));
150      Parameters.Add(new ValueParameter<DoubleValue>("Phi_G", "Weight for global best position.", new DoubleValue(3.7)));
151      Parameters.Add(new ValueLookupParameter<DoubleMatrix>("VelocityBounds", "Maximum Velocity in every dimension", new DoubleMatrix(new double[,] { { -1, 1 } })));
[5410]152      Parameters.Add(new ConstrainedValueParameter<IParticleUpdater>("ParticleUpdater", "Operator that calculates new position and velocity of a particle"));
153      Parameters.Add(new OptionalConstrainedValueParameter<ITopologyInitializer>("TopologyInitializer", "Creates neighborhood description vectors"));
154      Parameters.Add(new OptionalConstrainedValueParameter<ITopologyUpdater>("TopologyUpdater", "Updates the neighborhood description vectors"));
[5311]155      Parameters.Add(new OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier>("OmegaUpdater", "Updates the omega parameter"));
156      Parameters.Add(new OptionalConstrainedValueParameter<IDiscreteDoubleMatrixModifier>("VelocityBoundsUpdater", "Adjusts the velocity bounds."));
[5209]157      ParticleUpdaterParameter.ActualValue = ParticleUpdaterParameter.ValidValues.SingleOrDefault(v => v.GetType() == typeof(TotallyConnectedParticleUpdater));
[5033]158
[3348]159      RandomCreator randomCreator = new RandomCreator();
[5033]160      VariableCreator variableCreator = new VariableCreator();
[3348]161      SolutionsCreator solutionsCreator = new SolutionsCreator();
[5033]162      CombinedOperator particleCreator = new CombinedOperator();
163      Placeholder evaluatorPlaceholder = new Placeholder();
164      Assigner bestPersonalQualityAssigner = new Assigner();
165      BestPointInitializer bestPositionInitializer = new BestPointInitializer();
[5209]166      Placeholder topologyInitializerPlaceholder = new Placeholder();
167      NeighborUpdater neighborUpdater = new NeighborUpdater();
[5033]168      Placeholder analyzerPlaceholder = new Placeholder();
169      UniformSubScopesProcessor uniformSubScopeProcessor = new UniformSubScopesProcessor();
[5209]170      Placeholder particleUpdaterPlaceholder = new Placeholder();
171      Placeholder topologyUpdaterPlaceholder = new Placeholder();
172      UniformSubScopesProcessor uniformSubscopesProcessor2 = new UniformSubScopesProcessor();
[5418]173      UniformSubScopesProcessor evaluationProcessor = new UniformSubScopesProcessor();
[5209]174      NeighborUpdater neighborUpdater2 = new NeighborUpdater();
[5033]175      Placeholder evaluatorPlaceholder2 = new Placeholder();
176      SwarmUpdater swarmUpdater = new SwarmUpdater();
177      Placeholder analyzerPlaceholder2 = new Placeholder();
178      IntCounter currentIterationCounter = new IntCounter();
179      Comparator currentIterationComparator = new Comparator();
180      ConditionalBranch conditionalBranch = new ConditionalBranch();
[5225]181      Placeholder velocityBoundsUpdaterPlaceholder = new Placeholder();
182      Placeholder omegaUpdaterPlaceholder = new Placeholder();
[3348]183
[5033]184      OperatorGraph.InitialOperator = randomCreator;
[3682]185
[5033]186      randomCreator.SetSeedRandomlyParameter.Value = null;
[3348]187      randomCreator.SeedParameter.Value = null;
[5033]188      randomCreator.Successor = variableCreator;
[4068]189
[5033]190      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("CurrentIteration", new IntValue(0)));
191      variableCreator.Successor = solutionsCreator;
[4068]192
[5033]193      solutionsCreator.NumberOfSolutionsParameter.ActualName = "SwarmSize";
194      solutionsCreator.EvaluatorParameter.Value = evaluatorPlaceholder;
195      solutionsCreator.SolutionCreatorParameter.Value = particleCreator;
196      solutionsCreator.Successor = bestPositionInitializer;
[4068]197
[5033]198      InitializeParticleCreator(particleCreator);
[3348]199
[5033]200      evaluatorPlaceholder.Name = "(Evaluator)";
201      evaluatorPlaceholder.OperatorParameter.ActualName = "Evaluator";
202      evaluatorPlaceholder.Successor = bestPersonalQualityAssigner;
[3348]203
[5033]204      bestPersonalQualityAssigner.LeftSideParameter.ActualName = "PersonalBestQuality";
205      bestPersonalQualityAssigner.RightSideParameter.ActualName = "Quality";
[3682]206
[5209]207      bestPositionInitializer.Successor = topologyInitializerPlaceholder;
[3682]208
[5209]209      topologyInitializerPlaceholder.Name = "(TopologyInitializer)";
210      topologyInitializerPlaceholder.OperatorParameter.ActualName = "TopologyInitializer";
211      topologyInitializerPlaceholder.Successor = neighborUpdater;
212
213      neighborUpdater.Successor = analyzerPlaceholder;
214
[5033]215      analyzerPlaceholder.Name = "(Analyzer)";
216      analyzerPlaceholder.OperatorParameter.ActualName = "Analyzer";
217      analyzerPlaceholder.Successor = uniformSubScopeProcessor;
[3682]218
[5209]219      uniformSubScopeProcessor.Operator = particleUpdaterPlaceholder;
[5418]220      uniformSubScopeProcessor.Successor = evaluationProcessor;
[3682]221
[5209]222      particleUpdaterPlaceholder.Name = "(ParticleUpdater)";
223      particleUpdaterPlaceholder.OperatorParameter.ActualName = "ParticleUpdater";
[3682]224
[5418]225      evaluationProcessor.Parallel = new BoolValue(true);
226      evaluationProcessor.Operator = evaluatorPlaceholder2;
227      evaluationProcessor.Successor = topologyUpdaterPlaceholder;
228
[5033]229      evaluatorPlaceholder2.Name = "(Evaluator)";
230      evaluatorPlaceholder2.OperatorParameter.ActualName = "Evaluator";
[3682]231
[5209]232      topologyUpdaterPlaceholder.Name = "(TopologyUpdater)";
233      topologyUpdaterPlaceholder.OperatorParameter.ActualName = "TopologyUpdater";
234      topologyUpdaterPlaceholder.Successor = neighborUpdater2;
235
236      neighborUpdater2.Successor = uniformSubscopesProcessor2;
237
238      uniformSubscopesProcessor2.Operator = swarmUpdater;
239      uniformSubscopesProcessor2.Successor = analyzerPlaceholder2;
240
[5033]241      analyzerPlaceholder2.Name = "(Analyzer)";
242      analyzerPlaceholder2.OperatorParameter.ActualName = "Analyzer";
243      analyzerPlaceholder2.Successor = currentIterationCounter;
244
245      currentIterationCounter.Name = "CurrentIteration++";
246      currentIterationCounter.ValueParameter.ActualName = "CurrentIteration";
[5225]247      currentIterationCounter.Successor = omegaUpdaterPlaceholder;
[5033]248
[5225]249      omegaUpdaterPlaceholder.Name = "(Omega Updater)";
250      omegaUpdaterPlaceholder.OperatorParameter.ActualName = "OmegaUpdater";
251      omegaUpdaterPlaceholder.Successor = velocityBoundsUpdaterPlaceholder;
252
253      velocityBoundsUpdaterPlaceholder.Name = "(Velocity Bounds Updater)";
254      velocityBoundsUpdaterPlaceholder.OperatorParameter.ActualName = "VelocityBoundsUpdater";
255      velocityBoundsUpdaterPlaceholder.Successor = currentIterationComparator;
256
[5033]257      currentIterationComparator.LeftSideParameter.ActualName = "CurrentIteration";
258      currentIterationComparator.Comparison = new Comparison(ComparisonType.Less);
259      currentIterationComparator.RightSideParameter.ActualName = "MaxIterations";
260      currentIterationComparator.ResultParameter.ActualName = "ContinueIteration";
261      currentIterationComparator.Successor = conditionalBranch;
262
263      conditionalBranch.Name = "ContinueIteration?";
264      conditionalBranch.ConditionParameter.ActualName = "ContinueIteration";
265      conditionalBranch.TrueBranch = uniformSubScopeProcessor;
266
[3719]267      InitializeAnalyzers();
[5311]268      InitVelocityBoundsUpdater();
[3719]269      UpdateAnalyzers();
[5311]270      UpdateOmegaUpdater();
271      InitOmegaUpdater();
[5410]272      UpdateTopologyInitializer();
[5342]273      Initialize();
[3348]274    }
275
[5410]276    public override IDeepCloneable Clone(Cloner cloner) {
277      return new ParticleSwarmOptimization(this, cloner);
[5342]278    }
279
[5435]280    [StorableHook(HookType.AfterDeserialization)]
281    private void AfterDeserialization() {
282      Initialize();
283    }
284
[5410]285    public override void Prepare() {
286      if (Problem != null) {
287        base.Prepare();
288        if (OmegaUpdater != null && OmegaUpdater.StartValueParameter.Value != null) {
289          this.OmegaParameter.ActualValue = new DoubleValue(OmegaUpdaterParameter.Value.StartValueParameter.Value.Value);
[5342]290        }
[5410]291        if (VelocityBoundsUpdater != null && VelocityBoundsUpdater.StartValueParameter.Value != null && VelocityBoundsParameter.Value != null) {
292          DoubleMatrix matrix = VelocityBoundsParameter.Value;
293          for (int i = 0; i < matrix.Rows; i++) {
294            matrix[i, 0] = -VelocityBoundsUpdater.StartValueParameter.Value.Value;
295            matrix[i, 1] = VelocityBoundsUpdater.StartValueParameter.Value.Value;
296          }
297        }
[5342]298      }
299    }
300
[5410]301    #region Events
302    protected override void OnProblemChanged() {
303      UpdateAnalyzers();
304      ParameterizeAnalyzers();
305      base.OnProblemChanged();
[5342]306    }
307
308    void TopologyInitializerParameter_ValueChanged(object sender, EventArgs e) {
[5410]309      this.UpdateTopologyParameters();
310    }
311
312    void VelocityBoundsUpdaterParameter_ValueChanged(object sender, EventArgs e) {
313      if (VelocityBoundsParameter.Value != null) {
314        foreach (IDiscreteDoubleMatrixModifier matrixOp in VelocityBoundsUpdaterParameter.Value.ScalingOperatorParameter.ValidValues) {
315          matrixOp.ValueParameter.ActualName = VelocityBoundsUpdater.ScaleParameter.Name;
316          matrixOp.StartValueParameter.Value = new DoubleValue(VelocityBoundsUpdater.ScaleParameter.ActualValue.Value);
[5342]317        }
318      }
319    }
[5410]320    #endregion
[5342]321
[5410]322    #region Helpers
323    private void Initialize() {
324      TopologyInitializerParameter.ValueChanged += new EventHandler(TopologyInitializerParameter_ValueChanged);
325    }
326
[5033]327    private static void InitializeParticleCreator(CombinedOperator particleCreator) {
328      Placeholder positionCreator = new Placeholder();
329      Assigner personalBestPositionAssigner = new Assigner();
330      UniformRandomRealVectorCreator velocityCreator = new UniformRandomRealVectorCreator();
331
332      particleCreator.Name = "Particle Creator";
333      particleCreator.OperatorGraph.InitialOperator = positionCreator;
334
335      positionCreator.Name = "(SolutionCreator)";
336      positionCreator.OperatorParameter.ActualName = "SolutionCreator";
337      positionCreator.Successor = personalBestPositionAssigner;
338
339      personalBestPositionAssigner.LeftSideParameter.ActualName = "PersonalBestPoint";
340      personalBestPositionAssigner.RightSideParameter.ActualName = "Point";
341      personalBestPositionAssigner.Successor = velocityCreator;
342
343      velocityCreator.LengthParameter.ActualName = "ProblemSize";
344      velocityCreator.BoundsParameter.ActualName = "VelocityBounds";
345      velocityCreator.RealVectorParameter.ActualName = "Velocity";
[3348]346    }
347
[5410]348    private void InitializeAnalyzers() {
349      qualityAnalyzer = new BestAverageWorstQualityAnalyzer();
350      ParameterizeAnalyzers();
[3348]351    }
352
[5410]353    private void ParameterizeAnalyzers() {
[5312]354      if (Problem != null) {
[5410]355        qualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
356        qualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
357        qualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
[5312]358      }
[3348]359    }
360
[5410]361    private void UpdateAnalyzers() {
362      Analyzer.Operators.Clear();
363      if (Problem != null) {
364        foreach (IAnalyzer analyzer in Problem.Operators.OfType<IAnalyzer>())
365          Analyzer.Operators.Add(analyzer);
366      }
367      Analyzer.Operators.Add(qualityAnalyzer);
[3348]368    }
[3415]369
[5311]370    private void InitVelocityBoundsUpdater() {
371      foreach (IDiscreteDoubleMatrixModifier matrixOp in ApplicationManager.Manager.GetInstances<IDiscreteDoubleMatrixModifier>()) {
372        VelocityBoundsUpdaterParameter.ValidValues.Add(matrixOp);
373        matrixOp.ValueParameter.ActualName = VelocityBoundsParameter.Name;
374        matrixOp.EndIndexParameter.ActualName = MaxIterationsParameter.Name;
375        matrixOp.StartIndexParameter.Value = new IntValue(0);
376        matrixOp.IndexParameter.ActualName = "CurrentIteration";
377        matrixOp.EndValueParameter.Value = new DoubleValue(0);
[5225]378      }
[5311]379      VelocityBoundsUpdaterParameter.ValueChanged += new EventHandler(VelocityBoundsUpdaterParameter_ValueChanged);
380    }
381
382    private void InitOmegaUpdater() {
383      foreach (IDiscreteDoubleValueModifier updater in OmegaUpdaterParameter.ValidValues) {
384        updater.EndIndexParameter.ActualName = MaxIterationsParameter.Name;
385        updater.StartIndexParameter.Value = new IntValue(0);
386        updater.IndexParameter.ActualName = "CurrentIteration";
387        updater.ValueParameter.ActualName = OmegaParameter.Name;
388        updater.StartValueParameter.Value = new DoubleValue(1);
389        updater.EndValueParameter.Value = new DoubleValue(0);
390      }
391    }
392
393    private void UpdateOmegaUpdater() {
394      IDiscreteDoubleValueModifier oldOmegaUpdater = OmegaUpdater;
395      OmegaUpdaterParameter.ValidValues.Clear();
396      foreach (IDiscreteDoubleValueModifier updater in ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>().OrderBy(x => x.Name)) {
397        OmegaUpdaterParameter.ValidValues.Add(updater);
398      }
399      if (oldOmegaUpdater != null) {
400        IDiscreteDoubleValueModifier updater = OmegaUpdaterParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldOmegaUpdater.GetType());
401        if (updater != null) OmegaUpdaterParameter.Value = updater;
402      }
403    }
404
[5410]405    private void UpdateTopologyInitializer() {
406      ITopologyInitializer oldTopologyInitializer = TopologyInitializer;
407      TopologyInitializerParameter.ValidValues.Clear();
408      foreach (ITopologyInitializer topologyInitializer in ApplicationManager.Manager.GetInstances<ITopologyInitializer>().OrderBy(x => x.Name)) {
409        TopologyInitializerParameter.ValidValues.Add(topologyInitializer);
[3348]410      }
[5410]411      if (oldTopologyInitializer != null && TopologyInitializerParameter.ValidValues.Any(x => x.GetType() == oldTopologyInitializer.GetType()))
412        TopologyInitializer = TopologyInitializerParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldTopologyInitializer.GetType());
413      UpdateTopologyParameters();
[3348]414    }
[3415]415
[5410]416    private void UpdateTopologyParameters() {
417      ITopologyUpdater oldTopologyUpdater = TopologyUpdater;
418      IParticleUpdater oldParticleUpdater = ParticleUpdater;
419      ClearTopologyParameters();
420      if (TopologyInitializer != null) {
421        foreach (ITopologyUpdater topologyUpdater in ApplicationManager.Manager.GetInstances<ITopologyUpdater>())
422          TopologyUpdaterParameter.ValidValues.Add(topologyUpdater);
423        foreach (IParticleUpdater particleUpdater in ApplicationManager.Manager.GetInstances<ILocalParticleUpdater>())
424          ParticleUpdaterParameter.ValidValues.Add(particleUpdater);
425      } else {
426        foreach (IParticleUpdater particleUpdater in ApplicationManager.Manager.GetInstances<IGlobalParticleUpdater>())
427          ParticleUpdaterParameter.ValidValues.Add(particleUpdater);
[3682]428      }
[5410]429      if (oldTopologyUpdater != null) {
430        ITopologyUpdater newTopologyUpdater = TopologyUpdaterParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldParticleUpdater.GetType());
431        if (newTopologyUpdater != null) TopologyUpdater = newTopologyUpdater;
432      }
433      if (oldParticleUpdater != null) {
434        IParticleUpdater newParticleUpdater = ParticleUpdaterParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldParticleUpdater.GetType());
435        if (newParticleUpdater != null) ParticleUpdater = newParticleUpdater;
436      }
[3682]437    }
438
[5410]439    private void ClearTopologyParameters() {
440      TopologyUpdaterParameter.ValidValues.Clear();
441      ParticleUpdaterParameter.ValidValues.Clear();
442    }
[3348]443    #endregion
[5410]444
[3348]445  }
446}
Note: See TracBrowser for help on using the repository browser.