Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Algorithms.EvolutionStrategy/3.3/EvolutionStrategy.cs @ 3659

Last change on this file since 3659 was 3658, checked in by swagner, 15 years ago

Worked on refactoring of algorithm analysis and tracing (#999)

  • removed specific analyzer interfaces
  • adapted MultiAnalyzer
  • Property svn:mime-type set to application/octet-stream
File size: 47.8 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.Collections.Generic;
24using System.Linq;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HeuristicLab.Data;
28using HeuristicLab.Operators;
29using HeuristicLab.Optimization;
30using HeuristicLab.Optimization.Operators;
31using HeuristicLab.Parameters;
32using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
33using HeuristicLab.PluginInfrastructure;
34using HeuristicLab.Random;
35using HeuristicLab.Analysis;
36
37namespace HeuristicLab.Algorithms.EvolutionStrategy {
38  /// <summary>
39  /// A standard genetic algorithm.
40  /// </summary>
41  [Item("Evolution Strategy", "An evolution strategy.")]
42  [Creatable("Algorithms")]
43  [StorableClass]
44  public sealed class EvolutionStrategy : EngineAlgorithm {
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 ValueParameter<IntValue> ParentsPerChildParameter {
66      get { return (ValueParameter<IntValue>)Parameters["ParentsPerChild"]; }
67    }
68    private ValueParameter<IntValue> ChildrenParameter {
69      get { return (ValueParameter<IntValue>)Parameters["Children"]; }
70    }
71    private ValueParameter<IntValue> MaximumGenerationsParameter {
72      get { return (ValueParameter<IntValue>)Parameters["MaximumGenerations"]; }
73    }
74    private ValueParameter<BoolValue> PlusSelectionParameter {
75      get { return (ValueParameter<BoolValue>)Parameters["PlusSelection"]; }
76    }
77    private ConstrainedValueParameter<IManipulator> MutatorParameter {
78      get { return (ConstrainedValueParameter<IManipulator>)Parameters["Mutator"]; }
79    }
80    private OptionalConstrainedValueParameter<ICrossover> RecombinatorParameter {
81      get { return (OptionalConstrainedValueParameter<ICrossover>)Parameters["Recombinator"]; }
82    }
83    private ValueParameter<MultiAnalyzer> AnalyzerParameter {
84      get { return (ValueParameter<MultiAnalyzer>)Parameters["Analyzer"]; }
85    }
86    private OptionalConstrainedValueParameter<IStrategyParameterCreator> StrategyParameterCreatorParameter {
87      get { return (OptionalConstrainedValueParameter<IStrategyParameterCreator>)Parameters["StrategyParameterCreator"]; }
88    }
89    private OptionalConstrainedValueParameter<IStrategyParameterCrossover> StrategyParameterCrossoverParameter {
90      get { return (OptionalConstrainedValueParameter<IStrategyParameterCrossover>)Parameters["StrategyParameterCrossover"]; }
91    }
92    private OptionalConstrainedValueParameter<IStrategyParameterManipulator> StrategyParameterManipulatorParameter {
93      get { return (OptionalConstrainedValueParameter<IStrategyParameterManipulator>)Parameters["StrategyParameterManipulator"]; }
94    }
95    #endregion
96
97    #region Properties
98    public IntValue Seed {
99      get { return SeedParameter.Value; }
100      set { SeedParameter.Value = value; }
101    }
102    public BoolValue SetSeedRandomly {
103      get { return SetSeedRandomlyParameter.Value; }
104      set { SetSeedRandomlyParameter.Value = value; }
105    }
106    public IntValue PopulationSize {
107      get { return PopulationSizeParameter.Value; }
108      set { PopulationSizeParameter.Value = value; }
109    }
110    public IntValue ParentsPerChild {
111      get { return ParentsPerChildParameter.Value; }
112      set { ParentsPerChildParameter.Value = value; }
113    }
114    public IntValue Children {
115      get { return ChildrenParameter.Value; }
116      set { ChildrenParameter.Value = value; }
117    }
118    public IntValue MaximumGenerations {
119      get { return MaximumGenerationsParameter.Value; }
120      set { MaximumGenerationsParameter.Value = value; }
121    }
122    private BoolValue PlusSelection {
123      get { return PlusSelectionParameter.Value; }
124      set { PlusSelectionParameter.Value = value; }
125    }
126    public IManipulator Mutator {
127      get { return MutatorParameter.Value; }
128      set { MutatorParameter.Value = value; }
129    }
130    public ICrossover Recombinator {
131      get { return RecombinatorParameter.Value; }
132      set { RecombinatorParameter.Value = value; }
133    }
134    public MultiAnalyzer Analyzer {
135      get { return AnalyzerParameter.Value; }
136      set { AnalyzerParameter.Value = value; }
137    }
138    public IStrategyParameterCreator StrategyParameterCreator {
139      get { return StrategyParameterCreatorParameter.Value; }
140      set { StrategyParameterCreatorParameter.Value = value; }
141    }
142    public IStrategyParameterCrossover StrategyParameterCrossover {
143      get { return StrategyParameterCrossoverParameter.Value; }
144      set { StrategyParameterCrossoverParameter.Value = value; }
145    }
146    public IStrategyParameterManipulator StrategyParameterManipulator {
147      get { return StrategyParameterManipulatorParameter.Value; }
148      set { StrategyParameterManipulatorParameter.Value = value; }
149    }
150
151    private RandomCreator RandomCreator {
152      get { return (RandomCreator)OperatorGraph.InitialOperator; }
153    }
154    private SolutionsCreator SolutionsCreator {
155      get { return (SolutionsCreator)RandomCreator.Successor; }
156    }
157    private EvolutionStrategyMainLoop MainLoop {
158      get { return (EvolutionStrategyMainLoop)((UniformSubScopesProcessor)SolutionsCreator.Successor).Successor; }
159    }
160
161    private PopulationBestAverageWorstQualityAnalyzer qualityAnalyzer;
162    #endregion
163
164    public EvolutionStrategy()
165      : base() {
166      Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
167      Parameters.Add(new ValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
168      Parameters.Add(new ValueParameter<IntValue>("PopulationSize", "µ (mu) - the size of the population.", new IntValue(5)));
169      Parameters.Add(new ValueParameter<IntValue>("ParentsPerChild", "ρ (rho) - how many parents should be recombined.", new IntValue(1)));
170      Parameters.Add(new ValueParameter<IntValue>("Children", "λ (lambda) - the size of the offspring population.", new IntValue(10)));
171      Parameters.Add(new ValueParameter<IntValue>("MaximumGenerations", "The maximum number of generations which should be processed.", new IntValue(1000)));
172      Parameters.Add(new ValueParameter<BoolValue>("PlusSelection", "True for plus selection (elitist population), false for comma selection (non-elitist population).", new BoolValue(true)));
173      Parameters.Add(new OptionalConstrainedValueParameter<ICrossover>("Recombinator", "The operator used to cross solutions."));
174      Parameters.Add(new ConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions."));
175      Parameters.Add(new OptionalConstrainedValueParameter<IStrategyParameterCreator>("StrategyParameterCreator", "The operator that creates the strategy parameters."));
176      Parameters.Add(new OptionalConstrainedValueParameter<IStrategyParameterCrossover>("StrategyParameterCrossover", "The operator that recombines the strategy parameters."));
177      Parameters.Add(new OptionalConstrainedValueParameter<IStrategyParameterManipulator>("StrategyParameterManipulator", "The operator that manipulates the strategy parameters."));
178      Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze each generation.", new MultiAnalyzer()));
179     
180      RandomCreator randomCreator = new RandomCreator();
181      SolutionsCreator solutionsCreator = new SolutionsCreator();
182      UniformSubScopesProcessor strategyVectorProcessor = new UniformSubScopesProcessor();
183      Placeholder strategyVectorCreator = new Placeholder();
184      EvolutionStrategyMainLoop mainLoop = new EvolutionStrategyMainLoop();
185      OperatorGraph.InitialOperator = randomCreator;
186
187      randomCreator.RandomParameter.ActualName = "Random";
188      randomCreator.SeedParameter.ActualName = SeedParameter.Name;
189      randomCreator.SeedParameter.Value = null;
190      randomCreator.SetSeedRandomlyParameter.ActualName = SetSeedRandomlyParameter.Name;
191      randomCreator.SetSeedRandomlyParameter.Value = null;
192      randomCreator.Successor = solutionsCreator;
193
194      solutionsCreator.NumberOfSolutionsParameter.ActualName = PopulationSizeParameter.Name;
195      solutionsCreator.Successor = strategyVectorProcessor;
196
197      strategyVectorProcessor.Operator = strategyVectorCreator;
198      strategyVectorProcessor.Successor = mainLoop;
199
200      strategyVectorCreator.OperatorParameter.ActualName = "StrategyParameterCreator";
201
202      mainLoop.RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
203      mainLoop.PopulationSizeParameter.ActualName = PopulationSizeParameter.Name;
204      mainLoop.ParentsPerChildParameter.ActualName = ParentsPerChildParameter.Name;
205      mainLoop.ChildrenParameter.ActualName = ChildrenParameter.Name;
206      mainLoop.MaximumGenerationsParameter.ActualName = MaximumGenerationsParameter.Name;
207      mainLoop.MutatorParameter.ActualName = MutatorParameter.Name;
208      mainLoop.RecombinatorParameter.ActualName = RecombinatorParameter.Name;
209      mainLoop.AnalyzerParameter.ActualName = AnalyzerParameter.Name;
210      mainLoop.ResultsParameter.ActualName = "Results";
211
212      Initialize();
213    }
214    [StorableConstructor]
215    private EvolutionStrategy(bool deserializing) : base(deserializing) { }
216
217    public override IDeepCloneable Clone(Cloner cloner) {
218      EvolutionStrategy clone = (EvolutionStrategy)base.Clone(cloner);
219      clone.Initialize();
220      return clone;
221    }
222
223    public override void Prepare() {
224      if (Problem != null) base.Prepare();
225    }
226
227    #region Events
228    protected override void OnProblemChanged() {
229      ParameterizeStochasticOperator(Problem.SolutionCreator);
230      ParameterizeStochasticOperator(Problem.Evaluator);
231      foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
232      ParameterizeSolutionsCreator();
233      ParameterizeMainLoop();
234      ParameterizeAnalyzers();
235      UpdateRecombinators();
236      UpdateMutators();
237      UpdateAnalyzers();
238      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
239      base.OnProblemChanged();
240    }
241    protected override void Problem_SolutionCreatorChanged(object sender, EventArgs e) {
242      ParameterizeStochasticOperator(Problem.SolutionCreator);
243      ParameterizeSolutionsCreator();
244      base.Problem_SolutionCreatorChanged(sender, e);
245    }
246    protected override void Problem_EvaluatorChanged(object sender, EventArgs e) {
247      ParameterizeStochasticOperator(Problem.Evaluator);
248      ParameterizeSolutionsCreator();
249      ParameterizeMainLoop();
250      ParameterizeAnalyzers();
251      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
252      base.Problem_EvaluatorChanged(sender, e);
253    }
254    protected override void Problem_OperatorsChanged(object sender, EventArgs e) {
255      foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
256      UpdateRecombinators();
257      UpdateMutators();
258      UpdateAnalyzers();
259      base.Problem_OperatorsChanged(sender, e);
260    }
261    private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
262      ParameterizeMainLoop();
263      ParameterizeAnalyzers();
264    }
265    private void PopulationSizeParameter_ValueChanged(object sender, EventArgs e) {
266      PopulationSize.ValueChanged += new EventHandler(PopulationSize_ValueChanged);
267      PopulationSize_ValueChanged(null, EventArgs.Empty);
268    }
269    private void PopulationSize_ValueChanged(object sender, EventArgs e) {
270      if (PopulationSize.Value <= 0) PopulationSize.Value = 1;
271      if (!PlusSelection.Value && Children.Value < PopulationSize.Value)
272        Children.Value = PopulationSize.Value;
273    }
274    private void ParentsPerChildParameter_ValueChanged(object sender, EventArgs e) {
275      ParentsPerChild.ValueChanged += new EventHandler(ParentsPerChild_ValueChanged);
276      ParentsPerChild_ValueChanged(null, EventArgs.Empty);
277    }
278    private void ParentsPerChild_ValueChanged(object sender, EventArgs e) {
279      if (ParentsPerChild.Value < 1 || ParentsPerChild.Value > 1 && RecombinatorParameter.ValidValues.Count == 0)
280        ParentsPerChild.Value = 1;
281      if (ParentsPerChild.Value > 1 && Recombinator == null) Recombinator = RecombinatorParameter.ValidValues.First();
282      if (ParentsPerChild.Value > 1 && ParentsPerChild.Value > PopulationSize.Value)
283        PopulationSize.Value = ParentsPerChild.Value;
284    }
285    private void ChildrenParameter_ValueChanged(object sender, EventArgs e) {
286      Children.ValueChanged += new EventHandler(Children_ValueChanged);
287      Children_ValueChanged(null, EventArgs.Empty);
288    }
289    private void Children_ValueChanged(object sender, EventArgs e) {
290      if (Children.Value <= 0) Children.Value = 1;
291      if (!PlusSelection.Value && Children.Value < PopulationSize.Value)
292        PopulationSize.Value = Children.Value;
293    }
294    private void PlusSelectionParameter_ValueChanged(object sender, EventArgs e) {
295      PlusSelection.ValueChanged += new EventHandler(PlusSelection_ValueChanged);
296      PlusSelection_ValueChanged(null, EventArgs.Empty);
297    }
298    private void PlusSelection_ValueChanged(object sender, EventArgs e) {
299      if (!PlusSelection.Value && Children.Value < PopulationSize.Value)
300        Children.Value = PopulationSize.Value;
301    }
302    private void RecombinatorParameter_ValueChanged(object sender, EventArgs e) {
303      if (Recombinator == null && ParentsPerChild.Value > 1) ParentsPerChild.Value = 1;
304      else if (Recombinator != null && ParentsPerChild.Value == 1) ParentsPerChild.Value = 2;
305      if (Recombinator != null && Mutator is ISelfAdaptiveManipulator && StrategyParameterCrossover == null) {
306        if (StrategyParameterCrossoverParameter.ValidValues.Count > 0)
307          StrategyParameterCrossover = StrategyParameterCrossoverParameter.ValidValues.First();
308      }
309    }
310    private void MutatorParameter_ValueChanged(object sender, EventArgs e) {
311      if (Mutator is ISelfAdaptiveManipulator) {
312        UpdateStrategyParameterOperators();
313        if (StrategyParameterCreatorParameter.ValidValues.Count == 0) throw new InvalidOperationException("ERROR: There is no strategy parameter creator for this manipulation operator.");
314      } else {
315        StrategyParameterCreatorParameter.ValidValues.Clear();
316        StrategyParameterCrossoverParameter.ValidValues.Clear();
317        StrategyParameterManipulatorParameter.ValidValues.Clear();
318        UpdateRecombinators();
319      }
320    }
321    private void StrategyParameterCreatorParameter_ValueChanged(object sender, EventArgs e) {
322      if (Mutator is ISelfAdaptiveManipulator && StrategyParameterCreator == null && StrategyParameterCreatorParameter.ValidValues.Count > 0)
323        StrategyParameterCreator = StrategyParameterCreatorParameter.ValidValues.First();
324    }
325    private void StrategyParameterCrossoverParameter_ValueChanged(object sender, EventArgs e) {
326      if (Mutator is ISelfAdaptiveManipulator && Recombinator != null && StrategyParameterCrossover == null && StrategyParameterCrossoverParameter.ValidValues.Count > 0)
327        StrategyParameterCrossover = StrategyParameterCrossoverParameter.ValidValues.First();
328    }
329    #endregion
330
331    #region Helpers
332    [StorableHook(HookType.AfterDeserialization)]
333    private void Initialize() {
334      InitializeAnalyzers();
335      UpdateAnalyzers();
336      PopulationSizeParameter.ValueChanged += new EventHandler(PopulationSizeParameter_ValueChanged);
337      PopulationSize.ValueChanged += new EventHandler(PopulationSize_ValueChanged);
338      ParentsPerChildParameter.ValueChanged += new EventHandler(ParentsPerChildParameter_ValueChanged);
339      ParentsPerChild.ValueChanged += new EventHandler(ParentsPerChild_ValueChanged);
340      ChildrenParameter.ValueChanged += new EventHandler(ChildrenParameter_ValueChanged);
341      Children.ValueChanged += new EventHandler(Children_ValueChanged);
342      PlusSelectionParameter.ValueChanged += new EventHandler(PlusSelectionParameter_ValueChanged);
343      PlusSelection.ValueChanged += new EventHandler(PlusSelection_ValueChanged);
344      RecombinatorParameter.ValueChanged += new EventHandler(RecombinatorParameter_ValueChanged);
345      MutatorParameter.ValueChanged += new EventHandler(MutatorParameter_ValueChanged);
346      StrategyParameterCrossoverParameter.ValueChanged += new EventHandler(StrategyParameterCrossoverParameter_ValueChanged);
347      StrategyParameterCreatorParameter.ValueChanged += new EventHandler(StrategyParameterCreatorParameter_ValueChanged);
348      if (Problem != null)
349        Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
350    }
351    private void ParameterizeSolutionsCreator() {
352      SolutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
353      SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name;
354    }
355    private void ParameterizeMainLoop() {
356      MainLoop.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
357      MainLoop.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
358      MainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
359      MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
360    }
361    private void ParameterizeStochasticOperator(IOperator op) {
362      if (op is IStochasticOperator)
363        ((IStochasticOperator)op).RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
364    }
365    private void InitializeAnalyzers() {
366      qualityAnalyzer = new PopulationBestAverageWorstQualityAnalyzer();
367      ParameterizeAnalyzers();
368    }
369    private void ParameterizeAnalyzers() {
370      qualityAnalyzer.ResultsParameter.ActualName = "Results";
371      if (Problem != null) {
372        qualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
373        qualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
374        qualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
375      }
376    }
377    private void UpdateStrategyParameterOperators() {
378      IStrategyParameterCreator oldStrategyCreator = StrategyParameterCreator;
379      IStrategyParameterCrossover oldStrategyCrossover = StrategyParameterCrossover;
380      IStrategyParameterManipulator oldStrategyManipulator = StrategyParameterManipulator;
381      ClearStrategyParameterOperators();
382      ISelfAdaptiveManipulator manipulator = (Mutator as ISelfAdaptiveManipulator);
383      if (manipulator != null) {
384        var operators = Problem.Operators.Where(x => manipulator.StrategyParameterType.IsAssignableFrom(x.GetType())).OrderBy(x => x.Name);
385        foreach (IStrategyParameterCreator strategyCreator in operators.OfType<IStrategyParameterCreator>())
386          StrategyParameterCreatorParameter.ValidValues.Add(strategyCreator);
387        foreach (IStrategyParameterCrossover strategyRecombinator in operators.OfType<IStrategyParameterCrossover>())
388          StrategyParameterCrossoverParameter.ValidValues.Add(strategyRecombinator);
389        foreach (IStrategyParameterManipulator strategyManipulator in operators.OfType<IStrategyParameterManipulator>())
390          StrategyParameterManipulatorParameter.ValidValues.Add(strategyManipulator);
391
392        if (StrategyParameterCrossoverParameter.ValidValues.Count == 0)
393          RecombinatorParameter.ValidValues.Clear(); // if there is no strategy parameter crossover, there can be no crossover when the mutation operator needs strategy parameters
394
395        if (oldStrategyCreator != null) {
396          IStrategyParameterCreator tmp1 = StrategyParameterCreatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldStrategyCreator.GetType());
397          if (tmp1 != null) StrategyParameterCreator = tmp1;
398        } else if (StrategyParameterCreatorParameter.ValidValues.Count > 0) StrategyParameterCreator = StrategyParameterCreatorParameter.ValidValues.First();
399        if (oldStrategyCrossover != null) {
400          IStrategyParameterCrossover tmp2 = StrategyParameterCrossoverParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldStrategyCrossover.GetType());
401          if (tmp2 != null) StrategyParameterCrossover = tmp2;
402        } else if (StrategyParameterCrossoverParameter.ValidValues.Count > 0) StrategyParameterCrossover = StrategyParameterCrossoverParameter.ValidValues.First();
403        if (oldStrategyManipulator != null) {
404          IStrategyParameterManipulator tmp3 = StrategyParameterManipulatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldStrategyManipulator.GetType());
405          if (tmp3 != null) StrategyParameterManipulator = tmp3;
406        } else if (StrategyParameterManipulatorParameter.ValidValues.Count > 0) StrategyParameterManipulator = StrategyParameterManipulatorParameter.ValidValues.First();
407      }
408    }
409    private void ClearStrategyParameterOperators() {
410      StrategyParameterCreatorParameter.ValidValues.Clear();
411      StrategyParameterCrossoverParameter.ValidValues.Clear();
412      StrategyParameterManipulatorParameter.ValidValues.Clear();
413    }
414    private void UpdateRecombinators() {
415      ICrossover oldRecombinator = Recombinator;
416      RecombinatorParameter.ValidValues.Clear();
417      foreach (ICrossover recombinator in Problem.Operators.OfType<ICrossover>().OrderBy(x => x.Name)) {
418        RecombinatorParameter.ValidValues.Add(recombinator);
419      }
420      if (oldRecombinator != null) {
421        ICrossover recombinator = RecombinatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldRecombinator.GetType());
422        if (recombinator != null) RecombinatorParameter.Value = recombinator;
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      Analyzer.Operators.Add(qualityAnalyzer);
438      if (Problem != null) {
439        foreach (IAnalyzer analyzer in Problem.Operators.OfType<IAnalyzer>().OrderBy(x => x.Name))
440          Analyzer.Operators.Add(analyzer);
441      }
442    }
443    #endregion
444  }
445}
Note: See TracBrowser for help on using the repository browser.