Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3/OffspringSelectionGeneticAlgorithm.cs @ 5483

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

Updated year of copyrights (#1406)

File size: 24.8 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 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.OffspringSelectionGeneticAlgorithm {
37  /// <summary>
38  /// An offspring selection genetic algorithm.
39  /// </summary>
40  [Item("Offspring Selection Genetic Algorithm", "An offspring selection genetic algorithm (Affenzeller, M. et al. 2009. Genetic Algorithms and Genetic Programming - Modern Concepts and Practical Applications. CRC Press).")]
41  [Creatable("Algorithms")]
42  [StorableClass]
43  public sealed class OffspringSelectionGeneticAlgorithm : 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> PopulationSizeParameter {
64      get { return (ValueParameter<IntValue>)Parameters["PopulationSize"]; }
65    }
66    private ConstrainedValueParameter<ISelector> SelectorParameter {
67      get { return (ConstrainedValueParameter<ISelector>)Parameters["Selector"]; }
68    }
69    private ConstrainedValueParameter<ICrossover> CrossoverParameter {
70      get { return (ConstrainedValueParameter<ICrossover>)Parameters["Crossover"]; }
71    }
72    private ValueParameter<PercentValue> MutationProbabilityParameter {
73      get { return (ValueParameter<PercentValue>)Parameters["MutationProbability"]; }
74    }
75    private OptionalConstrainedValueParameter<IManipulator> MutatorParameter {
76      get { return (OptionalConstrainedValueParameter<IManipulator>)Parameters["Mutator"]; }
77    }
78    private ValueParameter<IntValue> ElitesParameter {
79      get { return (ValueParameter<IntValue>)Parameters["Elites"]; }
80    }
81    private ValueParameter<IntValue> MaximumGenerationsParameter {
82      get { return (ValueParameter<IntValue>)Parameters["MaximumGenerations"]; }
83    }
84    private ValueLookupParameter<DoubleValue> SuccessRatioParameter {
85      get { return (ValueLookupParameter<DoubleValue>)Parameters["SuccessRatio"]; }
86    }
87    private ValueLookupParameter<DoubleValue> ComparisonFactorLowerBoundParameter {
88      get { return (ValueLookupParameter<DoubleValue>)Parameters["ComparisonFactorLowerBound"]; }
89    }
90    private ValueLookupParameter<DoubleValue> ComparisonFactorUpperBoundParameter {
91      get { return (ValueLookupParameter<DoubleValue>)Parameters["ComparisonFactorUpperBound"]; }
92    }
93    private OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier> ComparisonFactorModifierParameter {
94      get { return (OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier>)Parameters["ComparisonFactorModifier"]; }
95    }
96    private ValueLookupParameter<DoubleValue> MaximumSelectionPressureParameter {
97      get { return (ValueLookupParameter<DoubleValue>)Parameters["MaximumSelectionPressure"]; }
98    }
99    private ValueLookupParameter<BoolValue> OffspringSelectionBeforeMutationParameter {
100      get { return (ValueLookupParameter<BoolValue>)Parameters["OffspringSelectionBeforeMutation"]; }
101    }
102    private ValueLookupParameter<IntValue> SelectedParentsParameter {
103      get { return (ValueLookupParameter<IntValue>)Parameters["SelectedParents"]; }
104    }
105    private ValueParameter<MultiAnalyzer> AnalyzerParameter {
106      get { return (ValueParameter<MultiAnalyzer>)Parameters["Analyzer"]; }
107    }
108    private ValueParameter<IntValue> MaximumEvaluatedSolutionsParameter {
109      get { return (ValueParameter<IntValue>)Parameters["MaximumEvaluatedSolutions"]; }
110    }
111    #endregion
112
113    #region Properties
114    public IntValue Seed {
115      get { return SeedParameter.Value; }
116      set { SeedParameter.Value = value; }
117    }
118    public BoolValue SetSeedRandomly {
119      get { return SetSeedRandomlyParameter.Value; }
120      set { SetSeedRandomlyParameter.Value = value; }
121    }
122    public IntValue PopulationSize {
123      get { return PopulationSizeParameter.Value; }
124      set { PopulationSizeParameter.Value = value; }
125    }
126    public ISelector Selector {
127      get { return SelectorParameter.Value; }
128      set { SelectorParameter.Value = value; }
129    }
130    public ICrossover Crossover {
131      get { return CrossoverParameter.Value; }
132      set { CrossoverParameter.Value = value; }
133    }
134    public PercentValue MutationProbability {
135      get { return MutationProbabilityParameter.Value; }
136      set { MutationProbabilityParameter.Value = value; }
137    }
138    public IManipulator Mutator {
139      get { return MutatorParameter.Value; }
140      set { MutatorParameter.Value = value; }
141    }
142    public IntValue Elites {
143      get { return ElitesParameter.Value; }
144      set { ElitesParameter.Value = value; }
145    }
146    public IntValue MaximumGenerations {
147      get { return MaximumGenerationsParameter.Value; }
148      set { MaximumGenerationsParameter.Value = value; }
149    }
150    public DoubleValue SuccessRatio {
151      get { return SuccessRatioParameter.Value; }
152      set { SuccessRatioParameter.Value = value; }
153    }
154    public DoubleValue ComparisonFactorLowerBound {
155      get { return ComparisonFactorLowerBoundParameter.Value; }
156      set { ComparisonFactorLowerBoundParameter.Value = value; }
157    }
158    public DoubleValue ComparisonFactorUpperBound {
159      get { return ComparisonFactorUpperBoundParameter.Value; }
160      set { ComparisonFactorUpperBoundParameter.Value = value; }
161    }
162    public IDiscreteDoubleValueModifier ComparisonFactorModifier {
163      get { return ComparisonFactorModifierParameter.Value; }
164      set { ComparisonFactorModifierParameter.Value = value; }
165    }
166    public DoubleValue MaximumSelectionPressure {
167      get { return MaximumSelectionPressureParameter.Value; }
168      set { MaximumSelectionPressureParameter.Value = value; }
169    }
170    public BoolValue OffspringSelectionBeforeMutation {
171      get { return OffspringSelectionBeforeMutationParameter.Value; }
172      set { OffspringSelectionBeforeMutationParameter.Value = value; }
173    }
174    public IntValue SelectedParents {
175      get { return SelectedParentsParameter.Value; }
176      set { SelectedParentsParameter.Value = value; }
177    }
178    public MultiAnalyzer Analyzer {
179      get { return AnalyzerParameter.Value; }
180      set { AnalyzerParameter.Value = value; }
181    }
182    public IntValue MaximumEvaluatedSolutions {
183      get { return MaximumEvaluatedSolutionsParameter.Value; }
184      set { MaximumEvaluatedSolutionsParameter.Value = value; }
185    }
186    private RandomCreator RandomCreator {
187      get { return (RandomCreator)OperatorGraph.InitialOperator; }
188    }
189    private SolutionsCreator SolutionsCreator {
190      get { return (SolutionsCreator)RandomCreator.Successor; }
191    }
192    private OffspringSelectionGeneticAlgorithmMainLoop MainLoop {
193      get { return FindMainLoop(SolutionsCreator.Successor); }
194    }
195    [Storable]
196    private BestAverageWorstQualityAnalyzer qualityAnalyzer;
197    [Storable]
198    private ValueAnalyzer selectionPressureAnalyzer;
199    #endregion
200
201    [StorableConstructor]
202    private OffspringSelectionGeneticAlgorithm(bool deserializing) : base(deserializing) { }
203    [StorableHook(HookType.AfterDeserialization)]
204    private void AfterDeserialization() {
205      Initialize();
206    }
207    private OffspringSelectionGeneticAlgorithm(OffspringSelectionGeneticAlgorithm original, Cloner cloner)
208      : base(original, cloner) {
209      qualityAnalyzer = cloner.Clone(original.qualityAnalyzer);
210      selectionPressureAnalyzer = cloner.Clone(original.selectionPressureAnalyzer);
211      Initialize();
212    }
213    public override IDeepCloneable Clone(Cloner cloner) {
214      return new OffspringSelectionGeneticAlgorithm(this, cloner);
215    }
216    public OffspringSelectionGeneticAlgorithm()
217      : base() {
218      Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
219      Parameters.Add(new ValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
220      Parameters.Add(new ValueParameter<IntValue>("PopulationSize", "The size of the population of solutions.", new IntValue(100)));
221      Parameters.Add(new ConstrainedValueParameter<ISelector>("Selector", "The operator used to select solutions for reproduction."));
222      Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions."));
223      Parameters.Add(new ValueParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution.", new PercentValue(0.05)));
224      Parameters.Add(new OptionalConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions."));
225      Parameters.Add(new ValueParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.", new IntValue(1)));
226      Parameters.Add(new ValueParameter<IntValue>("MaximumGenerations", "The maximum number of generations which should be processed.", new IntValue(1000)));
227      Parameters.Add(new ValueLookupParameter<DoubleValue>("SuccessRatio", "The ratio of successful to total children that should be achieved.", new DoubleValue(1)));
228      Parameters.Add(new ValueLookupParameter<DoubleValue>("ComparisonFactorLowerBound", "The lower bound of the comparison factor (start).", new DoubleValue(0)));
229      Parameters.Add(new ValueLookupParameter<DoubleValue>("ComparisonFactorUpperBound", "The upper bound of the comparison factor (end).", new DoubleValue(1)));
230      Parameters.Add(new OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier>("ComparisonFactorModifier", "The operator used to modify the comparison factor.", new ItemSet<IDiscreteDoubleValueModifier>(new IDiscreteDoubleValueModifier[] { new LinearDiscreteDoubleValueModifier() }), new LinearDiscreteDoubleValueModifier()));
231      Parameters.Add(new ValueLookupParameter<DoubleValue>("MaximumSelectionPressure", "The maximum selection pressure that terminates the algorithm.", new DoubleValue(100)));
232      Parameters.Add(new ValueLookupParameter<BoolValue>("OffspringSelectionBeforeMutation", "True if the offspring selection step should be applied before mutation, false if it should be applied after mutation.", new BoolValue(false)));
233      Parameters.Add(new ValueLookupParameter<IntValue>("SelectedParents", "How much parents should be selected each time the offspring selection step is performed until the population is filled. This parameter should be about the same or twice the size of PopulationSize for smaller problems, and less for large problems.", new IntValue(200)));
234      Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze each generation.", new MultiAnalyzer()));
235      Parameters.Add(new ValueParameter<IntValue>("MaximumEvaluatedSolutions", "The maximum number of evaluated solutions (approximately).", new IntValue(int.MaxValue)));
236
237      RandomCreator randomCreator = new RandomCreator();
238      SolutionsCreator solutionsCreator = new SolutionsCreator();
239      SubScopesCounter subScopesCounter = new SubScopesCounter();
240      ResultsCollector resultsCollector = new ResultsCollector();
241      OffspringSelectionGeneticAlgorithmMainLoop mainLoop = new OffspringSelectionGeneticAlgorithmMainLoop();
242      OperatorGraph.InitialOperator = randomCreator;
243
244      randomCreator.RandomParameter.ActualName = "Random";
245      randomCreator.SeedParameter.ActualName = SeedParameter.Name;
246      randomCreator.SeedParameter.Value = null;
247      randomCreator.SetSeedRandomlyParameter.ActualName = SetSeedRandomlyParameter.Name;
248      randomCreator.SetSeedRandomlyParameter.Value = null;
249      randomCreator.Successor = solutionsCreator;
250
251      solutionsCreator.NumberOfSolutionsParameter.ActualName = PopulationSizeParameter.Name;
252      solutionsCreator.Successor = subScopesCounter;
253
254      subScopesCounter.Name = "Initialize EvaluatedSolutions";
255      subScopesCounter.ValueParameter.ActualName = "EvaluatedSolutions";
256      subScopesCounter.Successor = resultsCollector;
257
258      resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Evaluated Solutions", "", "EvaluatedSolutions"));
259      resultsCollector.ResultsParameter.ActualName = "Results";
260      resultsCollector.Successor = mainLoop;
261
262      mainLoop.AnalyzerParameter.ActualName = AnalyzerParameter.Name;
263      mainLoop.ComparisonFactorModifierParameter.ActualName = ComparisonFactorModifierParameter.Name;
264      mainLoop.ComparisonFactorParameter.ActualName = "ComparisonFactor";
265      mainLoop.ComparisonFactorStartParameter.ActualName = ComparisonFactorLowerBoundParameter.Name;
266      mainLoop.CrossoverParameter.ActualName = CrossoverParameter.Name;
267      mainLoop.ElitesParameter.ActualName = ElitesParameter.Name;
268      mainLoop.EvaluatedSolutionsParameter.ActualName = "EvaluatedSolutions";
269      mainLoop.MaximumGenerationsParameter.ActualName = MaximumGenerationsParameter.Name;
270      mainLoop.MaximumSelectionPressureParameter.ActualName = MaximumSelectionPressureParameter.Name;
271      mainLoop.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
272      mainLoop.MutatorParameter.ActualName = MutatorParameter.Name;
273      mainLoop.OffspringSelectionBeforeMutationParameter.ActualName = OffspringSelectionBeforeMutationParameter.Name;
274      mainLoop.RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
275      mainLoop.ResultsParameter.ActualName = "Results";
276      mainLoop.SelectorParameter.ActualName = SelectorParameter.Name;
277      mainLoop.SuccessRatioParameter.ActualName = SuccessRatioParameter.Name;
278
279      foreach (ISelector selector in ApplicationManager.Manager.GetInstances<ISelector>().Where(x => !(x is IMultiObjectiveSelector)).OrderBy(x => x.Name))
280        SelectorParameter.ValidValues.Add(selector);
281      ISelector proportionalSelector = SelectorParameter.ValidValues.FirstOrDefault(x => x.GetType().Name.Equals("ProportionalSelector"));
282      if (proportionalSelector != null) SelectorParameter.Value = proportionalSelector;
283      ParameterizeSelectors();
284
285      foreach (IDiscreteDoubleValueModifier modifier in ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>().OrderBy(x => x.Name))
286        ComparisonFactorModifierParameter.ValidValues.Add(modifier);
287      IDiscreteDoubleValueModifier linearModifier = ComparisonFactorModifierParameter.ValidValues.FirstOrDefault(x => x.GetType().Name.Equals("LinearDiscreteDoubleValueModifier"));
288      if (linearModifier != null) ComparisonFactorModifierParameter.Value = linearModifier;
289      ParameterizeComparisonFactorModifiers();
290
291      qualityAnalyzer = new BestAverageWorstQualityAnalyzer();
292      selectionPressureAnalyzer = new ValueAnalyzer();
293      ParameterizeAnalyzers();
294      UpdateAnalyzers();
295
296      Initialize();
297    }
298
299
300
301    public override void Prepare() {
302      if (Problem != null) base.Prepare();
303    }
304
305    #region Events
306    protected override void OnProblemChanged() {
307      ParameterizeStochasticOperator(Problem.SolutionCreator);
308      ParameterizeStochasticOperator(Problem.Evaluator);
309      foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
310      ParameterizeSolutionsCreator();
311      ParameterizMainLoop();
312      ParameterizeSelectors();
313      ParameterizeAnalyzers();
314      ParameterizeIterationBasedOperators();
315      UpdateCrossovers();
316      UpdateMutators();
317      UpdateAnalyzers();
318      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
319      base.OnProblemChanged();
320    }
321
322    protected override void Problem_SolutionCreatorChanged(object sender, EventArgs e) {
323      ParameterizeStochasticOperator(Problem.SolutionCreator);
324      ParameterizeSolutionsCreator();
325      base.Problem_SolutionCreatorChanged(sender, e);
326    }
327    protected override void Problem_EvaluatorChanged(object sender, EventArgs e) {
328      ParameterizeStochasticOperator(Problem.Evaluator);
329      ParameterizeSolutionsCreator();
330      ParameterizMainLoop();
331      ParameterizeSelectors();
332      ParameterizeAnalyzers();
333      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
334      base.Problem_EvaluatorChanged(sender, e);
335    }
336    protected override void Problem_OperatorsChanged(object sender, EventArgs e) {
337      foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
338      ParameterizeIterationBasedOperators();
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      PopulationSize.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      ParameterizMainLoop();
360      ParameterizeSelectors();
361      ParameterizeAnalyzers();
362    }
363    #endregion
364
365    #region Helpers
366    private void Initialize() {
367      PopulationSizeParameter.ValueChanged += new EventHandler(PopulationSizeParameter_ValueChanged);
368      PopulationSize.ValueChanged += new EventHandler(PopulationSize_ValueChanged);
369      ElitesParameter.ValueChanged += new EventHandler(ElitesParameter_ValueChanged);
370      Elites.ValueChanged += new EventHandler(Elites_ValueChanged);
371      if (Problem != null) {
372        Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
373      }
374    }
375    private void ParameterizeSolutionsCreator() {
376      SolutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
377      SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name;
378    }
379    private void ParameterizMainLoop() {
380      MainLoop.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
381      MainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
382      MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
383    }
384    private void ParameterizeStochasticOperator(IOperator op) {
385      if (op is IStochasticOperator)
386        ((IStochasticOperator)op).RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
387    }
388    private void ParameterizeSelectors() {
389      foreach (ISelector selector in SelectorParameter.ValidValues) {
390        selector.CopySelected = new BoolValue(true);
391        selector.NumberOfSelectedSubScopesParameter.Value = null;
392        selector.NumberOfSelectedSubScopesParameter.ActualName = SelectedParentsParameter.Name;
393        ParameterizeStochasticOperator(selector);
394      }
395      if (Problem != null) {
396        foreach (ISingleObjectiveSelector selector in SelectorParameter.ValidValues.OfType<ISingleObjectiveSelector>()) {
397          selector.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
398          selector.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
399        }
400      }
401    }
402    private void ParameterizeAnalyzers() {
403      qualityAnalyzer.ResultsParameter.ActualName = "Results";
404      selectionPressureAnalyzer.Name = "SelectionPressure Analyzer";
405      selectionPressureAnalyzer.ResultsParameter.ActualName = "Results";
406      selectionPressureAnalyzer.ValueParameter.ActualName = "SelectionPressure";
407      selectionPressureAnalyzer.ValueParameter.Depth = 0;
408      selectionPressureAnalyzer.ValuesParameter.ActualName = "Selection Pressure History";
409      if (Problem != null) {
410        qualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
411        qualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
412        qualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
413      }
414    }
415    private void ParameterizeComparisonFactorModifiers() {
416      foreach (IDiscreteDoubleValueModifier modifier in ComparisonFactorModifierParameter.ValidValues) {
417        modifier.IndexParameter.ActualName = "Generations";
418        modifier.EndIndexParameter.ActualName = MaximumGenerationsParameter.Name;
419        modifier.EndValueParameter.ActualName = ComparisonFactorUpperBoundParameter.Name;
420        modifier.StartIndexParameter.Value = new IntValue(0);
421        modifier.StartValueParameter.ActualName = ComparisonFactorLowerBoundParameter.Name;
422        modifier.ValueParameter.ActualName = "ComparisonFactor";
423      }
424    }
425    private void ParameterizeIterationBasedOperators() {
426      if (Problem != null) {
427        foreach (IIterationBasedOperator op in Problem.Operators.OfType<IIterationBasedOperator>()) {
428          op.IterationsParameter.ActualName = "Generations";
429          op.MaximumIterationsParameter.ActualName = MaximumGenerationsParameter.Name;
430        }
431      }
432    }
433    private void UpdateCrossovers() {
434      ICrossover oldCrossover = CrossoverParameter.Value;
435      CrossoverParameter.ValidValues.Clear();
436      foreach (ICrossover crossover in Problem.Operators.OfType<ICrossover>().OrderBy(x => x.Name))
437        CrossoverParameter.ValidValues.Add(crossover);
438      if (oldCrossover != null) {
439        ICrossover crossover = CrossoverParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldCrossover.GetType());
440        if (crossover != null) CrossoverParameter.Value = crossover;
441      }
442    }
443    private void UpdateMutators() {
444      IManipulator oldMutator = MutatorParameter.Value;
445      MutatorParameter.ValidValues.Clear();
446      foreach (IManipulator mutator in Problem.Operators.OfType<IManipulator>().OrderBy(x => x.Name))
447        MutatorParameter.ValidValues.Add(mutator);
448      if (oldMutator != null) {
449        IManipulator mutator = MutatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMutator.GetType());
450        if (mutator != null) MutatorParameter.Value = mutator;
451      }
452    }
453    private void UpdateAnalyzers() {
454      Analyzer.Operators.Clear();
455      if (Problem != null) {
456        foreach (IAnalyzer analyzer in Problem.Operators.OfType<IAnalyzer>()) {
457          foreach (IScopeTreeLookupParameter param in analyzer.Parameters.OfType<IScopeTreeLookupParameter>())
458            param.Depth = 1;
459          Analyzer.Operators.Add(analyzer);
460        }
461      }
462      Analyzer.Operators.Add(qualityAnalyzer);
463      Analyzer.Operators.Add(selectionPressureAnalyzer);
464    }
465    private OffspringSelectionGeneticAlgorithmMainLoop FindMainLoop(IOperator start) {
466      IOperator mainLoop = start;
467      while (mainLoop != null && !(mainLoop is OffspringSelectionGeneticAlgorithmMainLoop))
468        mainLoop = ((SingleSuccessorOperator)mainLoop).Successor;
469      if (mainLoop == null) return null;
470      else return (OffspringSelectionGeneticAlgorithmMainLoop)mainLoop;
471    }
472    #endregion
473  }
474}
Note: See TracBrowser for help on using the repository browser.