Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 5356 was 5356, checked in by abeham, 13 years ago

#1344

  • Adapted all algorithms to count evaluated solutions / moves and outside of the parallel region
  • Used the same pattern in every algorithm: Initialize and collect the variable in the Algorithm and increment it in the main loops and main operators
File size: 25.0 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 {
190        return (IslandGeneticAlgorithmMainLoop)(
191          (ResultsCollector)(
192            (UniformSubScopesProcessor)(
193              (VariableCreator)IslandProcessor.Successor
194            ).Successor
195          ).Successor
196        ).Successor;
197      }
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    [StorableHook(HookType.AfterDeserialization)]
208    private void AfterDeserialization() {
209      Initialize();
210    }
211    private IslandGeneticAlgorithm(IslandGeneticAlgorithm original, Cloner cloner)
212      : base(original, cloner) {
213      islandQualityAnalyzer = cloner.Clone(original.islandQualityAnalyzer);
214      qualityAnalyzer = cloner.Clone(original.qualityAnalyzer);
215      Initialize();
216    }
217    public override IDeepCloneable Clone(Cloner cloner) {
218      return new IslandGeneticAlgorithm(this, cloner);
219    }
220
221    public IslandGeneticAlgorithm()
222      : base() {
223      Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
224      Parameters.Add(new ValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
225      Parameters.Add(new ValueParameter<IntValue>("NumberOfIslands", "The number of islands.", new IntValue(5)));
226      Parameters.Add(new ValueParameter<IntValue>("MigrationInterval", "The number of generations that should pass between migration phases.", new IntValue(20)));
227      Parameters.Add(new ValueParameter<PercentValue>("MigrationRate", "The proportion of individuals that should migrate between the islands.", new PercentValue(0.15)));
228      Parameters.Add(new ConstrainedValueParameter<IMigrator>("Migrator", "The migration strategy."));
229      Parameters.Add(new ConstrainedValueParameter<ISelector>("EmigrantsSelector", "Selects the individuals that will be migrated."));
230      Parameters.Add(new ConstrainedValueParameter<IReplacer>("ImmigrationReplacer", "Selects the population from the unification of the original population and the immigrants."));
231      Parameters.Add(new ValueParameter<IntValue>("PopulationSize", "The size of the population of solutions.", new IntValue(100)));
232      Parameters.Add(new ValueParameter<IntValue>("MaximumGenerations", "The maximum number of generations that should be processed.", new IntValue(1000)));
233      Parameters.Add(new ConstrainedValueParameter<ISelector>("Selector", "The operator used to select solutions for reproduction."));
234      Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions."));
235      Parameters.Add(new ValueParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution.", new PercentValue(0.05)));
236      Parameters.Add(new OptionalConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions."));
237      Parameters.Add(new ValueParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.", new IntValue(1)));
238      Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze the islands.", new MultiAnalyzer()));
239      Parameters.Add(new ValueParameter<MultiAnalyzer>("IslandAnalyzer", "The operator used to analyze each island.", new MultiAnalyzer()));
240
241      RandomCreator randomCreator = new RandomCreator();
242      SubScopesCreator populationCreator = new SubScopesCreator();
243      UniformSubScopesProcessor ussp1 = new UniformSubScopesProcessor();
244      SolutionsCreator solutionsCreator = new SolutionsCreator();
245      VariableCreator variableCreator = new VariableCreator();
246      UniformSubScopesProcessor ussp2 = new UniformSubScopesProcessor();
247      SubScopesCounter subScopesCounter = new SubScopesCounter();
248      ResultsCollector resultsCollector = new ResultsCollector();
249      IslandGeneticAlgorithmMainLoop mainLoop = new IslandGeneticAlgorithmMainLoop();
250      OperatorGraph.InitialOperator = randomCreator;
251
252      randomCreator.RandomParameter.ActualName = "Random";
253      randomCreator.SeedParameter.ActualName = SeedParameter.Name;
254      randomCreator.SeedParameter.Value = null;
255      randomCreator.SetSeedRandomlyParameter.ActualName = SetSeedRandomlyParameter.Name;
256      randomCreator.SetSeedRandomlyParameter.Value = null;
257      randomCreator.Successor = populationCreator;
258
259      populationCreator.NumberOfSubScopesParameter.ActualName = NumberOfIslandsParameter.Name;
260      populationCreator.Successor = ussp1;
261
262      ussp1.Operator = solutionsCreator;
263      ussp1.Successor = variableCreator;
264
265      solutionsCreator.NumberOfSolutionsParameter.ActualName = PopulationSizeParameter.Name;
266      solutionsCreator.Successor = null;
267
268      variableCreator.Name = "Initialize EvaluatedSolutions";
269      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("EvaluatedSolutions", new IntValue()));
270      variableCreator.Successor = ussp2;
271
272      ussp2.Operator = subScopesCounter;
273      ussp2.Successor = resultsCollector;
274
275      subScopesCounter.Name = "Count EvaluatedSolutions";
276      subScopesCounter.ValueParameter.ActualName = "EvaluatedSolutions";
277      subScopesCounter.Successor = null;
278
279      resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Evaluated Solutions", null, "EvaluatedSolutions"));
280      resultsCollector.ResultsParameter.ActualName = "Results";
281      resultsCollector.Successor = mainLoop;
282
283      mainLoop.EmigrantsSelectorParameter.ActualName = EmigrantsSelectorParameter.Name;
284      mainLoop.ImmigrationReplacerParameter.ActualName = ImmigrationReplacerParameter.Name;
285      mainLoop.MaximumGenerationsParameter.ActualName = MaximumGenerationsParameter.Name;
286      mainLoop.MigrationIntervalParameter.ActualName = MigrationIntervalParameter.Name;
287      mainLoop.MigrationRateParameter.ActualName = MigrationRateParameter.Name;
288      mainLoop.MigratorParameter.ActualName = MigratorParameter.Name;
289      mainLoop.NumberOfIslandsParameter.ActualName = NumberOfIslandsParameter.Name;
290      mainLoop.SelectorParameter.ActualName = SelectorParameter.Name;
291      mainLoop.CrossoverParameter.ActualName = CrossoverParameter.Name;
292      mainLoop.ElitesParameter.ActualName = ElitesParameter.Name;
293      mainLoop.MutatorParameter.ActualName = MutatorParameter.Name;
294      mainLoop.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
295      mainLoop.RandomParameter.ActualName = randomCreator.RandomParameter.ActualName;
296      mainLoop.ResultsParameter.ActualName = "Results";
297      mainLoop.AnalyzerParameter.ActualName = AnalyzerParameter.Name;
298      mainLoop.IslandAnalyzerParameter.ActualName = IslandAnalyzerParameter.Name;
299      mainLoop.EvaluatedSolutionsParameter.ActualName = "EvaluatedSolutions";
300      mainLoop.Successor = null;
301
302      foreach (ISelector selector in ApplicationManager.Manager.GetInstances<ISelector>().Where(x => !(x is IMultiObjectiveSelector)).OrderBy(x => x.Name))
303        SelectorParameter.ValidValues.Add(selector);
304      ISelector proportionalSelector = SelectorParameter.ValidValues.FirstOrDefault(x => x.GetType().Name.Equals("ProportionalSelector"));
305      if (proportionalSelector != null) SelectorParameter.Value = proportionalSelector;
306
307      foreach (ISelector selector in ApplicationManager.Manager.GetInstances<ISelector>().Where(x => !(x is IMultiObjectiveSelector)).OrderBy(x => x.Name))
308        EmigrantsSelectorParameter.ValidValues.Add(selector);
309
310      foreach (IReplacer replacer in ApplicationManager.Manager.GetInstances<IReplacer>().OrderBy(x => x.Name))
311        ImmigrationReplacerParameter.ValidValues.Add(replacer);
312
313      ParameterizeSelectors();
314
315      foreach (IMigrator migrator in ApplicationManager.Manager.GetInstances<IMigrator>().OrderBy(x => x.Name))
316        MigratorParameter.ValidValues.Add(migrator);
317
318      qualityAnalyzer = new BestAverageWorstQualityAnalyzer();
319      islandQualityAnalyzer = new BestAverageWorstQualityAnalyzer();
320      ParameterizeAnalyzers();
321      UpdateAnalyzers();
322
323      Initialize();
324    }
325
326    public override void Prepare() {
327      if (Problem != null) base.Prepare();
328    }
329
330    #region Events
331    protected override void OnProblemChanged() {
332      ParameterizeStochasticOperator(Problem.SolutionCreator);
333      ParameterizeStochasticOperator(Problem.Evaluator);
334      foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
335      ParameterizeSolutionsCreator();
336      ParameterizeMainLoop();
337      ParameterizeSelectors();
338      ParameterizeAnalyzers();
339      ParameterizeIterationBasedOperators();
340      UpdateCrossovers();
341      UpdateMutators();
342      UpdateAnalyzers();
343      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
344      base.OnProblemChanged();
345    }
346
347    protected override void Problem_SolutionCreatorChanged(object sender, EventArgs e) {
348      ParameterizeStochasticOperator(Problem.SolutionCreator);
349      ParameterizeSolutionsCreator();
350      base.Problem_SolutionCreatorChanged(sender, e);
351    }
352    protected override void Problem_EvaluatorChanged(object sender, EventArgs e) {
353      ParameterizeStochasticOperator(Problem.Evaluator);
354      ParameterizeSolutionsCreator();
355      ParameterizeMainLoop();
356      ParameterizeSelectors();
357      ParameterizeAnalyzers();
358      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
359      base.Problem_EvaluatorChanged(sender, e);
360    }
361    protected override void Problem_OperatorsChanged(object sender, EventArgs e) {
362      foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
363      ParameterizeIterationBasedOperators();
364      UpdateCrossovers();
365      UpdateMutators();
366      UpdateAnalyzers();
367      base.Problem_OperatorsChanged(sender, e);
368    }
369    private void ElitesParameter_ValueChanged(object sender, EventArgs e) {
370      Elites.ValueChanged += new EventHandler(Elites_ValueChanged);
371      ParameterizeSelectors();
372    }
373    private void Elites_ValueChanged(object sender, EventArgs e) {
374      ParameterizeSelectors();
375    }
376    private void PopulationSizeParameter_ValueChanged(object sender, EventArgs e) {
377      NumberOfIslands.ValueChanged += new EventHandler(PopulationSize_ValueChanged);
378      ParameterizeSelectors();
379    }
380    private void PopulationSize_ValueChanged(object sender, EventArgs e) {
381      ParameterizeSelectors();
382    }
383    private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
384      ParameterizeMainLoop();
385      ParameterizeSelectors();
386      ParameterizeAnalyzers();
387    }
388    private void MigrationRateParameter_ValueChanged(object sender, EventArgs e) {
389      MigrationRate.ValueChanged += new EventHandler(MigrationRate_ValueChanged);
390      ParameterizeSelectors();
391    }
392    private void MigrationRate_ValueChanged(object sender, EventArgs e) {
393      ParameterizeSelectors();
394    }
395    #endregion
396
397    #region Helpers
398    private void Initialize() {
399      PopulationSizeParameter.ValueChanged += new EventHandler(PopulationSizeParameter_ValueChanged);
400      PopulationSize.ValueChanged += new EventHandler(PopulationSize_ValueChanged);
401      MigrationRateParameter.ValueChanged += new EventHandler(MigrationRateParameter_ValueChanged);
402      MigrationRate.ValueChanged += new EventHandler(MigrationRate_ValueChanged);
403      ElitesParameter.ValueChanged += new EventHandler(ElitesParameter_ValueChanged);
404      Elites.ValueChanged += new EventHandler(Elites_ValueChanged);
405      if (Problem != null) {
406        Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
407      }
408    }
409    private void ParameterizeSolutionsCreator() {
410      SolutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
411      SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name;
412    }
413    private void ParameterizeMainLoop() {
414      MainLoop.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
415      MainLoop.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
416      MainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
417      MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
418    }
419    private void ParameterizeStochasticOperator(IOperator op) {
420      if (op is IStochasticOperator)
421        ((IStochasticOperator)op).RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
422    }
423    private void ParameterizeSelectors() {
424      foreach (ISelector selector in SelectorParameter.ValidValues) {
425        selector.CopySelected = new BoolValue(true);
426        selector.NumberOfSelectedSubScopesParameter.Value = new IntValue(2 * (PopulationSize.Value - Elites.Value));
427        ParameterizeStochasticOperator(selector);
428      }
429      foreach (ISelector selector in EmigrantsSelectorParameter.ValidValues) {
430        selector.CopySelected = new BoolValue(true);
431        selector.NumberOfSelectedSubScopesParameter.Value = new IntValue((int)Math.Ceiling(PopulationSize.Value * MigrationRate.Value));
432        ParameterizeStochasticOperator(selector);
433      }
434      foreach (IReplacer replacer in ImmigrationReplacerParameter.ValidValues) {
435        ParameterizeStochasticOperator(replacer);
436      }
437      if (Problem != null) {
438        foreach (ISingleObjectiveSelector selector in SelectorParameter.ValidValues.OfType<ISingleObjectiveSelector>()) {
439          selector.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
440          selector.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
441        }
442        foreach (ISingleObjectiveSelector selector in EmigrantsSelectorParameter.ValidValues.OfType<ISingleObjectiveSelector>()) {
443          selector.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
444          selector.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
445        }
446        foreach (ISingleObjectiveReplacer selector in ImmigrationReplacerParameter.ValidValues.OfType<ISingleObjectiveReplacer>()) {
447          selector.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
448          selector.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
449        }
450      }
451    }
452    private void ParameterizeAnalyzers() {
453      islandQualityAnalyzer.ResultsParameter.ActualName = "Results";
454      islandQualityAnalyzer.QualityParameter.Depth = 1;
455      qualityAnalyzer.ResultsParameter.ActualName = "Results";
456      qualityAnalyzer.QualityParameter.Depth = 2;
457
458      if (Problem != null) {
459        islandQualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
460        islandQualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
461        islandQualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
462        qualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
463        qualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
464        qualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
465      }
466    }
467    private void ParameterizeIterationBasedOperators() {
468      if (Problem != null) {
469        foreach (IIterationBasedOperator op in Problem.Operators.OfType<IIterationBasedOperator>()) {
470          op.IterationsParameter.ActualName = "Generations";
471          op.MaximumIterationsParameter.ActualName = "MaximumGenerations";
472        }
473      }
474    }
475    private void UpdateCrossovers() {
476      ICrossover oldCrossover = CrossoverParameter.Value;
477      CrossoverParameter.ValidValues.Clear();
478      foreach (ICrossover crossover in Problem.Operators.OfType<ICrossover>().OrderBy(x => x.Name))
479        CrossoverParameter.ValidValues.Add(crossover);
480      if (oldCrossover != null) {
481        ICrossover crossover = CrossoverParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldCrossover.GetType());
482        if (crossover != null) CrossoverParameter.Value = crossover;
483      }
484    }
485    private void UpdateMutators() {
486      IManipulator oldMutator = MutatorParameter.Value;
487      MutatorParameter.ValidValues.Clear();
488      foreach (IManipulator mutator in Problem.Operators.OfType<IManipulator>().OrderBy(x => x.Name))
489        MutatorParameter.ValidValues.Add(mutator);
490      if (oldMutator != null) {
491        IManipulator mutator = MutatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMutator.GetType());
492        if (mutator != null) MutatorParameter.Value = mutator;
493      }
494    }
495    private void UpdateAnalyzers() {
496      IslandAnalyzer.Operators.Clear();
497      Analyzer.Operators.Clear();
498      IslandAnalyzer.Operators.Add(islandQualityAnalyzer);
499      if (Problem != null) {
500        foreach (IAnalyzer analyzer in Problem.Operators.OfType<IAnalyzer>()) {
501          foreach (IScopeTreeLookupParameter param in analyzer.Parameters.OfType<IScopeTreeLookupParameter>())
502            param.Depth = 2;
503          Analyzer.Operators.Add(analyzer);
504        }
505      }
506      Analyzer.Operators.Add(qualityAnalyzer);
507    }
508    #endregion
509  }
510}
Note: See TracBrowser for help on using the repository browser.