Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ParameterBinding/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3/SASEGASA.cs @ 8418

Last change on this file since 8418 was 4722, checked in by swagner, 14 years ago

Merged cloning refactoring branch back into trunk (#922)

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