Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ParameterBinding/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3/OffspringSelectionGeneticAlgorithm.cs @ 7347

Last change on this file since 7347 was 4722, checked in by swagner, 14 years ago

Merged cloning refactoring branch back into trunk (#922)

File size: 23.7 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    [StorableHook(HookType.AfterDeserialization)]
203    private void AfterDeserialization() {
204      Initialize();
205    }
206    private OffspringSelectionGeneticAlgorithm(OffspringSelectionGeneticAlgorithm original, Cloner cloner)
207      : base(original, cloner) {
208      qualityAnalyzer = cloner.Clone(original.qualityAnalyzer);
209      selectionPressureAnalyzer = cloner.Clone(original.selectionPressureAnalyzer);
210      Initialize();
211    }
212    public override IDeepCloneable Clone(Cloner cloner) {
213      return new OffspringSelectionGeneticAlgorithm(this, cloner);
214    }
215    public OffspringSelectionGeneticAlgorithm()
216      : base() {
217      Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
218      Parameters.Add(new ValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
219      Parameters.Add(new ValueParameter<IntValue>("PopulationSize", "The size of the population of solutions.", new IntValue(100)));
220      Parameters.Add(new ConstrainedValueParameter<ISelector>("Selector", "The operator used to select solutions for reproduction."));
221      Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions."));
222      Parameters.Add(new ValueParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution.", new PercentValue(0.05)));
223      Parameters.Add(new OptionalConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions."));
224      Parameters.Add(new ValueParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.", new IntValue(1)));
225      Parameters.Add(new ValueParameter<IntValue>("MaximumGenerations", "The maximum number of generations which should be processed.", new IntValue(1000)));
226      Parameters.Add(new ValueLookupParameter<DoubleValue>("SuccessRatio", "The ratio of successful to total children that should be achieved.", new DoubleValue(1)));
227      Parameters.Add(new ValueLookupParameter<DoubleValue>("ComparisonFactorLowerBound", "The lower bound of the comparison factor (start).", new DoubleValue(0)));
228      Parameters.Add(new ValueLookupParameter<DoubleValue>("ComparisonFactorUpperBound", "The upper bound of the comparison factor (end).", new DoubleValue(1)));
229      Parameters.Add(new OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier>("ComparisonFactorModifier", "The operator used to modify the comparison factor.", new ItemSet<IDiscreteDoubleValueModifier>(new IDiscreteDoubleValueModifier[] { new LinearDiscreteDoubleValueModifier() }), new LinearDiscreteDoubleValueModifier()));
230      Parameters.Add(new ValueLookupParameter<DoubleValue>("MaximumSelectionPressure", "The maximum selection pressure that terminates the algorithm.", new DoubleValue(100)));
231      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)));
232      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)));
233      Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze each generation.", new MultiAnalyzer()));
234      Parameters.Add(new ValueParameter<IntValue>("MaximumEvaluatedSolutions", "The maximum number of evaluated solutions (approximately).", new IntValue(int.MaxValue)));
235
236      RandomCreator randomCreator = new RandomCreator();
237      SolutionsCreator solutionsCreator = new SolutionsCreator();
238      OffspringSelectionGeneticAlgorithmMainLoop mainLoop = new OffspringSelectionGeneticAlgorithmMainLoop();
239      OperatorGraph.InitialOperator = randomCreator;
240
241      randomCreator.RandomParameter.ActualName = "Random";
242      randomCreator.SeedParameter.ActualName = SeedParameter.Name;
243      randomCreator.SeedParameter.Value = null;
244      randomCreator.SetSeedRandomlyParameter.ActualName = SetSeedRandomlyParameter.Name;
245      randomCreator.SetSeedRandomlyParameter.Value = null;
246      randomCreator.Successor = solutionsCreator;
247
248      solutionsCreator.NumberOfSolutionsParameter.ActualName = PopulationSizeParameter.Name;
249      solutionsCreator.Successor = mainLoop;
250
251      mainLoop.AnalyzerParameter.ActualName = AnalyzerParameter.Name;
252      mainLoop.ComparisonFactorModifierParameter.ActualName = ComparisonFactorModifierParameter.Name;
253      mainLoop.ComparisonFactorParameter.ActualName = "ComparisonFactor";
254      mainLoop.ComparisonFactorStartParameter.ActualName = ComparisonFactorLowerBoundParameter.Name;
255      mainLoop.CrossoverParameter.ActualName = CrossoverParameter.Name;
256      mainLoop.ElitesParameter.ActualName = ElitesParameter.Name;
257      mainLoop.MaximumGenerationsParameter.ActualName = MaximumGenerationsParameter.Name;
258      mainLoop.MaximumSelectionPressureParameter.ActualName = MaximumSelectionPressureParameter.Name;
259      mainLoop.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
260      mainLoop.MutatorParameter.ActualName = MutatorParameter.Name;
261      mainLoop.OffspringSelectionBeforeMutationParameter.ActualName = OffspringSelectionBeforeMutationParameter.Name;
262      mainLoop.RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
263      mainLoop.ResultsParameter.ActualName = "Results";
264      mainLoop.SelectorParameter.ActualName = SelectorParameter.Name;
265      mainLoop.SuccessRatioParameter.ActualName = SuccessRatioParameter.Name;
266
267      foreach (ISelector selector in ApplicationManager.Manager.GetInstances<ISelector>().Where(x => !(x is IMultiObjectiveSelector)).OrderBy(x => x.Name))
268        SelectorParameter.ValidValues.Add(selector);
269      ISelector proportionalSelector = SelectorParameter.ValidValues.FirstOrDefault(x => x.GetType().Name.Equals("ProportionalSelector"));
270      if (proportionalSelector != null) SelectorParameter.Value = proportionalSelector;
271      ParameterizeSelectors();
272
273      foreach (IDiscreteDoubleValueModifier modifier in ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>().OrderBy(x => x.Name))
274        ComparisonFactorModifierParameter.ValidValues.Add(modifier);
275      IDiscreteDoubleValueModifier linearModifier = ComparisonFactorModifierParameter.ValidValues.FirstOrDefault(x => x.GetType().Name.Equals("LinearDiscreteDoubleValueModifier"));
276      if (linearModifier != null) ComparisonFactorModifierParameter.Value = linearModifier;
277      ParameterizeComparisonFactorModifiers();
278
279      qualityAnalyzer = new BestAverageWorstQualityAnalyzer();
280      selectionPressureAnalyzer = new ValueAnalyzer();
281      ParameterizeAnalyzers();
282      UpdateAnalyzers();
283
284      Initialize();
285    }
286
287
288
289    public override void Prepare() {
290      if (Problem != null) base.Prepare();
291    }
292
293    #region Events
294    protected override void OnProblemChanged() {
295      ParameterizeStochasticOperator(Problem.SolutionCreator);
296      ParameterizeStochasticOperator(Problem.Evaluator);
297      foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
298      ParameterizeSolutionsCreator();
299      ParameterizMainLoop();
300      ParameterizeSelectors();
301      ParameterizeAnalyzers();
302      ParameterizeIterationBasedOperators();
303      UpdateCrossovers();
304      UpdateMutators();
305      UpdateAnalyzers();
306      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
307      base.OnProblemChanged();
308    }
309
310    protected override void Problem_SolutionCreatorChanged(object sender, EventArgs e) {
311      ParameterizeStochasticOperator(Problem.SolutionCreator);
312      ParameterizeSolutionsCreator();
313      base.Problem_SolutionCreatorChanged(sender, e);
314    }
315    protected override void Problem_EvaluatorChanged(object sender, EventArgs e) {
316      ParameterizeStochasticOperator(Problem.Evaluator);
317      ParameterizeSolutionsCreator();
318      ParameterizMainLoop();
319      ParameterizeSelectors();
320      ParameterizeAnalyzers();
321      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
322      base.Problem_EvaluatorChanged(sender, e);
323    }
324    protected override void Problem_OperatorsChanged(object sender, EventArgs e) {
325      foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
326      ParameterizeIterationBasedOperators();
327      UpdateCrossovers();
328      UpdateMutators();
329      UpdateAnalyzers();
330      base.Problem_OperatorsChanged(sender, e);
331    }
332    private void ElitesParameter_ValueChanged(object sender, EventArgs e) {
333      Elites.ValueChanged += new EventHandler(Elites_ValueChanged);
334      ParameterizeSelectors();
335    }
336    private void Elites_ValueChanged(object sender, EventArgs e) {
337      ParameterizeSelectors();
338    }
339    private void PopulationSizeParameter_ValueChanged(object sender, EventArgs e) {
340      PopulationSize.ValueChanged += new EventHandler(PopulationSize_ValueChanged);
341      ParameterizeSelectors();
342    }
343    private void PopulationSize_ValueChanged(object sender, EventArgs e) {
344      ParameterizeSelectors();
345    }
346    private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
347      ParameterizMainLoop();
348      ParameterizeSelectors();
349      ParameterizeAnalyzers();
350    }
351    #endregion
352
353    #region Helpers
354    private void Initialize() {
355      PopulationSizeParameter.ValueChanged += new EventHandler(PopulationSizeParameter_ValueChanged);
356      PopulationSize.ValueChanged += new EventHandler(PopulationSize_ValueChanged);
357      ElitesParameter.ValueChanged += new EventHandler(ElitesParameter_ValueChanged);
358      Elites.ValueChanged += new EventHandler(Elites_ValueChanged);
359      if (Problem != null) {
360        Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
361      }
362    }
363    private void ParameterizeSolutionsCreator() {
364      SolutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
365      SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name;
366    }
367    private void ParameterizMainLoop() {
368      MainLoop.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
369      MainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
370      MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
371    }
372    private void ParameterizeStochasticOperator(IOperator op) {
373      if (op is IStochasticOperator)
374        ((IStochasticOperator)op).RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
375    }
376    private void ParameterizeSelectors() {
377      foreach (ISelector selector in SelectorParameter.ValidValues) {
378        selector.CopySelected = new BoolValue(true);
379        selector.NumberOfSelectedSubScopesParameter.Value = null;
380        selector.NumberOfSelectedSubScopesParameter.ActualName = SelectedParentsParameter.Name;
381        ParameterizeStochasticOperator(selector);
382      }
383      if (Problem != null) {
384        foreach (ISingleObjectiveSelector selector in SelectorParameter.ValidValues.OfType<ISingleObjectiveSelector>()) {
385          selector.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
386          selector.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
387        }
388      }
389    }
390    private void ParameterizeAnalyzers() {
391      qualityAnalyzer.ResultsParameter.ActualName = "Results";
392      selectionPressureAnalyzer.Name = "SelectionPressure Analyzer";
393      selectionPressureAnalyzer.ResultsParameter.ActualName = "Results";
394      selectionPressureAnalyzer.ValueParameter.ActualName = "SelectionPressure";
395      selectionPressureAnalyzer.ValueParameter.Depth = 0;
396      selectionPressureAnalyzer.ValuesParameter.ActualName = "Selection Pressure History";
397      if (Problem != null) {
398        qualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
399        qualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
400        qualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
401      }
402    }
403    private void ParameterizeComparisonFactorModifiers() {
404      foreach (IDiscreteDoubleValueModifier modifier in ComparisonFactorModifierParameter.ValidValues) {
405        modifier.IndexParameter.ActualName = "Generations";
406        modifier.EndIndexParameter.ActualName = MaximumGenerationsParameter.Name;
407        modifier.EndValueParameter.ActualName = ComparisonFactorUpperBoundParameter.Name;
408        modifier.StartIndexParameter.Value = new IntValue(0);
409        modifier.StartValueParameter.ActualName = ComparisonFactorLowerBoundParameter.Name;
410        modifier.ValueParameter.ActualName = "ComparisonFactor";
411      }
412    }
413    private void ParameterizeIterationBasedOperators() {
414      if (Problem != null) {
415        foreach (IIterationBasedOperator op in Problem.Operators.OfType<IIterationBasedOperator>()) {
416          op.IterationsParameter.ActualName = "Generations";
417          op.MaximumIterationsParameter.ActualName = MaximumGenerationsParameter.Name;
418        }
419      }
420    }
421    private void UpdateCrossovers() {
422      ICrossover oldCrossover = CrossoverParameter.Value;
423      CrossoverParameter.ValidValues.Clear();
424      foreach (ICrossover crossover in Problem.Operators.OfType<ICrossover>().OrderBy(x => x.Name))
425        CrossoverParameter.ValidValues.Add(crossover);
426      if (oldCrossover != null) {
427        ICrossover crossover = CrossoverParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldCrossover.GetType());
428        if (crossover != null) CrossoverParameter.Value = crossover;
429      }
430    }
431    private void UpdateMutators() {
432      IManipulator oldMutator = MutatorParameter.Value;
433      MutatorParameter.ValidValues.Clear();
434      foreach (IManipulator mutator in Problem.Operators.OfType<IManipulator>().OrderBy(x => x.Name))
435        MutatorParameter.ValidValues.Add(mutator);
436      if (oldMutator != null) {
437        IManipulator mutator = MutatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMutator.GetType());
438        if (mutator != null) MutatorParameter.Value = mutator;
439      }
440    }
441    private void UpdateAnalyzers() {
442      Analyzer.Operators.Clear();
443      if (Problem != null) {
444        foreach (IAnalyzer analyzer in Problem.Operators.OfType<IAnalyzer>()) {
445          foreach (IScopeTreeLookupParameter param in analyzer.Parameters.OfType<IScopeTreeLookupParameter>())
446            param.Depth = 1;
447          Analyzer.Operators.Add(analyzer);
448        }
449      }
450      Analyzer.Operators.Add(qualityAnalyzer);
451      Analyzer.Operators.Add(selectionPressureAnalyzer);
452    }
453    #endregion
454  }
455}
Note: See TracBrowser for help on using the repository browser.