source: branches/ALPS/HeuristicLab.Algorithms.ALPS.OffspringSelection/3.3/AlpsOffspringSelectionGeneticAlgorithm.cs @ 12550

Last change on this file since 12550 was 12550, checked in by pfleck, 7 years ago

#2375

  • Renamed SelectionPressureAnalyzer for layers.
  • Moved updating of terminators to concrete ALPS implementation instead of abstract base class.
File size: 25.5 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 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.Collections.Generic;
24using System.Linq;
25using HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm;
26using HeuristicLab.Analysis;
27using HeuristicLab.Common;
28using HeuristicLab.Core;
29using HeuristicLab.Data;
30using HeuristicLab.Operators;
31using HeuristicLab.Optimization;
32using HeuristicLab.Optimization.Operators;
33using HeuristicLab.Parameters;
34using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
35using HeuristicLab.PluginInfrastructure;
36using HeuristicLab.Random;
37using HeuristicLab.Selection;
38
39namespace HeuristicLab.Algorithms.ALPS.OffspringSelection {
40  [Item("ALPS Offspring Selection Genetic Algorithm", "A genetic algorithm with an age-layered population structure and Offspring Selection.")]
41  [Creatable("Algorithms")]
42  [StorableClass]
43  public sealed class AlpsOffspringSelectionGeneticAlgorithm : Alps {
44    #region Parameter Properties
45    private IValueParameter<IntArray> PopulationSizeParameter {
46      get { return (IValueParameter<IntArray>)Parameters["PopulationSize"]; }
47    }
48    public IConstrainedValueParameter<ISelector> SelectorParameter {
49      get { return (IConstrainedValueParameter<ISelector>)Parameters["Selector"]; }
50    }
51    public IConstrainedValueParameter<ICrossover> CrossoverParameter {
52      get { return (IConstrainedValueParameter<ICrossover>)Parameters["Crossover"]; }
53    }
54    private IValueParameter<PercentValue> MutationProbabilityParameter {
55      get { return (IValueParameter<PercentValue>)Parameters["MutationProbability"]; }
56    }
57    public IConstrainedValueParameter<IManipulator> MutatorParameter {
58      get { return (IConstrainedValueParameter<IManipulator>)Parameters["Mutator"]; }
59    }
60    private IValueParameter<IntValue> ElitesParameter {
61      get { return (IValueParameter<IntValue>)Parameters["Elites"]; }
62    }
63    private IFixedValueParameter<BoolValue> ReevaluateElitesParameter {
64      get { return (IFixedValueParameter<BoolValue>)Parameters["ReevaluateElites"]; }
65    }
66    private IFixedValueParameter<IntValue> MaximumGenerationsParameter {
67      get { return (IFixedValueParameter<IntValue>)Parameters["MaximumGenerations"]; }
68    }
69    private ValueLookupParameter<DoubleValue> SuccessRatioParameter {
70      get { return (ValueLookupParameter<DoubleValue>)Parameters["SuccessRatio"]; }
71    }
72    private ValueLookupParameter<DoubleValue> ComparisonFactorLowerBoundParameter {
73      get { return (ValueLookupParameter<DoubleValue>)Parameters["ComparisonFactorLowerBound"]; }
74    }
75    private ValueLookupParameter<DoubleValue> ComparisonFactorUpperBoundParameter {
76      get { return (ValueLookupParameter<DoubleValue>)Parameters["ComparisonFactorUpperBound"]; }
77    }
78    public IConstrainedValueParameter<IDiscreteDoubleValueModifier> ComparisonFactorModifierParameter {
79      get { return (IConstrainedValueParameter<IDiscreteDoubleValueModifier>)Parameters["ComparisonFactorModifier"]; }
80    }
81    private IFixedValueParameter<DoubleValue> MaximumSelectionPressureParameter {
82      get { return (IFixedValueParameter<DoubleValue>)Parameters["MaximumSelectionPressure"]; }
83    }
84    private ValueLookupParameter<BoolValue> OffspringSelectionBeforeMutationParameter {
85      get { return (ValueLookupParameter<BoolValue>)Parameters["OffspringSelectionBeforeMutation"]; }
86    }
87    private ValueLookupParameter<IntValue> SelectedParentsParameter {
88      get { return (ValueLookupParameter<IntValue>)Parameters["SelectedParents"]; }
89    }
90    private IValueParameter<IntValue> MaximumEvaluatedSolutionsParameter {
91      get { return (IValueParameter<IntValue>)Parameters["MaximumEvaluatedSolutions"]; }
92    }
93    private IFixedValueParameter<BoolValue> FillPopulationWithParentsParameter {
94      get { return (IFixedValueParameter<BoolValue>)Parameters["FillPopulationWithParents"]; }
95    }
96    #endregion
97
98    #region Properties
99    public IntArray PopulationSize {
100      get { return PopulationSizeParameter.Value; }
101      set { PopulationSizeParameter.Value = value; }
102    }
103    public ISelector Selector {
104      get { return SelectorParameter.Value; }
105      set { SelectorParameter.Value = value; }
106    }
107    public ICrossover Crossover {
108      get { return CrossoverParameter.Value; }
109      set { CrossoverParameter.Value = value; }
110    }
111    public PercentValue MutationProbability {
112      get { return MutationProbabilityParameter.Value; }
113      set { MutationProbabilityParameter.Value = value; }
114    }
115    public IManipulator Mutator {
116      get { return MutatorParameter.Value; }
117      set { MutatorParameter.Value = value; }
118    }
119    public IntValue Elites {
120      get { return ElitesParameter.Value; }
121      set { ElitesParameter.Value = value; }
122    }
123    public bool ReevaluteElites {
124      get { return ReevaluateElitesParameter.Value.Value; }
125      set { ReevaluateElitesParameter.Value.Value = value; }
126    }
127    public int MaximumGenerations {
128      get { return MaximumGenerationsParameter.Value.Value; }
129      set { MaximumGenerationsParameter.Value.Value = value; }
130    }
131    public DoubleValue SuccessRatio {
132      get { return SuccessRatioParameter.Value; }
133      set { SuccessRatioParameter.Value = value; }
134    }
135    public DoubleValue ComparisonFactorLowerBound {
136      get { return ComparisonFactorLowerBoundParameter.Value; }
137      set { ComparisonFactorLowerBoundParameter.Value = value; }
138    }
139    public DoubleValue ComparisonFactorUpperBound {
140      get { return ComparisonFactorUpperBoundParameter.Value; }
141      set { ComparisonFactorUpperBoundParameter.Value = value; }
142    }
143    public IDiscreteDoubleValueModifier ComparisonFactorModifier {
144      get { return ComparisonFactorModifierParameter.Value; }
145      set { ComparisonFactorModifierParameter.Value = value; }
146    }
147    public double MaximumSelectionPressure {
148      get { return MaximumSelectionPressureParameter.Value.Value; }
149      set { MaximumSelectionPressureParameter.Value.Value = value; }
150    }
151    public BoolValue OffspringSelectionBeforeMutation {
152      get { return OffspringSelectionBeforeMutationParameter.Value; }
153      set { OffspringSelectionBeforeMutationParameter.Value = value; }
154    }
155    public IntValue SelectedParents {
156      get { return SelectedParentsParameter.Value; }
157      set { SelectedParentsParameter.Value = value; }
158    }
159    public bool FillPopulationWithParents {
160      get { return FillPopulationWithParentsParameter.Value.Value; }
161      set { FillPopulationWithParentsParameter.Value.Value = value; }
162    }
163
164    private AlpsOffspringSelectionGeneticAlgorithmMainLoop MainLoop {
165      get { return OperatorGraph.Iterate().OfType<AlpsOffspringSelectionGeneticAlgorithmMainLoop>().First(); }
166    }
167    #endregion
168
169    [Storable]
170    private ValueAnalyzer layerSelectionPressureAnalyzer;
171    [Storable]
172    private SuccessfulOffspringAnalyzer successfulOffspringAnalyzer;
173
174    [Storable]
175    private ComparisonTerminator<IntValue> generationsTerminator;
176    //[Storable]private ComparisonTerminator<DoubleValue> selectionPressureTerminator;
177
178    [StorableConstructor]
179    private AlpsOffspringSelectionGeneticAlgorithm(bool deserializing)
180      : base(deserializing) { }
181    private AlpsOffspringSelectionGeneticAlgorithm(AlpsOffspringSelectionGeneticAlgorithm original, Cloner cloner)
182      : base(original, cloner) {
183      layerSelectionPressureAnalyzer = cloner.Clone(original.layerSelectionPressureAnalyzer);
184      successfulOffspringAnalyzer = cloner.Clone(original.successfulOffspringAnalyzer);
185      generationsTerminator = cloner.Clone(original.generationsTerminator);
186      //selectionPressureTerminator = cloner.Clone(original.selectionPressureTerminator);
187      Initialize();
188    }
189    public override IDeepCloneable Clone(Cloner cloner) {
190      return new AlpsOffspringSelectionGeneticAlgorithm(this, cloner);
191    }
192
193    public AlpsOffspringSelectionGeneticAlgorithm()
194      : base() {
195      Parameters.Add(new ValueParameter<IntArray>("PopulationSize", "The size of the population of solutions each layer.", new IntArray(new[] { 100 })));
196      Parameters.Add(new ConstrainedValueParameter<ISelector>("Selector", "The operator used to select solutions for reproduction."));
197      Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions."));
198      Parameters.Add(new ValueParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution.", new PercentValue(0.05)));
199      Parameters.Add(new OptionalConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions."));
200      Parameters.Add(new ValueParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.", new IntValue(1)));
201      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 });
202      Parameters.Add(new FixedValueParameter<IntValue>("MaximumGenerations", "The maximum number of generations which should be processed.", new IntValue(1000)));
203      Parameters.Add(new ValueLookupParameter<DoubleValue>("SuccessRatio", "The ratio of successful to total children that should be achieved.", new DoubleValue(1)));
204      Parameters.Add(new ValueLookupParameter<DoubleValue>("ComparisonFactorLowerBound", "The lower bound of the comparison factor (start).", new DoubleValue(0)));
205      Parameters.Add(new ValueLookupParameter<DoubleValue>("ComparisonFactorUpperBound", "The upper bound of the comparison factor (end).", new DoubleValue(1)));
206      Parameters.Add(new OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier>("ComparisonFactorModifier", "The operator used to modify the comparison factor.", new ItemSet<IDiscreteDoubleValueModifier>(new IDiscreteDoubleValueModifier[] { new LinearDiscreteDoubleValueModifier() }), new LinearDiscreteDoubleValueModifier()));
207      Parameters.Add(new FixedValueParameter<DoubleValue>("MaximumSelectionPressure", "The maximum selection pressure that terminates the algorithm.", new DoubleValue(100)));
208      Parameters.Add(new ValueLookupParameter<BoolValue>("OffspringSelectionBeforeMutation", "True if the offspring selection step should be applied before mutation, false if it should be applied after mutation.", new BoolValue(false)));
209      Parameters.Add(new ValueLookupParameter<IntValue>("SelectedParents", "How much parents should be selected each time the offspring selection step is performed until the population is filled. This parameter should be about the same or twice the size of PopulationSize for smaller problems, and less for large problems.", new IntValue(200)));
210      Parameters.Add(new FixedValueParameter<BoolValue>("FillPopulationWithParents", "True if the population should be filled with parent individual or false if worse children should be used when the maximum selection pressure is exceeded.", new BoolValue(false)) { Hidden = true });
211
212      var globalRandomCreator = new RandomCreator();
213      var layer0Creator = new SubScopesCreator() { Name = "Create Layer Zero" };
214      var layer0Processor = new LayerUniformSubScopesProcessor();
215      var localRandomCreator = new LocalRandomCreator();
216      var layerVariableCreator = new VariableCreator();
217      var layerSolutionsCreator = new SolutionsCreator();
218      var initializeAgeProcessor = new UniformSubScopesProcessor();
219      var initializeAge = new VariableCreator() { Name = "Initialize Age" };
220      var initializeLayerPopulationSize = new SubScopesCounter() { Name = "Init LayerPopulationCounter" };
221      var initializeLocalEvaluatedSolutions = new Assigner() { Name = "Initialize LayerEvaluatedSolutions" };
222      var initializeGlobalEvaluatedSolutions = new DataReducer() { Name = "Initialize EvaluatedSolutions" };
223      var resultsCollector = new ResultsCollector();
224      var mainLoop = new AlpsOffspringSelectionGeneticAlgorithmMainLoop();
225
226      OperatorGraph.InitialOperator = globalRandomCreator;
227
228      globalRandomCreator.RandomParameter.ActualName = "GlobalRandom";
229      globalRandomCreator.SeedParameter.Value = null;
230      globalRandomCreator.SetSeedRandomlyParameter.Value = null;
231      globalRandomCreator.Successor = layer0Creator;
232
233      layer0Creator.NumberOfSubScopesParameter.Value = new IntValue(1);
234      layer0Creator.Successor = layer0Processor;
235
236      layer0Processor.Operator = localRandomCreator;
237      layer0Processor.Successor = initializeGlobalEvaluatedSolutions;
238
239      localRandomCreator.Successor = layerVariableCreator;
240
241      layerVariableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Layer", new IntValue(0)));
242      layerVariableCreator.Successor = layerSolutionsCreator;
243
244      layerSolutionsCreator.NumberOfSolutionsParameter.ActualName = PopulationSizeParameter.Name;
245      layerSolutionsCreator.Successor = initializeAgeProcessor;
246
247      initializeAgeProcessor.Operator = initializeAge;
248      initializeAgeProcessor.Successor = initializeLayerPopulationSize;
249
250      initializeLayerPopulationSize.ValueParameter.ActualName = "LayerPopulationSize";
251      initializeLayerPopulationSize.Successor = initializeLocalEvaluatedSolutions;
252
253      initializeAge.CollectedValues.Add(new ValueParameter<IntValue>("Age", new IntValue(0)));
254      initializeAge.Successor = null;
255
256      initializeLocalEvaluatedSolutions.LeftSideParameter.ActualName = "LayerEvaluatedSolutions";
257      initializeLocalEvaluatedSolutions.RightSideParameter.ActualName = "LayerPopulationSize";
258      initializeLocalEvaluatedSolutions.Successor = null;
259
260      initializeGlobalEvaluatedSolutions.ReductionOperation.Value.Value = ReductionOperations.Sum;
261      initializeGlobalEvaluatedSolutions.TargetOperation.Value.Value = ReductionOperations.Assign;
262      initializeGlobalEvaluatedSolutions.ParameterToReduce.ActualName = "LayerEvaluatedSolutions";
263      initializeGlobalEvaluatedSolutions.TargetParameter.ActualName = "EvaluatedSolutions";
264      initializeGlobalEvaluatedSolutions.Successor = resultsCollector;
265
266      resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Evaluated Solutions", null, "EvaluatedSolutions"));
267      resultsCollector.Successor = mainLoop;
268
269      mainLoop.ComparisonFactorModifierParameter.ActualName = ComparisonFactorModifierParameter.Name;
270      mainLoop.ComparisonFactorParameter.ActualName = "ComparisonFactor";
271      mainLoop.ComparisonFactorStartParameter.ActualName = ComparisonFactorLowerBoundParameter.Name;
272
273
274      foreach (var selector in ApplicationManager.Manager.GetInstances<ISelector>().Where(s => !(s is IMultiObjectiveSelector)).OrderBy(s => Name))
275        SelectorParameter.ValidValues.Add(selector);
276      var tournamentSelector = SelectorParameter.ValidValues.OfType<TournamentSelector>().FirstOrDefault();
277      if (tournamentSelector != null) {
278        tournamentSelector.GroupSizeParameter.Value = new IntValue(4);
279        SelectorParameter.Value = tournamentSelector;
280      }
281      ParameterizeSelectors();
282
283      foreach (IDiscreteDoubleValueModifier modifier in ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>().OrderBy(x => x.Name))
284        ComparisonFactorModifierParameter.ValidValues.Add(modifier);
285      IDiscreteDoubleValueModifier linearModifier = ComparisonFactorModifierParameter.ValidValues.FirstOrDefault(x => x.GetType().Name.Equals("LinearDiscreteDoubleValueModifier"));
286      if (linearModifier != null) ComparisonFactorModifierParameter.Value = linearModifier;
287      ParameterizeComparisonFactorModifiers();
288
289      layerSelectionPressureAnalyzer = new ValueAnalyzer();
290      successfulOffspringAnalyzer = new SuccessfulOffspringAnalyzer();
291      layerSelectionPressureAnalyzer.Name = "SelectionPressure Analyzer";
292      //layerSelectionPressureAnalyzer.ResultsParameter.ActualName = "Results";
293      layerSelectionPressureAnalyzer.ValueParameter.ActualName = "SelectionPressure";
294      layerSelectionPressureAnalyzer.ValueParameter.Depth = 0;
295      layerSelectionPressureAnalyzer.ValuesParameter.ActualName = "Selection Pressure History";
296      //successfulOffspringAnalyzer.ResultsParameter.ActualName = "Results";
297      successfulOffspringAnalyzer.GenerationsParameter.ActualName = "Generations";
298      successfulOffspringAnalyzer.SuccessfulOffspringFlagParameter.Value.Value = "SuccessfulOffspring";
299      successfulOffspringAnalyzer.DepthParameter.Value = new IntValue(1);
300
301      generationsTerminator = new ComparisonTerminator<IntValue>("Generations", ComparisonType.Less, MaximumGenerationsParameter) { Name = "Generations" };
302      //selectionPressureTerminator = new ComparisonTerminator<DoubleValue>("SelectionPressure", ComparisonType.Less, MaximumSelectionPressureParameter) { Name = "Selection Pressure" };
303
304      UpdateAnalyzers();
305      UpdateTerminators();
306
307      Initialize();
308    }
309
310    #region Events
311    protected override void OnProblemChanged() {
312      base.OnProblemChanged();
313      ParameterizeSolutionsCreator();
314      ParameterizeMainLoop();
315      ParameterizeSelectors();
316      ParameterizeIterationBasedOperators();
317      UpdateCrossovers();
318      UpdateMutators();
319      UpdateAnalyzers();
320      UpdateTerminators();
321    }
322    protected override void Problem_SolutionCreatorChanged(object sender, EventArgs e) {
323      base.Problem_SolutionCreatorChanged(sender, e);
324      ParameterizeSolutionsCreator();
325    }
326    protected override void Problem_EvaluatorChanged(object sender, EventArgs e) {
327      base.Problem_EvaluatorChanged(sender, e);
328      ParameterizeSolutionsCreator();
329      ParameterizeMainLoop();
330      ParameterizeSelectors();
331    }
332    protected override void Problem_OperatorsChanged(object sender, EventArgs e) {
333      base.Problem_OperatorsChanged(sender, e);
334      ParameterizeIterationBasedOperators();
335      UpdateCrossovers();
336      UpdateMutators();
337      UpdateAnalyzers();
338      UpdateTerminators();
339    }
340    protected override void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
341      base.Evaluator_QualityParameter_ActualNameChanged(sender, e);
342      ParameterizeMainLoop();
343      ParameterizeSelectors();
344    }
345    #endregion
346    #region Parameterization
347    private void Initialize() {
348    }
349    private void ParameterizeSolutionsCreator() {
350      MainLoop.LayerUpdator.SolutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
351      MainLoop.LayerUpdator.SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name;
352    }
353    private void ParameterizeMainLoop() {
354      MainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
355      MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
356      MainLoop.MainOperator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
357      MainLoop.MainOperator.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
358      MainLoop.MainOperator.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
359      MainLoop.LayerUpdator.SolutionsCreator.NumberOfSolutionsParameter.ActualName = PopulationSizeParameter.Name;
360    }
361    private void ParameterizeSelectors() {
362      foreach (var selector in SelectorParameter.ValidValues) {
363        selector.CopySelected = new BoolValue(true);
364        selector.NumberOfSelectedSubScopesParameter.Value = null;
365        selector.NumberOfSelectedSubScopesParameter.ActualName = SelectedParentsParameter.Name;
366        selector.NumberOfSelectedSubScopesParameter.Hidden = true;
367        ParameterizeStochasticOperatorForLayer(selector);
368      }
369      if (Problem != null) {
370        foreach (var selector in SelectorParameter.ValidValues.OfType<ISingleObjectiveSelector>()) {
371          selector.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
372          selector.MaximizationParameter.Hidden = true;
373          selector.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
374          selector.QualityParameter.Hidden = true;
375        }
376      }
377    }
378    private void ParameterizeComparisonFactorModifiers() {
379      foreach (IDiscreteDoubleValueModifier modifier in ComparisonFactorModifierParameter.ValidValues) {
380        modifier.IndexParameter.ActualName = "Generations";
381        modifier.EndIndexParameter.ActualName = MaximumGenerationsParameter.Name;
382        modifier.EndValueParameter.ActualName = ComparisonFactorUpperBoundParameter.Name;
383        modifier.StartIndexParameter.Value = new IntValue(0);
384        modifier.StartValueParameter.ActualName = ComparisonFactorLowerBoundParameter.Name;
385        modifier.ValueParameter.ActualName = "ComparisonFactor";
386      }
387    }
388    private void ParameterizeIterationBasedOperators() {
389      if (Problem != null) {
390        foreach (var @operator in Problem.Operators.OfType<IIterationBasedOperator>()) {
391          @operator.IterationsParameter.ActualName = "Generations";
392          @operator.IterationsParameter.Hidden = true;
393          @operator.MaximumIterationsParameter.ActualName = MaximumGenerationsParameter.Name;
394          @operator.MaximumIterationsParameter.Hidden = true;
395        }
396      }
397    }
398
399    protected override ReductionOperations GetAgeInheritanceReduction(AgeInheritance ageInheritance) {
400      switch (ageInheritance) {
401        case ALPS.AgeInheritance.Older: return ReductionOperations.Max;
402        case ALPS.AgeInheritance.Agerage: return ReductionOperations.Avg;
403        case ALPS.AgeInheritance.Younger: return ReductionOperations.Min;
404        default: throw new NotSupportedException("AgeInheritance " + ageInheritance + " is not supported.");
405      }
406    }
407    #endregion
408
409    #region Updates
410    private void UpdateTerminators() {
411      var newTerminators = new Dictionary<ITerminator, bool> {
412        {generationsTerminator, !Terminators.Operators.Contains(generationsTerminator) || Terminators.Operators.ItemChecked(generationsTerminator)},
413        //{selectionPressureTerminator, !Terminators.Operators.Contains(generationsTerminator) || Terminators.Operators.ItemChecked(selectionPressureTerminator)},
414        {evaluationsTerminator, Terminators.Operators.Contains(evaluationsTerminator) && Terminators.Operators.ItemChecked(evaluationsTerminator)},
415        {qualityTerminator, Terminators.Operators.Contains(qualityTerminator) && Terminators.Operators.ItemChecked(qualityTerminator) },
416        {executionTimeTerminator, Terminators.Operators.Contains(executionTimeTerminator) && Terminators.Operators.ItemChecked(executionTimeTerminator)}
417      };
418      if (Problem != null) {
419        foreach (var terminator in Problem.Operators.OfType<ITerminator>())
420          newTerminators.Add(terminator, !Terminators.Operators.Contains(terminator) || Terminators.Operators.ItemChecked(terminator));
421      }
422
423      Terminators.Operators.Clear();
424
425      foreach (var newTerminator in newTerminators)
426        Terminators.Operators.Add(newTerminator.Key, newTerminator.Value);
427    }
428    private void UpdateCrossovers() {
429      var oldCrossover = CrossoverParameter.Value;
430      var defaultCrossover = Problem.Operators.OfType<ICrossover>().FirstOrDefault();
431      CrossoverParameter.ValidValues.Clear();
432      foreach (var crossover in Problem.Operators.OfType<ICrossover>().OrderBy(c => c.Name)) {
433        ParameterizeStochasticOperatorForLayer(crossover);
434        CrossoverParameter.ValidValues.Add(crossover);
435      }
436      if (oldCrossover != null) {
437        var crossover = CrossoverParameter.ValidValues.FirstOrDefault(c => c.GetType() == oldCrossover.GetType());
438        if (crossover != null)
439          CrossoverParameter.Value = crossover;
440        else
441          oldCrossover = null;
442      }
443      if (oldCrossover == null && defaultCrossover != null)
444        CrossoverParameter.Value = defaultCrossover;
445    }
446    private void UpdateMutators() {
447      var oldMutator = MutatorParameter.Value;
448      MutatorParameter.ValidValues.Clear();
449      foreach (var mutator in Problem.Operators.OfType<IManipulator>().OrderBy(m => m.Name)) {
450        ParameterizeStochasticOperatorForLayer(mutator);
451        MutatorParameter.ValidValues.Add(mutator);
452      }
453      if (oldMutator != null) {
454        var mutator = MutatorParameter.ValidValues.FirstOrDefault(m => m.GetType() == oldMutator.GetType());
455        if (mutator != null)
456          MutatorParameter.Value = mutator;
457      }
458    }
459    private void UpdateAnalyzers() {
460      LayerAnalyzer.Operators.Add(layerSelectionPressureAnalyzer, layerSelectionPressureAnalyzer.EnabledByDefault);
461      layerSelectionPressureAnalyzer.ValueParameter.Depth = 0; // Correct Depth because the depth of layer-analyzers is automatically set to 1
462      LayerAnalyzer.Operators.Add(successfulOffspringAnalyzer, successfulOffspringAnalyzer.EnabledByDefault);
463    }
464    #endregion
465  }
466}
Note: See TracBrowser for help on using the repository browser.