Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 3689 was 3689, checked in by abeham, 14 years ago

#893

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