Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 3799 was 3799, checked in by gkronber, 14 years ago

Changed execution order of analyzers (algorithm analyzers after problem analyzers) #893

File size: 28.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using HeuristicLab.Analysis;
26using HeuristicLab.Common;
27using HeuristicLab.Core;
28using HeuristicLab.Data;
29using HeuristicLab.Operators;
30using HeuristicLab.Optimization;
31using HeuristicLab.Optimization.Operators;
32using HeuristicLab.Parameters;
33using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
34using HeuristicLab.PluginInfrastructure;
35using HeuristicLab.Random;
36using HeuristicLab.Selection;
37
38namespace HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm {
39  /// <summary>
40  /// The self-adaptive segregative genetic algorithm with simulated annealing aspects (Affenzeller, M. et al. 2009. Genetic Algorithms and Genetic Programming - Modern Concepts and Practical Applications. CRC Press).
41  /// </summary>
42  [Item("SASEGASA", "The self-adaptive segregative genetic algorithm with simulated annealing aspects (Affenzeller, M. et al. 2009. Genetic Algorithms and Genetic Programming - Modern Concepts and Practical Applications. CRC Press).")]
43  [Creatable("Algorithms")]
44  [StorableClass]
45  public sealed class SASEGASA : EngineAlgorithm {
46
47    #region Problem Properties
48    public override Type ProblemType {
49      get { return typeof(ISingleObjectiveProblem); }
50    }
51    public new ISingleObjectiveProblem Problem {
52      get { return (ISingleObjectiveProblem)base.Problem; }
53      set { base.Problem = value; }
54    }
55    #endregion
56
57    #region Parameter Properties
58    private ValueParameter<IntValue> SeedParameter {
59      get { return (ValueParameter<IntValue>)Parameters["Seed"]; }
60    }
61    private ValueParameter<BoolValue> SetSeedRandomlyParameter {
62      get { return (ValueParameter<BoolValue>)Parameters["SetSeedRandomly"]; }
63    }
64    private ValueParameter<IntValue> NumberOfVillagesParameter {
65      get { return (ValueParameter<IntValue>)Parameters["NumberOfVillages"]; }
66    }
67    private ValueParameter<IntValue> PopulationSizeParameter {
68      get { return (ValueParameter<IntValue>)Parameters["PopulationSize"]; }
69    }
70    private ValueParameter<IntValue> MaximumGenerationsParameter {
71      get { return (ValueParameter<IntValue>)Parameters["MaximumGenerations"]; }
72    }
73    private ConstrainedValueParameter<ISelector> SelectorParameter {
74      get { return (ConstrainedValueParameter<ISelector>)Parameters["Selector"]; }
75    }
76    private ConstrainedValueParameter<ICrossover> CrossoverParameter {
77      get { return (ConstrainedValueParameter<ICrossover>)Parameters["Crossover"]; }
78    }
79    private ValueParameter<PercentValue> MutationProbabilityParameter {
80      get { return (ValueParameter<PercentValue>)Parameters["MutationProbability"]; }
81    }
82    private OptionalConstrainedValueParameter<IManipulator> MutatorParameter {
83      get { return (OptionalConstrainedValueParameter<IManipulator>)Parameters["Mutator"]; }
84    }
85    private ValueParameter<IntValue> ElitesParameter {
86      get { return (ValueParameter<IntValue>)Parameters["Elites"]; }
87    }
88    private ValueLookupParameter<DoubleValue> SuccessRatioParameter {
89      get { return (ValueLookupParameter<DoubleValue>)Parameters["SuccessRatio"]; }
90    }
91    private ValueLookupParameter<DoubleValue> ComparisonFactorLowerBoundParameter {
92      get { return (ValueLookupParameter<DoubleValue>)Parameters["ComparisonFactorLowerBound"]; }
93    }
94    private ValueLookupParameter<DoubleValue> ComparisonFactorUpperBoundParameter {
95      get { return (ValueLookupParameter<DoubleValue>)Parameters["ComparisonFactorUpperBound"]; }
96    }
97    private OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier> ComparisonFactorModifierParameter {
98      get { return (OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier>)Parameters["ComparisonFactorModifier"]; }
99    }
100    private ValueLookupParameter<DoubleValue> MaximumSelectionPressureParameter {
101      get { return (ValueLookupParameter<DoubleValue>)Parameters["MaximumSelectionPressure"]; }
102    }
103    private ValueLookupParameter<DoubleValue> FinalMaximumSelectionPressureParameter {
104      get { return (ValueLookupParameter<DoubleValue>)Parameters["FinalMaximumSelectionPressure"]; }
105    }
106    private ValueLookupParameter<BoolValue> OffspringSelectionBeforeMutationParameter {
107      get { return (ValueLookupParameter<BoolValue>)Parameters["OffspringSelectionBeforeMutation"]; }
108    }
109    private ValueLookupParameter<IntValue> SelectedParentsParameter {
110      get { return (ValueLookupParameter<IntValue>)Parameters["SelectedParents"]; }
111    }
112    private ValueParameter<MultiAnalyzer> AnalyzerParameter {
113      get { return (ValueParameter<MultiAnalyzer>)Parameters["Analyzer"]; }
114    }
115    private ValueParameter<MultiAnalyzer> VillageAnalyzerParameter {
116      get { return (ValueParameter<MultiAnalyzer>)Parameters["VillageAnalyzer"]; }
117    }
118    #endregion
119
120    #region Properties
121    public IntValue Seed {
122      get { return SeedParameter.Value; }
123      set { SeedParameter.Value = value; }
124    }
125    public BoolValue SetSeedRandomly {
126      get { return SetSeedRandomlyParameter.Value; }
127      set { SetSeedRandomlyParameter.Value = value; }
128    }
129    public IntValue NumberOfVillages {
130      get { return NumberOfVillagesParameter.Value; }
131      set { NumberOfVillagesParameter.Value = value; }
132    }
133    public IntValue PopulationSize {
134      get { return PopulationSizeParameter.Value; }
135      set { PopulationSizeParameter.Value = value; }
136    }
137    public IntValue MaximumGenerations {
138      get { return MaximumGenerationsParameter.Value; }
139      set { MaximumGenerationsParameter.Value = value; }
140    }
141    public ISelector Selector {
142      get { return SelectorParameter.Value; }
143      set { SelectorParameter.Value = value; }
144    }
145    public ICrossover Crossover {
146      get { return CrossoverParameter.Value; }
147      set { CrossoverParameter.Value = value; }
148    }
149    public PercentValue MutationProbability {
150      get { return MutationProbabilityParameter.Value; }
151      set { MutationProbabilityParameter.Value = value; }
152    }
153    public IManipulator Mutator {
154      get { return MutatorParameter.Value; }
155      set { MutatorParameter.Value = value; }
156    }
157    public IntValue Elites {
158      get { return ElitesParameter.Value; }
159      set { ElitesParameter.Value = value; }
160    }
161    public DoubleValue SuccessRatio {
162      get { return SuccessRatioParameter.Value; }
163      set { SuccessRatioParameter.Value = value; }
164    }
165    public DoubleValue ComparisonFactorLowerBound {
166      get { return ComparisonFactorLowerBoundParameter.Value; }
167      set { ComparisonFactorLowerBoundParameter.Value = value; }
168    }
169    public DoubleValue ComparisonFactorUpperBound {
170      get { return ComparisonFactorUpperBoundParameter.Value; }
171      set { ComparisonFactorUpperBoundParameter.Value = value; }
172    }
173    public IDiscreteDoubleValueModifier ComparisonFactorModifier {
174      get { return ComparisonFactorModifierParameter.Value; }
175      set { ComparisonFactorModifierParameter.Value = value; }
176    }
177    public DoubleValue MaximumSelectionPressure {
178      get { return MaximumSelectionPressureParameter.Value; }
179      set { MaximumSelectionPressureParameter.Value = value; }
180    }
181    public DoubleValue FinalMaximumSelectionPressure {
182      get { return FinalMaximumSelectionPressureParameter.Value; }
183      set { FinalMaximumSelectionPressureParameter.Value = value; }
184    }
185    public BoolValue OffspringSelectionBeforeMutation {
186      get { return OffspringSelectionBeforeMutationParameter.Value; }
187      set { OffspringSelectionBeforeMutationParameter.Value = value; }
188    }
189    public IntValue SelectedParents {
190      get { return SelectedParentsParameter.Value; }
191      set { SelectedParentsParameter.Value = value; }
192    }
193    public MultiAnalyzer Analyzer {
194      get { return AnalyzerParameter.Value; }
195      set { AnalyzerParameter.Value = value; }
196    }
197    public MultiAnalyzer VillageAnalyzer {
198      get { return VillageAnalyzerParameter.Value; }
199      set { VillageAnalyzerParameter.Value = value; }
200    }
201    private RandomCreator RandomCreator {
202      get { return (RandomCreator)OperatorGraph.InitialOperator; }
203    }
204    private UniformSubScopesProcessor VillageProcessor {
205      get { return ((RandomCreator.Successor as SubScopesCreator).Successor as UniformSubScopesProcessor); }
206    }
207    private SolutionsCreator SolutionsCreator {
208      get { return (SolutionsCreator)VillageProcessor.Operator; }
209    }
210    private SASEGASAMainLoop MainLoop {
211      get { return (SASEGASAMainLoop)VillageProcessor.Successor; }
212    }
213    [Storable]
214    private BestAverageWorstQualityAnalyzer villageQualityAnalyzer;
215    [Storable]
216    private BestAverageWorstQualityAnalyzer qualityAnalyzer;
217    [Storable]
218    private ValueAnalyzer villageSelectionPressureAnalyzer;
219    [Storable]
220    private ValueAnalyzer selectionPressureAnalyzer;
221    #endregion
222
223    [StorableConstructor]
224    private SASEGASA(bool deserializing) : base(deserializing) { }
225    public SASEGASA()
226      : base() {
227      Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
228      Parameters.Add(new ValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
229      Parameters.Add(new ValueParameter<IntValue>("NumberOfVillages", "The initial number of villages.", new IntValue(10)));
230      Parameters.Add(new ValueParameter<IntValue>("PopulationSize", "The size of the population of solutions.", new IntValue(100)));
231      Parameters.Add(new ValueParameter<IntValue>("MaximumGenerations", "The maximum number of generations that should be processed.", new IntValue(1000)));
232      Parameters.Add(new ConstrainedValueParameter<ISelector>("Selector", "The operator used to select solutions for reproduction."));
233      Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions."));
234      Parameters.Add(new ValueParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution.", new PercentValue(0.05)));
235      Parameters.Add(new OptionalConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions."));
236      Parameters.Add(new ValueParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.", new IntValue(1)));
237      Parameters.Add(new ValueLookupParameter<DoubleValue>("SuccessRatio", "The ratio of successful to total children that should be achieved.", new DoubleValue(1)));
238      Parameters.Add(new ValueLookupParameter<DoubleValue>("ComparisonFactorLowerBound", "The lower bound of the comparison factor (start).", new DoubleValue(0.3)));
239      Parameters.Add(new ValueLookupParameter<DoubleValue>("ComparisonFactorUpperBound", "The upper bound of the comparison factor (end).", new DoubleValue(0.7)));
240      Parameters.Add(new OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier>("ComparisonFactorModifier", "The operator used to modify the comparison factor.", new ItemSet<IDiscreteDoubleValueModifier>(new IDiscreteDoubleValueModifier[] { new LinearDiscreteDoubleValueModifier() }), new LinearDiscreteDoubleValueModifier()));
241      Parameters.Add(new ValueLookupParameter<DoubleValue>("MaximumSelectionPressure", "The maximum selection pressure that terminates the algorithm.", new DoubleValue(100)));
242      Parameters.Add(new ValueLookupParameter<DoubleValue>("FinalMaximumSelectionPressure", "The maximum selection pressure used when there is only one village left.", new DoubleValue(100)));
243      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)));
244      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)));
245      Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze the villages.", new MultiAnalyzer()));
246      Parameters.Add(new ValueParameter<MultiAnalyzer>("VillageAnalyzer", "The operator used to analyze each village.", new MultiAnalyzer()));
247     
248      RandomCreator randomCreator = new RandomCreator();
249      SubScopesCreator populationCreator = new SubScopesCreator();
250      UniformSubScopesProcessor ussp1 = new UniformSubScopesProcessor();
251      SolutionsCreator solutionsCreator = new SolutionsCreator();
252      SASEGASAMainLoop mainLoop = new SASEGASAMainLoop();
253      OperatorGraph.InitialOperator = randomCreator;
254
255      randomCreator.RandomParameter.ActualName = "Random";
256      randomCreator.SeedParameter.ActualName = SeedParameter.Name;
257      randomCreator.SeedParameter.Value = null;
258      randomCreator.SetSeedRandomlyParameter.ActualName = SetSeedRandomlyParameter.Name;
259      randomCreator.SetSeedRandomlyParameter.Value = null;
260      randomCreator.Successor = populationCreator;
261
262      populationCreator.NumberOfSubScopesParameter.ActualName = NumberOfVillagesParameter.Name;
263      populationCreator.Successor = ussp1;
264
265      ussp1.Operator = solutionsCreator;
266      ussp1.Successor = mainLoop;
267
268      solutionsCreator.NumberOfSolutionsParameter.ActualName = PopulationSizeParameter.Name;
269      solutionsCreator.Successor = null;
270
271      mainLoop.NumberOfVillagesParameter.ActualName = NumberOfVillagesParameter.Name;
272      mainLoop.SelectorParameter.ActualName = SelectorParameter.Name;
273      mainLoop.CrossoverParameter.ActualName = CrossoverParameter.Name;
274      mainLoop.ElitesParameter.ActualName = ElitesParameter.Name;
275      mainLoop.MutatorParameter.ActualName = MutatorParameter.Name;
276      mainLoop.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
277      mainLoop.RandomParameter.ActualName = randomCreator.RandomParameter.ActualName;
278      mainLoop.ResultsParameter.ActualName = "Results";
279      mainLoop.SuccessRatioParameter.ActualName = SuccessRatioParameter.Name;
280      mainLoop.ComparisonFactorStartParameter.ActualName = ComparisonFactorLowerBoundParameter.Name;
281      mainLoop.ComparisonFactorModifierParameter.ActualName = ComparisonFactorModifierParameter.Name;
282      mainLoop.MaximumSelectionPressureParameter.ActualName = MaximumSelectionPressureParameter.Name;
283      mainLoop.FinalMaximumSelectionPressureParameter.ActualName = FinalMaximumSelectionPressureParameter.Name;
284      mainLoop.MaximumGenerationsParameter.ActualName = MaximumGenerationsParameter.Name;
285      mainLoop.OffspringSelectionBeforeMutationParameter.ActualName = OffspringSelectionBeforeMutationParameter.Name;
286      mainLoop.Successor = null;
287
288      foreach (ISelector selector in ApplicationManager.Manager.GetInstances<ISelector>().Where(x => !(x is IMultiObjectiveSelector)).OrderBy(x => x.Name))
289        SelectorParameter.ValidValues.Add(selector);
290      ISelector proportionalSelector = SelectorParameter.ValidValues.FirstOrDefault(x => x.GetType().Name.Equals("ProportionalSelector"));
291      if (proportionalSelector != null) SelectorParameter.Value = proportionalSelector;
292
293      ParameterizeSelectors();
294
295      foreach (IDiscreteDoubleValueModifier modifier in ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>().OrderBy(x => x.Name))
296        ComparisonFactorModifierParameter.ValidValues.Add(modifier);
297      IDiscreteDoubleValueModifier linearModifier = ComparisonFactorModifierParameter.ValidValues.FirstOrDefault(x => x.GetType().Name.Equals("LinearDiscreteDoubleValueModifier"));
298      if (linearModifier != null) ComparisonFactorModifierParameter.Value = linearModifier;
299      ParameterizeComparisonFactorModifiers();
300
301      qualityAnalyzer = new BestAverageWorstQualityAnalyzer();
302      villageQualityAnalyzer = new BestAverageWorstQualityAnalyzer();
303      selectionPressureAnalyzer = new ValueAnalyzer();
304      villageSelectionPressureAnalyzer = new ValueAnalyzer();
305      ParameterizeAnalyzers();
306      UpdateAnalyzers();
307
308      Initialize();
309    }
310
311    public override IDeepCloneable Clone(Cloner cloner) {
312      SASEGASA clone = (SASEGASA)base.Clone(cloner);
313      clone.qualityAnalyzer = (BestAverageWorstQualityAnalyzer)cloner.Clone(qualityAnalyzer);
314      clone.villageQualityAnalyzer = (BestAverageWorstQualityAnalyzer)cloner.Clone(villageQualityAnalyzer);
315      clone.selectionPressureAnalyzer = (ValueAnalyzer)cloner.Clone(selectionPressureAnalyzer);
316      clone.villageSelectionPressureAnalyzer = (ValueAnalyzer)cloner.Clone(villageSelectionPressureAnalyzer);
317      clone.Initialize();
318      return clone;
319    }
320
321    public override void Prepare() {
322      if (Problem != null) base.Prepare();
323    }
324
325    #region Events
326    protected override void OnProblemChanged() {
327      ParameterizeStochasticOperator(Problem.SolutionCreator);
328      ParameterizeStochasticOperator(Problem.Evaluator);
329      foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
330      ParameterizeSolutionsCreator();
331      ParameterizeMainLoop();
332      ParameterizeSelectors();
333      ParameterizeAnalyzers();
334      ParameterizeIterationBasedOperators();
335      UpdateCrossovers();
336      UpdateMutators();
337      UpdateAnalyzers();
338      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
339      base.OnProblemChanged();
340    }
341
342    protected override void Problem_SolutionCreatorChanged(object sender, EventArgs e) {
343      ParameterizeStochasticOperator(Problem.SolutionCreator);
344      ParameterizeSolutionsCreator();
345      base.Problem_SolutionCreatorChanged(sender, e);
346    }
347    protected override void Problem_EvaluatorChanged(object sender, EventArgs e) {
348      ParameterizeStochasticOperator(Problem.Evaluator);
349      ParameterizeSolutionsCreator();
350      ParameterizeMainLoop();
351      ParameterizeSelectors();
352      ParameterizeAnalyzers();
353      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
354      base.Problem_EvaluatorChanged(sender, e);
355    }
356    protected override void Problem_OperatorsChanged(object sender, EventArgs e) {
357      foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
358      ParameterizeIterationBasedOperators();
359      UpdateCrossovers();
360      UpdateMutators();
361      UpdateAnalyzers();
362      base.Problem_OperatorsChanged(sender, e);
363    }
364    private void ElitesParameter_ValueChanged(object sender, EventArgs e) {
365      Elites.ValueChanged += new EventHandler(Elites_ValueChanged);
366      ParameterizeSelectors();
367    }
368    private void Elites_ValueChanged(object sender, EventArgs e) {
369      ParameterizeSelectors();
370    }
371    private void PopulationSizeParameter_ValueChanged(object sender, EventArgs e) {
372      NumberOfVillages.ValueChanged += new EventHandler(PopulationSize_ValueChanged);
373      ParameterizeSelectors();
374    }
375    private void PopulationSize_ValueChanged(object sender, EventArgs e) {
376      ParameterizeSelectors();
377    }
378    private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
379      ParameterizeMainLoop();
380      ParameterizeSelectors();
381      ParameterizeAnalyzers();
382    }
383    private void MaximumGenerationsParameter_ValueChanged(object sender, EventArgs e) {
384      MaximumGenerations.ValueChanged += new EventHandler(MaximumGenerations_ValueChanged);
385      MaximumGenerations_ValueChanged(sender, e);
386    }
387    private void MaximumGenerations_ValueChanged(object sender, EventArgs e) {
388      if (MaximumGenerations.Value < NumberOfVillages.Value) NumberOfVillages.Value = MaximumGenerations.Value;
389      ParameterizeMainLoop();
390    }
391    private void NumberOfVillagesParameter_ValueChanged(object sender, EventArgs e) {
392      NumberOfVillages.ValueChanged += new EventHandler(NumberOfVillages_ValueChanged);
393      NumberOfVillages_ValueChanged(sender, e);
394    }
395    private void NumberOfVillages_ValueChanged(object sender, EventArgs e) {
396      if (NumberOfVillages.Value > MaximumGenerations.Value) MaximumGenerations.Value = NumberOfVillages.Value;
397      ParameterizeComparisonFactorModifiers();
398      ParameterizeMainLoop();
399    }
400    #endregion
401
402    #region Helpers
403    [StorableHook(HookType.AfterDeserialization)]
404    private void Initialize() {
405      NumberOfVillagesParameter.ValueChanged += new EventHandler(NumberOfVillagesParameter_ValueChanged);
406      NumberOfVillages.ValueChanged += new EventHandler(NumberOfVillages_ValueChanged);
407      PopulationSizeParameter.ValueChanged += new EventHandler(PopulationSizeParameter_ValueChanged);
408      PopulationSize.ValueChanged += new EventHandler(PopulationSize_ValueChanged);
409      ElitesParameter.ValueChanged += new EventHandler(ElitesParameter_ValueChanged);
410      Elites.ValueChanged += new EventHandler(Elites_ValueChanged);
411      MaximumGenerationsParameter.ValueChanged += new EventHandler(MaximumGenerationsParameter_ValueChanged);
412      MaximumGenerations.ValueChanged += new EventHandler(MaximumGenerations_ValueChanged);
413      if (Problem != null) {
414        Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
415      }
416    }
417    private void ParameterizeSolutionsCreator() {
418      SolutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
419      SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name;
420    }
421    private void ParameterizeMainLoop() {
422      MainLoop.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
423      MainLoop.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
424      MainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
425      MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
426      MainLoop.MigrationIntervalParameter.Value = new IntValue(MaximumGenerations.Value / NumberOfVillages.Value);
427    }
428    private void ParameterizeStochasticOperator(IOperator op) {
429      if (op is IStochasticOperator)
430        ((IStochasticOperator)op).RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
431    }
432    private void ParameterizeSelectors() {
433      foreach (ISelector selector in SelectorParameter.ValidValues) {
434        selector.CopySelected = new BoolValue(true);
435        selector.NumberOfSelectedSubScopesParameter.Value = null;
436        selector.NumberOfSelectedSubScopesParameter.ActualName = SelectedParentsParameter.Name;
437        ParameterizeStochasticOperator(selector);
438      }
439      if (Problem != null) {
440        foreach (ISingleObjectiveSelector selector in SelectorParameter.ValidValues.OfType<ISingleObjectiveSelector>()) {
441          selector.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
442          selector.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
443        }
444      }
445    }
446    private void ParameterizeAnalyzers() {
447      villageQualityAnalyzer.ResultsParameter.ActualName = "Results";
448      villageQualityAnalyzer.QualityParameter.Depth = 1;
449      qualityAnalyzer.ResultsParameter.ActualName = "Results";
450      qualityAnalyzer.QualityParameter.Depth = 2;
451
452      villageSelectionPressureAnalyzer.ResultsParameter.ActualName = "Results";
453      villageSelectionPressureAnalyzer.Name = "SelectionPressure Analyzer";
454      villageSelectionPressureAnalyzer.ValueParameter.Depth = 0;
455      villageSelectionPressureAnalyzer.ValueParameter.ActualName = "SelectionPressure";
456      villageSelectionPressureAnalyzer.ValuesParameter.ActualName = "Selection Pressure History";
457
458      selectionPressureAnalyzer.ResultsParameter.ActualName = "Results";
459      selectionPressureAnalyzer.Name = "SelectionPressure Analyzer";
460      selectionPressureAnalyzer.ValueParameter.Depth = 1;
461      selectionPressureAnalyzer.ValueParameter.ActualName = "SelectionPressure";
462      selectionPressureAnalyzer.ValuesParameter.ActualName = "Selection Pressure History";
463
464      if (Problem != null) {
465        villageQualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
466        villageQualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
467        villageQualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
468
469        qualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
470        qualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
471        qualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
472      }
473    }
474    private void ParameterizeComparisonFactorModifiers() {
475      foreach (IDiscreteDoubleValueModifier modifier in ComparisonFactorModifierParameter.ValidValues) {
476        modifier.IndexParameter.ActualName = "Reunifications";
477        modifier.StartIndexParameter.Value = new IntValue(0);
478        modifier.StartValueParameter.ActualName = ComparisonFactorLowerBoundParameter.Name;
479        modifier.EndIndexParameter.Value = new IntValue(NumberOfVillages.Value - 1);
480        modifier.EndValueParameter.ActualName = ComparisonFactorUpperBoundParameter.Name;
481        modifier.ValueParameter.ActualName = "ComparisonFactor";
482      }
483    }
484    private void ParameterizeIterationBasedOperators() {
485      if (Problem != null) {
486        foreach (IIterationBasedOperator op in Problem.Operators.OfType<IIterationBasedOperator>()) {
487          op.IterationsParameter.ActualName = "Generations";
488          op.MaximumIterationsParameter.ActualName = MaximumGenerationsParameter.Name;
489        }
490      }
491    }
492    private void UpdateCrossovers() {
493      ICrossover oldCrossover = CrossoverParameter.Value;
494      CrossoverParameter.ValidValues.Clear();
495      foreach (ICrossover crossover in Problem.Operators.OfType<ICrossover>().OrderBy(x => x.Name))
496        CrossoverParameter.ValidValues.Add(crossover);
497      if (oldCrossover != null) {
498        ICrossover crossover = CrossoverParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldCrossover.GetType());
499        if (crossover != null) CrossoverParameter.Value = crossover;
500      }
501    }
502    private void UpdateMutators() {
503      IManipulator oldMutator = MutatorParameter.Value;
504      MutatorParameter.ValidValues.Clear();
505      foreach (IManipulator mutator in Problem.Operators.OfType<IManipulator>().OrderBy(x => x.Name))
506        MutatorParameter.ValidValues.Add(mutator);
507      if (oldMutator != null) {
508        IManipulator mutator = MutatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMutator.GetType());
509        if (mutator != null) MutatorParameter.Value = mutator;
510      }
511    }
512    private void UpdateAnalyzers() {
513      VillageAnalyzer.Operators.Clear();
514      Analyzer.Operators.Clear();
515      VillageAnalyzer.Operators.Add(villageQualityAnalyzer);
516      VillageAnalyzer.Operators.Add(villageSelectionPressureAnalyzer);
517      if (Problem != null) {
518        foreach (IAnalyzer analyzer in Problem.Operators.OfType<IAnalyzer>().OrderBy(x => x.Name)) {
519          foreach (IScopeTreeLookupParameter param in analyzer.Parameters.OfType<IScopeTreeLookupParameter>())
520            param.Depth = 2;
521          Analyzer.Operators.Add(analyzer);
522        }
523      }
524      Analyzer.Operators.Add(qualityAnalyzer);
525      Analyzer.Operators.Add(selectionPressureAnalyzer);
526    }
527    #endregion
528  }
529}
Note: See TracBrowser for help on using the repository browser.