Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 3671 was 3662, checked in by swagner, 14 years ago

Worked on refactoring of algorithm analysis and tracing (#999)

  • adapted analyzers
File size: 27.7 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 MultipopulationBestAverageWorstQualityAnalyzer qualityAnalyzer;
227    #endregion
228
229    [StorableConstructor]
230    private SASEGASA(bool deserializing) : base(deserializing) { }
231    public SASEGASA()
232      : base() {
233      Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
234      Parameters.Add(new ValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
235      Parameters.Add(new ValueParameter<IntValue>("NumberOfVillages", "The initial number of villages.", new IntValue(10)));
236      Parameters.Add(new ValueParameter<IntValue>("PopulationSize", "The size of the population of solutions.", new IntValue(100)));
237      Parameters.Add(new ValueParameter<IntValue>("MaximumGenerations", "The maximum number of generations that should be processed.", new IntValue(1000)));
238      Parameters.Add(new ConstrainedValueParameter<ISelector>("Selector", "The operator used to select solutions for reproduction."));
239      Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions."));
240      Parameters.Add(new ValueParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution.", new PercentValue(0.05)));
241      Parameters.Add(new OptionalConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions."));
242      Parameters.Add(new ValueParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.", new IntValue(1)));
243      Parameters.Add(new ValueParameter<BoolValue>("Parallel", "True if the villages should be run in parallel (also requires a parallel engine)", new BoolValue(false)));
244      Parameters.Add(new ValueLookupParameter<DoubleValue>("SuccessRatio", "The ratio of successful to total children that should be achieved.", new DoubleValue(1)));
245      Parameters.Add(new ValueLookupParameter<DoubleValue>("ComparisonFactorLowerBound", "The lower bound of the comparison factor (start).", new DoubleValue(0.3)));
246      Parameters.Add(new ValueLookupParameter<DoubleValue>("ComparisonFactorUpperBound", "The upper bound of the comparison factor (end).", new DoubleValue(0.7)));
247      Parameters.Add(new OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier>("ComparisonFactorModifier", "The operator used to modify the comparison factor.", new ItemSet<IDiscreteDoubleValueModifier>(new IDiscreteDoubleValueModifier[] { new LinearDiscreteDoubleValueModifier() }), new LinearDiscreteDoubleValueModifier()));
248      Parameters.Add(new ValueLookupParameter<DoubleValue>("MaximumSelectionPressure", "The maximum selection pressure that terminates the algorithm.", new DoubleValue(100)));
249      Parameters.Add(new ValueLookupParameter<DoubleValue>("FinalMaximumSelectionPressure", "The maximum selection pressure used when there is only one village left.", new DoubleValue(100)));
250      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)));
251      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)));
252      Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze the villages.", new MultiAnalyzer()));
253      Parameters.Add(new ValueParameter<MultiAnalyzer>("VillageAnalyzer", "The operator used to analyze each village.", new MultiAnalyzer()));
254     
255      RandomCreator randomCreator = new RandomCreator();
256      SubScopesCreator populationCreator = new SubScopesCreator();
257      UniformSubScopesProcessor ussp1 = new UniformSubScopesProcessor();
258      SolutionsCreator solutionsCreator = new SolutionsCreator();
259      SASEGASAMainLoop mainLoop = new SASEGASAMainLoop();
260      OperatorGraph.InitialOperator = randomCreator;
261
262      randomCreator.RandomParameter.ActualName = "Random";
263      randomCreator.SeedParameter.ActualName = SeedParameter.Name;
264      randomCreator.SeedParameter.Value = null;
265      randomCreator.SetSeedRandomlyParameter.ActualName = SetSeedRandomlyParameter.Name;
266      randomCreator.SetSeedRandomlyParameter.Value = null;
267      randomCreator.Successor = populationCreator;
268
269      populationCreator.NumberOfSubScopesParameter.ActualName = NumberOfVillagesParameter.Name;
270      populationCreator.Successor = ussp1;
271
272      ussp1.Parallel = null;
273      ussp1.ParallelParameter.ActualName = ParallelParameter.Name;
274      ussp1.Operator = solutionsCreator;
275      ussp1.Successor = mainLoop;
276
277      solutionsCreator.NumberOfSolutionsParameter.ActualName = PopulationSizeParameter.Name;
278      solutionsCreator.Successor = null;
279
280
281      mainLoop.NumberOfVillagesParameter.ActualName = NumberOfVillagesParameter.Name;
282      mainLoop.SelectorParameter.ActualName = SelectorParameter.Name;
283      mainLoop.CrossoverParameter.ActualName = CrossoverParameter.Name;
284      mainLoop.ElitesParameter.ActualName = ElitesParameter.Name;
285      mainLoop.MutatorParameter.ActualName = MutatorParameter.Name;
286      mainLoop.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
287      mainLoop.RandomParameter.ActualName = randomCreator.RandomParameter.ActualName;
288      mainLoop.ResultsParameter.ActualName = "Results";
289      mainLoop.SuccessRatioParameter.ActualName = SuccessRatioParameter.Name;
290      mainLoop.ComparisonFactorLowerBoundParameter.ActualName = ComparisonFactorLowerBoundParameter.Name;
291      mainLoop.ComparisonFactorModifierParameter.ActualName = ComparisonFactorModifierParameter.Name;
292      mainLoop.ComparisonFactorUpperBoundParameter.ActualName = ComparisonFactorUpperBoundParameter.Name;
293      mainLoop.MaximumSelectionPressureParameter.ActualName = MaximumSelectionPressureParameter.Name;
294      mainLoop.FinalMaximumSelectionPressureParameter.ActualName = FinalMaximumSelectionPressureParameter.Name;
295      mainLoop.MaximumGenerationsParameter.ActualName = MaximumGenerationsParameter.Name;
296      mainLoop.OffspringSelectionBeforeMutationParameter.ActualName = OffspringSelectionBeforeMutationParameter.Name;
297      mainLoop.Successor = null;
298
299      Initialize();
300    }
301
302    public override IDeepCloneable Clone(Cloner cloner) {
303      SASEGASA clone = (SASEGASA)base.Clone(cloner);
304      clone.Initialize();
305      return clone;
306    }
307
308    public override void Prepare() {
309      if (Problem != null) base.Prepare();
310    }
311
312    #region Events
313    protected override void OnProblemChanged() {
314      ParameterizeStochasticOperator(Problem.SolutionCreator);
315      ParameterizeStochasticOperator(Problem.Evaluator);
316      foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
317      ParameterizeSolutionsCreator();
318      ParameterizeMainLoop();
319      ParameterizeSelectors();
320      ParameterizeAnalyzers();
321      UpdateCrossovers();
322      UpdateMutators();
323      UpdateAnalyzers();
324      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
325      base.OnProblemChanged();
326    }
327
328    protected override void Problem_SolutionCreatorChanged(object sender, EventArgs e) {
329      ParameterizeStochasticOperator(Problem.SolutionCreator);
330      ParameterizeSolutionsCreator();
331      base.Problem_SolutionCreatorChanged(sender, e);
332    }
333    protected override void Problem_EvaluatorChanged(object sender, EventArgs e) {
334      ParameterizeStochasticOperator(Problem.Evaluator);
335      ParameterizeSolutionsCreator();
336      ParameterizeMainLoop();
337      ParameterizeSelectors();
338      ParameterizeAnalyzers();
339      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
340      base.Problem_EvaluatorChanged(sender, e);
341    }
342    protected override void Problem_OperatorsChanged(object sender, EventArgs e) {
343      foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
344      UpdateCrossovers();
345      UpdateMutators();
346      UpdateAnalyzers();
347      base.Problem_OperatorsChanged(sender, e);
348    }
349    private void ElitesParameter_ValueChanged(object sender, EventArgs e) {
350      Elites.ValueChanged += new EventHandler(Elites_ValueChanged);
351      ParameterizeSelectors();
352    }
353    private void Elites_ValueChanged(object sender, EventArgs e) {
354      ParameterizeSelectors();
355    }
356    private void PopulationSizeParameter_ValueChanged(object sender, EventArgs e) {
357      NumberOfVillages.ValueChanged += new EventHandler(PopulationSize_ValueChanged);
358      ParameterizeSelectors();
359    }
360    private void PopulationSize_ValueChanged(object sender, EventArgs e) {
361      ParameterizeSelectors();
362    }
363    private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
364      ParameterizeMainLoop();
365      ParameterizeSelectors();
366      ParameterizeAnalyzers();
367    }
368    private void MaximumGenerationsParameter_ValueChanged(object sender, EventArgs e) {
369      MaximumGenerations.ValueChanged += new EventHandler(MaximumGenerations_ValueChanged);
370      MaximumGenerations_ValueChanged(sender, e);
371    }
372    private void MaximumGenerations_ValueChanged(object sender, EventArgs e) {
373      if (MaximumGenerations.Value < NumberOfVillages.Value) NumberOfVillages.Value = MaximumGenerations.Value;
374      ParameterizeMainLoop();
375    }
376    private void NumberOfVillagesParameter_ValueChanged(object sender, EventArgs e) {
377      NumberOfVillages.ValueChanged += new EventHandler(NumberOfVillages_ValueChanged);
378      NumberOfVillages_ValueChanged(sender, e);
379    }
380    private void NumberOfVillages_ValueChanged(object sender, EventArgs e) {
381      if (NumberOfVillages.Value > MaximumGenerations.Value) MaximumGenerations.Value = NumberOfVillages.Value;
382      ParameterizeComparisonFactorModifiers();
383      ParameterizeMainLoop();
384    }
385    #endregion
386
387    #region Helpers
388    [StorableHook(HookType.AfterDeserialization)]
389    private void Initialize() {
390      InitializeSelectors();
391      InitializeAnalyzers();
392      UpdateSelectors();
393      UpdateAnalyzers();
394      InitializeComparisonFactorModifiers();
395      UpdateComparisonFactorModifiers();
396      NumberOfVillagesParameter.ValueChanged += new EventHandler(NumberOfVillagesParameter_ValueChanged);
397      NumberOfVillages.ValueChanged += new EventHandler(NumberOfVillages_ValueChanged);
398      PopulationSizeParameter.ValueChanged += new EventHandler(PopulationSizeParameter_ValueChanged);
399      PopulationSize.ValueChanged += new EventHandler(PopulationSize_ValueChanged);
400      ElitesParameter.ValueChanged += new EventHandler(ElitesParameter_ValueChanged);
401      Elites.ValueChanged += new EventHandler(Elites_ValueChanged);
402      MaximumGenerationsParameter.ValueChanged += new EventHandler(MaximumGenerationsParameter_ValueChanged);
403      MaximumGenerations.ValueChanged += new EventHandler(MaximumGenerations_ValueChanged);
404      if (Problem != null) {
405        UpdateCrossovers();
406        UpdateMutators();
407        Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
408      }
409    }
410    private void ParameterizeSolutionsCreator() {
411      SolutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
412      SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name;
413    }
414    private void ParameterizeMainLoop() {
415      MainLoop.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
416      MainLoop.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
417      MainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
418      MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
419      MainLoop.MigrationIntervalParameter.Value = new IntValue(MaximumGenerations.Value / NumberOfVillages.Value);
420    }
421    private void ParameterizeStochasticOperator(IOperator op) {
422      if (op is IStochasticOperator)
423        ((IStochasticOperator)op).RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
424    }
425    private void InitializeSelectors() {
426      selectors = new List<ISelector>();
427      selectors.AddRange(ApplicationManager.Manager.GetInstances<ISelector>().Where(x => !(x is IMultiObjectiveSelector)).OrderBy(x => x.Name));
428      ParameterizeSelectors();
429    }
430    private void InitializeAnalyzers() {
431      villageQualityAnalyzer = new BestAverageWorstQualityAnalyzer();
432      //qualityAnalyzer = new MultipopulationBestAverageWorstQualityAnalyzer();
433      ParameterizeAnalyzers();
434    }
435    private void InitializeComparisonFactorModifiers() {
436      comparisonFactorModifiers = new List<IDiscreteDoubleValueModifier>();
437      comparisonFactorModifiers.AddRange(ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>().OrderBy(x => x.Name));
438      ParameterizeComparisonFactorModifiers();
439    }
440    private void ParameterizeSelectors() {
441      foreach (ISelector selector in Selectors) {
442        selector.CopySelected = new BoolValue(true);
443        selector.NumberOfSelectedSubScopesParameter.Value = null;
444        selector.NumberOfSelectedSubScopesParameter.ActualName = SelectedParentsParameter.Name;
445        ParameterizeStochasticOperator(selector);
446      }
447      if (Problem != null) {
448        foreach (ISingleObjectiveSelector selector in Selectors.OfType<ISingleObjectiveSelector>()) {
449          selector.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
450          selector.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
451        }
452      }
453    }
454    private void ParameterizeAnalyzers() {
455      villageQualityAnalyzer.ResultsParameter.ActualName = "Results";
456      //qualityAnalyzer.ResultsParameter.ActualName = "Results";
457      if (Problem != null) {
458        villageQualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
459        villageQualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
460        villageQualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
461      }
462    }
463    private void ParameterizeComparisonFactorModifiers() {
464      foreach (IDiscreteDoubleValueModifier modifier in comparisonFactorModifiers) {
465        modifier.IndexParameter.ActualName = "Reunifications";
466        modifier.StartIndexParameter.Value = new IntValue(0);
467        modifier.StartValueParameter.ActualName = ComparisonFactorLowerBoundParameter.Name;
468        modifier.EndIndexParameter.Value = new IntValue(NumberOfVillages.Value - 1);
469        modifier.EndValueParameter.ActualName = ComparisonFactorUpperBoundParameter.Name;
470        modifier.ValueParameter.ActualName = "ComparisonFactor";
471      }
472    }
473    private void UpdateSelectors() {
474      ISelector oldSelector = SelectorParameter.Value;
475      SelectorParameter.ValidValues.Clear();
476      foreach (ISelector selector in Selectors.OrderBy(x => x.Name))
477        SelectorParameter.ValidValues.Add(selector);
478
479      ISelector proportionalSelector = SelectorParameter.ValidValues.FirstOrDefault(x => x.GetType().Name.Equals("ProportionalSelector"));
480      if (proportionalSelector != null) SelectorParameter.Value = proportionalSelector;
481
482      if (oldSelector != null) {
483        ISelector selector = SelectorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldSelector.GetType());
484        if (selector != null) SelectorParameter.Value = selector;
485      }
486    }
487    private void UpdateComparisonFactorModifiers() {
488      IDiscreteDoubleValueModifier oldModifier = ComparisonFactorModifier;
489
490      ComparisonFactorModifierParameter.ValidValues.Clear();
491      foreach (IDiscreteDoubleValueModifier modifier in comparisonFactorModifiers)
492        ComparisonFactorModifierParameter.ValidValues.Add(modifier);
493
494      if (oldModifier != null) {
495        IDiscreteDoubleValueModifier mod = ComparisonFactorModifierParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldModifier.GetType());
496        if (mod != null) ComparisonFactorModifierParameter.Value = mod;
497      }
498    }
499    private void UpdateCrossovers() {
500      ICrossover oldCrossover = CrossoverParameter.Value;
501      CrossoverParameter.ValidValues.Clear();
502      foreach (ICrossover crossover in Problem.Operators.OfType<ICrossover>().OrderBy(x => x.Name))
503        CrossoverParameter.ValidValues.Add(crossover);
504      if (oldCrossover != null) {
505        ICrossover crossover = CrossoverParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldCrossover.GetType());
506        if (crossover != null) CrossoverParameter.Value = crossover;
507      }
508    }
509    private void UpdateMutators() {
510      IManipulator oldMutator = MutatorParameter.Value;
511      MutatorParameter.ValidValues.Clear();
512      foreach (IManipulator mutator in Problem.Operators.OfType<IManipulator>().OrderBy(x => x.Name))
513        MutatorParameter.ValidValues.Add(mutator);
514      if (oldMutator != null) {
515        IManipulator mutator = MutatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMutator.GetType());
516        if (mutator != null) MutatorParameter.Value = mutator;
517      }
518    }
519    private void UpdateAnalyzers() {
520      VillageAnalyzer.Operators.Clear();
521      Analyzer.Operators.Clear();
522      VillageAnalyzer.Operators.Add(villageQualityAnalyzer);
523      //Analyzer.Operators.Add(qualityAnalyzer);
524      if (Problem != null) {
525        foreach (IAnalyzer analyzer in Problem.Operators.OfType<IAnalyzer>().OrderBy(x => x.Name)) {
526          VillageAnalyzer.Operators.Add(analyzer);
527        }
528        foreach (IAnalyzer analyzer in Problem.Operators.OfType<IAnalyzer>().OrderBy(x => x.Name))
529          Analyzer.Operators.Add(analyzer);
530      }
531    }
532    #endregion
533  }
534}
Note: See TracBrowser for help on using the repository browser.