Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 8330 was 8121, checked in by gkronber, 12 years ago

#1797 added an interface IConstrainedValueParameter, added a test case to check the name, visibility and type of the parameter-property for constrainedValueParameters, corrected all properties in IParameterizedItems

File size: 26.0 KB
RevLine 
[3378]1#region License Information
2/* HeuristicLab
[7259]3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[3378]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;
[3650]24using HeuristicLab.Analysis;
[4068]25using HeuristicLab.Common;
[3378]26using HeuristicLab.Core;
27using HeuristicLab.Data;
[5356]28using HeuristicLab.Operators;
[3378]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>
[3379]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).")]
[3378]41  [Creatable("Algorithms")]
42  [StorableClass]
[5809]43  public sealed class OffspringSelectionGeneticAlgorithm : HeuristicOptimizationEngineAlgorithm, IStorableContent {
[4437]44    public string Filename { get; set; }
45
[3378]46    #region Problem Properties
47    public override Type ProblemType {
[5809]48      get { return typeof(ISingleObjectiveHeuristicOptimizationProblem); }
[3378]49    }
[5809]50    public new ISingleObjectiveHeuristicOptimizationProblem Problem {
51      get { return (ISingleObjectiveHeuristicOptimizationProblem)base.Problem; }
[3378]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    }
[8121]66    public IConstrainedValueParameter<ISelector> SelectorParameter {
67      get { return (IConstrainedValueParameter<ISelector>)Parameters["Selector"]; }
[3378]68    }
[8121]69    public IConstrainedValueParameter<ICrossover> CrossoverParameter {
70      get { return (IConstrainedValueParameter<ICrossover>)Parameters["Crossover"]; }
[3378]71    }
72    private ValueParameter<PercentValue> MutationProbabilityParameter {
73      get { return (ValueParameter<PercentValue>)Parameters["MutationProbability"]; }
74    }
[8121]75    public IConstrainedValueParameter<IManipulator> MutatorParameter {
76      get { return (IConstrainedValueParameter<IManipulator>)Parameters["Mutator"]; }
[3378]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    }
[3379]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    }
[8121]93    public IConstrainedValueParameter<IDiscreteDoubleValueModifier> ComparisonFactorModifierParameter {
94      get { return (IConstrainedValueParameter<IDiscreteDoubleValueModifier>)Parameters["ComparisonFactorModifier"]; }
[3379]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    }
[3510]102    private ValueLookupParameter<IntValue> SelectedParentsParameter {
103      get { return (ValueLookupParameter<IntValue>)Parameters["SelectedParents"]; }
104    }
[3658]105    private ValueParameter<MultiAnalyzer> AnalyzerParameter {
106      get { return (ValueParameter<MultiAnalyzer>)Parameters["Analyzer"]; }
[3650]107    }
[3891]108    private ValueParameter<IntValue> MaximumEvaluatedSolutionsParameter {
109      get { return (ValueParameter<IntValue>)Parameters["MaximumEvaluatedSolutions"]; }
110    }
[3378]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    }
[3510]150    public DoubleValue SuccessRatio {
[3379]151      get { return SuccessRatioParameter.Value; }
152      set { SuccessRatioParameter.Value = value; }
153    }
[3510]154    public DoubleValue ComparisonFactorLowerBound {
[3379]155      get { return ComparisonFactorLowerBoundParameter.Value; }
156      set { ComparisonFactorLowerBoundParameter.Value = value; }
157    }
[3510]158    public DoubleValue ComparisonFactorUpperBound {
[3379]159      get { return ComparisonFactorUpperBoundParameter.Value; }
160      set { ComparisonFactorUpperBoundParameter.Value = value; }
161    }
[3510]162    public IDiscreteDoubleValueModifier ComparisonFactorModifier {
[3379]163      get { return ComparisonFactorModifierParameter.Value; }
164      set { ComparisonFactorModifierParameter.Value = value; }
165    }
[3510]166    public DoubleValue MaximumSelectionPressure {
[3379]167      get { return MaximumSelectionPressureParameter.Value; }
168      set { MaximumSelectionPressureParameter.Value = value; }
169    }
[3510]170    public BoolValue OffspringSelectionBeforeMutation {
[3379]171      get { return OffspringSelectionBeforeMutationParameter.Value; }
172      set { OffspringSelectionBeforeMutationParameter.Value = value; }
173    }
[3510]174    public IntValue SelectedParents {
175      get { return SelectedParentsParameter.Value; }
176      set { SelectedParentsParameter.Value = value; }
177    }
[3658]178    public MultiAnalyzer Analyzer {
[3650]179      get { return AnalyzerParameter.Value; }
180      set { AnalyzerParameter.Value = value; }
181    }
[3891]182    public IntValue MaximumEvaluatedSolutions {
183      get { return MaximumEvaluatedSolutionsParameter.Value; }
184      set { MaximumEvaluatedSolutionsParameter.Value = value; }
185    }
[3378]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 {
[5366]193      get { return FindMainLoop(SolutionsCreator.Successor); }
[3378]194    }
[3689]195    [Storable]
[3672]196    private BestAverageWorstQualityAnalyzer qualityAnalyzer;
[3689]197    [Storable]
[3672]198    private ValueAnalyzer selectionPressureAnalyzer;
[5683]199    [Storable]
200    private SuccessfulOffspringAnalyzer successfulOffspringAnalyzer;
[3378]201    #endregion
202
[3379]203    [StorableConstructor]
204    private OffspringSelectionGeneticAlgorithm(bool deserializing) : base(deserializing) { }
[4722]205    [StorableHook(HookType.AfterDeserialization)]
206    private void AfterDeserialization() {
[5683]207      #region Backwards Compatibility
208      if (successfulOffspringAnalyzer == null)
209        successfulOffspringAnalyzer = new SuccessfulOffspringAnalyzer();
210      #endregion
[7172]211
[4722]212      Initialize();
213    }
214    private OffspringSelectionGeneticAlgorithm(OffspringSelectionGeneticAlgorithm original, Cloner cloner)
215      : base(original, cloner) {
216      qualityAnalyzer = cloner.Clone(original.qualityAnalyzer);
217      selectionPressureAnalyzer = cloner.Clone(original.selectionPressureAnalyzer);
[5683]218      successfulOffspringAnalyzer = cloner.Clone(original.successfulOffspringAnalyzer);
[4722]219      Initialize();
220    }
221    public override IDeepCloneable Clone(Cloner cloner) {
222      return new OffspringSelectionGeneticAlgorithm(this, cloner);
223    }
[3378]224    public OffspringSelectionGeneticAlgorithm()
225      : base() {
226      Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
227      Parameters.Add(new ValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
228      Parameters.Add(new ValueParameter<IntValue>("PopulationSize", "The size of the population of solutions.", new IntValue(100)));
229      Parameters.Add(new ConstrainedValueParameter<ISelector>("Selector", "The operator used to select solutions for reproduction."));
230      Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions."));
231      Parameters.Add(new ValueParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution.", new PercentValue(0.05)));
232      Parameters.Add(new OptionalConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions."));
233      Parameters.Add(new ValueParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.", new IntValue(1)));
234      Parameters.Add(new ValueParameter<IntValue>("MaximumGenerations", "The maximum number of generations which should be processed.", new IntValue(1000)));
[3379]235      Parameters.Add(new ValueLookupParameter<DoubleValue>("SuccessRatio", "The ratio of successful to total children that should be achieved.", new DoubleValue(1)));
236      Parameters.Add(new ValueLookupParameter<DoubleValue>("ComparisonFactorLowerBound", "The lower bound of the comparison factor (start).", new DoubleValue(0)));
237      Parameters.Add(new ValueLookupParameter<DoubleValue>("ComparisonFactorUpperBound", "The upper bound of the comparison factor (end).", new DoubleValue(1)));
[3426]238      Parameters.Add(new OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier>("ComparisonFactorModifier", "The operator used to modify the comparison factor.", new ItemSet<IDiscreteDoubleValueModifier>(new IDiscreteDoubleValueModifier[] { new LinearDiscreteDoubleValueModifier() }), new LinearDiscreteDoubleValueModifier()));
[3379]239      Parameters.Add(new ValueLookupParameter<DoubleValue>("MaximumSelectionPressure", "The maximum selection pressure that terminates the algorithm.", new DoubleValue(100)));
240      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)));
[3735]241      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)));
[3658]242      Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze each generation.", new MultiAnalyzer()));
[3891]243      Parameters.Add(new ValueParameter<IntValue>("MaximumEvaluatedSolutions", "The maximum number of evaluated solutions (approximately).", new IntValue(int.MaxValue)));
244
[3378]245      RandomCreator randomCreator = new RandomCreator();
246      SolutionsCreator solutionsCreator = new SolutionsCreator();
[5356]247      SubScopesCounter subScopesCounter = new SubScopesCounter();
248      ResultsCollector resultsCollector = new ResultsCollector();
[3378]249      OffspringSelectionGeneticAlgorithmMainLoop mainLoop = new OffspringSelectionGeneticAlgorithmMainLoop();
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 = solutionsCreator;
258
259      solutionsCreator.NumberOfSolutionsParameter.ActualName = PopulationSizeParameter.Name;
[5356]260      solutionsCreator.Successor = subScopesCounter;
[3378]261
[5356]262      subScopesCounter.Name = "Initialize EvaluatedSolutions";
263      subScopesCounter.ValueParameter.ActualName = "EvaluatedSolutions";
264      subScopesCounter.Successor = resultsCollector;
265
266      resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Evaluated Solutions", "", "EvaluatedSolutions"));
267      resultsCollector.ResultsParameter.ActualName = "Results";
268      resultsCollector.Successor = mainLoop;
269
[3744]270      mainLoop.AnalyzerParameter.ActualName = AnalyzerParameter.Name;
271      mainLoop.ComparisonFactorModifierParameter.ActualName = ComparisonFactorModifierParameter.Name;
272      mainLoop.ComparisonFactorParameter.ActualName = "ComparisonFactor";
273      mainLoop.ComparisonFactorStartParameter.ActualName = ComparisonFactorLowerBoundParameter.Name;
[3378]274      mainLoop.CrossoverParameter.ActualName = CrossoverParameter.Name;
275      mainLoop.ElitesParameter.ActualName = ElitesParameter.Name;
[5356]276      mainLoop.EvaluatedSolutionsParameter.ActualName = "EvaluatedSolutions";
[3378]277      mainLoop.MaximumGenerationsParameter.ActualName = MaximumGenerationsParameter.Name;
[3744]278      mainLoop.MaximumSelectionPressureParameter.ActualName = MaximumSelectionPressureParameter.Name;
279      mainLoop.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
[3378]280      mainLoop.MutatorParameter.ActualName = MutatorParameter.Name;
[3744]281      mainLoop.OffspringSelectionBeforeMutationParameter.ActualName = OffspringSelectionBeforeMutationParameter.Name;
[3378]282      mainLoop.RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
283      mainLoop.ResultsParameter.ActualName = "Results";
[3744]284      mainLoop.SelectorParameter.ActualName = SelectorParameter.Name;
285      mainLoop.SuccessRatioParameter.ActualName = SuccessRatioParameter.Name;
[3378]286
[3689]287      foreach (ISelector selector in ApplicationManager.Manager.GetInstances<ISelector>().Where(x => !(x is IMultiObjectiveSelector)).OrderBy(x => x.Name))
288        SelectorParameter.ValidValues.Add(selector);
289      ISelector proportionalSelector = SelectorParameter.ValidValues.FirstOrDefault(x => x.GetType().Name.Equals("ProportionalSelector"));
290      if (proportionalSelector != null) SelectorParameter.Value = proportionalSelector;
291      ParameterizeSelectors();
292
293      foreach (IDiscreteDoubleValueModifier modifier in ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>().OrderBy(x => x.Name))
294        ComparisonFactorModifierParameter.ValidValues.Add(modifier);
295      IDiscreteDoubleValueModifier linearModifier = ComparisonFactorModifierParameter.ValidValues.FirstOrDefault(x => x.GetType().Name.Equals("LinearDiscreteDoubleValueModifier"));
296      if (linearModifier != null) ComparisonFactorModifierParameter.Value = linearModifier;
297      ParameterizeComparisonFactorModifiers();
298
299      qualityAnalyzer = new BestAverageWorstQualityAnalyzer();
300      selectionPressureAnalyzer = new ValueAnalyzer();
[5683]301      successfulOffspringAnalyzer = new SuccessfulOffspringAnalyzer();
[3689]302      ParameterizeAnalyzers();
303      UpdateAnalyzers();
304
[3378]305      Initialize();
306    }
307
308
[4722]309
[3378]310    public override void Prepare() {
311      if (Problem != null) base.Prepare();
312    }
313
314    #region Events
315    protected override void OnProblemChanged() {
316      ParameterizeStochasticOperator(Problem.SolutionCreator);
317      ParameterizeStochasticOperator(Problem.Evaluator);
[7999]318      foreach (IOperator op in Problem.Operators.OfType<IOperator>()) ParameterizeStochasticOperator(op);
[3378]319      ParameterizeSolutionsCreator();
[3379]320      ParameterizMainLoop();
[3378]321      ParameterizeSelectors();
[3650]322      ParameterizeAnalyzers();
[3750]323      ParameterizeIterationBasedOperators();
[3378]324      UpdateCrossovers();
325      UpdateMutators();
[3650]326      UpdateAnalyzers();
[3378]327      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
328      base.OnProblemChanged();
329    }
330
331    protected override void Problem_SolutionCreatorChanged(object sender, EventArgs e) {
332      ParameterizeStochasticOperator(Problem.SolutionCreator);
333      ParameterizeSolutionsCreator();
334      base.Problem_SolutionCreatorChanged(sender, e);
335    }
336    protected override void Problem_EvaluatorChanged(object sender, EventArgs e) {
337      ParameterizeStochasticOperator(Problem.Evaluator);
338      ParameterizeSolutionsCreator();
[3379]339      ParameterizMainLoop();
[3378]340      ParameterizeSelectors();
[3650]341      ParameterizeAnalyzers();
[3378]342      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
343      base.Problem_EvaluatorChanged(sender, e);
344    }
345    protected override void Problem_OperatorsChanged(object sender, EventArgs e) {
[7999]346      foreach (IOperator op in Problem.Operators.OfType<IOperator>()) ParameterizeStochasticOperator(op);
[3750]347      ParameterizeIterationBasedOperators();
[3378]348      UpdateCrossovers();
349      UpdateMutators();
[3650]350      UpdateAnalyzers();
[3378]351      base.Problem_OperatorsChanged(sender, e);
352    }
353    private void ElitesParameter_ValueChanged(object sender, EventArgs e) {
354      Elites.ValueChanged += new EventHandler(Elites_ValueChanged);
355      ParameterizeSelectors();
356    }
357    private void Elites_ValueChanged(object sender, EventArgs e) {
358      ParameterizeSelectors();
359    }
360    private void PopulationSizeParameter_ValueChanged(object sender, EventArgs e) {
361      PopulationSize.ValueChanged += new EventHandler(PopulationSize_ValueChanged);
362      ParameterizeSelectors();
363    }
364    private void PopulationSize_ValueChanged(object sender, EventArgs e) {
365      ParameterizeSelectors();
366    }
367    private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
[3379]368      ParameterizMainLoop();
[3378]369      ParameterizeSelectors();
[3650]370      ParameterizeAnalyzers();
[3378]371    }
372    #endregion
373
374    #region Helpers
375    private void Initialize() {
376      PopulationSizeParameter.ValueChanged += new EventHandler(PopulationSizeParameter_ValueChanged);
377      PopulationSize.ValueChanged += new EventHandler(PopulationSize_ValueChanged);
378      ElitesParameter.ValueChanged += new EventHandler(ElitesParameter_ValueChanged);
379      Elites.ValueChanged += new EventHandler(Elites_ValueChanged);
380      if (Problem != null) {
381        Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
382      }
383    }
384    private void ParameterizeSolutionsCreator() {
385      SolutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
386      SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name;
387    }
[3379]388    private void ParameterizMainLoop() {
[3378]389      MainLoop.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
390      MainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
391      MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
392    }
393    private void ParameterizeStochasticOperator(IOperator op) {
394      if (op is IStochasticOperator)
395        ((IStochasticOperator)op).RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
396    }
397    private void ParameterizeSelectors() {
[3689]398      foreach (ISelector selector in SelectorParameter.ValidValues) {
[3378]399        selector.CopySelected = new BoolValue(true);
[3510]400        selector.NumberOfSelectedSubScopesParameter.Value = null;
401        selector.NumberOfSelectedSubScopesParameter.ActualName = SelectedParentsParameter.Name;
[3378]402        ParameterizeStochasticOperator(selector);
403      }
404      if (Problem != null) {
[3689]405        foreach (ISingleObjectiveSelector selector in SelectorParameter.ValidValues.OfType<ISingleObjectiveSelector>()) {
[3378]406          selector.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
407          selector.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
408        }
409      }
410    }
[3650]411    private void ParameterizeAnalyzers() {
[3672]412      qualityAnalyzer.ResultsParameter.ActualName = "Results";
413      selectionPressureAnalyzer.Name = "SelectionPressure Analyzer";
414      selectionPressureAnalyzer.ResultsParameter.ActualName = "Results";
415      selectionPressureAnalyzer.ValueParameter.ActualName = "SelectionPressure";
416      selectionPressureAnalyzer.ValueParameter.Depth = 0;
417      selectionPressureAnalyzer.ValuesParameter.ActualName = "Selection Pressure History";
[5683]418      successfulOffspringAnalyzer.ResultsParameter.ActualName = "Results";
419      successfulOffspringAnalyzer.GenerationsParameter.ActualName = "Generations";
[5725]420      successfulOffspringAnalyzer.SuccessfulOffspringFlagParameter.Value.Value = "SuccessfulOffspring";
[5683]421      successfulOffspringAnalyzer.DepthParameter.Value = new IntValue(1);
[3650]422      if (Problem != null) {
[3672]423        qualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
424        qualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
425        qualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
[3650]426      }
427    }
[3379]428    private void ParameterizeComparisonFactorModifiers() {
[3689]429      foreach (IDiscreteDoubleValueModifier modifier in ComparisonFactorModifierParameter.ValidValues) {
[3413]430        modifier.IndexParameter.ActualName = "Generations";
[3379]431        modifier.EndIndexParameter.ActualName = MaximumGenerationsParameter.Name;
432        modifier.EndValueParameter.ActualName = ComparisonFactorUpperBoundParameter.Name;
433        modifier.StartIndexParameter.Value = new IntValue(0);
434        modifier.StartValueParameter.ActualName = ComparisonFactorLowerBoundParameter.Name;
[3413]435        modifier.ValueParameter.ActualName = "ComparisonFactor";
[3379]436      }
437    }
[3750]438    private void ParameterizeIterationBasedOperators() {
439      if (Problem != null) {
440        foreach (IIterationBasedOperator op in Problem.Operators.OfType<IIterationBasedOperator>()) {
441          op.IterationsParameter.ActualName = "Generations";
442          op.MaximumIterationsParameter.ActualName = MaximumGenerationsParameter.Name;
443        }
444      }
445    }
[3378]446    private void UpdateCrossovers() {
447      ICrossover oldCrossover = CrossoverParameter.Value;
448      CrossoverParameter.ValidValues.Clear();
[7493]449      ICrossover defaultCrossover = Problem.Operators.OfType<ICrossover>().FirstOrDefault();
450
[3378]451      foreach (ICrossover crossover in Problem.Operators.OfType<ICrossover>().OrderBy(x => x.Name))
452        CrossoverParameter.ValidValues.Add(crossover);
[7493]453
[3378]454      if (oldCrossover != null) {
455        ICrossover crossover = CrossoverParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldCrossover.GetType());
456        if (crossover != null) CrossoverParameter.Value = crossover;
[7509]457        else oldCrossover = null;
458      }
459      if (oldCrossover == null && defaultCrossover != null)
[7493]460        CrossoverParameter.Value = defaultCrossover;
[3378]461    }
462    private void UpdateMutators() {
463      IManipulator oldMutator = MutatorParameter.Value;
464      MutatorParameter.ValidValues.Clear();
465      foreach (IManipulator mutator in Problem.Operators.OfType<IManipulator>().OrderBy(x => x.Name))
466        MutatorParameter.ValidValues.Add(mutator);
467      if (oldMutator != null) {
468        IManipulator mutator = MutatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMutator.GetType());
469        if (mutator != null) MutatorParameter.Value = mutator;
470      }
471    }
[3650]472    private void UpdateAnalyzers() {
473      Analyzer.Operators.Clear();
474      if (Problem != null) {
[3816]475        foreach (IAnalyzer analyzer in Problem.Operators.OfType<IAnalyzer>()) {
[3672]476          foreach (IScopeTreeLookupParameter param in analyzer.Parameters.OfType<IScopeTreeLookupParameter>())
477            param.Depth = 1;
[7172]478          Analyzer.Operators.Add(analyzer, analyzer.EnabledByDefault);
[3672]479        }
[3650]480      }
[7172]481      Analyzer.Operators.Add(qualityAnalyzer, qualityAnalyzer.EnabledByDefault);
482      Analyzer.Operators.Add(selectionPressureAnalyzer, selectionPressureAnalyzer.EnabledByDefault);
483      Analyzer.Operators.Add(successfulOffspringAnalyzer, successfulOffspringAnalyzer.EnabledByDefault);
[3650]484    }
[5366]485    private OffspringSelectionGeneticAlgorithmMainLoop FindMainLoop(IOperator start) {
486      IOperator mainLoop = start;
487      while (mainLoop != null && !(mainLoop is OffspringSelectionGeneticAlgorithmMainLoop))
488        mainLoop = ((SingleSuccessorOperator)mainLoop).Successor;
489      if (mainLoop == null) return null;
490      else return (OffspringSelectionGeneticAlgorithmMainLoop)mainLoop;
491    }
[3378]492    #endregion
493  }
494}
Note: See TracBrowser for help on using the repository browser.