Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3/IslandOffspringSelectionGeneticAlgorithm.cs @ 3704

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

#839

  • removed parallel parameter from multipopulation algorithms
File size: 31.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using HeuristicLab.Analysis;
26using HeuristicLab.Common;
27using HeuristicLab.Core;
28using HeuristicLab.Data;
29using HeuristicLab.Operators;
30using HeuristicLab.Optimization;
31using HeuristicLab.Optimization.Operators;
32using HeuristicLab.Parameters;
33using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
34using HeuristicLab.PluginInfrastructure;
35using HeuristicLab.Random;
36
37namespace HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm {
38  /// <summary>
39  /// An offspring selection island genetic algorithm.
40  /// </summary>
41  [Item("Island Offspring Selection Genetic Algorithm", "An island offspring selection genetic algorithm.")]
42  [Creatable("Algorithms")]
43  [StorableClass]
44  public sealed class IslandOffspringSelectionGeneticAlgorithm : EngineAlgorithm {
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> NumberOfIslandsParameter {
64      get { return (ValueParameter<IntValue>)Parameters["NumberOfIslands"]; }
65    }
66    private ValueParameter<IntValue> MigrationIntervalParameter {
67      get { return (ValueParameter<IntValue>)Parameters["MigrationInterval"]; }
68    }
69    private ValueParameter<PercentValue> MigrationRateParameter {
70      get { return (ValueParameter<PercentValue>)Parameters["MigrationRate"]; }
71    }
72    private ConstrainedValueParameter<IMigrator> MigratorParameter {
73      get { return (ConstrainedValueParameter<IMigrator>)Parameters["Migrator"]; }
74    }
75    private ConstrainedValueParameter<ISelector> EmigrantsSelectorParameter {
76      get { return (ConstrainedValueParameter<ISelector>)Parameters["EmigrantsSelector"]; }
77    }
78    private ConstrainedValueParameter<IReplacer> ImmigrationReplacerParameter {
79      get { return (ConstrainedValueParameter<IReplacer>)Parameters["ImmigrationReplacer"]; }
80    }
81    private ValueParameter<IntValue> PopulationSizeParameter {
82      get { return (ValueParameter<IntValue>)Parameters["PopulationSize"]; }
83    }
84    private ValueParameter<IntValue> MaximumGenerationsParameter {
85      get { return (ValueParameter<IntValue>)Parameters["MaximumGenerations"]; }
86    }
87    private ConstrainedValueParameter<ISelector> SelectorParameter {
88      get { return (ConstrainedValueParameter<ISelector>)Parameters["Selector"]; }
89    }
90    private ConstrainedValueParameter<ICrossover> CrossoverParameter {
91      get { return (ConstrainedValueParameter<ICrossover>)Parameters["Crossover"]; }
92    }
93    private ValueParameter<PercentValue> MutationProbabilityParameter {
94      get { return (ValueParameter<PercentValue>)Parameters["MutationProbability"]; }
95    }
96    private OptionalConstrainedValueParameter<IManipulator> MutatorParameter {
97      get { return (OptionalConstrainedValueParameter<IManipulator>)Parameters["Mutator"]; }
98    }
99    private ValueParameter<IntValue> ElitesParameter {
100      get { return (ValueParameter<IntValue>)Parameters["Elites"]; }
101    }
102    private ValueLookupParameter<DoubleValue> SuccessRatioParameter {
103      get { return (ValueLookupParameter<DoubleValue>)Parameters["SuccessRatio"]; }
104    }
105    private ValueLookupParameter<DoubleValue> ComparisonFactorLowerBoundParameter {
106      get { return (ValueLookupParameter<DoubleValue>)Parameters["ComparisonFactorLowerBound"]; }
107    }
108    private ValueLookupParameter<DoubleValue> ComparisonFactorUpperBoundParameter {
109      get { return (ValueLookupParameter<DoubleValue>)Parameters["ComparisonFactorUpperBound"]; }
110    }
111    private OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier> ComparisonFactorModifierParameter {
112      get { return (OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier>)Parameters["ComparisonFactorModifier"]; }
113    }
114    private ValueLookupParameter<DoubleValue> MaximumSelectionPressureParameter {
115      get { return (ValueLookupParameter<DoubleValue>)Parameters["MaximumSelectionPressure"]; }
116    }
117    private ValueLookupParameter<BoolValue> OffspringSelectionBeforeMutationParameter {
118      get { return (ValueLookupParameter<BoolValue>)Parameters["OffspringSelectionBeforeMutation"]; }
119    }
120    private ValueLookupParameter<IntValue> SelectedParentsParameter {
121      get { return (ValueLookupParameter<IntValue>)Parameters["SelectedParents"]; }
122    }
123    private ValueParameter<MultiAnalyzer> AnalyzerParameter {
124      get { return (ValueParameter<MultiAnalyzer>)Parameters["Analyzer"]; }
125    }
126    private ValueParameter<MultiAnalyzer> IslandAnalyzerParameter {
127      get { return (ValueParameter<MultiAnalyzer>)Parameters["IslandAnalyzer"]; }
128    }
129    #endregion
130
131    #region Properties
132    public IntValue Seed {
133      get { return SeedParameter.Value; }
134      set { SeedParameter.Value = value; }
135    }
136    public BoolValue SetSeedRandomly {
137      get { return SetSeedRandomlyParameter.Value; }
138      set { SetSeedRandomlyParameter.Value = value; }
139    }
140    public IntValue NumberOfIslands {
141      get { return NumberOfIslandsParameter.Value; }
142      set { NumberOfIslandsParameter.Value = value; }
143    }
144    public IntValue MigrationInterval {
145      get { return MigrationIntervalParameter.Value; }
146      set { MigrationIntervalParameter.Value = value; }
147    }
148    public PercentValue MigrationRate {
149      get { return MigrationRateParameter.Value; }
150      set { MigrationRateParameter.Value = value; }
151    }
152    public IMigrator Migrator {
153      get { return MigratorParameter.Value; }
154      set { MigratorParameter.Value = value; }
155    }
156    public ISelector EmigrantsSelector {
157      get { return EmigrantsSelectorParameter.Value; }
158      set { EmigrantsSelectorParameter.Value = value; }
159    }
160    public IReplacer ImmigrationReplacer {
161      get { return ImmigrationReplacerParameter.Value; }
162      set { ImmigrationReplacerParameter.Value = value; }
163    }
164    public IntValue PopulationSize {
165      get { return PopulationSizeParameter.Value; }
166      set { PopulationSizeParameter.Value = value; }
167    }
168    public IntValue MaximumGenerations {
169      get { return MaximumGenerationsParameter.Value; }
170      set { MaximumGenerationsParameter.Value = value; }
171    }
172    public ISelector Selector {
173      get { return SelectorParameter.Value; }
174      set { SelectorParameter.Value = value; }
175    }
176    public ICrossover Crossover {
177      get { return CrossoverParameter.Value; }
178      set { CrossoverParameter.Value = value; }
179    }
180    public PercentValue MutationProbability {
181      get { return MutationProbabilityParameter.Value; }
182      set { MutationProbabilityParameter.Value = value; }
183    }
184    public IManipulator Mutator {
185      get { return MutatorParameter.Value; }
186      set { MutatorParameter.Value = value; }
187    }
188    public IntValue Elites {
189      get { return ElitesParameter.Value; }
190      set { ElitesParameter.Value = value; }
191    }
192    private DoubleValue SuccessRatio {
193      get { return SuccessRatioParameter.Value; }
194      set { SuccessRatioParameter.Value = value; }
195    }
196    private DoubleValue ComparisonFactorLowerBound {
197      get { return ComparisonFactorLowerBoundParameter.Value; }
198      set { ComparisonFactorLowerBoundParameter.Value = value; }
199    }
200    private DoubleValue ComparisonFactorUpperBound {
201      get { return ComparisonFactorUpperBoundParameter.Value; }
202      set { ComparisonFactorUpperBoundParameter.Value = value; }
203    }
204    private IDiscreteDoubleValueModifier ComparisonFactorModifier {
205      get { return ComparisonFactorModifierParameter.Value; }
206      set { ComparisonFactorModifierParameter.Value = value; }
207    }
208    private DoubleValue MaximumSelectionPressure {
209      get { return MaximumSelectionPressureParameter.Value; }
210      set { MaximumSelectionPressureParameter.Value = value; }
211    }
212    private BoolValue OffspringSelectionBeforeMutation {
213      get { return OffspringSelectionBeforeMutationParameter.Value; }
214      set { OffspringSelectionBeforeMutationParameter.Value = value; }
215    }
216    public MultiAnalyzer Analyzer {
217      get { return AnalyzerParameter.Value; }
218      set { AnalyzerParameter.Value = value; }
219    }
220    public MultiAnalyzer IslandAnalyzer {
221      get { return IslandAnalyzerParameter.Value; }
222      set { IslandAnalyzerParameter.Value = value; }
223    }
224    private RandomCreator RandomCreator {
225      get { return (RandomCreator)OperatorGraph.InitialOperator; }
226    }
227    private UniformSubScopesProcessor IslandProcessor {
228      get { return ((RandomCreator.Successor as SubScopesCreator).Successor as UniformSubScopesProcessor); }
229    }
230    private SolutionsCreator SolutionsCreator {
231      get { return (SolutionsCreator)IslandProcessor.Operator; }
232    }
233    private IslandOffspringSelectionGeneticAlgorithmMainLoop MainLoop {
234      get { return (IslandOffspringSelectionGeneticAlgorithmMainLoop)IslandProcessor.Successor; }
235    }
236    [Storable]
237    private BestAverageWorstQualityAnalyzer islandQualityAnalyzer;
238    [Storable]
239    private BestAverageWorstQualityAnalyzer qualityAnalyzer;
240    [Storable]
241    private ValueAnalyzer islandSelectionPressureAnalyzer;
242    [Storable]
243    private ValueAnalyzer selectionPressureAnalyzer;
244    #endregion
245
246    [StorableConstructor]
247    private IslandOffspringSelectionGeneticAlgorithm(bool deserializing) : base(deserializing) { }
248    public IslandOffspringSelectionGeneticAlgorithm()
249      : base() {
250      Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
251      Parameters.Add(new ValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
252      Parameters.Add(new ValueParameter<IntValue>("NumberOfIslands", "The number of islands.", new IntValue(5)));
253      Parameters.Add(new ValueParameter<IntValue>("MigrationInterval", "The number of generations that should pass between migration phases.", new IntValue(20)));
254      Parameters.Add(new ValueParameter<PercentValue>("MigrationRate", "The proportion of individuals that should migrate between the islands.", new PercentValue(0.15)));
255      Parameters.Add(new ConstrainedValueParameter<IMigrator>("Migrator", "The migration strategy."));
256      Parameters.Add(new ConstrainedValueParameter<ISelector>("EmigrantsSelector", "Selects the individuals that will be migrated."));
257      Parameters.Add(new ConstrainedValueParameter<IReplacer>("ImmigrationReplacer", "Replaces part of the original population with the immigrants."));
258      Parameters.Add(new ValueParameter<IntValue>("PopulationSize", "The size of the population of solutions of each island.", new IntValue(100)));
259      Parameters.Add(new ValueParameter<IntValue>("MaximumGenerations", "The maximum number of generations that should be processed.", new IntValue(100)));
260      Parameters.Add(new ConstrainedValueParameter<ISelector>("Selector", "The operator used to select solutions for reproduction."));
261      Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions."));
262      Parameters.Add(new ValueParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution.", new PercentValue(0.05)));
263      Parameters.Add(new OptionalConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions."));
264      Parameters.Add(new ValueParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.", new IntValue(1)));
265      Parameters.Add(new ValueLookupParameter<DoubleValue>("SuccessRatio", "The ratio of successful to total children that should be achieved.", new DoubleValue(1)));
266      Parameters.Add(new ValueLookupParameter<DoubleValue>("ComparisonFactorLowerBound", "The lower bound of the comparison factor (start).", new DoubleValue(0)));
267      Parameters.Add(new ValueLookupParameter<DoubleValue>("ComparisonFactorUpperBound", "The upper bound of the comparison factor (end).", new DoubleValue(1)));
268      Parameters.Add(new OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier>("ComparisonFactorModifier", "The operator used to modify the comparison factor.", new ItemSet<IDiscreteDoubleValueModifier>(new IDiscreteDoubleValueModifier[] { new LinearDiscreteDoubleValueModifier() }), new LinearDiscreteDoubleValueModifier()));
269      Parameters.Add(new ValueLookupParameter<DoubleValue>("MaximumSelectionPressure", "The maximum selection pressure that terminates the algorithm.", new DoubleValue(100)));
270      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)));
271      Parameters.Add(new ValueLookupParameter<IntValue>("SelectedParents", "Should be about 2 * PopulationSize, for large problems use a smaller value to decrease memory footprint.", new IntValue(200)));
272      Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze the islands.", new MultiAnalyzer()));
273      Parameters.Add(new ValueParameter<MultiAnalyzer>("IslandAnalyzer", "The operator used to analyze each island.", new MultiAnalyzer()));
274     
275      RandomCreator randomCreator = new RandomCreator();
276      SubScopesCreator populationCreator = new SubScopesCreator();
277      UniformSubScopesProcessor ussp1 = new UniformSubScopesProcessor();
278      SolutionsCreator solutionsCreator = new SolutionsCreator();
279      IslandOffspringSelectionGeneticAlgorithmMainLoop mainLoop = new IslandOffspringSelectionGeneticAlgorithmMainLoop();
280      OperatorGraph.InitialOperator = randomCreator;
281
282      randomCreator.RandomParameter.ActualName = "Random";
283      randomCreator.SeedParameter.ActualName = SeedParameter.Name;
284      randomCreator.SeedParameter.Value = null;
285      randomCreator.SetSeedRandomlyParameter.ActualName = SetSeedRandomlyParameter.Name;
286      randomCreator.SetSeedRandomlyParameter.Value = null;
287      randomCreator.Successor = populationCreator;
288
289      populationCreator.NumberOfSubScopesParameter.ActualName = NumberOfIslandsParameter.Name;
290      populationCreator.Successor = ussp1;
291
292      ussp1.Operator = solutionsCreator;
293      ussp1.Successor = mainLoop;
294
295      solutionsCreator.NumberOfSolutionsParameter.ActualName = PopulationSizeParameter.Name;
296      solutionsCreator.Successor = null;
297
298      mainLoop.EmigrantsSelectorParameter.ActualName = EmigrantsSelectorParameter.Name;
299      mainLoop.ImmigrationReplacerParameter.ActualName = ImmigrationReplacerParameter.Name;
300      mainLoop.MaximumGenerationsParameter.ActualName = MaximumGenerationsParameter.Name;
301      mainLoop.MigrationIntervalParameter.ActualName = MigrationIntervalParameter.Name;
302      mainLoop.MigrationRateParameter.ActualName = MigrationRateParameter.Name;
303      mainLoop.MigratorParameter.ActualName = MigratorParameter.Name;
304      mainLoop.NumberOfIslandsParameter.ActualName = NumberOfIslandsParameter.Name;
305      mainLoop.SelectorParameter.ActualName = SelectorParameter.Name;
306      mainLoop.CrossoverParameter.ActualName = CrossoverParameter.Name;
307      mainLoop.ElitesParameter.ActualName = ElitesParameter.Name;
308      mainLoop.MutatorParameter.ActualName = MutatorParameter.Name;
309      mainLoop.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
310      mainLoop.RandomParameter.ActualName = randomCreator.RandomParameter.ActualName;
311      mainLoop.ResultsParameter.ActualName = "Results";
312      mainLoop.SuccessRatioParameter.ActualName = SuccessRatioParameter.Name;
313      mainLoop.ComparisonFactorParameter.ActualName = "ComparisonFactor";
314      mainLoop.ComparisonFactorModifierParameter.ActualName = ComparisonFactorModifierParameter.Name;
315      mainLoop.MaximumSelectionPressureParameter.ActualName = MaximumSelectionPressureParameter.Name;
316      mainLoop.OffspringSelectionBeforeMutationParameter.ActualName = OffspringSelectionBeforeMutationParameter.Name;
317      mainLoop.Successor = null;
318
319      foreach (ISelector selector in ApplicationManager.Manager.GetInstances<ISelector>().Where(x => !(x is IMultiObjectiveSelector)).OrderBy(x => x.Name))
320        SelectorParameter.ValidValues.Add(selector);
321      ISelector proportionalSelector = SelectorParameter.ValidValues.FirstOrDefault(x => x.GetType().Name.Equals("ProportionalSelector"));
322      if (proportionalSelector != null) SelectorParameter.Value = proportionalSelector;
323
324      foreach (ISelector selector in ApplicationManager.Manager.GetInstances<ISelector>().Where(x => !(x is IMultiObjectiveSelector)).OrderBy(x => x.Name))
325        EmigrantsSelectorParameter.ValidValues.Add(selector);
326
327      foreach (IReplacer replacer in ApplicationManager.Manager.GetInstances<IReplacer>().OrderBy(x => x.Name))
328        ImmigrationReplacerParameter.ValidValues.Add(replacer);
329
330      ParameterizeSelectors();
331
332      foreach (IMigrator migrator in ApplicationManager.Manager.GetInstances<IMigrator>().OrderBy(x => x.Name))
333        MigratorParameter.ValidValues.Add(migrator);
334
335      foreach (IDiscreteDoubleValueModifier modifier in ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>().OrderBy(x => x.Name))
336        ComparisonFactorModifierParameter.ValidValues.Add(modifier);
337      IDiscreteDoubleValueModifier linearModifier = ComparisonFactorModifierParameter.ValidValues.FirstOrDefault(x => x.GetType().Name.Equals("LinearDiscreteDoubleValueModifier"));
338      if (linearModifier != null) ComparisonFactorModifierParameter.Value = linearModifier;
339      ParameterizeComparisonFactorModifiers();
340
341      qualityAnalyzer = new BestAverageWorstQualityAnalyzer();
342      islandQualityAnalyzer = new BestAverageWorstQualityAnalyzer();
343      selectionPressureAnalyzer = new ValueAnalyzer();
344      islandSelectionPressureAnalyzer = new ValueAnalyzer();
345      ParameterizeAnalyzers();
346      UpdateAnalyzers();
347
348      Initialize();
349    }
350
351    public override IDeepCloneable Clone(Cloner cloner) {
352      IslandOffspringSelectionGeneticAlgorithm clone = (IslandOffspringSelectionGeneticAlgorithm)base.Clone(cloner);
353      clone.islandQualityAnalyzer = (BestAverageWorstQualityAnalyzer)cloner.Clone(islandQualityAnalyzer);
354      clone.qualityAnalyzer = (BestAverageWorstQualityAnalyzer)cloner.Clone(qualityAnalyzer);
355      clone.islandSelectionPressureAnalyzer = (ValueAnalyzer)cloner.Clone(islandSelectionPressureAnalyzer);
356      clone.selectionPressureAnalyzer = (ValueAnalyzer)cloner.Clone(selectionPressureAnalyzer);
357      clone.Initialize();
358      return clone;
359    }
360
361    public override void Prepare() {
362      if (Problem != null) base.Prepare();
363    }
364
365    #region Events
366    protected override void OnProblemChanged() {
367      ParameterizeStochasticOperator(Problem.SolutionCreator);
368      ParameterizeStochasticOperator(Problem.Evaluator);
369      foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
370      ParameterizeSolutionsCreator();
371      ParameterizeMainLoop();
372      ParameterizeSelectors();
373      ParameterizeAnalyzers();
374      UpdateCrossovers();
375      UpdateMutators();
376      UpdateAnalyzers();
377      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
378      base.OnProblemChanged();
379    }
380
381    protected override void Problem_SolutionCreatorChanged(object sender, EventArgs e) {
382      ParameterizeStochasticOperator(Problem.SolutionCreator);
383      ParameterizeSolutionsCreator();
384      base.Problem_SolutionCreatorChanged(sender, e);
385    }
386    protected override void Problem_EvaluatorChanged(object sender, EventArgs e) {
387      ParameterizeStochasticOperator(Problem.Evaluator);
388      ParameterizeSolutionsCreator();
389      ParameterizeMainLoop();
390      ParameterizeSelectors();
391      ParameterizeAnalyzers();
392      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
393      base.Problem_EvaluatorChanged(sender, e);
394    }
395    protected override void Problem_OperatorsChanged(object sender, EventArgs e) {
396      foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
397      UpdateCrossovers();
398      UpdateMutators();
399      UpdateAnalyzers();
400      base.Problem_OperatorsChanged(sender, e);
401    }
402    private void ElitesParameter_ValueChanged(object sender, EventArgs e) {
403      Elites.ValueChanged += new EventHandler(Elites_ValueChanged);
404      ParameterizeSelectors();
405    }
406    private void Elites_ValueChanged(object sender, EventArgs e) {
407      ParameterizeSelectors();
408    }
409    private void PopulationSizeParameter_ValueChanged(object sender, EventArgs e) {
410      NumberOfIslands.ValueChanged += new EventHandler(PopulationSize_ValueChanged);
411      ParameterizeSelectors();
412    }
413    private void PopulationSize_ValueChanged(object sender, EventArgs e) {
414      ParameterizeSelectors();
415    }
416    private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
417      ParameterizeMainLoop();
418      ParameterizeSelectors();
419      ParameterizeAnalyzers();
420    }
421    private void MigrationRateParameter_ValueChanged(object sender, EventArgs e) {
422      MigrationRate.ValueChanged += new EventHandler(MigrationRate_ValueChanged);
423      ParameterizeSelectors();
424    }
425    private void MigrationRate_ValueChanged(object sender, EventArgs e) {
426      ParameterizeSelectors();
427    }
428    private void MaximumMigrationsParameter_ValueChanged(object sender, EventArgs e) {
429      MaximumGenerations.ValueChanged += new EventHandler(MaximumMigrations_ValueChanged);
430      ParameterizeComparisonFactorModifiers();
431    }
432    private void MaximumMigrations_ValueChanged(object sender, EventArgs e) {
433      ParameterizeComparisonFactorModifiers();
434    }
435    private void MigrationIntervalParameter_ValueChanged(object sender, EventArgs e) {
436      MigrationInterval.ValueChanged += new EventHandler(MigrationInterval_ValueChanged);
437      ParameterizeComparisonFactorModifiers();
438    }
439    private void MigrationInterval_ValueChanged(object sender, EventArgs e) {
440      ParameterizeComparisonFactorModifiers();
441    }
442    #endregion
443
444    #region Helpers
445    [StorableHook(HookType.AfterDeserialization)]
446    private void Initialize() {
447      PopulationSizeParameter.ValueChanged += new EventHandler(PopulationSizeParameter_ValueChanged);
448      PopulationSize.ValueChanged += new EventHandler(PopulationSize_ValueChanged);
449      MigrationRateParameter.ValueChanged += new EventHandler(MigrationRateParameter_ValueChanged);
450      MigrationRate.ValueChanged += new EventHandler(MigrationRate_ValueChanged);
451      ElitesParameter.ValueChanged += new EventHandler(ElitesParameter_ValueChanged);
452      Elites.ValueChanged += new EventHandler(Elites_ValueChanged);
453      MigrationIntervalParameter.ValueChanged += new EventHandler(MigrationIntervalParameter_ValueChanged);
454      MigrationInterval.ValueChanged += new EventHandler(MigrationInterval_ValueChanged);
455      MaximumGenerationsParameter.ValueChanged += new EventHandler(MaximumMigrationsParameter_ValueChanged);
456      MaximumGenerations.ValueChanged += new EventHandler(MaximumMigrations_ValueChanged);
457      if (Problem != null) {
458        Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
459      }
460    }
461    private void ParameterizeSolutionsCreator() {
462      SolutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
463      SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name;
464    }
465    private void ParameterizeMainLoop() {
466      MainLoop.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
467      MainLoop.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
468      MainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
469      MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
470    }
471    private void ParameterizeStochasticOperator(IOperator op) {
472      if (op is IStochasticOperator)
473        ((IStochasticOperator)op).RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
474    }
475    private void ParameterizeSelectors() {
476      foreach (ISelector selector in SelectorParameter.ValidValues) {
477        selector.CopySelected = new BoolValue(true);
478        selector.NumberOfSelectedSubScopesParameter.Value = null;
479        selector.NumberOfSelectedSubScopesParameter.ActualName = SelectedParentsParameter.Name;
480        ParameterizeStochasticOperator(selector);
481      }
482      foreach (ISelector selector in EmigrantsSelectorParameter.ValidValues) {
483        selector.CopySelected = new BoolValue(true);
484        selector.NumberOfSelectedSubScopesParameter.Value = new IntValue((int)Math.Ceiling(PopulationSize.Value * MigrationRate.Value));
485        ParameterizeStochasticOperator(selector);
486      }
487      foreach (IReplacer selector in ImmigrationReplacerParameter.ValidValues) {
488        ParameterizeStochasticOperator(selector);
489      }
490      if (Problem != null) {
491        foreach (ISingleObjectiveSelector selector in SelectorParameter.ValidValues.OfType<ISingleObjectiveSelector>()) {
492          selector.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
493          selector.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
494        }
495        foreach (ISingleObjectiveSelector selector in EmigrantsSelectorParameter.ValidValues.OfType<ISingleObjectiveSelector>()) {
496          selector.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
497          selector.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
498        }
499        foreach (ISingleObjectiveReplacer replacer in ImmigrationReplacerParameter.ValidValues.OfType<ISingleObjectiveReplacer>()) {
500          replacer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
501          replacer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
502        }
503      }
504    }
505    private void ParameterizeAnalyzers() {
506      islandQualityAnalyzer.ResultsParameter.ActualName = "Results";
507      islandQualityAnalyzer.QualityParameter.Depth = 1;
508      qualityAnalyzer.ResultsParameter.ActualName = "Results";
509      qualityAnalyzer.QualityParameter.Depth = 2;
510
511      islandSelectionPressureAnalyzer.ResultsParameter.ActualName = "Results";
512      islandSelectionPressureAnalyzer.Name = "SelectionPressure Analyzer";
513      islandSelectionPressureAnalyzer.ValueParameter.Depth = 0;
514      islandSelectionPressureAnalyzer.ValueParameter.ActualName = "SelectionPressure";
515      islandSelectionPressureAnalyzer.ValuesParameter.ActualName = "Selection Pressure History";
516
517      selectionPressureAnalyzer.ResultsParameter.ActualName = "Results";
518      selectionPressureAnalyzer.Name = "SelectionPressure Analyzer";
519      selectionPressureAnalyzer.ValueParameter.Depth = 1;
520      selectionPressureAnalyzer.ValueParameter.ActualName = "SelectionPressure";
521      selectionPressureAnalyzer.ValuesParameter.ActualName = "Selection Pressure History";
522
523      if (Problem != null) {
524        islandQualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
525        islandQualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
526        islandQualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
527
528        qualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
529        qualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
530        qualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
531      }
532    }
533    private void ParameterizeComparisonFactorModifiers() {
534      foreach (IDiscreteDoubleValueModifier modifier in ComparisonFactorModifierParameter.ValidValues) {
535        modifier.IndexParameter.ActualName = "Generations";
536        modifier.EndIndexParameter.Value = new IntValue(MigrationInterval.Value * MaximumGenerations.Value);
537        modifier.EndValueParameter.ActualName = ComparisonFactorUpperBoundParameter.Name;
538        modifier.StartIndexParameter.Value = new IntValue(0);
539        modifier.StartValueParameter.ActualName = ComparisonFactorLowerBoundParameter.Name;
540        modifier.ValueParameter.ActualName = "ComparisonFactor";
541      }
542    }
543    private void UpdateCrossovers() {
544      ICrossover oldCrossover = CrossoverParameter.Value;
545      CrossoverParameter.ValidValues.Clear();
546      foreach (ICrossover crossover in Problem.Operators.OfType<ICrossover>().OrderBy(x => x.Name))
547        CrossoverParameter.ValidValues.Add(crossover);
548      if (oldCrossover != null) {
549        ICrossover crossover = CrossoverParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldCrossover.GetType());
550        if (crossover != null) CrossoverParameter.Value = crossover;
551      }
552    }
553    private void UpdateMutators() {
554      IManipulator oldMutator = MutatorParameter.Value;
555      MutatorParameter.ValidValues.Clear();
556      foreach (IManipulator mutator in Problem.Operators.OfType<IManipulator>().OrderBy(x => x.Name))
557        MutatorParameter.ValidValues.Add(mutator);
558      if (oldMutator != null) {
559        IManipulator mutator = MutatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMutator.GetType());
560        if (mutator != null) MutatorParameter.Value = mutator;
561      }
562    }
563    private void UpdateAnalyzers() {
564      IslandAnalyzer.Operators.Clear();
565      Analyzer.Operators.Clear();
566      IslandAnalyzer.Operators.Add(islandQualityAnalyzer);
567      IslandAnalyzer.Operators.Add(islandSelectionPressureAnalyzer);
568      Analyzer.Operators.Add(qualityAnalyzer);
569      Analyzer.Operators.Add(selectionPressureAnalyzer);
570      if (Problem != null) {
571        foreach (IAnalyzer analyzer in Problem.Operators.OfType<IAnalyzer>().OrderBy(x => x.Name)) {
572          foreach (IScopeTreeLookupParameter param in analyzer.Parameters.OfType<IScopeTreeLookupParameter>())
573            param.Depth = 2;
574          Analyzer.Operators.Add(analyzer);
575        }
576      }
577    }
578    #endregion
579  }
580}
Note: See TracBrowser for help on using the repository browser.