Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3/OffspringSelectionGeneticAlgorithm.cs @ 4437

Last change on this file since 4437 was 4437, checked in by swagner, 13 years ago

Implemented !IStorableContent separately for each algorithm (#1193)

File size: 23.6 KB
Line 
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;
24using HeuristicLab.Analysis;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HeuristicLab.Data;
28using HeuristicLab.Optimization;
29using HeuristicLab.Optimization.Operators;
30using HeuristicLab.Parameters;
31using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
32using HeuristicLab.PluginInfrastructure;
33using HeuristicLab.Random;
34
35namespace HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm {
36  /// <summary>
37  /// An offspring selection genetic algorithm.
38  /// </summary>
39  [Item("Offspring Selection Genetic Algorithm", "An offspring selection genetic algorithm (Affenzeller, M. et al. 2009. Genetic Algorithms and Genetic Programming - Modern Concepts and Practical Applications. CRC Press).")]
40  [Creatable("Algorithms")]
41  [StorableClass]
42  public sealed class OffspringSelectionGeneticAlgorithm : EngineAlgorithm, IStorableContent {
43    public string Filename { get; set; }
44
45    #region Problem Properties
46    public override Type ProblemType {
47      get { return typeof(ISingleObjectiveProblem); }
48    }
49    public new ISingleObjectiveProblem Problem {
50      get { return (ISingleObjectiveProblem)base.Problem; }
51      set { base.Problem = value; }
52    }
53    #endregion
54
55    #region Parameter Properties
56    private ValueParameter<IntValue> SeedParameter {
57      get { return (ValueParameter<IntValue>)Parameters["Seed"]; }
58    }
59    private ValueParameter<BoolValue> SetSeedRandomlyParameter {
60      get { return (ValueParameter<BoolValue>)Parameters["SetSeedRandomly"]; }
61    }
62    private ValueParameter<IntValue> PopulationSizeParameter {
63      get { return (ValueParameter<IntValue>)Parameters["PopulationSize"]; }
64    }
65    private ConstrainedValueParameter<ISelector> SelectorParameter {
66      get { return (ConstrainedValueParameter<ISelector>)Parameters["Selector"]; }
67    }
68    private ConstrainedValueParameter<ICrossover> CrossoverParameter {
69      get { return (ConstrainedValueParameter<ICrossover>)Parameters["Crossover"]; }
70    }
71    private ValueParameter<PercentValue> MutationProbabilityParameter {
72      get { return (ValueParameter<PercentValue>)Parameters["MutationProbability"]; }
73    }
74    private OptionalConstrainedValueParameter<IManipulator> MutatorParameter {
75      get { return (OptionalConstrainedValueParameter<IManipulator>)Parameters["Mutator"]; }
76    }
77    private ValueParameter<IntValue> ElitesParameter {
78      get { return (ValueParameter<IntValue>)Parameters["Elites"]; }
79    }
80    private ValueParameter<IntValue> MaximumGenerationsParameter {
81      get { return (ValueParameter<IntValue>)Parameters["MaximumGenerations"]; }
82    }
83    private ValueLookupParameter<DoubleValue> SuccessRatioParameter {
84      get { return (ValueLookupParameter<DoubleValue>)Parameters["SuccessRatio"]; }
85    }
86    private ValueLookupParameter<DoubleValue> ComparisonFactorLowerBoundParameter {
87      get { return (ValueLookupParameter<DoubleValue>)Parameters["ComparisonFactorLowerBound"]; }
88    }
89    private ValueLookupParameter<DoubleValue> ComparisonFactorUpperBoundParameter {
90      get { return (ValueLookupParameter<DoubleValue>)Parameters["ComparisonFactorUpperBound"]; }
91    }
92    private OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier> ComparisonFactorModifierParameter {
93      get { return (OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier>)Parameters["ComparisonFactorModifier"]; }
94    }
95    private ValueLookupParameter<DoubleValue> MaximumSelectionPressureParameter {
96      get { return (ValueLookupParameter<DoubleValue>)Parameters["MaximumSelectionPressure"]; }
97    }
98    private ValueLookupParameter<BoolValue> OffspringSelectionBeforeMutationParameter {
99      get { return (ValueLookupParameter<BoolValue>)Parameters["OffspringSelectionBeforeMutation"]; }
100    }
101    private ValueLookupParameter<IntValue> SelectedParentsParameter {
102      get { return (ValueLookupParameter<IntValue>)Parameters["SelectedParents"]; }
103    }
104    private ValueParameter<MultiAnalyzer> AnalyzerParameter {
105      get { return (ValueParameter<MultiAnalyzer>)Parameters["Analyzer"]; }
106    }
107    private ValueParameter<IntValue> MaximumEvaluatedSolutionsParameter {
108      get { return (ValueParameter<IntValue>)Parameters["MaximumEvaluatedSolutions"]; }
109    }
110    #endregion
111
112    #region Properties
113    public IntValue Seed {
114      get { return SeedParameter.Value; }
115      set { SeedParameter.Value = value; }
116    }
117    public BoolValue SetSeedRandomly {
118      get { return SetSeedRandomlyParameter.Value; }
119      set { SetSeedRandomlyParameter.Value = value; }
120    }
121    public IntValue PopulationSize {
122      get { return PopulationSizeParameter.Value; }
123      set { PopulationSizeParameter.Value = value; }
124    }
125    public ISelector Selector {
126      get { return SelectorParameter.Value; }
127      set { SelectorParameter.Value = value; }
128    }
129    public ICrossover Crossover {
130      get { return CrossoverParameter.Value; }
131      set { CrossoverParameter.Value = value; }
132    }
133    public PercentValue MutationProbability {
134      get { return MutationProbabilityParameter.Value; }
135      set { MutationProbabilityParameter.Value = value; }
136    }
137    public IManipulator Mutator {
138      get { return MutatorParameter.Value; }
139      set { MutatorParameter.Value = value; }
140    }
141    public IntValue Elites {
142      get { return ElitesParameter.Value; }
143      set { ElitesParameter.Value = value; }
144    }
145    public IntValue MaximumGenerations {
146      get { return MaximumGenerationsParameter.Value; }
147      set { MaximumGenerationsParameter.Value = value; }
148    }
149    public DoubleValue SuccessRatio {
150      get { return SuccessRatioParameter.Value; }
151      set { SuccessRatioParameter.Value = value; }
152    }
153    public DoubleValue ComparisonFactorLowerBound {
154      get { return ComparisonFactorLowerBoundParameter.Value; }
155      set { ComparisonFactorLowerBoundParameter.Value = value; }
156    }
157    public DoubleValue ComparisonFactorUpperBound {
158      get { return ComparisonFactorUpperBoundParameter.Value; }
159      set { ComparisonFactorUpperBoundParameter.Value = value; }
160    }
161    public IDiscreteDoubleValueModifier ComparisonFactorModifier {
162      get { return ComparisonFactorModifierParameter.Value; }
163      set { ComparisonFactorModifierParameter.Value = value; }
164    }
165    public DoubleValue MaximumSelectionPressure {
166      get { return MaximumSelectionPressureParameter.Value; }
167      set { MaximumSelectionPressureParameter.Value = value; }
168    }
169    public BoolValue OffspringSelectionBeforeMutation {
170      get { return OffspringSelectionBeforeMutationParameter.Value; }
171      set { OffspringSelectionBeforeMutationParameter.Value = value; }
172    }
173    public IntValue SelectedParents {
174      get { return SelectedParentsParameter.Value; }
175      set { SelectedParentsParameter.Value = value; }
176    }
177    public MultiAnalyzer Analyzer {
178      get { return AnalyzerParameter.Value; }
179      set { AnalyzerParameter.Value = value; }
180    }
181    public IntValue MaximumEvaluatedSolutions {
182      get { return MaximumEvaluatedSolutionsParameter.Value; }
183      set { MaximumEvaluatedSolutionsParameter.Value = value; }
184    }
185    private RandomCreator RandomCreator {
186      get { return (RandomCreator)OperatorGraph.InitialOperator; }
187    }
188    private SolutionsCreator SolutionsCreator {
189      get { return (SolutionsCreator)RandomCreator.Successor; }
190    }
191    private OffspringSelectionGeneticAlgorithmMainLoop MainLoop {
192      get { return (OffspringSelectionGeneticAlgorithmMainLoop)SolutionsCreator.Successor; }
193    }
194    [Storable]
195    private BestAverageWorstQualityAnalyzer qualityAnalyzer;
196    [Storable]
197    private ValueAnalyzer selectionPressureAnalyzer;
198    #endregion
199
200    [StorableConstructor]
201    private OffspringSelectionGeneticAlgorithm(bool deserializing) : base(deserializing) { }
202    public OffspringSelectionGeneticAlgorithm()
203      : base() {
204      Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
205      Parameters.Add(new ValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
206      Parameters.Add(new ValueParameter<IntValue>("PopulationSize", "The size of the population of solutions.", new IntValue(100)));
207      Parameters.Add(new ConstrainedValueParameter<ISelector>("Selector", "The operator used to select solutions for reproduction."));
208      Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions."));
209      Parameters.Add(new ValueParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution.", new PercentValue(0.05)));
210      Parameters.Add(new OptionalConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions."));
211      Parameters.Add(new ValueParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.", new IntValue(1)));
212      Parameters.Add(new ValueParameter<IntValue>("MaximumGenerations", "The maximum number of generations which should be processed.", new IntValue(1000)));
213      Parameters.Add(new ValueLookupParameter<DoubleValue>("SuccessRatio", "The ratio of successful to total children that should be achieved.", new DoubleValue(1)));
214      Parameters.Add(new ValueLookupParameter<DoubleValue>("ComparisonFactorLowerBound", "The lower bound of the comparison factor (start).", new DoubleValue(0)));
215      Parameters.Add(new ValueLookupParameter<DoubleValue>("ComparisonFactorUpperBound", "The upper bound of the comparison factor (end).", new DoubleValue(1)));
216      Parameters.Add(new OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier>("ComparisonFactorModifier", "The operator used to modify the comparison factor.", new ItemSet<IDiscreteDoubleValueModifier>(new IDiscreteDoubleValueModifier[] { new LinearDiscreteDoubleValueModifier() }), new LinearDiscreteDoubleValueModifier()));
217      Parameters.Add(new ValueLookupParameter<DoubleValue>("MaximumSelectionPressure", "The maximum selection pressure that terminates the algorithm.", new DoubleValue(100)));
218      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)));
219      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)));
220      Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze each generation.", new MultiAnalyzer()));
221      Parameters.Add(new ValueParameter<IntValue>("MaximumEvaluatedSolutions", "The maximum number of evaluated solutions (approximately).", new IntValue(int.MaxValue)));
222
223      RandomCreator randomCreator = new RandomCreator();
224      SolutionsCreator solutionsCreator = new SolutionsCreator();
225      OffspringSelectionGeneticAlgorithmMainLoop mainLoop = new OffspringSelectionGeneticAlgorithmMainLoop();
226      OperatorGraph.InitialOperator = randomCreator;
227
228      randomCreator.RandomParameter.ActualName = "Random";
229      randomCreator.SeedParameter.ActualName = SeedParameter.Name;
230      randomCreator.SeedParameter.Value = null;
231      randomCreator.SetSeedRandomlyParameter.ActualName = SetSeedRandomlyParameter.Name;
232      randomCreator.SetSeedRandomlyParameter.Value = null;
233      randomCreator.Successor = solutionsCreator;
234
235      solutionsCreator.NumberOfSolutionsParameter.ActualName = PopulationSizeParameter.Name;
236      solutionsCreator.Successor = mainLoop;
237
238      mainLoop.AnalyzerParameter.ActualName = AnalyzerParameter.Name;
239      mainLoop.ComparisonFactorModifierParameter.ActualName = ComparisonFactorModifierParameter.Name;
240      mainLoop.ComparisonFactorParameter.ActualName = "ComparisonFactor";
241      mainLoop.ComparisonFactorStartParameter.ActualName = ComparisonFactorLowerBoundParameter.Name;
242      mainLoop.CrossoverParameter.ActualName = CrossoverParameter.Name;
243      mainLoop.ElitesParameter.ActualName = ElitesParameter.Name;
244      mainLoop.MaximumGenerationsParameter.ActualName = MaximumGenerationsParameter.Name;
245      mainLoop.MaximumSelectionPressureParameter.ActualName = MaximumSelectionPressureParameter.Name;
246      mainLoop.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
247      mainLoop.MutatorParameter.ActualName = MutatorParameter.Name;
248      mainLoop.OffspringSelectionBeforeMutationParameter.ActualName = OffspringSelectionBeforeMutationParameter.Name;
249      mainLoop.RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
250      mainLoop.ResultsParameter.ActualName = "Results";
251      mainLoop.SelectorParameter.ActualName = SelectorParameter.Name;
252      mainLoop.SuccessRatioParameter.ActualName = SuccessRatioParameter.Name;
253
254      foreach (ISelector selector in ApplicationManager.Manager.GetInstances<ISelector>().Where(x => !(x is IMultiObjectiveSelector)).OrderBy(x => x.Name))
255        SelectorParameter.ValidValues.Add(selector);
256      ISelector proportionalSelector = SelectorParameter.ValidValues.FirstOrDefault(x => x.GetType().Name.Equals("ProportionalSelector"));
257      if (proportionalSelector != null) SelectorParameter.Value = proportionalSelector;
258      ParameterizeSelectors();
259
260      foreach (IDiscreteDoubleValueModifier modifier in ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>().OrderBy(x => x.Name))
261        ComparisonFactorModifierParameter.ValidValues.Add(modifier);
262      IDiscreteDoubleValueModifier linearModifier = ComparisonFactorModifierParameter.ValidValues.FirstOrDefault(x => x.GetType().Name.Equals("LinearDiscreteDoubleValueModifier"));
263      if (linearModifier != null) ComparisonFactorModifierParameter.Value = linearModifier;
264      ParameterizeComparisonFactorModifiers();
265
266      qualityAnalyzer = new BestAverageWorstQualityAnalyzer();
267      selectionPressureAnalyzer = new ValueAnalyzer();
268      ParameterizeAnalyzers();
269      UpdateAnalyzers();
270
271      Initialize();
272    }
273
274    public override IDeepCloneable Clone(Cloner cloner) {
275      OffspringSelectionGeneticAlgorithm clone = (OffspringSelectionGeneticAlgorithm)base.Clone(cloner);
276      clone.qualityAnalyzer = (BestAverageWorstQualityAnalyzer)cloner.Clone(qualityAnalyzer);
277      clone.selectionPressureAnalyzer = (ValueAnalyzer)cloner.Clone(selectionPressureAnalyzer);
278      clone.Initialize();
279      return clone;
280    }
281
282    public override void Prepare() {
283      if (Problem != null) base.Prepare();
284    }
285
286    #region Events
287    protected override void OnProblemChanged() {
288      ParameterizeStochasticOperator(Problem.SolutionCreator);
289      ParameterizeStochasticOperator(Problem.Evaluator);
290      foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
291      ParameterizeSolutionsCreator();
292      ParameterizMainLoop();
293      ParameterizeSelectors();
294      ParameterizeAnalyzers();
295      ParameterizeIterationBasedOperators();
296      UpdateCrossovers();
297      UpdateMutators();
298      UpdateAnalyzers();
299      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
300      base.OnProblemChanged();
301    }
302
303    protected override void Problem_SolutionCreatorChanged(object sender, EventArgs e) {
304      ParameterizeStochasticOperator(Problem.SolutionCreator);
305      ParameterizeSolutionsCreator();
306      base.Problem_SolutionCreatorChanged(sender, e);
307    }
308    protected override void Problem_EvaluatorChanged(object sender, EventArgs e) {
309      ParameterizeStochasticOperator(Problem.Evaluator);
310      ParameterizeSolutionsCreator();
311      ParameterizMainLoop();
312      ParameterizeSelectors();
313      ParameterizeAnalyzers();
314      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
315      base.Problem_EvaluatorChanged(sender, e);
316    }
317    protected override void Problem_OperatorsChanged(object sender, EventArgs e) {
318      foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
319      ParameterizeIterationBasedOperators();
320      UpdateCrossovers();
321      UpdateMutators();
322      UpdateAnalyzers();
323      base.Problem_OperatorsChanged(sender, e);
324    }
325    private void ElitesParameter_ValueChanged(object sender, EventArgs e) {
326      Elites.ValueChanged += new EventHandler(Elites_ValueChanged);
327      ParameterizeSelectors();
328    }
329    private void Elites_ValueChanged(object sender, EventArgs e) {
330      ParameterizeSelectors();
331    }
332    private void PopulationSizeParameter_ValueChanged(object sender, EventArgs e) {
333      PopulationSize.ValueChanged += new EventHandler(PopulationSize_ValueChanged);
334      ParameterizeSelectors();
335    }
336    private void PopulationSize_ValueChanged(object sender, EventArgs e) {
337      ParameterizeSelectors();
338    }
339    private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
340      ParameterizMainLoop();
341      ParameterizeSelectors();
342      ParameterizeAnalyzers();
343    }
344    #endregion
345
346    #region Helpers
347    [StorableHook(HookType.AfterDeserialization)]
348    private void Initialize() {
349      PopulationSizeParameter.ValueChanged += new EventHandler(PopulationSizeParameter_ValueChanged);
350      PopulationSize.ValueChanged += new EventHandler(PopulationSize_ValueChanged);
351      ElitesParameter.ValueChanged += new EventHandler(ElitesParameter_ValueChanged);
352      Elites.ValueChanged += new EventHandler(Elites_ValueChanged);
353      if (Problem != null) {
354        Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
355      }
356    }
357    private void ParameterizeSolutionsCreator() {
358      SolutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
359      SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name;
360    }
361    private void ParameterizMainLoop() {
362      MainLoop.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
363      MainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
364      MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
365    }
366    private void ParameterizeStochasticOperator(IOperator op) {
367      if (op is IStochasticOperator)
368        ((IStochasticOperator)op).RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
369    }
370    private void ParameterizeSelectors() {
371      foreach (ISelector selector in SelectorParameter.ValidValues) {
372        selector.CopySelected = new BoolValue(true);
373        selector.NumberOfSelectedSubScopesParameter.Value = null;
374        selector.NumberOfSelectedSubScopesParameter.ActualName = SelectedParentsParameter.Name;
375        ParameterizeStochasticOperator(selector);
376      }
377      if (Problem != null) {
378        foreach (ISingleObjectiveSelector selector in SelectorParameter.ValidValues.OfType<ISingleObjectiveSelector>()) {
379          selector.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
380          selector.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
381        }
382      }
383    }
384    private void ParameterizeAnalyzers() {
385      qualityAnalyzer.ResultsParameter.ActualName = "Results";
386      selectionPressureAnalyzer.Name = "SelectionPressure Analyzer";
387      selectionPressureAnalyzer.ResultsParameter.ActualName = "Results";
388      selectionPressureAnalyzer.ValueParameter.ActualName = "SelectionPressure";
389      selectionPressureAnalyzer.ValueParameter.Depth = 0;
390      selectionPressureAnalyzer.ValuesParameter.ActualName = "Selection Pressure History";
391      if (Problem != null) {
392        qualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
393        qualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
394        qualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
395      }
396    }
397    private void ParameterizeComparisonFactorModifiers() {
398      foreach (IDiscreteDoubleValueModifier modifier in ComparisonFactorModifierParameter.ValidValues) {
399        modifier.IndexParameter.ActualName = "Generations";
400        modifier.EndIndexParameter.ActualName = MaximumGenerationsParameter.Name;
401        modifier.EndValueParameter.ActualName = ComparisonFactorUpperBoundParameter.Name;
402        modifier.StartIndexParameter.Value = new IntValue(0);
403        modifier.StartValueParameter.ActualName = ComparisonFactorLowerBoundParameter.Name;
404        modifier.ValueParameter.ActualName = "ComparisonFactor";
405      }
406    }
407    private void ParameterizeIterationBasedOperators() {
408      if (Problem != null) {
409        foreach (IIterationBasedOperator op in Problem.Operators.OfType<IIterationBasedOperator>()) {
410          op.IterationsParameter.ActualName = "Generations";
411          op.MaximumIterationsParameter.ActualName = MaximumGenerationsParameter.Name;
412        }
413      }
414    }
415    private void UpdateCrossovers() {
416      ICrossover oldCrossover = CrossoverParameter.Value;
417      CrossoverParameter.ValidValues.Clear();
418      foreach (ICrossover crossover in Problem.Operators.OfType<ICrossover>().OrderBy(x => x.Name))
419        CrossoverParameter.ValidValues.Add(crossover);
420      if (oldCrossover != null) {
421        ICrossover crossover = CrossoverParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldCrossover.GetType());
422        if (crossover != null) CrossoverParameter.Value = crossover;
423      }
424    }
425    private void UpdateMutators() {
426      IManipulator oldMutator = MutatorParameter.Value;
427      MutatorParameter.ValidValues.Clear();
428      foreach (IManipulator mutator in Problem.Operators.OfType<IManipulator>().OrderBy(x => x.Name))
429        MutatorParameter.ValidValues.Add(mutator);
430      if (oldMutator != null) {
431        IManipulator mutator = MutatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMutator.GetType());
432        if (mutator != null) MutatorParameter.Value = mutator;
433      }
434    }
435    private void UpdateAnalyzers() {
436      Analyzer.Operators.Clear();
437      if (Problem != null) {
438        foreach (IAnalyzer analyzer in Problem.Operators.OfType<IAnalyzer>()) {
439          foreach (IScopeTreeLookupParameter param in analyzer.Parameters.OfType<IScopeTreeLookupParameter>())
440            param.Depth = 1;
441          Analyzer.Operators.Add(analyzer);
442        }
443      }
444      Analyzer.Operators.Add(qualityAnalyzer);
445      Analyzer.Operators.Add(selectionPressureAnalyzer);
446    }
447    #endregion
448  }
449}
Note: See TracBrowser for help on using the repository browser.