Free cookie consent management tool by TermsFeed Policy Generator

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

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

Sorted usings and removed unused usings in entire solution (#1094)

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