Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 12966 was 12572, checked in by pfleck, 9 years ago

#2375

  • Fixed Plugin dependencies.
  • Added missing Hook.
File size: 25.6 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    [StorableHook(HookType.AfterDeserialization)]
182    private void AfterDeserialization() {
183      Initialize();
184    }
185    private AlpsOffspringSelectionGeneticAlgorithm(AlpsOffspringSelectionGeneticAlgorithm original, Cloner cloner)
186      : base(original, cloner) {
187      layerSelectionPressureAnalyzer = cloner.Clone(original.layerSelectionPressureAnalyzer);
188      successfulOffspringAnalyzer = cloner.Clone(original.successfulOffspringAnalyzer);
189      generationsTerminator = cloner.Clone(original.generationsTerminator);
190      //selectionPressureTerminator = cloner.Clone(original.selectionPressureTerminator);
191      Initialize();
192    }
193    public override IDeepCloneable Clone(Cloner cloner) {
194      return new AlpsOffspringSelectionGeneticAlgorithm(this, cloner);
195    }
196
197    public AlpsOffspringSelectionGeneticAlgorithm()
198      : base() {
199      Parameters.Add(new ValueParameter<IntArray>("PopulationSize", "The size of the population of solutions each layer.", new IntArray(new[] { 100 })));
200      Parameters.Add(new ConstrainedValueParameter<ISelector>("Selector", "The operator used to select solutions for reproduction."));
201      Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions."));
202      Parameters.Add(new ValueParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution.", new PercentValue(0.05)));
203      Parameters.Add(new OptionalConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions."));
204      Parameters.Add(new ValueParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.", new IntValue(1)));
205      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 });
206      Parameters.Add(new FixedValueParameter<IntValue>("MaximumGenerations", "The maximum number of generations which should be processed.", new IntValue(1000)));
207      Parameters.Add(new ValueLookupParameter<DoubleValue>("SuccessRatio", "The ratio of successful to total children that should be achieved.", new DoubleValue(1)));
208      Parameters.Add(new ValueLookupParameter<DoubleValue>("ComparisonFactorLowerBound", "The lower bound of the comparison factor (start).", new DoubleValue(0)));
209      Parameters.Add(new ValueLookupParameter<DoubleValue>("ComparisonFactorUpperBound", "The upper bound of the comparison factor (end).", new DoubleValue(1)));
210      Parameters.Add(new OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier>("ComparisonFactorModifier", "The operator used to modify the comparison factor.", new ItemSet<IDiscreteDoubleValueModifier>(new IDiscreteDoubleValueModifier[] { new LinearDiscreteDoubleValueModifier() }), new LinearDiscreteDoubleValueModifier()));
211      Parameters.Add(new FixedValueParameter<DoubleValue>("MaximumSelectionPressure", "The maximum selection pressure that terminates the algorithm.", new DoubleValue(100)));
212      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)));
213      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)));
214      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 });
215
216      var globalRandomCreator = new RandomCreator();
217      var layer0Creator = new SubScopesCreator() { Name = "Create Layer Zero" };
218      var layer0Processor = new LayerUniformSubScopesProcessor();
219      var localRandomCreator = new LocalRandomCreator();
220      var layerVariableCreator = new VariableCreator();
221      var layerSolutionsCreator = new SolutionsCreator();
222      var initializeAgeProcessor = new UniformSubScopesProcessor();
223      var initializeAge = new VariableCreator() { Name = "Initialize Age" };
224      var initializeLayerPopulationSize = new SubScopesCounter() { Name = "Init LayerPopulationCounter" };
225      var initializeLocalEvaluatedSolutions = new Assigner() { Name = "Initialize LayerEvaluatedSolutions" };
226      var initializeGlobalEvaluatedSolutions = new DataReducer() { Name = "Initialize EvaluatedSolutions" };
227      var resultsCollector = new ResultsCollector();
228      var mainLoop = new AlpsOffspringSelectionGeneticAlgorithmMainLoop();
229
230      OperatorGraph.InitialOperator = globalRandomCreator;
231
232      globalRandomCreator.RandomParameter.ActualName = "GlobalRandom";
233      globalRandomCreator.SeedParameter.Value = null;
234      globalRandomCreator.SetSeedRandomlyParameter.Value = null;
235      globalRandomCreator.Successor = layer0Creator;
236
237      layer0Creator.NumberOfSubScopesParameter.Value = new IntValue(1);
238      layer0Creator.Successor = layer0Processor;
239
240      layer0Processor.Operator = localRandomCreator;
241      layer0Processor.Successor = initializeGlobalEvaluatedSolutions;
242
243      localRandomCreator.Successor = layerVariableCreator;
244
245      layerVariableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Layer", new IntValue(0)));
246      layerVariableCreator.Successor = layerSolutionsCreator;
247
248      layerSolutionsCreator.NumberOfSolutionsParameter.ActualName = PopulationSizeParameter.Name;
249      layerSolutionsCreator.Successor = initializeAgeProcessor;
250
251      initializeAgeProcessor.Operator = initializeAge;
252      initializeAgeProcessor.Successor = initializeLayerPopulationSize;
253
254      initializeLayerPopulationSize.ValueParameter.ActualName = "LayerPopulationSize";
255      initializeLayerPopulationSize.Successor = initializeLocalEvaluatedSolutions;
256
257      initializeAge.CollectedValues.Add(new ValueParameter<IntValue>("Age", new IntValue(0)));
258      initializeAge.Successor = null;
259
260      initializeLocalEvaluatedSolutions.LeftSideParameter.ActualName = "LayerEvaluatedSolutions";
261      initializeLocalEvaluatedSolutions.RightSideParameter.ActualName = "LayerPopulationSize";
262      initializeLocalEvaluatedSolutions.Successor = null;
263
264      initializeGlobalEvaluatedSolutions.ReductionOperation.Value.Value = ReductionOperations.Sum;
265      initializeGlobalEvaluatedSolutions.TargetOperation.Value.Value = ReductionOperations.Assign;
266      initializeGlobalEvaluatedSolutions.ParameterToReduce.ActualName = "LayerEvaluatedSolutions";
267      initializeGlobalEvaluatedSolutions.TargetParameter.ActualName = "EvaluatedSolutions";
268      initializeGlobalEvaluatedSolutions.Successor = resultsCollector;
269
270      resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Evaluated Solutions", null, "EvaluatedSolutions"));
271      resultsCollector.Successor = mainLoop;
272
273      mainLoop.ComparisonFactorModifierParameter.ActualName = ComparisonFactorModifierParameter.Name;
274      mainLoop.ComparisonFactorParameter.ActualName = "ComparisonFactor";
275      mainLoop.ComparisonFactorStartParameter.ActualName = ComparisonFactorLowerBoundParameter.Name;
276
277
278      foreach (var selector in ApplicationManager.Manager.GetInstances<ISelector>().Where(s => !(s is IMultiObjectiveSelector)).OrderBy(s => Name))
279        SelectorParameter.ValidValues.Add(selector);
280      var tournamentSelector = SelectorParameter.ValidValues.OfType<TournamentSelector>().FirstOrDefault();
281      if (tournamentSelector != null) {
282        tournamentSelector.GroupSizeParameter.Value = new IntValue(4);
283        SelectorParameter.Value = tournamentSelector;
284      }
285      ParameterizeSelectors();
286
287      foreach (IDiscreteDoubleValueModifier modifier in ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>().OrderBy(x => x.Name))
288        ComparisonFactorModifierParameter.ValidValues.Add(modifier);
289      IDiscreteDoubleValueModifier linearModifier = ComparisonFactorModifierParameter.ValidValues.FirstOrDefault(x => x.GetType().Name.Equals("LinearDiscreteDoubleValueModifier"));
290      if (linearModifier != null) ComparisonFactorModifierParameter.Value = linearModifier;
291      ParameterizeComparisonFactorModifiers();
292
293      layerSelectionPressureAnalyzer = new ValueAnalyzer();
294      successfulOffspringAnalyzer = new SuccessfulOffspringAnalyzer();
295      layerSelectionPressureAnalyzer.Name = "SelectionPressure Analyzer";
296      //layerSelectionPressureAnalyzer.ResultsParameter.ActualName = "Results";
297      layerSelectionPressureAnalyzer.ValueParameter.ActualName = "SelectionPressure";
298      layerSelectionPressureAnalyzer.ValueParameter.Depth = 0;
299      layerSelectionPressureAnalyzer.ValuesParameter.ActualName = "Selection Pressure History";
300      //successfulOffspringAnalyzer.ResultsParameter.ActualName = "Results";
301      successfulOffspringAnalyzer.GenerationsParameter.ActualName = "Generations";
302      successfulOffspringAnalyzer.SuccessfulOffspringFlagParameter.Value.Value = "SuccessfulOffspring";
303      successfulOffspringAnalyzer.DepthParameter.Value = new IntValue(1);
304
305      generationsTerminator = new ComparisonTerminator<IntValue>("Generations", ComparisonType.Less, MaximumGenerationsParameter) { Name = "Generations" };
306      //selectionPressureTerminator = new ComparisonTerminator<DoubleValue>("SelectionPressure", ComparisonType.Less, MaximumSelectionPressureParameter) { Name = "Selection Pressure" };
307
308      UpdateAnalyzers();
309      UpdateTerminators();
310
311      Initialize();
312    }
313
314    #region Events
315    protected override void OnProblemChanged() {
316      base.OnProblemChanged();
317      ParameterizeSolutionsCreator();
318      ParameterizeMainLoop();
319      ParameterizeSelectors();
320      ParameterizeIterationBasedOperators();
321      UpdateCrossovers();
322      UpdateMutators();
323      UpdateAnalyzers();
324      UpdateTerminators();
325    }
326    protected override void Problem_SolutionCreatorChanged(object sender, EventArgs e) {
327      base.Problem_SolutionCreatorChanged(sender, e);
328      ParameterizeSolutionsCreator();
329    }
330    protected override void Problem_EvaluatorChanged(object sender, EventArgs e) {
331      base.Problem_EvaluatorChanged(sender, e);
332      ParameterizeSolutionsCreator();
333      ParameterizeMainLoop();
334      ParameterizeSelectors();
335    }
336    protected override void Problem_OperatorsChanged(object sender, EventArgs e) {
337      base.Problem_OperatorsChanged(sender, e);
338      ParameterizeIterationBasedOperators();
339      UpdateCrossovers();
340      UpdateMutators();
341      UpdateAnalyzers();
342      UpdateTerminators();
343    }
344    protected override void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
345      base.Evaluator_QualityParameter_ActualNameChanged(sender, e);
346      ParameterizeMainLoop();
347      ParameterizeSelectors();
348    }
349    #endregion
350    #region Parameterization
351    private void Initialize() {
352    }
353    private void ParameterizeSolutionsCreator() {
354      MainLoop.LayerUpdator.SolutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
355      MainLoop.LayerUpdator.SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name;
356    }
357    private void ParameterizeMainLoop() {
358      MainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
359      MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
360      MainLoop.MainOperator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
361      MainLoop.MainOperator.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
362      MainLoop.MainOperator.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
363      MainLoop.LayerUpdator.SolutionsCreator.NumberOfSolutionsParameter.ActualName = PopulationSizeParameter.Name;
364    }
365    private void ParameterizeSelectors() {
366      foreach (var selector in SelectorParameter.ValidValues) {
367        selector.CopySelected = new BoolValue(true);
368        selector.NumberOfSelectedSubScopesParameter.Value = null;
369        selector.NumberOfSelectedSubScopesParameter.ActualName = SelectedParentsParameter.Name;
370        selector.NumberOfSelectedSubScopesParameter.Hidden = true;
371        ParameterizeStochasticOperatorForLayer(selector);
372      }
373      if (Problem != null) {
374        foreach (var selector in SelectorParameter.ValidValues.OfType<ISingleObjectiveSelector>()) {
375          selector.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
376          selector.MaximizationParameter.Hidden = true;
377          selector.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
378          selector.QualityParameter.Hidden = true;
379        }
380      }
381    }
382    private void ParameterizeComparisonFactorModifiers() {
383      foreach (IDiscreteDoubleValueModifier modifier in ComparisonFactorModifierParameter.ValidValues) {
384        modifier.IndexParameter.ActualName = "Generations";
385        modifier.EndIndexParameter.ActualName = MaximumGenerationsParameter.Name;
386        modifier.EndValueParameter.ActualName = ComparisonFactorUpperBoundParameter.Name;
387        modifier.StartIndexParameter.Value = new IntValue(0);
388        modifier.StartValueParameter.ActualName = ComparisonFactorLowerBoundParameter.Name;
389        modifier.ValueParameter.ActualName = "ComparisonFactor";
390      }
391    }
392    private void ParameterizeIterationBasedOperators() {
393      if (Problem != null) {
394        foreach (var @operator in Problem.Operators.OfType<IIterationBasedOperator>()) {
395          @operator.IterationsParameter.ActualName = "Generations";
396          @operator.IterationsParameter.Hidden = true;
397          @operator.MaximumIterationsParameter.ActualName = MaximumGenerationsParameter.Name;
398          @operator.MaximumIterationsParameter.Hidden = true;
399        }
400      }
401    }
402
403    protected override ReductionOperations GetAgeInheritanceReduction(AgeInheritance ageInheritance) {
404      switch (ageInheritance) {
405        case ALPS.AgeInheritance.Older: return ReductionOperations.Max;
406        case ALPS.AgeInheritance.Agerage: return ReductionOperations.Avg;
407        case ALPS.AgeInheritance.Younger: return ReductionOperations.Min;
408        default: throw new NotSupportedException("AgeInheritance " + ageInheritance + " is not supported.");
409      }
410    }
411    #endregion
412
413    #region Updates
414    private void UpdateTerminators() {
415      var newTerminators = new Dictionary<ITerminator, bool> {
416        {generationsTerminator, !Terminators.Operators.Contains(generationsTerminator) || Terminators.Operators.ItemChecked(generationsTerminator)},
417        //{selectionPressureTerminator, !Terminators.Operators.Contains(generationsTerminator) || Terminators.Operators.ItemChecked(selectionPressureTerminator)},
418        {evaluationsTerminator, Terminators.Operators.Contains(evaluationsTerminator) && Terminators.Operators.ItemChecked(evaluationsTerminator)},
419        {qualityTerminator, Terminators.Operators.Contains(qualityTerminator) && Terminators.Operators.ItemChecked(qualityTerminator) },
420        {executionTimeTerminator, Terminators.Operators.Contains(executionTimeTerminator) && Terminators.Operators.ItemChecked(executionTimeTerminator)}
421      };
422      if (Problem != null) {
423        foreach (var terminator in Problem.Operators.OfType<ITerminator>())
424          newTerminators.Add(terminator, !Terminators.Operators.Contains(terminator) || Terminators.Operators.ItemChecked(terminator));
425      }
426
427      Terminators.Operators.Clear();
428
429      foreach (var newTerminator in newTerminators)
430        Terminators.Operators.Add(newTerminator.Key, newTerminator.Value);
431    }
432    private void UpdateCrossovers() {
433      var oldCrossover = CrossoverParameter.Value;
434      var defaultCrossover = Problem.Operators.OfType<ICrossover>().FirstOrDefault();
435      CrossoverParameter.ValidValues.Clear();
436      foreach (var crossover in Problem.Operators.OfType<ICrossover>().OrderBy(c => c.Name)) {
437        ParameterizeStochasticOperatorForLayer(crossover);
438        CrossoverParameter.ValidValues.Add(crossover);
439      }
440      if (oldCrossover != null) {
441        var crossover = CrossoverParameter.ValidValues.FirstOrDefault(c => c.GetType() == oldCrossover.GetType());
442        if (crossover != null)
443          CrossoverParameter.Value = crossover;
444        else
445          oldCrossover = null;
446      }
447      if (oldCrossover == null && defaultCrossover != null)
448        CrossoverParameter.Value = defaultCrossover;
449    }
450    private void UpdateMutators() {
451      var oldMutator = MutatorParameter.Value;
452      MutatorParameter.ValidValues.Clear();
453      foreach (var mutator in Problem.Operators.OfType<IManipulator>().OrderBy(m => m.Name)) {
454        ParameterizeStochasticOperatorForLayer(mutator);
455        MutatorParameter.ValidValues.Add(mutator);
456      }
457      if (oldMutator != null) {
458        var mutator = MutatorParameter.ValidValues.FirstOrDefault(m => m.GetType() == oldMutator.GetType());
459        if (mutator != null)
460          MutatorParameter.Value = mutator;
461      }
462    }
463    private void UpdateAnalyzers() {
464      LayerAnalyzer.Operators.Add(layerSelectionPressureAnalyzer, layerSelectionPressureAnalyzer.EnabledByDefault);
465      layerSelectionPressureAnalyzer.ValueParameter.Depth = 0; // Correct Depth because the depth of layer-analyzers is automatically set to 1
466      LayerAnalyzer.Operators.Add(successfulOffspringAnalyzer, successfulOffspringAnalyzer.EnabledByDefault);
467    }
468    #endregion
469  }
470}
Note: See TracBrowser for help on using the repository browser.