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

Last change on this file since 3429 was 3429, checked in by abeham, 11 years ago

Added an OS Island GA #976
Wired the parallel parameter in the standard Island GA #971

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