Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Algorithms.GeneticAlgorithm/3.3/IslandGeneticAlgorithm.cs @ 4722

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

Merged cloning refactoring branch back into trunk (#922)

File size: 23.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.Linq;
24using HeuristicLab.Analysis;
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;
35
36namespace HeuristicLab.Algorithms.GeneticAlgorithm {
37  /// <summary>
38  /// An island genetic algorithm.
39  /// </summary>
40  [Item("Island Genetic Algorithm", "An island genetic algorithm.")]
41  [Creatable("Algorithms")]
42  [StorableClass]
43  public sealed class IslandGeneticAlgorithm : EngineAlgorithm, IStorableContent {
44    public string Filename { get; set; }
45
46    #region Problem Properties
47    public override Type ProblemType {
48      get { return typeof(ISingleObjectiveProblem); }
49    }
50    public new ISingleObjectiveProblem Problem {
51      get { return (ISingleObjectiveProblem)base.Problem; }
52      set { base.Problem = value; }
53    }
54    #endregion
55
56    #region Parameter Properties
57    private ValueParameter<IntValue> SeedParameter {
58      get { return (ValueParameter<IntValue>)Parameters["Seed"]; }
59    }
60    private ValueParameter<BoolValue> SetSeedRandomlyParameter {
61      get { return (ValueParameter<BoolValue>)Parameters["SetSeedRandomly"]; }
62    }
63    private ValueParameter<IntValue> NumberOfIslandsParameter {
64      get { return (ValueParameter<IntValue>)Parameters["NumberOfIslands"]; }
65    }
66    private ValueParameter<IntValue> MigrationIntervalParameter {
67      get { return (ValueParameter<IntValue>)Parameters["MigrationInterval"]; }
68    }
69    private ValueParameter<PercentValue> MigrationRateParameter {
70      get { return (ValueParameter<PercentValue>)Parameters["MigrationRate"]; }
71    }
72    private ConstrainedValueParameter<IMigrator> MigratorParameter {
73      get { return (ConstrainedValueParameter<IMigrator>)Parameters["Migrator"]; }
74    }
75    private ConstrainedValueParameter<ISelector> EmigrantsSelectorParameter {
76      get { return (ConstrainedValueParameter<ISelector>)Parameters["EmigrantsSelector"]; }
77    }
78    private ConstrainedValueParameter<IReplacer> ImmigrationReplacerParameter {
79      get { return (ConstrainedValueParameter<IReplacer>)Parameters["ImmigrationReplacer"]; }
80    }
81    private ValueParameter<IntValue> PopulationSizeParameter {
82      get { return (ValueParameter<IntValue>)Parameters["PopulationSize"]; }
83    }
84    private ValueParameter<IntValue> MaximumGenerationsParameter {
85      get { return (ValueParameter<IntValue>)Parameters["MaximumGenerations"]; }
86    }
87    private ConstrainedValueParameter<ISelector> SelectorParameter {
88      get { return (ConstrainedValueParameter<ISelector>)Parameters["Selector"]; }
89    }
90    private ConstrainedValueParameter<ICrossover> CrossoverParameter {
91      get { return (ConstrainedValueParameter<ICrossover>)Parameters["Crossover"]; }
92    }
93    private ValueParameter<PercentValue> MutationProbabilityParameter {
94      get { return (ValueParameter<PercentValue>)Parameters["MutationProbability"]; }
95    }
96    private OptionalConstrainedValueParameter<IManipulator> MutatorParameter {
97      get { return (OptionalConstrainedValueParameter<IManipulator>)Parameters["Mutator"]; }
98    }
99    private ValueParameter<IntValue> ElitesParameter {
100      get { return (ValueParameter<IntValue>)Parameters["Elites"]; }
101    }
102    private ValueParameter<MultiAnalyzer> AnalyzerParameter {
103      get { return (ValueParameter<MultiAnalyzer>)Parameters["Analyzer"]; }
104    }
105    private ValueParameter<MultiAnalyzer> IslandAnalyzerParameter {
106      get { return (ValueParameter<MultiAnalyzer>)Parameters["IslandAnalyzer"]; }
107    }
108    #endregion
109
110    #region Properties
111    public IntValue Seed {
112      get { return SeedParameter.Value; }
113      set { SeedParameter.Value = value; }
114    }
115    public BoolValue SetSeedRandomly {
116      get { return SetSeedRandomlyParameter.Value; }
117      set { SetSeedRandomlyParameter.Value = value; }
118    }
119    public IntValue NumberOfIslands {
120      get { return NumberOfIslandsParameter.Value; }
121      set { NumberOfIslandsParameter.Value = value; }
122    }
123    public IntValue MigrationInterval {
124      get { return MigrationIntervalParameter.Value; }
125      set { MigrationIntervalParameter.Value = value; }
126    }
127    public PercentValue MigrationRate {
128      get { return MigrationRateParameter.Value; }
129      set { MigrationRateParameter.Value = value; }
130    }
131    public IMigrator Migrator {
132      get { return MigratorParameter.Value; }
133      set { MigratorParameter.Value = value; }
134    }
135    public ISelector EmigrantsSelector {
136      get { return EmigrantsSelectorParameter.Value; }
137      set { EmigrantsSelectorParameter.Value = value; }
138    }
139    public IReplacer ImmigrationReplacer {
140      get { return ImmigrationReplacerParameter.Value; }
141      set { ImmigrationReplacerParameter.Value = value; }
142    }
143    public IntValue PopulationSize {
144      get { return PopulationSizeParameter.Value; }
145      set { PopulationSizeParameter.Value = value; }
146    }
147    public IntValue MaximumGenerations {
148      get { return MaximumGenerationsParameter.Value; }
149      set { MaximumGenerationsParameter.Value = value; }
150    }
151    public ISelector Selector {
152      get { return SelectorParameter.Value; }
153      set { SelectorParameter.Value = value; }
154    }
155    public ICrossover Crossover {
156      get { return CrossoverParameter.Value; }
157      set { CrossoverParameter.Value = value; }
158    }
159    public PercentValue MutationProbability {
160      get { return MutationProbabilityParameter.Value; }
161      set { MutationProbabilityParameter.Value = value; }
162    }
163    public IManipulator Mutator {
164      get { return MutatorParameter.Value; }
165      set { MutatorParameter.Value = value; }
166    }
167    public IntValue Elites {
168      get { return ElitesParameter.Value; }
169      set { ElitesParameter.Value = value; }
170    }
171    public MultiAnalyzer Analyzer {
172      get { return AnalyzerParameter.Value; }
173      set { AnalyzerParameter.Value = value; }
174    }
175    public MultiAnalyzer IslandAnalyzer {
176      get { return IslandAnalyzerParameter.Value; }
177      set { IslandAnalyzerParameter.Value = value; }
178    }
179    private RandomCreator RandomCreator {
180      get { return (RandomCreator)OperatorGraph.InitialOperator; }
181    }
182    private UniformSubScopesProcessor IslandProcessor {
183      get { return ((RandomCreator.Successor as SubScopesCreator).Successor as UniformSubScopesProcessor); }
184    }
185    private SolutionsCreator SolutionsCreator {
186      get { return (SolutionsCreator)IslandProcessor.Operator; }
187    }
188    private IslandGeneticAlgorithmMainLoop MainLoop {
189      get { return (IslandGeneticAlgorithmMainLoop)IslandProcessor.Successor; }
190    }
191    [Storable]
192    private BestAverageWorstQualityAnalyzer islandQualityAnalyzer;
193    [Storable]
194    private BestAverageWorstQualityAnalyzer qualityAnalyzer;
195    #endregion
196
197    [StorableConstructor]
198    private IslandGeneticAlgorithm(bool deserializing) : base(deserializing) { }
199    [StorableHook(HookType.AfterDeserialization)]
200    private void AfterDeserialization() {
201      Initialize();
202    }
203    private IslandGeneticAlgorithm(IslandGeneticAlgorithm original, Cloner cloner)
204      : base(original, cloner) {
205      islandQualityAnalyzer = cloner.Clone(original.islandQualityAnalyzer);
206      qualityAnalyzer = cloner.Clone(original.qualityAnalyzer);
207      Initialize();
208    }
209    public override IDeepCloneable Clone(Cloner cloner) {
210      return new IslandGeneticAlgorithm(this, cloner);
211    }
212
213    public IslandGeneticAlgorithm()
214      : base() {
215      Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
216      Parameters.Add(new ValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
217      Parameters.Add(new ValueParameter<IntValue>("NumberOfIslands", "The number of islands.", new IntValue(5)));
218      Parameters.Add(new ValueParameter<IntValue>("MigrationInterval", "The number of generations that should pass between migration phases.", new IntValue(20)));
219      Parameters.Add(new ValueParameter<PercentValue>("MigrationRate", "The proportion of individuals that should migrate between the islands.", new PercentValue(0.15)));
220      Parameters.Add(new ConstrainedValueParameter<IMigrator>("Migrator", "The migration strategy."));
221      Parameters.Add(new ConstrainedValueParameter<ISelector>("EmigrantsSelector", "Selects the individuals that will be migrated."));
222      Parameters.Add(new ConstrainedValueParameter<IReplacer>("ImmigrationReplacer", "Selects the population from the unification of the original population and the immigrants."));
223      Parameters.Add(new ValueParameter<IntValue>("PopulationSize", "The size of the population of solutions.", new IntValue(100)));
224      Parameters.Add(new ValueParameter<IntValue>("MaximumGenerations", "The maximum number of generations that should be processed.", new IntValue(1000)));
225      Parameters.Add(new ConstrainedValueParameter<ISelector>("Selector", "The operator used to select solutions for reproduction."));
226      Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions."));
227      Parameters.Add(new ValueParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution.", new PercentValue(0.05)));
228      Parameters.Add(new OptionalConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions."));
229      Parameters.Add(new ValueParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.", new IntValue(1)));
230      Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze the islands.", new MultiAnalyzer()));
231      Parameters.Add(new ValueParameter<MultiAnalyzer>("IslandAnalyzer", "The operator used to analyze each island.", new MultiAnalyzer()));
232
233      RandomCreator randomCreator = new RandomCreator();
234      SubScopesCreator populationCreator = new SubScopesCreator();
235      UniformSubScopesProcessor ussp1 = new UniformSubScopesProcessor();
236      SolutionsCreator solutionsCreator = new SolutionsCreator();
237      IslandGeneticAlgorithmMainLoop mainLoop = new IslandGeneticAlgorithmMainLoop();
238      OperatorGraph.InitialOperator = randomCreator;
239
240      randomCreator.RandomParameter.ActualName = "Random";
241      randomCreator.SeedParameter.ActualName = SeedParameter.Name;
242      randomCreator.SeedParameter.Value = null;
243      randomCreator.SetSeedRandomlyParameter.ActualName = SetSeedRandomlyParameter.Name;
244      randomCreator.SetSeedRandomlyParameter.Value = null;
245      randomCreator.Successor = populationCreator;
246
247      populationCreator.NumberOfSubScopesParameter.ActualName = NumberOfIslandsParameter.Name;
248      populationCreator.Successor = ussp1;
249
250      ussp1.Operator = solutionsCreator;
251      ussp1.Successor = mainLoop;
252
253      solutionsCreator.NumberOfSolutionsParameter.ActualName = PopulationSizeParameter.Name;
254      solutionsCreator.Successor = null;
255
256      mainLoop.EmigrantsSelectorParameter.ActualName = EmigrantsSelectorParameter.Name;
257      mainLoop.ImmigrationReplacerParameter.ActualName = ImmigrationReplacerParameter.Name;
258      mainLoop.MaximumGenerationsParameter.ActualName = MaximumGenerationsParameter.Name;
259      mainLoop.MigrationIntervalParameter.ActualName = MigrationIntervalParameter.Name;
260      mainLoop.MigrationRateParameter.ActualName = MigrationRateParameter.Name;
261      mainLoop.MigratorParameter.ActualName = MigratorParameter.Name;
262      mainLoop.NumberOfIslandsParameter.ActualName = NumberOfIslandsParameter.Name;
263      mainLoop.SelectorParameter.ActualName = SelectorParameter.Name;
264      mainLoop.CrossoverParameter.ActualName = CrossoverParameter.Name;
265      mainLoop.ElitesParameter.ActualName = ElitesParameter.Name;
266      mainLoop.MutatorParameter.ActualName = MutatorParameter.Name;
267      mainLoop.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
268      mainLoop.RandomParameter.ActualName = randomCreator.RandomParameter.ActualName;
269      mainLoop.ResultsParameter.ActualName = "Results";
270      mainLoop.AnalyzerParameter.ActualName = AnalyzerParameter.Name;
271      mainLoop.IslandAnalyzerParameter.ActualName = IslandAnalyzerParameter.Name;
272      mainLoop.Successor = null;
273
274      foreach (ISelector selector in ApplicationManager.Manager.GetInstances<ISelector>().Where(x => !(x is IMultiObjectiveSelector)).OrderBy(x => x.Name))
275        SelectorParameter.ValidValues.Add(selector);
276      ISelector proportionalSelector = SelectorParameter.ValidValues.FirstOrDefault(x => x.GetType().Name.Equals("ProportionalSelector"));
277      if (proportionalSelector != null) SelectorParameter.Value = proportionalSelector;
278
279      foreach (ISelector selector in ApplicationManager.Manager.GetInstances<ISelector>().Where(x => !(x is IMultiObjectiveSelector)).OrderBy(x => x.Name))
280        EmigrantsSelectorParameter.ValidValues.Add(selector);
281
282      foreach (IReplacer replacer in ApplicationManager.Manager.GetInstances<IReplacer>().OrderBy(x => x.Name))
283        ImmigrationReplacerParameter.ValidValues.Add(replacer);
284
285      ParameterizeSelectors();
286
287      foreach (IMigrator migrator in ApplicationManager.Manager.GetInstances<IMigrator>().OrderBy(x => x.Name))
288        MigratorParameter.ValidValues.Add(migrator);
289
290      qualityAnalyzer = new BestAverageWorstQualityAnalyzer();
291      islandQualityAnalyzer = new BestAverageWorstQualityAnalyzer();
292      ParameterizeAnalyzers();
293      UpdateAnalyzers();
294
295      Initialize();
296    }
297
298    public override void Prepare() {
299      if (Problem != null) base.Prepare();
300    }
301
302    #region Events
303    protected override void OnProblemChanged() {
304      ParameterizeStochasticOperator(Problem.SolutionCreator);
305      ParameterizeStochasticOperator(Problem.Evaluator);
306      foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
307      ParameterizeSolutionsCreator();
308      ParameterizeMainLoop();
309      ParameterizeSelectors();
310      ParameterizeAnalyzers();
311      ParameterizeIterationBasedOperators();
312      UpdateCrossovers();
313      UpdateMutators();
314      UpdateAnalyzers();
315      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
316      base.OnProblemChanged();
317    }
318
319    protected override void Problem_SolutionCreatorChanged(object sender, EventArgs e) {
320      ParameterizeStochasticOperator(Problem.SolutionCreator);
321      ParameterizeSolutionsCreator();
322      base.Problem_SolutionCreatorChanged(sender, e);
323    }
324    protected override void Problem_EvaluatorChanged(object sender, EventArgs e) {
325      ParameterizeStochasticOperator(Problem.Evaluator);
326      ParameterizeSolutionsCreator();
327      ParameterizeMainLoop();
328      ParameterizeSelectors();
329      ParameterizeAnalyzers();
330      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
331      base.Problem_EvaluatorChanged(sender, e);
332    }
333    protected override void Problem_OperatorsChanged(object sender, EventArgs e) {
334      foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
335      ParameterizeIterationBasedOperators();
336      UpdateCrossovers();
337      UpdateMutators();
338      UpdateAnalyzers();
339      base.Problem_OperatorsChanged(sender, e);
340    }
341    private void ElitesParameter_ValueChanged(object sender, EventArgs e) {
342      Elites.ValueChanged += new EventHandler(Elites_ValueChanged);
343      ParameterizeSelectors();
344    }
345    private void Elites_ValueChanged(object sender, EventArgs e) {
346      ParameterizeSelectors();
347    }
348    private void PopulationSizeParameter_ValueChanged(object sender, EventArgs e) {
349      NumberOfIslands.ValueChanged += new EventHandler(PopulationSize_ValueChanged);
350      ParameterizeSelectors();
351    }
352    private void PopulationSize_ValueChanged(object sender, EventArgs e) {
353      ParameterizeSelectors();
354    }
355    private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
356      ParameterizeMainLoop();
357      ParameterizeSelectors();
358      ParameterizeAnalyzers();
359    }
360    private void MigrationRateParameter_ValueChanged(object sender, EventArgs e) {
361      MigrationRate.ValueChanged += new EventHandler(MigrationRate_ValueChanged);
362      ParameterizeSelectors();
363    }
364    private void MigrationRate_ValueChanged(object sender, EventArgs e) {
365      ParameterizeSelectors();
366    }
367    #endregion
368
369    #region Helpers
370    private void Initialize() {
371      PopulationSizeParameter.ValueChanged += new EventHandler(PopulationSizeParameter_ValueChanged);
372      PopulationSize.ValueChanged += new EventHandler(PopulationSize_ValueChanged);
373      MigrationRateParameter.ValueChanged += new EventHandler(MigrationRateParameter_ValueChanged);
374      MigrationRate.ValueChanged += new EventHandler(MigrationRate_ValueChanged);
375      ElitesParameter.ValueChanged += new EventHandler(ElitesParameter_ValueChanged);
376      Elites.ValueChanged += new EventHandler(Elites_ValueChanged);
377      if (Problem != null) {
378        Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
379      }
380    }
381    private void ParameterizeSolutionsCreator() {
382      SolutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
383      SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name;
384    }
385    private void ParameterizeMainLoop() {
386      MainLoop.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
387      MainLoop.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
388      MainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
389      MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
390    }
391    private void ParameterizeStochasticOperator(IOperator op) {
392      if (op is IStochasticOperator)
393        ((IStochasticOperator)op).RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
394    }
395    private void ParameterizeSelectors() {
396      foreach (ISelector selector in SelectorParameter.ValidValues) {
397        selector.CopySelected = new BoolValue(true);
398        selector.NumberOfSelectedSubScopesParameter.Value = new IntValue(2 * (PopulationSize.Value - Elites.Value));
399        ParameterizeStochasticOperator(selector);
400      }
401      foreach (ISelector selector in EmigrantsSelectorParameter.ValidValues) {
402        selector.CopySelected = new BoolValue(true);
403        selector.NumberOfSelectedSubScopesParameter.Value = new IntValue((int)Math.Ceiling(PopulationSize.Value * MigrationRate.Value));
404        ParameterizeStochasticOperator(selector);
405      }
406      foreach (IReplacer replacer in ImmigrationReplacerParameter.ValidValues) {
407        ParameterizeStochasticOperator(replacer);
408      }
409      if (Problem != null) {
410        foreach (ISingleObjectiveSelector selector in SelectorParameter.ValidValues.OfType<ISingleObjectiveSelector>()) {
411          selector.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
412          selector.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
413        }
414        foreach (ISingleObjectiveSelector selector in EmigrantsSelectorParameter.ValidValues.OfType<ISingleObjectiveSelector>()) {
415          selector.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
416          selector.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
417        }
418        foreach (ISingleObjectiveReplacer selector in ImmigrationReplacerParameter.ValidValues.OfType<ISingleObjectiveReplacer>()) {
419          selector.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
420          selector.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
421        }
422      }
423    }
424    private void ParameterizeAnalyzers() {
425      islandQualityAnalyzer.ResultsParameter.ActualName = "Results";
426      islandQualityAnalyzer.QualityParameter.Depth = 1;
427      qualityAnalyzer.ResultsParameter.ActualName = "Results";
428      qualityAnalyzer.QualityParameter.Depth = 2;
429
430      if (Problem != null) {
431        islandQualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
432        islandQualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
433        islandQualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
434        qualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
435        qualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
436        qualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
437      }
438    }
439    private void ParameterizeIterationBasedOperators() {
440      if (Problem != null) {
441        foreach (IIterationBasedOperator op in Problem.Operators.OfType<IIterationBasedOperator>()) {
442          op.IterationsParameter.ActualName = "Generations";
443          op.MaximumIterationsParameter.ActualName = "MaximumGenerations";
444        }
445      }
446    }
447    private void UpdateCrossovers() {
448      ICrossover oldCrossover = CrossoverParameter.Value;
449      CrossoverParameter.ValidValues.Clear();
450      foreach (ICrossover crossover in Problem.Operators.OfType<ICrossover>().OrderBy(x => x.Name))
451        CrossoverParameter.ValidValues.Add(crossover);
452      if (oldCrossover != null) {
453        ICrossover crossover = CrossoverParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldCrossover.GetType());
454        if (crossover != null) CrossoverParameter.Value = crossover;
455      }
456    }
457    private void UpdateMutators() {
458      IManipulator oldMutator = MutatorParameter.Value;
459      MutatorParameter.ValidValues.Clear();
460      foreach (IManipulator mutator in Problem.Operators.OfType<IManipulator>().OrderBy(x => x.Name))
461        MutatorParameter.ValidValues.Add(mutator);
462      if (oldMutator != null) {
463        IManipulator mutator = MutatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMutator.GetType());
464        if (mutator != null) MutatorParameter.Value = mutator;
465      }
466    }
467    private void UpdateAnalyzers() {
468      IslandAnalyzer.Operators.Clear();
469      Analyzer.Operators.Clear();
470      IslandAnalyzer.Operators.Add(islandQualityAnalyzer);
471      if (Problem != null) {
472        foreach (IAnalyzer analyzer in Problem.Operators.OfType<IAnalyzer>()) {
473          foreach (IScopeTreeLookupParameter param in analyzer.Parameters.OfType<IScopeTreeLookupParameter>())
474            param.Depth = 2;
475          Analyzer.Operators.Add(analyzer);
476        }
477      }
478      Analyzer.Operators.Add(qualityAnalyzer);
479    }
480    #endregion
481  }
482}
Note: See TracBrowser for help on using the repository browser.