Free cookie consent management tool by TermsFeed Policy Generator

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

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

Adaptions according to the new IContent interface (#969).

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