Free cookie consent management tool by TermsFeed Policy Generator

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

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

Implemented !IStorableContent separately for each algorithm (#1193)

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    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 ValueLookupParameter<DoubleValue>("SuccessRatio", "The ratio of successful to total children that should be achieved.", new DoubleValue(1)));
244      Parameters.Add(new ValueLookupParameter<DoubleValue>("ComparisonFactorLowerBound", "The lower bound of the comparison factor (start).", new DoubleValue(0.3)));
245      Parameters.Add(new ValueLookupParameter<DoubleValue>("ComparisonFactorUpperBound", "The upper bound of the comparison factor (end).", new DoubleValue(0.7)));
246      Parameters.Add(new OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier>("ComparisonFactorModifier", "The operator used to modify the comparison factor.", new ItemSet<IDiscreteDoubleValueModifier>(new IDiscreteDoubleValueModifier[] { new LinearDiscreteDoubleValueModifier() }), new LinearDiscreteDoubleValueModifier()));
247      Parameters.Add(new ValueLookupParameter<DoubleValue>("MaximumSelectionPressure", "The maximum selection pressure that terminates the algorithm.", new DoubleValue(100)));
248      Parameters.Add(new ValueLookupParameter<DoubleValue>("FinalMaximumSelectionPressure", "The maximum selection pressure used when there is only one village left.", new DoubleValue(100)));
249      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)));
250      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)));
251      Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze the villages.", new MultiAnalyzer()));
252      Parameters.Add(new ValueParameter<MultiAnalyzer>("VillageAnalyzer", "The operator used to analyze each village.", new MultiAnalyzer()));
253      Parameters.Add(new ValueParameter<IntValue>("MaximumEvaluatedSolutions", "The maximum number of evaluated solutions (approximately).", new IntValue(int.MaxValue)));
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.Operator = solutionsCreator;
273      ussp1.Successor = mainLoop;
274
275      solutionsCreator.NumberOfSolutionsParameter.ActualName = PopulationSizeParameter.Name;
276      solutionsCreator.Successor = null;
277
278      mainLoop.NumberOfVillagesParameter.ActualName = NumberOfVillagesParameter.Name;
279      mainLoop.SelectorParameter.ActualName = SelectorParameter.Name;
280      mainLoop.CrossoverParameter.ActualName = CrossoverParameter.Name;
281      mainLoop.ElitesParameter.ActualName = ElitesParameter.Name;
282      mainLoop.MutatorParameter.ActualName = MutatorParameter.Name;
283      mainLoop.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
284      mainLoop.RandomParameter.ActualName = randomCreator.RandomParameter.ActualName;
285      mainLoop.ResultsParameter.ActualName = "Results";
286      mainLoop.SuccessRatioParameter.ActualName = SuccessRatioParameter.Name;
287      mainLoop.ComparisonFactorStartParameter.ActualName = ComparisonFactorLowerBoundParameter.Name;
288      mainLoop.ComparisonFactorModifierParameter.ActualName = ComparisonFactorModifierParameter.Name;
289      mainLoop.MaximumSelectionPressureParameter.ActualName = MaximumSelectionPressureParameter.Name;
290      mainLoop.FinalMaximumSelectionPressureParameter.ActualName = FinalMaximumSelectionPressureParameter.Name;
291      mainLoop.MaximumGenerationsParameter.ActualName = MaximumGenerationsParameter.Name;
292      mainLoop.OffspringSelectionBeforeMutationParameter.ActualName = OffspringSelectionBeforeMutationParameter.Name;
293      mainLoop.Successor = null;
294
295      foreach (ISelector selector in ApplicationManager.Manager.GetInstances<ISelector>().Where(x => !(x is IMultiObjectiveSelector)).OrderBy(x => x.Name))
296        SelectorParameter.ValidValues.Add(selector);
297      ISelector proportionalSelector = SelectorParameter.ValidValues.FirstOrDefault(x => x.GetType().Name.Equals("ProportionalSelector"));
298      if (proportionalSelector != null) SelectorParameter.Value = proportionalSelector;
299
300      ParameterizeSelectors();
301
302      foreach (IDiscreteDoubleValueModifier modifier in ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>().OrderBy(x => x.Name))
303        ComparisonFactorModifierParameter.ValidValues.Add(modifier);
304      IDiscreteDoubleValueModifier linearModifier = ComparisonFactorModifierParameter.ValidValues.FirstOrDefault(x => x.GetType().Name.Equals("LinearDiscreteDoubleValueModifier"));
305      if (linearModifier != null) ComparisonFactorModifierParameter.Value = linearModifier;
306      ParameterizeComparisonFactorModifiers();
307
308      qualityAnalyzer = new BestAverageWorstQualityAnalyzer();
309      villageQualityAnalyzer = new BestAverageWorstQualityAnalyzer();
310      selectionPressureAnalyzer = new ValueAnalyzer();
311      villageSelectionPressureAnalyzer = new ValueAnalyzer();
312      ParameterizeAnalyzers();
313      UpdateAnalyzers();
314
315      Initialize();
316    }
317
318    public override IDeepCloneable Clone(Cloner cloner) {
319      SASEGASA clone = (SASEGASA)base.Clone(cloner);
320      clone.qualityAnalyzer = (BestAverageWorstQualityAnalyzer)cloner.Clone(qualityAnalyzer);
321      clone.villageQualityAnalyzer = (BestAverageWorstQualityAnalyzer)cloner.Clone(villageQualityAnalyzer);
322      clone.selectionPressureAnalyzer = (ValueAnalyzer)cloner.Clone(selectionPressureAnalyzer);
323      clone.villageSelectionPressureAnalyzer = (ValueAnalyzer)cloner.Clone(villageSelectionPressureAnalyzer);
324      clone.Initialize();
325      return clone;
326    }
327
328    public override void Prepare() {
329      if (Problem != null) base.Prepare();
330    }
331
332    #region Events
333    protected override void OnProblemChanged() {
334      ParameterizeStochasticOperator(Problem.SolutionCreator);
335      ParameterizeStochasticOperator(Problem.Evaluator);
336      foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
337      ParameterizeSolutionsCreator();
338      ParameterizeMainLoop();
339      ParameterizeSelectors();
340      ParameterizeAnalyzers();
341      ParameterizeIterationBasedOperators();
342      UpdateCrossovers();
343      UpdateMutators();
344      UpdateAnalyzers();
345      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
346      base.OnProblemChanged();
347    }
348
349    protected override void Problem_SolutionCreatorChanged(object sender, EventArgs e) {
350      ParameterizeStochasticOperator(Problem.SolutionCreator);
351      ParameterizeSolutionsCreator();
352      base.Problem_SolutionCreatorChanged(sender, e);
353    }
354    protected override void Problem_EvaluatorChanged(object sender, EventArgs e) {
355      ParameterizeStochasticOperator(Problem.Evaluator);
356      ParameterizeSolutionsCreator();
357      ParameterizeMainLoop();
358      ParameterizeSelectors();
359      ParameterizeAnalyzers();
360      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
361      base.Problem_EvaluatorChanged(sender, e);
362    }
363    protected override void Problem_OperatorsChanged(object sender, EventArgs e) {
364      foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
365      ParameterizeIterationBasedOperators();
366      UpdateCrossovers();
367      UpdateMutators();
368      UpdateAnalyzers();
369      base.Problem_OperatorsChanged(sender, e);
370    }
371    private void ElitesParameter_ValueChanged(object sender, EventArgs e) {
372      Elites.ValueChanged += new EventHandler(Elites_ValueChanged);
373      ParameterizeSelectors();
374    }
375    private void Elites_ValueChanged(object sender, EventArgs e) {
376      ParameterizeSelectors();
377    }
378    private void PopulationSizeParameter_ValueChanged(object sender, EventArgs e) {
379      NumberOfVillages.ValueChanged += new EventHandler(PopulationSize_ValueChanged);
380      ParameterizeSelectors();
381    }
382    private void PopulationSize_ValueChanged(object sender, EventArgs e) {
383      ParameterizeSelectors();
384    }
385    private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
386      ParameterizeMainLoop();
387      ParameterizeSelectors();
388      ParameterizeAnalyzers();
389    }
390    private void MaximumGenerationsParameter_ValueChanged(object sender, EventArgs e) {
391      MaximumGenerations.ValueChanged += new EventHandler(MaximumGenerations_ValueChanged);
392      MaximumGenerations_ValueChanged(sender, e);
393    }
394    private void MaximumGenerations_ValueChanged(object sender, EventArgs e) {
395      if (MaximumGenerations.Value < NumberOfVillages.Value) NumberOfVillages.Value = MaximumGenerations.Value;
396      ParameterizeMainLoop();
397    }
398    private void NumberOfVillagesParameter_ValueChanged(object sender, EventArgs e) {
399      NumberOfVillages.ValueChanged += new EventHandler(NumberOfVillages_ValueChanged);
400      NumberOfVillages_ValueChanged(sender, e);
401    }
402    private void NumberOfVillages_ValueChanged(object sender, EventArgs e) {
403      if (NumberOfVillages.Value > MaximumGenerations.Value) MaximumGenerations.Value = NumberOfVillages.Value;
404      ParameterizeComparisonFactorModifiers();
405      ParameterizeMainLoop();
406    }
407    #endregion
408
409    #region Helpers
410    [StorableHook(HookType.AfterDeserialization)]
411    private void Initialize() {
412      NumberOfVillagesParameter.ValueChanged += new EventHandler(NumberOfVillagesParameter_ValueChanged);
413      NumberOfVillages.ValueChanged += new EventHandler(NumberOfVillages_ValueChanged);
414      PopulationSizeParameter.ValueChanged += new EventHandler(PopulationSizeParameter_ValueChanged);
415      PopulationSize.ValueChanged += new EventHandler(PopulationSize_ValueChanged);
416      ElitesParameter.ValueChanged += new EventHandler(ElitesParameter_ValueChanged);
417      Elites.ValueChanged += new EventHandler(Elites_ValueChanged);
418      MaximumGenerationsParameter.ValueChanged += new EventHandler(MaximumGenerationsParameter_ValueChanged);
419      MaximumGenerations.ValueChanged += new EventHandler(MaximumGenerations_ValueChanged);
420      if (Problem != null) {
421        Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
422      }
423    }
424    private void ParameterizeSolutionsCreator() {
425      SolutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
426      SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name;
427    }
428    private void ParameterizeMainLoop() {
429      MainLoop.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
430      MainLoop.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
431      MainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
432      MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
433      MainLoop.MigrationIntervalParameter.Value = new IntValue(MaximumGenerations.Value / NumberOfVillages.Value);
434    }
435    private void ParameterizeStochasticOperator(IOperator op) {
436      if (op is IStochasticOperator)
437        ((IStochasticOperator)op).RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
438    }
439    private void ParameterizeSelectors() {
440      foreach (ISelector selector in SelectorParameter.ValidValues) {
441        selector.CopySelected = new BoolValue(true);
442        selector.NumberOfSelectedSubScopesParameter.Value = null;
443        selector.NumberOfSelectedSubScopesParameter.ActualName = SelectedParentsParameter.Name;
444        ParameterizeStochasticOperator(selector);
445      }
446      if (Problem != null) {
447        foreach (ISingleObjectiveSelector selector in SelectorParameter.ValidValues.OfType<ISingleObjectiveSelector>()) {
448          selector.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
449          selector.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
450        }
451      }
452    }
453    private void ParameterizeAnalyzers() {
454      villageQualityAnalyzer.ResultsParameter.ActualName = "Results";
455      villageQualityAnalyzer.QualityParameter.Depth = 1;
456      qualityAnalyzer.ResultsParameter.ActualName = "Results";
457      qualityAnalyzer.QualityParameter.Depth = 2;
458
459      villageSelectionPressureAnalyzer.ResultsParameter.ActualName = "Results";
460      villageSelectionPressureAnalyzer.Name = "SelectionPressure Analyzer";
461      villageSelectionPressureAnalyzer.ValueParameter.Depth = 0;
462      villageSelectionPressureAnalyzer.ValueParameter.ActualName = "SelectionPressure";
463      villageSelectionPressureAnalyzer.ValuesParameter.ActualName = "Selection Pressure History";
464
465      selectionPressureAnalyzer.ResultsParameter.ActualName = "Results";
466      selectionPressureAnalyzer.Name = "SelectionPressure Analyzer";
467      selectionPressureAnalyzer.ValueParameter.Depth = 1;
468      selectionPressureAnalyzer.ValueParameter.ActualName = "SelectionPressure";
469      selectionPressureAnalyzer.ValuesParameter.ActualName = "Selection Pressure History";
470
471      if (Problem != null) {
472        villageQualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
473        villageQualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
474        villageQualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
475
476        qualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
477        qualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
478        qualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
479      }
480    }
481    private void ParameterizeComparisonFactorModifiers() {
482      foreach (IDiscreteDoubleValueModifier modifier in ComparisonFactorModifierParameter.ValidValues) {
483        modifier.IndexParameter.ActualName = "Reunifications";
484        modifier.StartIndexParameter.Value = new IntValue(0);
485        modifier.StartValueParameter.ActualName = ComparisonFactorLowerBoundParameter.Name;
486        modifier.EndIndexParameter.Value = new IntValue(NumberOfVillages.Value - 1);
487        modifier.EndValueParameter.ActualName = ComparisonFactorUpperBoundParameter.Name;
488        modifier.ValueParameter.ActualName = "ComparisonFactor";
489      }
490    }
491    private void ParameterizeIterationBasedOperators() {
492      if (Problem != null) {
493        foreach (IIterationBasedOperator op in Problem.Operators.OfType<IIterationBasedOperator>()) {
494          op.IterationsParameter.ActualName = "Generations";
495          op.MaximumIterationsParameter.ActualName = MaximumGenerationsParameter.Name;
496        }
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      VillageAnalyzer.Operators.Add(villageSelectionPressureAnalyzer);
524      if (Problem != null) {
525        foreach (IAnalyzer analyzer in Problem.Operators.OfType<IAnalyzer>()) {
526          foreach (IScopeTreeLookupParameter param in analyzer.Parameters.OfType<IScopeTreeLookupParameter>())
527            param.Depth = 2;
528          Analyzer.Operators.Add(analyzer);
529        }
530      }
531      Analyzer.Operators.Add(qualityAnalyzer);
532      Analyzer.Operators.Add(selectionPressureAnalyzer);
533    }
534    #endregion
535  }
536}
Note: See TracBrowser for help on using the repository browser.