Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 3754 was 3750, checked in by abeham, 15 years ago

#893

  • Fixed wiring of iteration based operators like the michalewicz manipulators for real vector encoding
  • Property svn:mime-type set to application/octet-stream
File size: 48.9 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    [Storable]
161    private BestAverageWorstQualityAnalyzer 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      qualityAnalyzer = new BestAverageWorstQualityAnalyzer();
213      ParameterizeAnalyzers();
214      UpdateAnalyzers();
215
216      Initialize();
217    }
218    [StorableConstructor]
219    private EvolutionStrategy(bool deserializing) : base(deserializing) { }
220
221    public override IDeepCloneable Clone(Cloner cloner) {
222      EvolutionStrategy clone = (EvolutionStrategy)base.Clone(cloner);
223      clone.qualityAnalyzer = (BestAverageWorstQualityAnalyzer)cloner.Clone(qualityAnalyzer);
224      clone.Initialize();
225      return clone;
226    }
227
228    public override void Prepare() {
229      if (Problem != null) base.Prepare();
230    }
231
232    #region Events
233    protected override void OnProblemChanged() {
234      ParameterizeStochasticOperator(Problem.SolutionCreator);
235      ParameterizeStochasticOperator(Problem.Evaluator);
236      foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
237      ParameterizeSolutionsCreator();
238      ParameterizeMainLoop();
239      ParameterizeAnalyzers();
240      ParameterizeIterationBasedOperators();
241      UpdateRecombinators();
242      UpdateMutators();
243      UpdateAnalyzers();
244      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
245      base.OnProblemChanged();
246    }
247    protected override void Problem_SolutionCreatorChanged(object sender, EventArgs e) {
248      ParameterizeStochasticOperator(Problem.SolutionCreator);
249      ParameterizeSolutionsCreator();
250      base.Problem_SolutionCreatorChanged(sender, e);
251    }
252    protected override void Problem_EvaluatorChanged(object sender, EventArgs e) {
253      ParameterizeStochasticOperator(Problem.Evaluator);
254      ParameterizeSolutionsCreator();
255      ParameterizeMainLoop();
256      ParameterizeAnalyzers();
257      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
258      base.Problem_EvaluatorChanged(sender, e);
259    }
260    protected override void Problem_OperatorsChanged(object sender, EventArgs e) {
261      foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
262      ParameterizeIterationBasedOperators();
263      UpdateRecombinators();
264      UpdateMutators();
265      UpdateAnalyzers();
266      base.Problem_OperatorsChanged(sender, e);
267    }
268    private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
269      ParameterizeMainLoop();
270      ParameterizeAnalyzers();
271    }
272    private void PopulationSizeParameter_ValueChanged(object sender, EventArgs e) {
273      PopulationSize.ValueChanged += new EventHandler(PopulationSize_ValueChanged);
274      PopulationSize_ValueChanged(null, EventArgs.Empty);
275    }
276    private void PopulationSize_ValueChanged(object sender, EventArgs e) {
277      if (PopulationSize.Value <= 0) PopulationSize.Value = 1;
278      if (!PlusSelection.Value && Children.Value < PopulationSize.Value)
279        Children.Value = PopulationSize.Value;
280      if (PopulationSize.Value < ParentsPerChild.Value)
281        ParentsPerChild.Value = PopulationSize.Value;
282    }
283    private void ParentsPerChildParameter_ValueChanged(object sender, EventArgs e) {
284      ParentsPerChild.ValueChanged += new EventHandler(ParentsPerChild_ValueChanged);
285      ParentsPerChild_ValueChanged(null, EventArgs.Empty);
286    }
287    private void ParentsPerChild_ValueChanged(object sender, EventArgs e) {
288      if (ParentsPerChild.Value < 1 || ParentsPerChild.Value > 1 && RecombinatorParameter.ValidValues.Count == 0)
289        ParentsPerChild.Value = 1;
290      if (ParentsPerChild.Value > 1 && Recombinator == null) Recombinator = RecombinatorParameter.ValidValues.First();
291      if (ParentsPerChild.Value > 1 && ParentsPerChild.Value > PopulationSize.Value)
292        PopulationSize.Value = ParentsPerChild.Value;
293    }
294    private void ChildrenParameter_ValueChanged(object sender, EventArgs e) {
295      Children.ValueChanged += new EventHandler(Children_ValueChanged);
296      Children_ValueChanged(null, EventArgs.Empty);
297    }
298    private void Children_ValueChanged(object sender, EventArgs e) {
299      if (Children.Value <= 0) Children.Value = 1;
300      if (!PlusSelection.Value && Children.Value < PopulationSize.Value)
301        PopulationSize.Value = Children.Value;
302    }
303    private void PlusSelectionParameter_ValueChanged(object sender, EventArgs e) {
304      PlusSelection.ValueChanged += new EventHandler(PlusSelection_ValueChanged);
305      PlusSelection_ValueChanged(null, EventArgs.Empty);
306    }
307    private void PlusSelection_ValueChanged(object sender, EventArgs e) {
308      if (!PlusSelection.Value && Children.Value < PopulationSize.Value)
309        Children.Value = PopulationSize.Value;
310    }
311    private void RecombinatorParameter_ValueChanged(object sender, EventArgs e) {
312      if (Recombinator == null && ParentsPerChild.Value > 1) ParentsPerChild.Value = 1;
313      else if (Recombinator != null && ParentsPerChild.Value == 1) ParentsPerChild.Value = 2;
314      if (Recombinator != null && Mutator is ISelfAdaptiveManipulator && StrategyParameterCrossover == null) {
315        if (StrategyParameterCrossoverParameter.ValidValues.Count > 0)
316          StrategyParameterCrossover = StrategyParameterCrossoverParameter.ValidValues.First();
317      }
318    }
319    private void MutatorParameter_ValueChanged(object sender, EventArgs e) {
320      if (Mutator is ISelfAdaptiveManipulator) {
321        UpdateStrategyParameterOperators();
322        if (StrategyParameterCreatorParameter.ValidValues.Count == 0) throw new InvalidOperationException("ERROR: There is no strategy parameter creator for this manipulation operator.");
323      } else {
324        StrategyParameterCreatorParameter.ValidValues.Clear();
325        StrategyParameterCrossoverParameter.ValidValues.Clear();
326        StrategyParameterManipulatorParameter.ValidValues.Clear();
327        UpdateRecombinators();
328      }
329    }
330    private void StrategyParameterCreatorParameter_ValueChanged(object sender, EventArgs e) {
331      if (Mutator is ISelfAdaptiveManipulator && StrategyParameterCreator == null && StrategyParameterCreatorParameter.ValidValues.Count > 0)
332        StrategyParameterCreator = StrategyParameterCreatorParameter.ValidValues.First();
333    }
334    private void StrategyParameterCrossoverParameter_ValueChanged(object sender, EventArgs e) {
335      if (Mutator is ISelfAdaptiveManipulator && Recombinator != null && StrategyParameterCrossover == null && StrategyParameterCrossoverParameter.ValidValues.Count > 0)
336        StrategyParameterCrossover = StrategyParameterCrossoverParameter.ValidValues.First();
337    }
338    #endregion
339
340    #region Helpers
341    [StorableHook(HookType.AfterDeserialization)]
342    private void Initialize() {
343      PopulationSizeParameter.ValueChanged += new EventHandler(PopulationSizeParameter_ValueChanged);
344      PopulationSize.ValueChanged += new EventHandler(PopulationSize_ValueChanged);
345      ParentsPerChildParameter.ValueChanged += new EventHandler(ParentsPerChildParameter_ValueChanged);
346      ParentsPerChild.ValueChanged += new EventHandler(ParentsPerChild_ValueChanged);
347      ChildrenParameter.ValueChanged += new EventHandler(ChildrenParameter_ValueChanged);
348      Children.ValueChanged += new EventHandler(Children_ValueChanged);
349      PlusSelectionParameter.ValueChanged += new EventHandler(PlusSelectionParameter_ValueChanged);
350      PlusSelection.ValueChanged += new EventHandler(PlusSelection_ValueChanged);
351      RecombinatorParameter.ValueChanged += new EventHandler(RecombinatorParameter_ValueChanged);
352      MutatorParameter.ValueChanged += new EventHandler(MutatorParameter_ValueChanged);
353      StrategyParameterCrossoverParameter.ValueChanged += new EventHandler(StrategyParameterCrossoverParameter_ValueChanged);
354      StrategyParameterCreatorParameter.ValueChanged += new EventHandler(StrategyParameterCreatorParameter_ValueChanged);
355      if (Problem != null)
356        Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
357    }
358    private void ParameterizeSolutionsCreator() {
359      SolutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
360      SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name;
361    }
362    private void ParameterizeMainLoop() {
363      MainLoop.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
364      MainLoop.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
365      MainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
366      MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
367    }
368    private void ParameterizeStochasticOperator(IOperator op) {
369      if (op is IStochasticOperator)
370        ((IStochasticOperator)op).RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
371    }
372    private void ParameterizeAnalyzers() {
373      qualityAnalyzer.ResultsParameter.ActualName = "Results";
374      if (Problem != null) {
375        qualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
376        qualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
377        qualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
378      }
379    }
380    private void ParameterizeIterationBasedOperators() {
381      if (Problem != null) {
382        foreach (IIterationBasedOperator op in Problem.Operators.OfType<IIterationBasedOperator>()) {
383          op.IterationsParameter.ActualName = "Generations";
384          op.MaximumIterationsParameter.ActualName = "MaximumGenerations";
385        }
386      }
387    }
388    private void UpdateStrategyParameterOperators() {
389      IStrategyParameterCreator oldStrategyCreator = StrategyParameterCreator;
390      IStrategyParameterCrossover oldStrategyCrossover = StrategyParameterCrossover;
391      IStrategyParameterManipulator oldStrategyManipulator = StrategyParameterManipulator;
392      ClearStrategyParameterOperators();
393      ISelfAdaptiveManipulator manipulator = (Mutator as ISelfAdaptiveManipulator);
394      if (manipulator != null) {
395        var operators = Problem.Operators.Where(x => manipulator.StrategyParameterType.IsAssignableFrom(x.GetType())).OrderBy(x => x.Name);
396        foreach (IStrategyParameterCreator strategyCreator in operators.OfType<IStrategyParameterCreator>())
397          StrategyParameterCreatorParameter.ValidValues.Add(strategyCreator);
398        foreach (IStrategyParameterCrossover strategyRecombinator in operators.OfType<IStrategyParameterCrossover>())
399          StrategyParameterCrossoverParameter.ValidValues.Add(strategyRecombinator);
400        foreach (IStrategyParameterManipulator strategyManipulator in operators.OfType<IStrategyParameterManipulator>())
401          StrategyParameterManipulatorParameter.ValidValues.Add(strategyManipulator);
402
403        if (StrategyParameterCrossoverParameter.ValidValues.Count == 0)
404          RecombinatorParameter.ValidValues.Clear(); // if there is no strategy parameter crossover, there can be no crossover when the mutation operator needs strategy parameters
405
406        if (oldStrategyCreator != null) {
407          IStrategyParameterCreator tmp1 = StrategyParameterCreatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldStrategyCreator.GetType());
408          if (tmp1 != null) StrategyParameterCreator = tmp1;
409        } else if (StrategyParameterCreatorParameter.ValidValues.Count > 0) StrategyParameterCreator = StrategyParameterCreatorParameter.ValidValues.First();
410        if (oldStrategyCrossover != null) {
411          IStrategyParameterCrossover tmp2 = StrategyParameterCrossoverParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldStrategyCrossover.GetType());
412          if (tmp2 != null) StrategyParameterCrossover = tmp2;
413        } else if (StrategyParameterCrossoverParameter.ValidValues.Count > 0) StrategyParameterCrossover = StrategyParameterCrossoverParameter.ValidValues.First();
414        if (oldStrategyManipulator != null) {
415          IStrategyParameterManipulator tmp3 = StrategyParameterManipulatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldStrategyManipulator.GetType());
416          if (tmp3 != null) StrategyParameterManipulator = tmp3;
417        } else if (StrategyParameterManipulatorParameter.ValidValues.Count > 0) StrategyParameterManipulator = StrategyParameterManipulatorParameter.ValidValues.First();
418      }
419    }
420    private void ClearStrategyParameterOperators() {
421      StrategyParameterCreatorParameter.ValidValues.Clear();
422      StrategyParameterCrossoverParameter.ValidValues.Clear();
423      StrategyParameterManipulatorParameter.ValidValues.Clear();
424    }
425    private void UpdateRecombinators() {
426      ICrossover oldRecombinator = Recombinator;
427      RecombinatorParameter.ValidValues.Clear();
428      foreach (ICrossover recombinator in Problem.Operators.OfType<ICrossover>().OrderBy(x => x.Name)) {
429        RecombinatorParameter.ValidValues.Add(recombinator);
430      }
431      if (oldRecombinator != null) {
432        ICrossover recombinator = RecombinatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldRecombinator.GetType());
433        if (recombinator != null) RecombinatorParameter.Value = recombinator;
434      }
435    }
436    private void UpdateMutators() {
437      IManipulator oldMutator = MutatorParameter.Value;
438      MutatorParameter.ValidValues.Clear();
439      foreach (IManipulator mutator in Problem.Operators.OfType<IManipulator>().OrderBy(x => x.Name))
440        MutatorParameter.ValidValues.Add(mutator);
441      if (oldMutator != null) {
442        IManipulator mutator = MutatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMutator.GetType());
443        if (mutator != null) MutatorParameter.Value = mutator;
444      }
445    }
446    private void UpdateAnalyzers() {
447      Analyzer.Operators.Clear();
448      Analyzer.Operators.Add(qualityAnalyzer);
449      if (Problem != null) {
450        foreach (IAnalyzer analyzer in Problem.Operators.OfType<IAnalyzer>().OrderBy(x => x.Name))
451          Analyzer.Operators.Add(analyzer);
452      }
453    }
454    #endregion
455  }
456}
Note: See TracBrowser for help on using the repository browser.