Free cookie consent management tool by TermsFeed Policy Generator

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

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

#999

  • updated Island OSGA, SASEGASA
  • minor changes to Island GA and OSGA
File size: 29.2 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 ValueParameter<BoolValue> ParallelParameter {
89      get { return (ValueParameter<BoolValue>)Parameters["Parallel"]; }
90    }
91    private ValueLookupParameter<DoubleValue> SuccessRatioParameter {
92      get { return (ValueLookupParameter<DoubleValue>)Parameters["SuccessRatio"]; }
93    }
94    private ValueLookupParameter<DoubleValue> ComparisonFactorLowerBoundParameter {
95      get { return (ValueLookupParameter<DoubleValue>)Parameters["ComparisonFactorLowerBound"]; }
96    }
97    private ValueLookupParameter<DoubleValue> ComparisonFactorUpperBoundParameter {
98      get { return (ValueLookupParameter<DoubleValue>)Parameters["ComparisonFactorUpperBound"]; }
99    }
100    private OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier> ComparisonFactorModifierParameter {
101      get { return (OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier>)Parameters["ComparisonFactorModifier"]; }
102    }
103    private ValueLookupParameter<DoubleValue> MaximumSelectionPressureParameter {
104      get { return (ValueLookupParameter<DoubleValue>)Parameters["MaximumSelectionPressure"]; }
105    }
106    private ValueLookupParameter<DoubleValue> FinalMaximumSelectionPressureParameter {
107      get { return (ValueLookupParameter<DoubleValue>)Parameters["FinalMaximumSelectionPressure"]; }
108    }
109    private ValueLookupParameter<BoolValue> OffspringSelectionBeforeMutationParameter {
110      get { return (ValueLookupParameter<BoolValue>)Parameters["OffspringSelectionBeforeMutation"]; }
111    }
112    private ValueLookupParameter<IntValue> SelectedParentsParameter {
113      get { return (ValueLookupParameter<IntValue>)Parameters["SelectedParents"]; }
114    }
115    private ValueParameter<MultiAnalyzer> AnalyzerParameter {
116      get { return (ValueParameter<MultiAnalyzer>)Parameters["Analyzer"]; }
117    }
118    private ValueParameter<MultiAnalyzer> VillageAnalyzerParameter {
119      get { return (ValueParameter<MultiAnalyzer>)Parameters["VillageAnalyzer"]; }
120    }
121    #endregion
122
123    #region Properties
124    public IntValue Seed {
125      get { return SeedParameter.Value; }
126      set { SeedParameter.Value = value; }
127    }
128    public BoolValue SetSeedRandomly {
129      get { return SetSeedRandomlyParameter.Value; }
130      set { SetSeedRandomlyParameter.Value = value; }
131    }
132    public IntValue NumberOfVillages {
133      get { return NumberOfVillagesParameter.Value; }
134      set { NumberOfVillagesParameter.Value = value; }
135    }
136    public IntValue PopulationSize {
137      get { return PopulationSizeParameter.Value; }
138      set { PopulationSizeParameter.Value = value; }
139    }
140    public IntValue MaximumGenerations {
141      get { return MaximumGenerationsParameter.Value; }
142      set { MaximumGenerationsParameter.Value = value; }
143    }
144    public ISelector Selector {
145      get { return SelectorParameter.Value; }
146      set { SelectorParameter.Value = value; }
147    }
148    public ICrossover Crossover {
149      get { return CrossoverParameter.Value; }
150      set { CrossoverParameter.Value = value; }
151    }
152    public PercentValue MutationProbability {
153      get { return MutationProbabilityParameter.Value; }
154      set { MutationProbabilityParameter.Value = value; }
155    }
156    public IManipulator Mutator {
157      get { return MutatorParameter.Value; }
158      set { MutatorParameter.Value = value; }
159    }
160    public IntValue Elites {
161      get { return ElitesParameter.Value; }
162      set { ElitesParameter.Value = value; }
163    }
164    public BoolValue Parallel {
165      get { return ParallelParameter.Value; }
166      set { ParallelParameter.Value = value; }
167    }
168    public DoubleValue SuccessRatio {
169      get { return SuccessRatioParameter.Value; }
170      set { SuccessRatioParameter.Value = value; }
171    }
172    public DoubleValue ComparisonFactorLowerBound {
173      get { return ComparisonFactorLowerBoundParameter.Value; }
174      set { ComparisonFactorLowerBoundParameter.Value = value; }
175    }
176    public DoubleValue ComparisonFactorUpperBound {
177      get { return ComparisonFactorUpperBoundParameter.Value; }
178      set { ComparisonFactorUpperBoundParameter.Value = value; }
179    }
180    public IDiscreteDoubleValueModifier ComparisonFactorModifier {
181      get { return ComparisonFactorModifierParameter.Value; }
182      set { ComparisonFactorModifierParameter.Value = value; }
183    }
184    public DoubleValue MaximumSelectionPressure {
185      get { return MaximumSelectionPressureParameter.Value; }
186      set { MaximumSelectionPressureParameter.Value = value; }
187    }
188    public DoubleValue FinalMaximumSelectionPressure {
189      get { return FinalMaximumSelectionPressureParameter.Value; }
190      set { FinalMaximumSelectionPressureParameter.Value = value; }
191    }
192    public BoolValue OffspringSelectionBeforeMutation {
193      get { return OffspringSelectionBeforeMutationParameter.Value; }
194      set { OffspringSelectionBeforeMutationParameter.Value = value; }
195    }
196    public IntValue SelectedParents {
197      get { return SelectedParentsParameter.Value; }
198      set { SelectedParentsParameter.Value = value; }
199    }
200    public MultiAnalyzer Analyzer {
201      get { return AnalyzerParameter.Value; }
202      set { AnalyzerParameter.Value = value; }
203    }
204    public MultiAnalyzer VillageAnalyzer {
205      get { return VillageAnalyzerParameter.Value; }
206      set { VillageAnalyzerParameter.Value = value; }
207    }
208    private List<ISelector> selectors;
209    private IEnumerable<ISelector> Selectors {
210      get { return selectors; }
211    }
212    private List<IDiscreteDoubleValueModifier> comparisonFactorModifiers;
213    private RandomCreator RandomCreator {
214      get { return (RandomCreator)OperatorGraph.InitialOperator; }
215    }
216    private UniformSubScopesProcessor VillageProcessor {
217      get { return ((RandomCreator.Successor as SubScopesCreator).Successor as UniformSubScopesProcessor); }
218    }
219    private SolutionsCreator SolutionsCreator {
220      get { return (SolutionsCreator)VillageProcessor.Operator; }
221    }
222    private SASEGASAMainLoop MainLoop {
223      get { return (SASEGASAMainLoop)VillageProcessor.Successor; }
224    }
225    private BestAverageWorstQualityAnalyzer villageQualityAnalyzer;
226    private BestAverageWorstQualityAnalyzer qualityAnalyzer;
227    private ValueAnalyzer villageSelectionPressureAnalyzer;
228    private ValueAnalyzer selectionPressureAnalyzer;
229    #endregion
230
231    [StorableConstructor]
232    private SASEGASA(bool deserializing) : base(deserializing) { }
233    public SASEGASA()
234      : base() {
235      Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
236      Parameters.Add(new ValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
237      Parameters.Add(new ValueParameter<IntValue>("NumberOfVillages", "The initial number of villages.", new IntValue(10)));
238      Parameters.Add(new ValueParameter<IntValue>("PopulationSize", "The size of the population of solutions.", new IntValue(100)));
239      Parameters.Add(new ValueParameter<IntValue>("MaximumGenerations", "The maximum number of generations that should be processed.", new IntValue(1000)));
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)));
245      Parameters.Add(new ValueParameter<BoolValue>("Parallel", "True if the villages should be run in parallel (also requires a parallel engine)", new BoolValue(false)));
246      Parameters.Add(new ValueLookupParameter<DoubleValue>("SuccessRatio", "The ratio of successful to total children that should be achieved.", new DoubleValue(1)));
247      Parameters.Add(new ValueLookupParameter<DoubleValue>("ComparisonFactorLowerBound", "The lower bound of the comparison factor (start).", new DoubleValue(0.3)));
248      Parameters.Add(new ValueLookupParameter<DoubleValue>("ComparisonFactorUpperBound", "The upper bound of the comparison factor (end).", new DoubleValue(0.7)));
249      Parameters.Add(new OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier>("ComparisonFactorModifier", "The operator used to modify the comparison factor.", new ItemSet<IDiscreteDoubleValueModifier>(new IDiscreteDoubleValueModifier[] { new LinearDiscreteDoubleValueModifier() }), new LinearDiscreteDoubleValueModifier()));
250      Parameters.Add(new ValueLookupParameter<DoubleValue>("MaximumSelectionPressure", "The maximum selection pressure that terminates the algorithm.", new DoubleValue(100)));
251      Parameters.Add(new ValueLookupParameter<DoubleValue>("FinalMaximumSelectionPressure", "The maximum selection pressure used when there is only one village left.", 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)));
253      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)));
254      Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze the villages.", new MultiAnalyzer()));
255      Parameters.Add(new ValueParameter<MultiAnalyzer>("VillageAnalyzer", "The operator used to analyze each village.", new MultiAnalyzer()));
256     
257      RandomCreator randomCreator = new RandomCreator();
258      SubScopesCreator populationCreator = new SubScopesCreator();
259      UniformSubScopesProcessor ussp1 = new UniformSubScopesProcessor();
260      SolutionsCreator solutionsCreator = new SolutionsCreator();
261      SASEGASAMainLoop mainLoop = new SASEGASAMainLoop();
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 = populationCreator;
270
271      populationCreator.NumberOfSubScopesParameter.ActualName = NumberOfVillagesParameter.Name;
272      populationCreator.Successor = ussp1;
273
274      ussp1.Parallel = null;
275      ussp1.ParallelParameter.ActualName = ParallelParameter.Name;
276      ussp1.Operator = solutionsCreator;
277      ussp1.Successor = mainLoop;
278
279      solutionsCreator.NumberOfSolutionsParameter.ActualName = PopulationSizeParameter.Name;
280      solutionsCreator.Successor = null;
281
282
283      mainLoop.NumberOfVillagesParameter.ActualName = NumberOfVillagesParameter.Name;
284      mainLoop.SelectorParameter.ActualName = SelectorParameter.Name;
285      mainLoop.CrossoverParameter.ActualName = CrossoverParameter.Name;
286      mainLoop.ElitesParameter.ActualName = ElitesParameter.Name;
287      mainLoop.MutatorParameter.ActualName = MutatorParameter.Name;
288      mainLoop.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
289      mainLoop.RandomParameter.ActualName = randomCreator.RandomParameter.ActualName;
290      mainLoop.ResultsParameter.ActualName = "Results";
291      mainLoop.SuccessRatioParameter.ActualName = SuccessRatioParameter.Name;
292      mainLoop.ComparisonFactorLowerBoundParameter.ActualName = ComparisonFactorLowerBoundParameter.Name;
293      mainLoop.ComparisonFactorModifierParameter.ActualName = ComparisonFactorModifierParameter.Name;
294      mainLoop.ComparisonFactorUpperBoundParameter.ActualName = ComparisonFactorUpperBoundParameter.Name;
295      mainLoop.MaximumSelectionPressureParameter.ActualName = MaximumSelectionPressureParameter.Name;
296      mainLoop.FinalMaximumSelectionPressureParameter.ActualName = FinalMaximumSelectionPressureParameter.Name;
297      mainLoop.MaximumGenerationsParameter.ActualName = MaximumGenerationsParameter.Name;
298      mainLoop.OffspringSelectionBeforeMutationParameter.ActualName = OffspringSelectionBeforeMutationParameter.Name;
299      mainLoop.Successor = null;
300
301      Initialize();
302    }
303
304    public override IDeepCloneable Clone(Cloner cloner) {
305      SASEGASA clone = (SASEGASA)base.Clone(cloner);
306      clone.Initialize();
307      return clone;
308    }
309
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);
318      foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
319      ParameterizeSolutionsCreator();
320      ParameterizeMainLoop();
321      ParameterizeSelectors();
322      ParameterizeAnalyzers();
323      UpdateCrossovers();
324      UpdateMutators();
325      UpdateAnalyzers();
326      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
327      base.OnProblemChanged();
328    }
329
330    protected override void Problem_SolutionCreatorChanged(object sender, EventArgs e) {
331      ParameterizeStochasticOperator(Problem.SolutionCreator);
332      ParameterizeSolutionsCreator();
333      base.Problem_SolutionCreatorChanged(sender, e);
334    }
335    protected override void Problem_EvaluatorChanged(object sender, EventArgs e) {
336      ParameterizeStochasticOperator(Problem.Evaluator);
337      ParameterizeSolutionsCreator();
338      ParameterizeMainLoop();
339      ParameterizeSelectors();
340      ParameterizeAnalyzers();
341      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
342      base.Problem_EvaluatorChanged(sender, e);
343    }
344    protected override void Problem_OperatorsChanged(object sender, EventArgs e) {
345      foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
346      UpdateCrossovers();
347      UpdateMutators();
348      UpdateAnalyzers();
349      base.Problem_OperatorsChanged(sender, e);
350    }
351    private void ElitesParameter_ValueChanged(object sender, EventArgs e) {
352      Elites.ValueChanged += new EventHandler(Elites_ValueChanged);
353      ParameterizeSelectors();
354    }
355    private void Elites_ValueChanged(object sender, EventArgs e) {
356      ParameterizeSelectors();
357    }
358    private void PopulationSizeParameter_ValueChanged(object sender, EventArgs e) {
359      NumberOfVillages.ValueChanged += new EventHandler(PopulationSize_ValueChanged);
360      ParameterizeSelectors();
361    }
362    private void PopulationSize_ValueChanged(object sender, EventArgs e) {
363      ParameterizeSelectors();
364    }
365    private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
366      ParameterizeMainLoop();
367      ParameterizeSelectors();
368      ParameterizeAnalyzers();
369    }
370    private void MaximumGenerationsParameter_ValueChanged(object sender, EventArgs e) {
371      MaximumGenerations.ValueChanged += new EventHandler(MaximumGenerations_ValueChanged);
372      MaximumGenerations_ValueChanged(sender, e);
373    }
374    private void MaximumGenerations_ValueChanged(object sender, EventArgs e) {
375      if (MaximumGenerations.Value < NumberOfVillages.Value) NumberOfVillages.Value = MaximumGenerations.Value;
376      ParameterizeMainLoop();
377    }
378    private void NumberOfVillagesParameter_ValueChanged(object sender, EventArgs e) {
379      NumberOfVillages.ValueChanged += new EventHandler(NumberOfVillages_ValueChanged);
380      NumberOfVillages_ValueChanged(sender, e);
381    }
382    private void NumberOfVillages_ValueChanged(object sender, EventArgs e) {
383      if (NumberOfVillages.Value > MaximumGenerations.Value) MaximumGenerations.Value = NumberOfVillages.Value;
384      ParameterizeComparisonFactorModifiers();
385      ParameterizeMainLoop();
386    }
387    #endregion
388
389    #region Helpers
390    [StorableHook(HookType.AfterDeserialization)]
391    private void Initialize() {
392      InitializeSelectors();
393      InitializeAnalyzers();
394      UpdateSelectors();
395      UpdateAnalyzers();
396      InitializeComparisonFactorModifiers();
397      UpdateComparisonFactorModifiers();
398      NumberOfVillagesParameter.ValueChanged += new EventHandler(NumberOfVillagesParameter_ValueChanged);
399      NumberOfVillages.ValueChanged += new EventHandler(NumberOfVillages_ValueChanged);
400      PopulationSizeParameter.ValueChanged += new EventHandler(PopulationSizeParameter_ValueChanged);
401      PopulationSize.ValueChanged += new EventHandler(PopulationSize_ValueChanged);
402      ElitesParameter.ValueChanged += new EventHandler(ElitesParameter_ValueChanged);
403      Elites.ValueChanged += new EventHandler(Elites_ValueChanged);
404      MaximumGenerationsParameter.ValueChanged += new EventHandler(MaximumGenerationsParameter_ValueChanged);
405      MaximumGenerations.ValueChanged += new EventHandler(MaximumGenerations_ValueChanged);
406      if (Problem != null) {
407        UpdateCrossovers();
408        UpdateMutators();
409        Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
410      }
411    }
412    private void ParameterizeSolutionsCreator() {
413      SolutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
414      SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name;
415    }
416    private void ParameterizeMainLoop() {
417      MainLoop.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
418      MainLoop.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
419      MainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
420      MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
421      MainLoop.MigrationIntervalParameter.Value = new IntValue(MaximumGenerations.Value / NumberOfVillages.Value);
422    }
423    private void ParameterizeStochasticOperator(IOperator op) {
424      if (op is IStochasticOperator)
425        ((IStochasticOperator)op).RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
426    }
427    private void InitializeSelectors() {
428      selectors = new List<ISelector>();
429      selectors.AddRange(ApplicationManager.Manager.GetInstances<ISelector>().Where(x => !(x is IMultiObjectiveSelector)).OrderBy(x => x.Name));
430      ParameterizeSelectors();
431    }
432    private void InitializeAnalyzers() {
433      villageQualityAnalyzer = new BestAverageWorstQualityAnalyzer();
434      qualityAnalyzer = new BestAverageWorstQualityAnalyzer();
435      villageSelectionPressureAnalyzer = new ValueAnalyzer();
436      selectionPressureAnalyzer = new ValueAnalyzer();
437      ParameterizeAnalyzers();
438    }
439    private void InitializeComparisonFactorModifiers() {
440      comparisonFactorModifiers = new List<IDiscreteDoubleValueModifier>();
441      comparisonFactorModifiers.AddRange(ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>().OrderBy(x => x.Name));
442      ParameterizeComparisonFactorModifiers();
443    }
444    private void ParameterizeSelectors() {
445      foreach (ISelector selector in Selectors) {
446        selector.CopySelected = new BoolValue(true);
447        selector.NumberOfSelectedSubScopesParameter.Value = null;
448        selector.NumberOfSelectedSubScopesParameter.ActualName = SelectedParentsParameter.Name;
449        ParameterizeStochasticOperator(selector);
450      }
451      if (Problem != null) {
452        foreach (ISingleObjectiveSelector selector in Selectors.OfType<ISingleObjectiveSelector>()) {
453          selector.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
454          selector.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
455        }
456      }
457    }
458    private void ParameterizeAnalyzers() {
459      villageQualityAnalyzer.ResultsParameter.ActualName = "Results";
460      villageQualityAnalyzer.QualityParameter.Depth = 1;
461      qualityAnalyzer.ResultsParameter.ActualName = "Results";
462      qualityAnalyzer.QualityParameter.Depth = 2;
463
464      villageSelectionPressureAnalyzer.ResultsParameter.ActualName = "Results";
465      villageSelectionPressureAnalyzer.Name = "SelectionPressure Analyzer";
466      villageSelectionPressureAnalyzer.ValueParameter.Depth = 0;
467      villageSelectionPressureAnalyzer.ValueParameter.ActualName = "SelectionPressure";
468      villageSelectionPressureAnalyzer.ValuesParameter.ActualName = "Selection Pressure History";
469
470      selectionPressureAnalyzer.ResultsParameter.ActualName = "Results";
471      selectionPressureAnalyzer.Name = "SelectionPressure Analyzer";
472      selectionPressureAnalyzer.ValueParameter.Depth = 1;
473      selectionPressureAnalyzer.ValueParameter.ActualName = "SelectionPressure";
474      selectionPressureAnalyzer.ValuesParameter.ActualName = "Selection Pressure History";
475
476      if (Problem != null) {
477        villageQualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
478        villageQualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
479        villageQualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
480
481        qualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
482        qualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
483        qualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
484      }
485    }
486    private void ParameterizeComparisonFactorModifiers() {
487      foreach (IDiscreteDoubleValueModifier modifier in comparisonFactorModifiers) {
488        modifier.IndexParameter.ActualName = "Reunifications";
489        modifier.StartIndexParameter.Value = new IntValue(0);
490        modifier.StartValueParameter.ActualName = ComparisonFactorLowerBoundParameter.Name;
491        modifier.EndIndexParameter.Value = new IntValue(NumberOfVillages.Value - 1);
492        modifier.EndValueParameter.ActualName = ComparisonFactorUpperBoundParameter.Name;
493        modifier.ValueParameter.ActualName = "ComparisonFactor";
494      }
495    }
496    private void UpdateSelectors() {
497      ISelector oldSelector = SelectorParameter.Value;
498      SelectorParameter.ValidValues.Clear();
499      foreach (ISelector selector in Selectors.OrderBy(x => x.Name))
500        SelectorParameter.ValidValues.Add(selector);
501
502      ISelector proportionalSelector = SelectorParameter.ValidValues.FirstOrDefault(x => x.GetType().Name.Equals("ProportionalSelector"));
503      if (proportionalSelector != null) SelectorParameter.Value = proportionalSelector;
504
505      if (oldSelector != null) {
506        ISelector selector = SelectorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldSelector.GetType());
507        if (selector != null) SelectorParameter.Value = selector;
508      }
509    }
510    private void UpdateComparisonFactorModifiers() {
511      IDiscreteDoubleValueModifier oldModifier = ComparisonFactorModifier;
512
513      ComparisonFactorModifierParameter.ValidValues.Clear();
514      foreach (IDiscreteDoubleValueModifier modifier in comparisonFactorModifiers)
515        ComparisonFactorModifierParameter.ValidValues.Add(modifier);
516
517      if (oldModifier != null) {
518        IDiscreteDoubleValueModifier mod = ComparisonFactorModifierParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldModifier.GetType());
519        if (mod != null) ComparisonFactorModifierParameter.Value = mod;
520      }
521    }
522    private void UpdateCrossovers() {
523      ICrossover oldCrossover = CrossoverParameter.Value;
524      CrossoverParameter.ValidValues.Clear();
525      foreach (ICrossover crossover in Problem.Operators.OfType<ICrossover>().OrderBy(x => x.Name))
526        CrossoverParameter.ValidValues.Add(crossover);
527      if (oldCrossover != null) {
528        ICrossover crossover = CrossoverParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldCrossover.GetType());
529        if (crossover != null) CrossoverParameter.Value = crossover;
530      }
531    }
532    private void UpdateMutators() {
533      IManipulator oldMutator = MutatorParameter.Value;
534      MutatorParameter.ValidValues.Clear();
535      foreach (IManipulator mutator in Problem.Operators.OfType<IManipulator>().OrderBy(x => x.Name))
536        MutatorParameter.ValidValues.Add(mutator);
537      if (oldMutator != null) {
538        IManipulator mutator = MutatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMutator.GetType());
539        if (mutator != null) MutatorParameter.Value = mutator;
540      }
541    }
542    private void UpdateAnalyzers() {
543      VillageAnalyzer.Operators.Clear();
544      Analyzer.Operators.Clear();
545      VillageAnalyzer.Operators.Add(villageQualityAnalyzer);
546      VillageAnalyzer.Operators.Add(villageSelectionPressureAnalyzer);
547      Analyzer.Operators.Add(qualityAnalyzer);
548      Analyzer.Operators.Add(selectionPressureAnalyzer);
549      if (Problem != null) {
550        foreach (IAnalyzer analyzer in Problem.Operators.OfType<IAnalyzer>().OrderBy(x => x.Name)) {
551          foreach (IScopeTreeLookupParameter param in analyzer.Parameters.OfType<IScopeTreeLookupParameter>())
552            param.Depth = 2;
553          Analyzer.Operators.Add(analyzer);
554        }
555      }
556    }
557    #endregion
558  }
559}
Note: See TracBrowser for help on using the repository browser.