Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 3580 was 3510, checked in by abeham, 15 years ago

Added a parameter to set the amount of selected parents #839, #976

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