Free cookie consent management tool by TermsFeed Policy Generator

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

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

Worked on refactoring of algorithm analysis and tracing (#999)

  • adapted GA and TSP
  • removed stuff related to visualizers
File size: 25.2 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      foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
298      ParameterizeSolutionsCreator();
299      ParameterizeMainLoop();
300      ParameterizeSelectors();
301      UpdateCrossovers();
302      UpdateMutators();
303      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
304      base.OnProblemChanged();
305    }
306
307    protected override void Problem_SolutionCreatorChanged(object sender, EventArgs e) {
308      ParameterizeStochasticOperator(Problem.SolutionCreator);
309      ParameterizeSolutionsCreator();
310      base.Problem_SolutionCreatorChanged(sender, e);
311    }
312    protected override void Problem_EvaluatorChanged(object sender, EventArgs e) {
313      ParameterizeStochasticOperator(Problem.Evaluator);
314      ParameterizeSolutionsCreator();
315      ParameterizeMainLoop();
316      ParameterizeSelectors();
317      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
318      base.Problem_EvaluatorChanged(sender, e);
319    }
320    protected override void Problem_OperatorsChanged(object sender, EventArgs e) {
321      foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
322      UpdateCrossovers();
323      UpdateMutators();
324      base.Problem_OperatorsChanged(sender, e);
325    }
326    private void ElitesParameter_ValueChanged(object sender, EventArgs e) {
327      Elites.ValueChanged += new EventHandler(Elites_ValueChanged);
328      ParameterizeSelectors();
329    }
330    private void Elites_ValueChanged(object sender, EventArgs e) {
331      ParameterizeSelectors();
332    }
333    private void PopulationSizeParameter_ValueChanged(object sender, EventArgs e) {
334      NumberOfVillages.ValueChanged += new EventHandler(PopulationSize_ValueChanged);
335      ParameterizeSelectors();
336    }
337    private void PopulationSize_ValueChanged(object sender, EventArgs e) {
338      ParameterizeSelectors();
339    }
340    private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
341      ParameterizeMainLoop();
342      ParameterizeSelectors();
343    }
344    private void MaximumGenerationsParameter_ValueChanged(object sender, EventArgs e) {
345      MaximumGenerations.ValueChanged += new EventHandler(MaximumGenerations_ValueChanged);
346      MaximumGenerations_ValueChanged(sender, e);
347    }
348    private void MaximumGenerations_ValueChanged(object sender, EventArgs e) {
349      if (MaximumGenerations.Value < NumberOfVillages.Value) NumberOfVillages.Value = MaximumGenerations.Value;
350      ParameterizeMainLoop();
351    }
352    private void NumberOfVillagesParameter_ValueChanged(object sender, EventArgs e) {
353      NumberOfVillages.ValueChanged += new EventHandler(NumberOfVillages_ValueChanged);
354      NumberOfVillages_ValueChanged(sender, e);
355    }
356    private void NumberOfVillages_ValueChanged(object sender, EventArgs e) {
357      if (NumberOfVillages.Value > MaximumGenerations.Value) MaximumGenerations.Value = NumberOfVillages.Value;
358      ParameterizeComparisonFactorModifiers();
359      ParameterizeMainLoop();
360    }
361    #endregion
362
363    #region Helpers
364    [StorableHook(HookType.AfterDeserialization)]
365    private void Initialize() {
366      InitializeSelectors();
367      UpdateSelectors();
368      InitializeComparisonFactorModifiers();
369      UpdateComparisonFactorModifiers();
370      NumberOfVillagesParameter.ValueChanged += new EventHandler(NumberOfVillagesParameter_ValueChanged);
371      NumberOfVillages.ValueChanged += new EventHandler(NumberOfVillages_ValueChanged);
372      PopulationSizeParameter.ValueChanged += new EventHandler(PopulationSizeParameter_ValueChanged);
373      PopulationSize.ValueChanged += new EventHandler(PopulationSize_ValueChanged);
374      ElitesParameter.ValueChanged += new EventHandler(ElitesParameter_ValueChanged);
375      Elites.ValueChanged += new EventHandler(Elites_ValueChanged);
376      MaximumGenerationsParameter.ValueChanged += new EventHandler(MaximumGenerationsParameter_ValueChanged);
377      MaximumGenerations.ValueChanged += new EventHandler(MaximumGenerations_ValueChanged);
378      if (Problem != null) {
379        UpdateCrossovers();
380        UpdateMutators();
381        Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
382      }
383    }
384    private void ParameterizeSolutionsCreator() {
385      SolutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
386      SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name;
387    }
388    private void ParameterizeMainLoop() {
389      MainLoop.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
390      MainLoop.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
391      MainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
392      MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
393      MainLoop.MigrationIntervalParameter.Value = new IntValue(MaximumGenerations.Value / NumberOfVillages.Value);
394    }
395    private void ParameterizeStochasticOperator(IOperator op) {
396      if (op is IStochasticOperator)
397        ((IStochasticOperator)op).RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
398    }
399    private void InitializeSelectors() {
400      selectors = new List<ISelector>();
401      selectors.AddRange(ApplicationManager.Manager.GetInstances<ISelector>().Where(x => !(x is IMultiObjectiveSelector)).OrderBy(x => x.Name));
402      ParameterizeSelectors();
403    }
404    private void InitializeComparisonFactorModifiers() {
405      comparisonFactorModifiers = new List<IDiscreteDoubleValueModifier>();
406      comparisonFactorModifiers.AddRange(ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>().OrderBy(x => x.Name));
407      ParameterizeComparisonFactorModifiers();
408    }
409    private void ParameterizeSelectors() {
410      foreach (ISelector selector in Selectors) {
411        selector.CopySelected = new BoolValue(true);
412        selector.NumberOfSelectedSubScopesParameter.Value = null;
413        selector.NumberOfSelectedSubScopesParameter.ActualName = SelectedParentsParameter.Name;
414        ParameterizeStochasticOperator(selector);
415      }
416      if (Problem != null) {
417        foreach (ISingleObjectiveSelector selector in Selectors.OfType<ISingleObjectiveSelector>()) {
418          selector.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
419          selector.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
420        }
421      }
422    }
423    private void ParameterizeComparisonFactorModifiers() {
424      foreach (IDiscreteDoubleValueModifier modifier in comparisonFactorModifiers) {
425        modifier.IndexParameter.ActualName = "Reunifications";
426        modifier.StartIndexParameter.Value = new IntValue(0);
427        modifier.StartValueParameter.ActualName = ComparisonFactorLowerBoundParameter.Name;
428        modifier.EndIndexParameter.Value = new IntValue(NumberOfVillages.Value - 1);
429        modifier.EndValueParameter.ActualName = ComparisonFactorUpperBoundParameter.Name;
430        modifier.ValueParameter.ActualName = "ComparisonFactor";
431      }
432    }
433    private void UpdateSelectors() {
434      ISelector oldSelector = SelectorParameter.Value;
435      SelectorParameter.ValidValues.Clear();
436      foreach (ISelector selector in Selectors.OrderBy(x => x.Name))
437        SelectorParameter.ValidValues.Add(selector);
438
439      ISelector proportionalSelector = SelectorParameter.ValidValues.FirstOrDefault(x => x.GetType().Name.Equals("ProportionalSelector"));
440      if (proportionalSelector != null) SelectorParameter.Value = proportionalSelector;
441
442      if (oldSelector != null) {
443        ISelector selector = SelectorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldSelector.GetType());
444        if (selector != null) SelectorParameter.Value = selector;
445      }
446    }
447    private void UpdateComparisonFactorModifiers() {
448      IDiscreteDoubleValueModifier oldModifier = ComparisonFactorModifier;
449
450      ComparisonFactorModifierParameter.ValidValues.Clear();
451      foreach (IDiscreteDoubleValueModifier modifier in comparisonFactorModifiers)
452        ComparisonFactorModifierParameter.ValidValues.Add(modifier);
453
454      if (oldModifier != null) {
455        IDiscreteDoubleValueModifier mod = ComparisonFactorModifierParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldModifier.GetType());
456        if (mod != null) ComparisonFactorModifierParameter.Value = mod;
457      }
458    }
459    private void UpdateCrossovers() {
460      ICrossover oldCrossover = CrossoverParameter.Value;
461      CrossoverParameter.ValidValues.Clear();
462      foreach (ICrossover crossover in Problem.Operators.OfType<ICrossover>().OrderBy(x => x.Name))
463        CrossoverParameter.ValidValues.Add(crossover);
464      if (oldCrossover != null) {
465        ICrossover crossover = CrossoverParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldCrossover.GetType());
466        if (crossover != null) CrossoverParameter.Value = crossover;
467      }
468    }
469    private void UpdateMutators() {
470      IManipulator oldMutator = MutatorParameter.Value;
471      MutatorParameter.ValidValues.Clear();
472      foreach (IManipulator mutator in Problem.Operators.OfType<IManipulator>().OrderBy(x => x.Name))
473        MutatorParameter.ValidValues.Add(mutator);
474      if (oldMutator != null) {
475        IManipulator mutator = MutatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMutator.GetType());
476        if (mutator != null) MutatorParameter.Value = mutator;
477      }
478    }
479    #endregion
480  }
481}
Note: See TracBrowser for help on using the repository browser.