Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 3704 was 3704, checked in by abeham, 14 years ago

#839

  • removed parallel parameter from multipopulation algorithms
File size: 27.8 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", "Should be about 2 * PopulationSize, for large problems use a smaller value to decrease memory footprint.", 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.ComparisonFactorLowerBoundParameter.ActualName = ComparisonFactorLowerBoundParameter.Name;
281      mainLoop.ComparisonFactorModifierParameter.ActualName = ComparisonFactorModifierParameter.Name;
282      mainLoop.ComparisonFactorUpperBoundParameter.ActualName = ComparisonFactorUpperBoundParameter.Name;
283      mainLoop.MaximumSelectionPressureParameter.ActualName = MaximumSelectionPressureParameter.Name;
284      mainLoop.FinalMaximumSelectionPressureParameter.ActualName = FinalMaximumSelectionPressureParameter.Name;
285      mainLoop.MaximumGenerationsParameter.ActualName = MaximumGenerationsParameter.Name;
286      mainLoop.OffspringSelectionBeforeMutationParameter.ActualName = OffspringSelectionBeforeMutationParameter.Name;
287      mainLoop.Successor = null;
288
289      foreach (ISelector selector in ApplicationManager.Manager.GetInstances<ISelector>().Where(x => !(x is IMultiObjectiveSelector)).OrderBy(x => x.Name))
290        SelectorParameter.ValidValues.Add(selector);
291      ISelector proportionalSelector = SelectorParameter.ValidValues.FirstOrDefault(x => x.GetType().Name.Equals("ProportionalSelector"));
292      if (proportionalSelector != null) SelectorParameter.Value = proportionalSelector;
293
294      ParameterizeSelectors();
295
296      foreach (IDiscreteDoubleValueModifier modifier in ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>().OrderBy(x => x.Name))
297        ComparisonFactorModifierParameter.ValidValues.Add(modifier);
298      IDiscreteDoubleValueModifier linearModifier = ComparisonFactorModifierParameter.ValidValues.FirstOrDefault(x => x.GetType().Name.Equals("LinearDiscreteDoubleValueModifier"));
299      if (linearModifier != null) ComparisonFactorModifierParameter.Value = linearModifier;
300      ParameterizeComparisonFactorModifiers();
301
302      qualityAnalyzer = new BestAverageWorstQualityAnalyzer();
303      villageQualityAnalyzer = new BestAverageWorstQualityAnalyzer();
304      selectionPressureAnalyzer = new ValueAnalyzer();
305      villageSelectionPressureAnalyzer = new ValueAnalyzer();
306      ParameterizeAnalyzers();
307      UpdateAnalyzers();
308
309      Initialize();
310    }
311
312    public override IDeepCloneable Clone(Cloner cloner) {
313      SASEGASA clone = (SASEGASA)base.Clone(cloner);
314      clone.qualityAnalyzer = (BestAverageWorstQualityAnalyzer)cloner.Clone(qualityAnalyzer);
315      clone.villageQualityAnalyzer = (BestAverageWorstQualityAnalyzer)cloner.Clone(villageQualityAnalyzer);
316      clone.selectionPressureAnalyzer = (ValueAnalyzer)cloner.Clone(selectionPressureAnalyzer);
317      clone.villageSelectionPressureAnalyzer = (ValueAnalyzer)cloner.Clone(villageSelectionPressureAnalyzer);
318      clone.Initialize();
319      return clone;
320    }
321
322    public override void Prepare() {
323      if (Problem != null) base.Prepare();
324    }
325
326    #region Events
327    protected override void OnProblemChanged() {
328      ParameterizeStochasticOperator(Problem.SolutionCreator);
329      ParameterizeStochasticOperator(Problem.Evaluator);
330      foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
331      ParameterizeSolutionsCreator();
332      ParameterizeMainLoop();
333      ParameterizeSelectors();
334      ParameterizeAnalyzers();
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      UpdateCrossovers();
359      UpdateMutators();
360      UpdateAnalyzers();
361      base.Problem_OperatorsChanged(sender, e);
362    }
363    private void ElitesParameter_ValueChanged(object sender, EventArgs e) {
364      Elites.ValueChanged += new EventHandler(Elites_ValueChanged);
365      ParameterizeSelectors();
366    }
367    private void Elites_ValueChanged(object sender, EventArgs e) {
368      ParameterizeSelectors();
369    }
370    private void PopulationSizeParameter_ValueChanged(object sender, EventArgs e) {
371      NumberOfVillages.ValueChanged += new EventHandler(PopulationSize_ValueChanged);
372      ParameterizeSelectors();
373    }
374    private void PopulationSize_ValueChanged(object sender, EventArgs e) {
375      ParameterizeSelectors();
376    }
377    private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
378      ParameterizeMainLoop();
379      ParameterizeSelectors();
380      ParameterizeAnalyzers();
381    }
382    private void MaximumGenerationsParameter_ValueChanged(object sender, EventArgs e) {
383      MaximumGenerations.ValueChanged += new EventHandler(MaximumGenerations_ValueChanged);
384      MaximumGenerations_ValueChanged(sender, e);
385    }
386    private void MaximumGenerations_ValueChanged(object sender, EventArgs e) {
387      if (MaximumGenerations.Value < NumberOfVillages.Value) NumberOfVillages.Value = MaximumGenerations.Value;
388      ParameterizeMainLoop();
389    }
390    private void NumberOfVillagesParameter_ValueChanged(object sender, EventArgs e) {
391      NumberOfVillages.ValueChanged += new EventHandler(NumberOfVillages_ValueChanged);
392      NumberOfVillages_ValueChanged(sender, e);
393    }
394    private void NumberOfVillages_ValueChanged(object sender, EventArgs e) {
395      if (NumberOfVillages.Value > MaximumGenerations.Value) MaximumGenerations.Value = NumberOfVillages.Value;
396      ParameterizeComparisonFactorModifiers();
397      ParameterizeMainLoop();
398    }
399    #endregion
400
401    #region Helpers
402    [StorableHook(HookType.AfterDeserialization)]
403    private void Initialize() {
404      NumberOfVillagesParameter.ValueChanged += new EventHandler(NumberOfVillagesParameter_ValueChanged);
405      NumberOfVillages.ValueChanged += new EventHandler(NumberOfVillages_ValueChanged);
406      PopulationSizeParameter.ValueChanged += new EventHandler(PopulationSizeParameter_ValueChanged);
407      PopulationSize.ValueChanged += new EventHandler(PopulationSize_ValueChanged);
408      ElitesParameter.ValueChanged += new EventHandler(ElitesParameter_ValueChanged);
409      Elites.ValueChanged += new EventHandler(Elites_ValueChanged);
410      MaximumGenerationsParameter.ValueChanged += new EventHandler(MaximumGenerationsParameter_ValueChanged);
411      MaximumGenerations.ValueChanged += new EventHandler(MaximumGenerations_ValueChanged);
412      if (Problem != null) {
413        Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
414      }
415    }
416    private void ParameterizeSolutionsCreator() {
417      SolutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
418      SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name;
419    }
420    private void ParameterizeMainLoop() {
421      MainLoop.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
422      MainLoop.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
423      MainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
424      MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
425      MainLoop.MigrationIntervalParameter.Value = new IntValue(MaximumGenerations.Value / NumberOfVillages.Value);
426    }
427    private void ParameterizeStochasticOperator(IOperator op) {
428      if (op is IStochasticOperator)
429        ((IStochasticOperator)op).RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
430    }
431    private void ParameterizeSelectors() {
432      foreach (ISelector selector in SelectorParameter.ValidValues) {
433        selector.CopySelected = new BoolValue(true);
434        selector.NumberOfSelectedSubScopesParameter.Value = null;
435        selector.NumberOfSelectedSubScopesParameter.ActualName = SelectedParentsParameter.Name;
436        ParameterizeStochasticOperator(selector);
437      }
438      if (Problem != null) {
439        foreach (ISingleObjectiveSelector selector in SelectorParameter.ValidValues.OfType<ISingleObjectiveSelector>()) {
440          selector.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
441          selector.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
442        }
443      }
444    }
445    private void ParameterizeAnalyzers() {
446      villageQualityAnalyzer.ResultsParameter.ActualName = "Results";
447      villageQualityAnalyzer.QualityParameter.Depth = 1;
448      qualityAnalyzer.ResultsParameter.ActualName = "Results";
449      qualityAnalyzer.QualityParameter.Depth = 2;
450
451      villageSelectionPressureAnalyzer.ResultsParameter.ActualName = "Results";
452      villageSelectionPressureAnalyzer.Name = "SelectionPressure Analyzer";
453      villageSelectionPressureAnalyzer.ValueParameter.Depth = 0;
454      villageSelectionPressureAnalyzer.ValueParameter.ActualName = "SelectionPressure";
455      villageSelectionPressureAnalyzer.ValuesParameter.ActualName = "Selection Pressure History";
456
457      selectionPressureAnalyzer.ResultsParameter.ActualName = "Results";
458      selectionPressureAnalyzer.Name = "SelectionPressure Analyzer";
459      selectionPressureAnalyzer.ValueParameter.Depth = 1;
460      selectionPressureAnalyzer.ValueParameter.ActualName = "SelectionPressure";
461      selectionPressureAnalyzer.ValuesParameter.ActualName = "Selection Pressure History";
462
463      if (Problem != null) {
464        villageQualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
465        villageQualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
466        villageQualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
467
468        qualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
469        qualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
470        qualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
471      }
472    }
473    private void ParameterizeComparisonFactorModifiers() {
474      foreach (IDiscreteDoubleValueModifier modifier in ComparisonFactorModifierParameter.ValidValues) {
475        modifier.IndexParameter.ActualName = "Reunifications";
476        modifier.StartIndexParameter.Value = new IntValue(0);
477        modifier.StartValueParameter.ActualName = ComparisonFactorLowerBoundParameter.Name;
478        modifier.EndIndexParameter.Value = new IntValue(NumberOfVillages.Value - 1);
479        modifier.EndValueParameter.ActualName = ComparisonFactorUpperBoundParameter.Name;
480        modifier.ValueParameter.ActualName = "ComparisonFactor";
481      }
482    }
483    private void UpdateCrossovers() {
484      ICrossover oldCrossover = CrossoverParameter.Value;
485      CrossoverParameter.ValidValues.Clear();
486      foreach (ICrossover crossover in Problem.Operators.OfType<ICrossover>().OrderBy(x => x.Name))
487        CrossoverParameter.ValidValues.Add(crossover);
488      if (oldCrossover != null) {
489        ICrossover crossover = CrossoverParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldCrossover.GetType());
490        if (crossover != null) CrossoverParameter.Value = crossover;
491      }
492    }
493    private void UpdateMutators() {
494      IManipulator oldMutator = MutatorParameter.Value;
495      MutatorParameter.ValidValues.Clear();
496      foreach (IManipulator mutator in Problem.Operators.OfType<IManipulator>().OrderBy(x => x.Name))
497        MutatorParameter.ValidValues.Add(mutator);
498      if (oldMutator != null) {
499        IManipulator mutator = MutatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMutator.GetType());
500        if (mutator != null) MutatorParameter.Value = mutator;
501      }
502    }
503    private void UpdateAnalyzers() {
504      VillageAnalyzer.Operators.Clear();
505      Analyzer.Operators.Clear();
506      VillageAnalyzer.Operators.Add(villageQualityAnalyzer);
507      VillageAnalyzer.Operators.Add(villageSelectionPressureAnalyzer);
508      Analyzer.Operators.Add(qualityAnalyzer);
509      Analyzer.Operators.Add(selectionPressureAnalyzer);
510      if (Problem != null) {
511        foreach (IAnalyzer analyzer in Problem.Operators.OfType<IAnalyzer>().OrderBy(x => x.Name)) {
512          foreach (IScopeTreeLookupParameter param in analyzer.Parameters.OfType<IScopeTreeLookupParameter>())
513            param.Depth = 2;
514          Analyzer.Operators.Add(analyzer);
515        }
516      }
517    }
518    #endregion
519  }
520}
Note: See TracBrowser for help on using the repository browser.