source: branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/AlpsGeneticAlgorithm.cs @ 11586

Last change on this file since 11586 was 11586, checked in by pfleck, 5 years ago

#2269 Implemented LayerUpdator.

  • Added First/LastSubScopeProcessor.
  • Added two Calculators because ExpressionCalculator does not support required features yet.
  • Added some wiring.
  • Small bugfixes and refactorings.
File size: 24.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2014 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;
24using HeuristicLab.Analysis;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HeuristicLab.Data;
28using HeuristicLab.Operators;
29using HeuristicLab.Optimization;
30using HeuristicLab.Optimization.Operators;
31using HeuristicLab.Parameters;
32using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
33using HeuristicLab.PluginInfrastructure;
34using HeuristicLab.Random;
35using HeuristicLab.Selection;
36
37namespace HeuristicLab.Algorithms.ALPS {
38  [Item("ALPS Genetic Algorithm", "A genetic algorithm with an age-layered population structure.")]
39  [Creatable("Algorithms")]
40  [StorableClass]
41  public sealed class AlpsGeneticAlgorithm : HeuristicOptimizationEngineAlgorithm, IStorableContent {
42    public string Filename { get; set; }
43
44    #region Problem Properties
45    public override Type ProblemType {
46      get { return typeof(ISingleObjectiveHeuristicOptimizationProblem); }
47    }
48    public new ISingleObjectiveHeuristicOptimizationProblem Problem {
49      get { return (ISingleObjectiveHeuristicOptimizationProblem)base.Problem; }
50      set { base.Problem = value; }
51    }
52    #endregion
53
54    #region Parameter Properties
55    private IValueParameter<IntValue> SeedParameter {
56      get { return (IValueParameter<IntValue>)Parameters["Seed"]; }
57    }
58    private IValueParameter<BoolValue> SetSeedRandomlyParameter {
59      get { return (IValueParameter<BoolValue>)Parameters["SetSeedRandomly"]; }
60    }
61    private IValueParameter<MultiAnalyzer> AnalyzerParameter {
62      get { return (IValueParameter<MultiAnalyzer>)Parameters["Analyzer"]; }
63    }
64    private IValueParameter<MultiAnalyzer> LayerAnalyzerParameter {
65      get { return (IValueParameter<MultiAnalyzer>)Parameters["LayerAnalyzer"]; }
66    }
67    private IValueParameter<IntValue> NumberOfLayersParameter {
68      get { return (IValueParameter<IntValue>)Parameters["NumberOfLayers"]; }
69    }
70    private IValueParameter<IntValue> PopulationSizeParameter {
71      get { return (IValueParameter<IntValue>)Parameters["PopulationSize"]; }
72    }
73    private IValueParameter<IntValue> MaximumGenerationsParameter {
74      get { return (IValueParameter<IntValue>)Parameters["MaximumGenerations"]; }
75    }
76    private IValueParameter<AgingScheme> AgingSchemeParameter {
77      get { return (IValueParameter<AgingScheme>)Parameters["AgingScheme"]; }
78    }
79    private IValueParameter<IntValue> AgeGapParameter {
80      get { return (IValueParameter<IntValue>)Parameters["AgeGap"]; }
81    }
82    private IValueParameter<IntArray> AgeLimitsParameter {
83      get { return (IValueParameter<IntArray>)Parameters["AgeLimits"]; }
84    }
85    private IValueParameter<ReductionOperation> AgeInheritanceParameter {
86      get { return (IValueParameter<ReductionOperation>)Parameters["AgeInheritance"]; }
87    }
88    public IConstrainedValueParameter<ISelector> SelectorParameter {
89      get { return (IConstrainedValueParameter<ISelector>)Parameters["Selector"]; }
90    }
91    public IConstrainedValueParameter<ICrossover> CrossoverParameter {
92      get { return (IConstrainedValueParameter<ICrossover>)Parameters["Crossover"]; }
93    }
94    private IValueParameter<PercentValue> MutationProbabilityParameter {
95      get { return (IValueParameter<PercentValue>)Parameters["MutationProbability"]; }
96    }
97    public IConstrainedValueParameter<IManipulator> MutatorParameter {
98      get { return (IConstrainedValueParameter<IManipulator>)Parameters["Mutator"]; }
99    }
100    private IValueParameter<IntValue> ElitesParameter {
101      get { return (IValueParameter<IntValue>)Parameters["Elites"]; }
102    }
103    private IFixedValueParameter<BoolValue> ReevaluateElitesParameter {
104      get { return (IFixedValueParameter<BoolValue>)Parameters["ReevaluateElites"]; }
105    }
106    #endregion
107
108    #region Properties
109    public IntValue Seed {
110      get { return SeedParameter.Value; }
111      set { SeedParameter.Value = value; }
112    }
113    public BoolValue SetSeedRandomly {
114      get { return SetSeedRandomlyParameter.Value; }
115      set { SetSeedRandomlyParameter.Value = value; }
116    }
117    public MultiAnalyzer Analyzer {
118      get { return AnalyzerParameter.Value; }
119      set { AnalyzerParameter.Value = value; }
120    }
121    public MultiAnalyzer LayerAnalyzer {
122      get { return LayerAnalyzerParameter.Value; }
123      set { LayerAnalyzerParameter.Value = value; }
124    }
125    public IntValue NumberOfLayers {
126      get { return NumberOfLayersParameter.Value; }
127      set { NumberOfLayersParameter.Value = value; }
128    }
129
130    public IntValue PopulationSize {
131      get { return PopulationSizeParameter.Value; }
132      set { PopulationSizeParameter.Value = value; }
133    }
134    public IntValue MaximumGenerations {
135      get { return MaximumGenerationsParameter.Value; }
136      set { MaximumGenerationsParameter.Value = value; }
137    }
138    public AgingScheme AgingScheme {
139      get { return AgingSchemeParameter.Value; }
140      set { AgingSchemeParameter.Value = value; }
141    }
142    public IntValue AgeGap {
143      get { return AgeGapParameter.Value; }
144      set { AgeGapParameter.Value = value; }
145    }
146    public IntArray AgeLimits {
147      get { return AgeLimitsParameter.Value; }
148      set { AgeLimitsParameter.Value = value; }
149    }
150    public ReductionOperation AgeInheritance {
151      get { return AgeInheritanceParameter.Value; }
152      set { AgeInheritanceParameter.Value = value; }
153    }
154    public ISelector Selector {
155      get { return SelectorParameter.Value; }
156      set { SelectorParameter.Value = value; }
157    }
158    public ICrossover Crossover {
159      get { return CrossoverParameter.Value; }
160      set { CrossoverParameter.Value = value; }
161    }
162    public PercentValue MutationProbability {
163      get { return MutationProbabilityParameter.Value; }
164      set { MutationProbabilityParameter.Value = value; }
165    }
166    public IManipulator Mutator {
167      get { return MutatorParameter.Value; }
168      set { MutatorParameter.Value = value; }
169    }
170    public IntValue Elites {
171      get { return ElitesParameter.Value; }
172      set { ElitesParameter.Value = value; }
173    }
174    public bool ReevaluteElites {
175      get { return ReevaluateElitesParameter.Value.Value; }
176      set { ReevaluateElitesParameter.Value.Value = value; }
177    }
178
179    private RandomCreator GlobalRandomCreator {
180      get { return (RandomCreator)OperatorGraph.InitialOperator; }
181    }
182    private SolutionsCreator SolutionsCreator {
183      get { return OperatorGraph.Iterate().OfType<SolutionsCreator>().First(); }
184    }
185
186    private AlpsGeneticAlgorithmMainLoop MainLoop {
187      get { return OperatorGraph.Iterate().OfType<AlpsGeneticAlgorithmMainLoop>().First(); }
188    }
189
190    [Storable]
191    private BestAverageWorstQualityAnalyzer qualityAnalyzer;
192    [Storable]
193    private BestAverageWorstQualityAnalyzer layerQualityAnalyzer;
194    #endregion
195
196    [StorableConstructor]
197    private AlpsGeneticAlgorithm(bool deserializing)
198      : base(deserializing) { }
199    private AlpsGeneticAlgorithm(AlpsGeneticAlgorithm original, Cloner cloner)
200      : base(original, cloner) {
201      qualityAnalyzer = cloner.Clone(original.qualityAnalyzer);
202      layerQualityAnalyzer = cloner.Clone(original.layerQualityAnalyzer);
203      Initialize();
204    }
205    public override IDeepCloneable Clone(Cloner cloner) {
206      return new AlpsGeneticAlgorithm(this, cloner);
207    }
208    public AlpsGeneticAlgorithm()
209      : base() {
210      Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
211      Parameters.Add(new ValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
212      Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze the islands.", new MultiAnalyzer()));
213      Parameters.Add(new ValueParameter<MultiAnalyzer>("LayerAnalyzer", "The operator used to analyze each layer.", new MultiAnalyzer()));
214      Parameters.Add(new ValueParameter<IntValue>("NumberOfLayers", "The number of layers.", new IntValue(5)));
215      Parameters.Add(new ValueParameter<IntValue>("PopulationSize", "The size of the population of solutions each layer.", new IntValue(20)));
216      Parameters.Add(new ValueParameter<IntValue>("MaximumGenerations", "The maximum number of generations that should be processed.", new IntValue(1000)));
217      Parameters.Add(new ValueParameter<AgingScheme>("AgingScheme", "The aging scheme for setting the age-limits for the layers.", new AgingScheme(AgingSchemes.Polynomial)));
218      Parameters.Add(new ValueParameter<IntValue>("AgeGap", "The frequency of reseeding the lowest layer and scaling factor for the age-limits for the layers", new IntValue(5)));
219      Parameters.Add(new ValueParameter<IntArray>("AgeLimits", new IntArray(new[] { 5, 20, 45, 80, 125 })) { Hidden = true });
220      Parameters.Add(new ValueParameter<ReductionOperation>("AgeInheritance", "The operator for determining the age of an offspring based the parents' age.", new ReductionOperation(ReductionOperations.Max)) { Hidden = true });
221      Parameters.Add(new ConstrainedValueParameter<ISelector>("Selector", "The operator used to select solutions for reproduction."));
222      Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions."));
223      Parameters.Add(new ValueParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution.", new PercentValue(0.05)));
224      Parameters.Add(new OptionalConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions."));
225      Parameters.Add(new ValueParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.", new IntValue(1)));
226      Parameters.Add(new FixedValueParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)", new BoolValue(false)) { Hidden = true });
227
228      var globalRandomCreator = new RandomCreator();
229      var layer0Creator = new SubScopesCreator() { Name = "Create Layer Zero" };
230      var layer0Processor = new SubScopesProcessor();
231      var localRandomCreator = new LocalRandomCreator();
232      var layerVariableCreator = new VariableCreator();
233      var layerSolutionsCreator = new SolutionsCreator();
234      var initializeAgeProcessor = new UniformSubScopesProcessor();
235      var initializeAge = new VariableCreator() { Name = "Initialize Age" };
236      var initializeLocalEvaluatedSolutions = new SubScopesCounter();
237      var initializeGlobalEvaluatedSolutions = new DataReducer() { Name = "Initialize EvaluatedSolutions" };
238      var resultsCollector = new ResultsCollector();
239      var mainLoop = new AlpsGeneticAlgorithmMainLoop();
240
241      OperatorGraph.InitialOperator = globalRandomCreator;
242
243      globalRandomCreator.RandomParameter.ActualName = "GlobalRandom";
244      globalRandomCreator.SeedParameter.Value = null;
245      globalRandomCreator.SetSeedRandomlyParameter.Value = null;
246      globalRandomCreator.Successor = layer0Creator;
247
248      layer0Creator.NumberOfSubScopesParameter.Value = new IntValue(1);
249      layer0Creator.Successor = layer0Processor;
250
251      layer0Processor.Operators.Add(localRandomCreator);
252      layer0Processor.Successor = initializeGlobalEvaluatedSolutions;
253
254      localRandomCreator.Successor = layerVariableCreator;
255
256      layerVariableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Layer", new IntValue(0)));
257      layerVariableCreator.Successor = layerSolutionsCreator;
258
259      layerSolutionsCreator.NumberOfSolutionsParameter.ActualName = PopulationSizeParameter.Name;
260      layerSolutionsCreator.Successor = initializeAgeProcessor;
261
262      initializeAgeProcessor.Operator = initializeAge;
263      initializeAgeProcessor.Successor = initializeLocalEvaluatedSolutions;
264
265      initializeAge.CollectedValues.Add(new ValueParameter<IntValue>("Age", new IntValue(0)));
266      initializeAge.Successor = null;
267
268      initializeLocalEvaluatedSolutions.ValueParameter.ActualName = "EvaluatedSolutions";
269      initializeLocalEvaluatedSolutions.Successor = null;
270
271      initializeGlobalEvaluatedSolutions.ReductionOperation.Value.Value = ReductionOperations.Sum;
272      initializeGlobalEvaluatedSolutions.TargetOperation.Value.Value = ReductionOperations.Assign;
273      initializeGlobalEvaluatedSolutions.ParameterToReduce.ActualName = "EvaluatedSolutions";
274      initializeGlobalEvaluatedSolutions.TargetParameter.ActualName = "EvaluatedSolutions";
275      initializeGlobalEvaluatedSolutions.Successor = resultsCollector;
276
277      resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("EvaluatedSolutions"));
278      resultsCollector.Successor = mainLoop;
279
280      foreach (var selector in ApplicationManager.Manager.GetInstances<ISelector>().Where(s => !(s is IMultiObjectiveSelector)).OrderBy(s => Name))
281        SelectorParameter.ValidValues.Add(selector);
282      var porportionalSelector = SelectorParameter.ValidValues.FirstOrDefault(s => s is ProportionalSelector);
283      if (porportionalSelector != null) SelectorParameter.Value = porportionalSelector;
284
285      ParameterizeSelectors();
286
287      qualityAnalyzer = new BestAverageWorstQualityAnalyzer();
288      layerQualityAnalyzer = new BestAverageWorstQualityAnalyzer();
289      ParameterizeAnalyzers();
290      UpdateAnalyzers();
291
292      Initialize();
293    }
294
295    public override void Prepare() {
296      if (Problem != null)
297        base.Prepare();
298    }
299
300    #region Events
301    protected override void OnProblemChanged() {
302      ParameterizeStochasticOperator(Problem.SolutionCreator);
303      ParameterizeStochasticOperatorForLayer(Problem.Evaluator);
304      foreach (var @operator in Problem.Operators.OfType<IOperator>())
305        ParameterizeStochasticOperator(@operator);
306      ParameterizeSolutionsCreator();
307      ParameterizeMainLoop();
308      ParameterizeSelectors();
309      ParameterizeAnalyzers();
310      ParameterizeIterationBasedOperators();
311      UpdateCrossovers();
312      UpdateMutators();
313      UpdateAnalyzers();
314      Problem.Evaluator.QualityParameter.ActualNameChanged += Evaluator_QualityParameter_ActualNameChanged;
315      base.OnProblemChanged();
316    }
317
318    protected override void Problem_SolutionCreatorChanged(object sender, EventArgs e) {
319      ParameterizeStochasticOperator(Problem.SolutionCreator);
320      ParameterizeSolutionsCreator();
321      base.Problem_SolutionCreatorChanged(sender, e);
322    }
323    protected override void Problem_EvaluatorChanged(object sender, EventArgs e) {
324      ParameterizeStochasticOperatorForLayer(Problem.Evaluator);
325      ParameterizeSolutionsCreator();
326      ParameterizeMainLoop();
327      ParameterizeSelectors();
328      ParameterizeAnalyzers();
329      Problem.Evaluator.QualityParameter.ActualNameChanged += Evaluator_QualityParameter_ActualNameChanged;
330      base.Problem_EvaluatorChanged(sender, e);
331    }
332    protected override void Problem_OperatorsChanged(object sender, EventArgs e) {
333      foreach (var @operator in Problem.Operators.OfType<IOperator>())
334        ParameterizeStochasticOperator(@operator);
335      ParameterizeIterationBasedOperators();
336      UpdateCrossovers();
337      UpdateMutators();
338      UpdateAnalyzers();
339      base.Problem_OperatorsChanged(sender, e);
340    }
341    private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
342      ParameterizeMainLoop();
343      ParameterizeSelectors();
344      ParameterizeAnalyzers();
345    }
346
347    void PopulationSizeParameter_ValueChanged(object sender, EventArgs e) {
348      PopulationSizeParameter.ValueChanged += PopulationSize_ValueChanged;
349      ParameterizeSelectors();
350    }
351    void PopulationSize_ValueChanged(object sender, EventArgs e) {
352      ParameterizeSelectors();
353    }
354    void ElitesParameter_ValueChanged(object sender, EventArgs e) {
355      Elites.ValueChanged += ElitesParameter_ValueChanged;
356      ParameterizeSelectors();
357    }
358    void Elites_ValueChanged(object sender, EventArgs e) {
359      ParameterizeSelectors();
360    }
361    #endregion
362
363    #region Parameterization
364    private void Initialize() {
365      PopulationSizeParameter.ValueChanged += PopulationSizeParameter_ValueChanged;
366      PopulationSize.ValueChanged += PopulationSize_ValueChanged;
367      ElitesParameter.ValueChanged += ElitesParameter_ValueChanged;
368      Elites.ValueChanged += Elites_ValueChanged;
369      if (Problem != null)
370        Problem.Evaluator.QualityParameter.ActualNameChanged += Evaluator_QualityParameter_ActualNameChanged;
371    }
372    private void ParameterizeSolutionsCreator() {
373      SolutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
374      SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name;
375      MainLoop.EldersEmigrator.SolutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
376      MainLoop.EldersEmigrator.SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name;
377
378    }
379    private void ParameterizeMainLoop() {
380      //MainLoop.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
381      //MainLoop.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
382      //MainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
383      //MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
384      MainLoop.MainOperator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
385      MainLoop.MainOperator.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
386      MainLoop.MainOperator.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
387      MainLoop.EldersEmigrator.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
388      MainLoop.EldersEmigrator.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
389    }
390    private void ParameterizeSelectors() {
391      foreach (var selector in SelectorParameter.ValidValues) {
392        selector.CopySelected = new BoolValue(true);
393        selector.NumberOfSelectedSubScopesParameter.Value = new IntValue(2 * (PopulationSize.Value - Elites.Value));
394        selector.NumberOfSelectedSubScopesParameter.Hidden = true;
395        ParameterizeStochasticOperatorForLayer(selector);
396      }
397      if (Problem != null) {
398        foreach (var selector in SelectorParameter.ValidValues.OfType<ISingleObjectiveSelector>()) {
399          selector.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
400          selector.MaximizationParameter.Hidden = true;
401          selector.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
402          selector.QualityParameter.Hidden = true;
403        }
404      }
405    }
406    private void ParameterizeAnalyzers() {
407      qualityAnalyzer.ResultsParameter.ActualName = "Results";
408      qualityAnalyzer.ResultsParameter.Hidden = true;
409      qualityAnalyzer.QualityParameter.Depth = 2;
410      layerQualityAnalyzer.ResultsParameter.ActualName = "Results";
411      layerQualityAnalyzer.ResultsParameter.Hidden = true;
412      layerQualityAnalyzer.QualityParameter.Depth = 1;
413      if (Problem != null) {
414        qualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
415        qualityAnalyzer.MaximizationParameter.Hidden = true;
416        qualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
417        qualityAnalyzer.QualityParameter.Hidden = true;
418        qualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
419        qualityAnalyzer.BestKnownQualityParameter.Hidden = true;
420        layerQualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
421        layerQualityAnalyzer.MaximizationParameter.Hidden = true;
422        layerQualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
423        layerQualityAnalyzer.QualityParameter.Hidden = true;
424        layerQualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
425        layerQualityAnalyzer.BestKnownQualityParameter.Hidden = true;
426      }
427    }
428    private void ParameterizeIterationBasedOperators() {
429      if (Problem != null) {
430        foreach (var @operator in Problem.Operators.OfType<IIterationBasedOperator>()) {
431          @operator.IterationsParameter.ActualName = "Generations";
432          @operator.IterationsParameter.Hidden = true;
433          @operator.MaximumIterationsParameter.ActualName = "MaximumGenerations";
434          @operator.MaximumIterationsParameter.Hidden = true;
435        }
436      }
437    }
438    private void ParameterizeStochasticOperator(IOperator @operator) {
439      var stochasticOperator = @operator as IStochasticOperator;
440      if (stochasticOperator != null) {
441        stochasticOperator.RandomParameter.ActualName = GlobalRandomCreator.RandomParameter.ActualName;
442        stochasticOperator.RandomParameter.Hidden = true;
443      }
444    }
445    private void ParameterizeStochasticOperatorForLayer(IOperator @operator) {
446      var stochasticOperator = @operator as IStochasticOperator;
447      if (stochasticOperator != null) {
448        stochasticOperator.RandomParameter.ActualName = "LocalRandom";
449        stochasticOperator.RandomParameter.Hidden = true;
450      }
451    }
452
453    #endregion
454
455    #region Updates
456    private void UpdateCrossovers() {
457      var oldCrossover = CrossoverParameter.Value;
458      var defaultCrossover = Problem.Operators.OfType<ICrossover>().FirstOrDefault();
459      CrossoverParameter.ValidValues.Clear();
460      foreach (var crossover in Problem.Operators.OfType<ICrossover>().OrderBy(c => c.Name)) {
461        ParameterizeStochasticOperatorForLayer(crossover);
462        CrossoverParameter.ValidValues.Add(crossover);
463      }
464      if (oldCrossover != null) {
465        var crossover = CrossoverParameter.ValidValues.FirstOrDefault(c => c.GetType() == oldCrossover.GetType());
466        CrossoverParameter.Value = crossover;
467      }
468      if (oldCrossover == null && defaultCrossover != null)
469        CrossoverParameter.Value = defaultCrossover;
470    }
471    private void UpdateMutators() {
472      var oldMutator = MutatorParameter.Value;
473      MutatorParameter.ValidValues.Clear();
474      foreach (var mutator in Problem.Operators.OfType<IManipulator>().OrderBy(m => m.Name)) {
475        ParameterizeStochasticOperatorForLayer(mutator);
476        MutatorParameter.ValidValues.Add(mutator);
477      }
478      if (oldMutator != null) {
479        var mutator = MutatorParameter.ValidValues.FirstOrDefault(m => m.GetType() == oldMutator.GetType());
480        MutatorParameter.Value = mutator;
481      }
482    }
483    private void UpdateAnalyzers() {
484      Analyzer.Operators.Clear();
485      LayerAnalyzer.Operators.Clear();
486
487      Analyzer.Operators.Add(qualityAnalyzer, qualityAnalyzer.EnabledByDefault);
488      LayerAnalyzer.Operators.Add(layerQualityAnalyzer, layerQualityAnalyzer.EnabledByDefault);
489
490      if (Problem != null) {
491        foreach (var analyzer in Problem.Operators.OfType<IAnalyzer>()) {
492          foreach (var parameter in analyzer.Parameters.OfType<IScopeTreeLookupParameter>())
493            parameter.Depth = 2;
494          Analyzer.Operators.Add(analyzer, analyzer.EnabledByDefault);
495        }
496      }
497    }
498    #endregion
499  }
500}
Note: See TracBrowser for help on using the repository browser.