Free cookie consent management tool by TermsFeed Policy Generator

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

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

#2038: Added tagging comment

File size: 27.1 KB
RevLine 
[3378]1#region License Information
2/* HeuristicLab
[9456]3 * Copyright (C) 2002-2013 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    }
[9569]81    private IFixedValueParameter<BoolValue> ReevaluateElitesParameter {
82      get { return (IFixedValueParameter<BoolValue>)Parameters["ReevaluateElites"]; }
83    }
[3378]84    private ValueParameter<IntValue> MaximumGenerationsParameter {
85      get { return (ValueParameter<IntValue>)Parameters["MaximumGenerations"]; }
86    }
[3379]87    private ValueLookupParameter<DoubleValue> SuccessRatioParameter {
88      get { return (ValueLookupParameter<DoubleValue>)Parameters["SuccessRatio"]; }
89    }
90    private ValueLookupParameter<DoubleValue> ComparisonFactorLowerBoundParameter {
91      get { return (ValueLookupParameter<DoubleValue>)Parameters["ComparisonFactorLowerBound"]; }
92    }
93    private ValueLookupParameter<DoubleValue> ComparisonFactorUpperBoundParameter {
94      get { return (ValueLookupParameter<DoubleValue>)Parameters["ComparisonFactorUpperBound"]; }
95    }
[8121]96    public IConstrainedValueParameter<IDiscreteDoubleValueModifier> ComparisonFactorModifierParameter {
97      get { return (IConstrainedValueParameter<IDiscreteDoubleValueModifier>)Parameters["ComparisonFactorModifier"]; }
[3379]98    }
99    private ValueLookupParameter<DoubleValue> MaximumSelectionPressureParameter {
100      get { return (ValueLookupParameter<DoubleValue>)Parameters["MaximumSelectionPressure"]; }
101    }
102    private ValueLookupParameter<BoolValue> OffspringSelectionBeforeMutationParameter {
103      get { return (ValueLookupParameter<BoolValue>)Parameters["OffspringSelectionBeforeMutation"]; }
104    }
[3510]105    private ValueLookupParameter<IntValue> SelectedParentsParameter {
106      get { return (ValueLookupParameter<IntValue>)Parameters["SelectedParents"]; }
107    }
[3658]108    private ValueParameter<MultiAnalyzer> AnalyzerParameter {
109      get { return (ValueParameter<MultiAnalyzer>)Parameters["Analyzer"]; }
[3650]110    }
[3891]111    private ValueParameter<IntValue> MaximumEvaluatedSolutionsParameter {
112      get { return (ValueParameter<IntValue>)Parameters["MaximumEvaluatedSolutions"]; }
113    }
[3378]114    #endregion
115
116    #region Properties
117    public IntValue Seed {
118      get { return SeedParameter.Value; }
119      set { SeedParameter.Value = value; }
120    }
121    public BoolValue SetSeedRandomly {
122      get { return SetSeedRandomlyParameter.Value; }
123      set { SetSeedRandomlyParameter.Value = value; }
124    }
125    public IntValue PopulationSize {
126      get { return PopulationSizeParameter.Value; }
127      set { PopulationSizeParameter.Value = value; }
128    }
129    public ISelector Selector {
130      get { return SelectorParameter.Value; }
131      set { SelectorParameter.Value = value; }
132    }
133    public ICrossover Crossover {
134      get { return CrossoverParameter.Value; }
135      set { CrossoverParameter.Value = value; }
136    }
137    public PercentValue MutationProbability {
138      get { return MutationProbabilityParameter.Value; }
139      set { MutationProbabilityParameter.Value = value; }
140    }
141    public IManipulator Mutator {
142      get { return MutatorParameter.Value; }
143      set { MutatorParameter.Value = value; }
144    }
145    public IntValue Elites {
146      get { return ElitesParameter.Value; }
147      set { ElitesParameter.Value = value; }
148    }
[9569]149    public bool ReevaluteElites {
150      get { return ReevaluateElitesParameter.Value.Value; }
151      set { ReevaluateElitesParameter.Value.Value = value; }
152    }
[3378]153    public IntValue MaximumGenerations {
154      get { return MaximumGenerationsParameter.Value; }
155      set { MaximumGenerationsParameter.Value = value; }
156    }
[3510]157    public DoubleValue SuccessRatio {
[3379]158      get { return SuccessRatioParameter.Value; }
159      set { SuccessRatioParameter.Value = value; }
160    }
[3510]161    public DoubleValue ComparisonFactorLowerBound {
[3379]162      get { return ComparisonFactorLowerBoundParameter.Value; }
163      set { ComparisonFactorLowerBoundParameter.Value = value; }
164    }
[3510]165    public DoubleValue ComparisonFactorUpperBound {
[3379]166      get { return ComparisonFactorUpperBoundParameter.Value; }
167      set { ComparisonFactorUpperBoundParameter.Value = value; }
168    }
[3510]169    public IDiscreteDoubleValueModifier ComparisonFactorModifier {
[3379]170      get { return ComparisonFactorModifierParameter.Value; }
171      set { ComparisonFactorModifierParameter.Value = value; }
172    }
[3510]173    public DoubleValue MaximumSelectionPressure {
[3379]174      get { return MaximumSelectionPressureParameter.Value; }
175      set { MaximumSelectionPressureParameter.Value = value; }
176    }
[3510]177    public BoolValue OffspringSelectionBeforeMutation {
[3379]178      get { return OffspringSelectionBeforeMutationParameter.Value; }
179      set { OffspringSelectionBeforeMutationParameter.Value = value; }
180    }
[3510]181    public IntValue SelectedParents {
182      get { return SelectedParentsParameter.Value; }
183      set { SelectedParentsParameter.Value = value; }
184    }
[3658]185    public MultiAnalyzer Analyzer {
[3650]186      get { return AnalyzerParameter.Value; }
187      set { AnalyzerParameter.Value = value; }
188    }
[3891]189    public IntValue MaximumEvaluatedSolutions {
190      get { return MaximumEvaluatedSolutionsParameter.Value; }
191      set { MaximumEvaluatedSolutionsParameter.Value = value; }
192    }
[3378]193    private RandomCreator RandomCreator {
194      get { return (RandomCreator)OperatorGraph.InitialOperator; }
195    }
196    private SolutionsCreator SolutionsCreator {
197      get { return (SolutionsCreator)RandomCreator.Successor; }
198    }
199    private OffspringSelectionGeneticAlgorithmMainLoop MainLoop {
[5366]200      get { return FindMainLoop(SolutionsCreator.Successor); }
[3378]201    }
[3689]202    [Storable]
[3672]203    private BestAverageWorstQualityAnalyzer qualityAnalyzer;
[3689]204    [Storable]
[3672]205    private ValueAnalyzer selectionPressureAnalyzer;
[5683]206    [Storable]
207    private SuccessfulOffspringAnalyzer successfulOffspringAnalyzer;
[3378]208    #endregion
209
[3379]210    [StorableConstructor]
211    private OffspringSelectionGeneticAlgorithm(bool deserializing) : base(deserializing) { }
[4722]212    [StorableHook(HookType.AfterDeserialization)]
213    private void AfterDeserialization() {
[9592]214      // BackwardsCompatibility3.3
215      #region Backwards compatible code, remove with 3.4
[5683]216      if (successfulOffspringAnalyzer == null)
217        successfulOffspringAnalyzer = new SuccessfulOffspringAnalyzer();
[9569]218      if (!Parameters.ContainsKey("ReevaluateElites")) {
219        Parameters.Add(new FixedValueParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)", (BoolValue)new BoolValue(false).AsReadOnly()) { Hidden = true });
220      }
[5683]221      #endregion
[7172]222
[4722]223      Initialize();
224    }
225    private OffspringSelectionGeneticAlgorithm(OffspringSelectionGeneticAlgorithm original, Cloner cloner)
226      : base(original, cloner) {
227      qualityAnalyzer = cloner.Clone(original.qualityAnalyzer);
228      selectionPressureAnalyzer = cloner.Clone(original.selectionPressureAnalyzer);
[5683]229      successfulOffspringAnalyzer = cloner.Clone(original.successfulOffspringAnalyzer);
[4722]230      Initialize();
231    }
232    public override IDeepCloneable Clone(Cloner cloner) {
233      return new OffspringSelectionGeneticAlgorithm(this, cloner);
234    }
[3378]235    public OffspringSelectionGeneticAlgorithm()
236      : base() {
237      Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
238      Parameters.Add(new ValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
239      Parameters.Add(new ValueParameter<IntValue>("PopulationSize", "The size of the population of solutions.", new IntValue(100)));
240      Parameters.Add(new ConstrainedValueParameter<ISelector>("Selector", "The operator used to select solutions for reproduction."));
241      Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions."));
242      Parameters.Add(new ValueParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution.", new PercentValue(0.05)));
243      Parameters.Add(new OptionalConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions."));
244      Parameters.Add(new ValueParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.", new IntValue(1)));
[9569]245      Parameters.Add(new FixedValueParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)", new BoolValue(false)) { Hidden = true });
[3378]246      Parameters.Add(new ValueParameter<IntValue>("MaximumGenerations", "The maximum number of generations which should be processed.", new IntValue(1000)));
[3379]247      Parameters.Add(new ValueLookupParameter<DoubleValue>("SuccessRatio", "The ratio of successful to total children that should be achieved.", new DoubleValue(1)));
248      Parameters.Add(new ValueLookupParameter<DoubleValue>("ComparisonFactorLowerBound", "The lower bound of the comparison factor (start).", new DoubleValue(0)));
249      Parameters.Add(new ValueLookupParameter<DoubleValue>("ComparisonFactorUpperBound", "The upper bound of the comparison factor (end).", new DoubleValue(1)));
[3426]250      Parameters.Add(new OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier>("ComparisonFactorModifier", "The operator used to modify the comparison factor.", new ItemSet<IDiscreteDoubleValueModifier>(new IDiscreteDoubleValueModifier[] { new LinearDiscreteDoubleValueModifier() }), new LinearDiscreteDoubleValueModifier()));
[3379]251      Parameters.Add(new ValueLookupParameter<DoubleValue>("MaximumSelectionPressure", "The maximum selection pressure that terminates the algorithm.", new DoubleValue(100)));
252      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]253      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]254      Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze each generation.", new MultiAnalyzer()));
[3891]255      Parameters.Add(new ValueParameter<IntValue>("MaximumEvaluatedSolutions", "The maximum number of evaluated solutions (approximately).", new IntValue(int.MaxValue)));
256
[3378]257      RandomCreator randomCreator = new RandomCreator();
258      SolutionsCreator solutionsCreator = new SolutionsCreator();
[5356]259      SubScopesCounter subScopesCounter = new SubScopesCounter();
260      ResultsCollector resultsCollector = new ResultsCollector();
[3378]261      OffspringSelectionGeneticAlgorithmMainLoop mainLoop = new OffspringSelectionGeneticAlgorithmMainLoop();
262      OperatorGraph.InitialOperator = randomCreator;
263
264      randomCreator.RandomParameter.ActualName = "Random";
265      randomCreator.SeedParameter.ActualName = SeedParameter.Name;
266      randomCreator.SeedParameter.Value = null;
267      randomCreator.SetSeedRandomlyParameter.ActualName = SetSeedRandomlyParameter.Name;
268      randomCreator.SetSeedRandomlyParameter.Value = null;
269      randomCreator.Successor = solutionsCreator;
270
271      solutionsCreator.NumberOfSolutionsParameter.ActualName = PopulationSizeParameter.Name;
[5356]272      solutionsCreator.Successor = subScopesCounter;
[3378]273
[5356]274      subScopesCounter.Name = "Initialize EvaluatedSolutions";
275      subScopesCounter.ValueParameter.ActualName = "EvaluatedSolutions";
276      subScopesCounter.Successor = resultsCollector;
277
278      resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Evaluated Solutions", "", "EvaluatedSolutions"));
279      resultsCollector.ResultsParameter.ActualName = "Results";
280      resultsCollector.Successor = mainLoop;
281
[3744]282      mainLoop.AnalyzerParameter.ActualName = AnalyzerParameter.Name;
283      mainLoop.ComparisonFactorModifierParameter.ActualName = ComparisonFactorModifierParameter.Name;
284      mainLoop.ComparisonFactorParameter.ActualName = "ComparisonFactor";
285      mainLoop.ComparisonFactorStartParameter.ActualName = ComparisonFactorLowerBoundParameter.Name;
[3378]286      mainLoop.CrossoverParameter.ActualName = CrossoverParameter.Name;
287      mainLoop.ElitesParameter.ActualName = ElitesParameter.Name;
[9569]288      mainLoop.ReevaluateElitesParameter.ActualName = ReevaluateElitesParameter.Name;
[5356]289      mainLoop.EvaluatedSolutionsParameter.ActualName = "EvaluatedSolutions";
[3378]290      mainLoop.MaximumGenerationsParameter.ActualName = MaximumGenerationsParameter.Name;
[3744]291      mainLoop.MaximumSelectionPressureParameter.ActualName = MaximumSelectionPressureParameter.Name;
292      mainLoop.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
[3378]293      mainLoop.MutatorParameter.ActualName = MutatorParameter.Name;
[3744]294      mainLoop.OffspringSelectionBeforeMutationParameter.ActualName = OffspringSelectionBeforeMutationParameter.Name;
[3378]295      mainLoop.RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
296      mainLoop.ResultsParameter.ActualName = "Results";
[3744]297      mainLoop.SelectorParameter.ActualName = SelectorParameter.Name;
298      mainLoop.SuccessRatioParameter.ActualName = SuccessRatioParameter.Name;
[3378]299
[3689]300      foreach (ISelector selector in ApplicationManager.Manager.GetInstances<ISelector>().Where(x => !(x is IMultiObjectiveSelector)).OrderBy(x => x.Name))
301        SelectorParameter.ValidValues.Add(selector);
302      ISelector proportionalSelector = SelectorParameter.ValidValues.FirstOrDefault(x => x.GetType().Name.Equals("ProportionalSelector"));
303      if (proportionalSelector != null) SelectorParameter.Value = proportionalSelector;
304      ParameterizeSelectors();
305
306      foreach (IDiscreteDoubleValueModifier modifier in ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>().OrderBy(x => x.Name))
307        ComparisonFactorModifierParameter.ValidValues.Add(modifier);
308      IDiscreteDoubleValueModifier linearModifier = ComparisonFactorModifierParameter.ValidValues.FirstOrDefault(x => x.GetType().Name.Equals("LinearDiscreteDoubleValueModifier"));
309      if (linearModifier != null) ComparisonFactorModifierParameter.Value = linearModifier;
310      ParameterizeComparisonFactorModifiers();
311
312      qualityAnalyzer = new BestAverageWorstQualityAnalyzer();
313      selectionPressureAnalyzer = new ValueAnalyzer();
[5683]314      successfulOffspringAnalyzer = new SuccessfulOffspringAnalyzer();
[3689]315      ParameterizeAnalyzers();
316      UpdateAnalyzers();
317
[3378]318      Initialize();
319    }
320
321
[4722]322
[3378]323    public override void Prepare() {
324      if (Problem != null) base.Prepare();
325    }
326
327    #region Events
328    protected override void OnProblemChanged() {
329      ParameterizeStochasticOperator(Problem.SolutionCreator);
330      ParameterizeStochasticOperator(Problem.Evaluator);
[7999]331      foreach (IOperator op in Problem.Operators.OfType<IOperator>()) ParameterizeStochasticOperator(op);
[3378]332      ParameterizeSolutionsCreator();
[3379]333      ParameterizMainLoop();
[3378]334      ParameterizeSelectors();
[3650]335      ParameterizeAnalyzers();
[3750]336      ParameterizeIterationBasedOperators();
[3378]337      UpdateCrossovers();
338      UpdateMutators();
[3650]339      UpdateAnalyzers();
[3378]340      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
341      base.OnProblemChanged();
342    }
343
344    protected override void Problem_SolutionCreatorChanged(object sender, EventArgs e) {
345      ParameterizeStochasticOperator(Problem.SolutionCreator);
346      ParameterizeSolutionsCreator();
347      base.Problem_SolutionCreatorChanged(sender, e);
348    }
349    protected override void Problem_EvaluatorChanged(object sender, EventArgs e) {
350      ParameterizeStochasticOperator(Problem.Evaluator);
351      ParameterizeSolutionsCreator();
[3379]352      ParameterizMainLoop();
[3378]353      ParameterizeSelectors();
[3650]354      ParameterizeAnalyzers();
[3378]355      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
356      base.Problem_EvaluatorChanged(sender, e);
357    }
358    protected override void Problem_OperatorsChanged(object sender, EventArgs e) {
[7999]359      foreach (IOperator op in Problem.Operators.OfType<IOperator>()) ParameterizeStochasticOperator(op);
[3750]360      ParameterizeIterationBasedOperators();
[3378]361      UpdateCrossovers();
362      UpdateMutators();
[3650]363      UpdateAnalyzers();
[3378]364      base.Problem_OperatorsChanged(sender, e);
365    }
366    private void ElitesParameter_ValueChanged(object sender, EventArgs e) {
367      Elites.ValueChanged += new EventHandler(Elites_ValueChanged);
368      ParameterizeSelectors();
369    }
370    private void Elites_ValueChanged(object sender, EventArgs e) {
371      ParameterizeSelectors();
372    }
373    private void PopulationSizeParameter_ValueChanged(object sender, EventArgs e) {
374      PopulationSize.ValueChanged += new EventHandler(PopulationSize_ValueChanged);
375      ParameterizeSelectors();
376    }
377    private void PopulationSize_ValueChanged(object sender, EventArgs e) {
378      ParameterizeSelectors();
379    }
380    private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
[3379]381      ParameterizMainLoop();
[3378]382      ParameterizeSelectors();
[3650]383      ParameterizeAnalyzers();
[3378]384    }
385    #endregion
386
387    #region Helpers
388    private void Initialize() {
389      PopulationSizeParameter.ValueChanged += new EventHandler(PopulationSizeParameter_ValueChanged);
390      PopulationSize.ValueChanged += new EventHandler(PopulationSize_ValueChanged);
391      ElitesParameter.ValueChanged += new EventHandler(ElitesParameter_ValueChanged);
392      Elites.ValueChanged += new EventHandler(Elites_ValueChanged);
393      if (Problem != null) {
394        Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
395      }
396    }
397    private void ParameterizeSolutionsCreator() {
398      SolutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
399      SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name;
400    }
[3379]401    private void ParameterizMainLoop() {
[3378]402      MainLoop.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
403      MainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
404      MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
405    }
406    private void ParameterizeStochasticOperator(IOperator op) {
407      if (op is IStochasticOperator)
408        ((IStochasticOperator)op).RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
409    }
410    private void ParameterizeSelectors() {
[3689]411      foreach (ISelector selector in SelectorParameter.ValidValues) {
[3378]412        selector.CopySelected = new BoolValue(true);
[3510]413        selector.NumberOfSelectedSubScopesParameter.Value = null;
414        selector.NumberOfSelectedSubScopesParameter.ActualName = SelectedParentsParameter.Name;
[3378]415        ParameterizeStochasticOperator(selector);
416      }
417      if (Problem != null) {
[3689]418        foreach (ISingleObjectiveSelector selector in SelectorParameter.ValidValues.OfType<ISingleObjectiveSelector>()) {
[3378]419          selector.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
420          selector.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
421        }
422      }
423    }
[3650]424    private void ParameterizeAnalyzers() {
[3672]425      qualityAnalyzer.ResultsParameter.ActualName = "Results";
426      selectionPressureAnalyzer.Name = "SelectionPressure Analyzer";
427      selectionPressureAnalyzer.ResultsParameter.ActualName = "Results";
428      selectionPressureAnalyzer.ValueParameter.ActualName = "SelectionPressure";
429      selectionPressureAnalyzer.ValueParameter.Depth = 0;
430      selectionPressureAnalyzer.ValuesParameter.ActualName = "Selection Pressure History";
[5683]431      successfulOffspringAnalyzer.ResultsParameter.ActualName = "Results";
432      successfulOffspringAnalyzer.GenerationsParameter.ActualName = "Generations";
[5725]433      successfulOffspringAnalyzer.SuccessfulOffspringFlagParameter.Value.Value = "SuccessfulOffspring";
[5683]434      successfulOffspringAnalyzer.DepthParameter.Value = new IntValue(1);
[3650]435      if (Problem != null) {
[3672]436        qualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
437        qualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
438        qualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
[3650]439      }
440    }
[3379]441    private void ParameterizeComparisonFactorModifiers() {
[3689]442      foreach (IDiscreteDoubleValueModifier modifier in ComparisonFactorModifierParameter.ValidValues) {
[3413]443        modifier.IndexParameter.ActualName = "Generations";
[3379]444        modifier.EndIndexParameter.ActualName = MaximumGenerationsParameter.Name;
445        modifier.EndValueParameter.ActualName = ComparisonFactorUpperBoundParameter.Name;
446        modifier.StartIndexParameter.Value = new IntValue(0);
447        modifier.StartValueParameter.ActualName = ComparisonFactorLowerBoundParameter.Name;
[3413]448        modifier.ValueParameter.ActualName = "ComparisonFactor";
[3379]449      }
450    }
[3750]451    private void ParameterizeIterationBasedOperators() {
452      if (Problem != null) {
453        foreach (IIterationBasedOperator op in Problem.Operators.OfType<IIterationBasedOperator>()) {
454          op.IterationsParameter.ActualName = "Generations";
455          op.MaximumIterationsParameter.ActualName = MaximumGenerationsParameter.Name;
456        }
457      }
458    }
[3378]459    private void UpdateCrossovers() {
460      ICrossover oldCrossover = CrossoverParameter.Value;
461      CrossoverParameter.ValidValues.Clear();
[7493]462      ICrossover defaultCrossover = Problem.Operators.OfType<ICrossover>().FirstOrDefault();
463
[3378]464      foreach (ICrossover crossover in Problem.Operators.OfType<ICrossover>().OrderBy(x => x.Name))
465        CrossoverParameter.ValidValues.Add(crossover);
[7493]466
[3378]467      if (oldCrossover != null) {
468        ICrossover crossover = CrossoverParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldCrossover.GetType());
469        if (crossover != null) CrossoverParameter.Value = crossover;
[7509]470        else oldCrossover = null;
471      }
472      if (oldCrossover == null && defaultCrossover != null)
[7493]473        CrossoverParameter.Value = defaultCrossover;
[3378]474    }
475    private void UpdateMutators() {
476      IManipulator oldMutator = MutatorParameter.Value;
477      MutatorParameter.ValidValues.Clear();
478      foreach (IManipulator mutator in Problem.Operators.OfType<IManipulator>().OrderBy(x => x.Name))
479        MutatorParameter.ValidValues.Add(mutator);
480      if (oldMutator != null) {
481        IManipulator mutator = MutatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMutator.GetType());
482        if (mutator != null) MutatorParameter.Value = mutator;
483      }
484    }
[3650]485    private void UpdateAnalyzers() {
486      Analyzer.Operators.Clear();
487      if (Problem != null) {
[3816]488        foreach (IAnalyzer analyzer in Problem.Operators.OfType<IAnalyzer>()) {
[3672]489          foreach (IScopeTreeLookupParameter param in analyzer.Parameters.OfType<IScopeTreeLookupParameter>())
490            param.Depth = 1;
[7172]491          Analyzer.Operators.Add(analyzer, analyzer.EnabledByDefault);
[3672]492        }
[3650]493      }
[7172]494      Analyzer.Operators.Add(qualityAnalyzer, qualityAnalyzer.EnabledByDefault);
495      Analyzer.Operators.Add(selectionPressureAnalyzer, selectionPressureAnalyzer.EnabledByDefault);
496      Analyzer.Operators.Add(successfulOffspringAnalyzer, successfulOffspringAnalyzer.EnabledByDefault);
[3650]497    }
[5366]498    private OffspringSelectionGeneticAlgorithmMainLoop FindMainLoop(IOperator start) {
499      IOperator mainLoop = start;
500      while (mainLoop != null && !(mainLoop is OffspringSelectionGeneticAlgorithmMainLoop))
501        mainLoop = ((SingleSuccessorOperator)mainLoop).Successor;
502      if (mainLoop == null) return null;
503      else return (OffspringSelectionGeneticAlgorithmMainLoop)mainLoop;
504    }
[3378]505    #endregion
506  }
507}
Note: See TracBrowser for help on using the repository browser.