Free cookie consent management tool by TermsFeed Policy Generator

source: branches/LearningClassifierSystems/HeuristicLab.Algorithms.GAssist/3.3/GAssist.cs @ 9370

Last change on this file since 9370 was 9352, checked in by sforsten, 12 years ago

#1980:

  • added DecisionListView
  • added event handlers in *ProblemData
  • renamed project Problems.XCS.Views to Problems.lCS.Views and Problems.Instances.ConditionActionClassification to Problems.Instances.LCS
  • integrated niching in GAssist and added NichingTournamentSelector
  • minor code improvements and property changes
File size: 27.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 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.Optimization.Operators.LCS;
32using HeuristicLab.Parameters;
33using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
34using HeuristicLab.PluginInfrastructure;
35using HeuristicLab.Random;
36
37namespace HeuristicLab.Algorithms.GAssist {
38  /// <summary>
39  /// A genetic algorithm.
40  /// </summary>
41  [Item("GAssist", "A learning classifier system.")]
42  [Creatable("Algorithms")]
43  [StorableClass]
44  public sealed class GAssist : HeuristicOptimizationEngineAlgorithm, IStorableContent {
45    public string Filename { get; set; }
46
47    #region Problem Properties
48    public override Type ProblemType {
49      get { return typeof(IGAssistProblem); }
50    }
51    public new IGAssistProblem Problem {
52      get { return (IGAssistProblem)base.Problem; }
53      set { base.Problem = value; }
54    }
55    #endregion
56
57    #region Parameter Properties
58    private ValueParameter<IntValue> SeedParameter {
59      get { return (ValueParameter<IntValue>)Parameters["Seed"]; }
60    }
61    private ValueParameter<BoolValue> SetSeedRandomlyParameter {
62      get { return (ValueParameter<BoolValue>)Parameters["SetSeedRandomly"]; }
63    }
64    private ValueParameter<IntValue> PopulationSizeParameter {
65      get { return (ValueParameter<IntValue>)Parameters["PopulationSize"]; }
66    }
67    public IConstrainedValueParameter<IDefaultRuleOperator> DefaultRuleParameter {
68      get { return (IConstrainedValueParameter<IDefaultRuleOperator>)Parameters["DefaultRule"]; }
69    }
70    public IConstrainedValueParameter<INichingSingleObjectiveSelector> SelectorParameter {
71      get { return (IConstrainedValueParameter<INichingSingleObjectiveSelector>)Parameters["Selector"]; }
72    }
73    private ValueParameter<PercentValue> CrossoverProbabilityParameter {
74      get { return (ValueParameter<PercentValue>)Parameters["CrossoverProbability"]; }
75    }
76    public IConstrainedValueParameter<ICrossover> CrossoverParameter {
77      get { return (IConstrainedValueParameter<ICrossover>)Parameters["Crossover"]; }
78    }
79    private ValueParameter<PercentValue> MutationProbabilityParameter {
80      get { return (ValueParameter<PercentValue>)Parameters["MutationProbability"]; }
81    }
82    public IConstrainedValueParameter<IManipulator> MutatorParameter {
83      get { return (IConstrainedValueParameter<IManipulator>)Parameters["Mutator"]; }
84    }
85    private ValueParameter<IntValue> ElitesParameter {
86      get { return (ValueParameter<IntValue>)Parameters["Elites"]; }
87    }
88    private ValueParameter<MultiAnalyzer> AnalyzerParameter {
89      get { return (ValueParameter<MultiAnalyzer>)Parameters["Analyzer"]; }
90    }
91    private ValueParameter<GAssistSpecialStageMultiOperator> SpecialStagesParameter {
92      get { return (ValueParameter<GAssistSpecialStageMultiOperator>)Parameters["SpecialStages"]; }
93    }
94    private ValueParameter<IntValue> MaximumGenerationsParameter {
95      get { return (ValueParameter<IntValue>)Parameters["MaximumGenerations"]; }
96    }
97    private ValueParameter<PercentValue> StartReinitializeProbabilityParameter {
98      get { return (ValueParameter<PercentValue>)Parameters["StartReinitializeProbability"]; }
99    }
100    private ValueParameter<PercentValue> EndReinitializeProbabilityParameter {
101      get { return (ValueParameter<PercentValue>)Parameters["EndReinitializeProbability"]; }
102    }
103    public IConstrainedValueParameter<IDiscreteDoubleValueModifier> ReinitializeCurveOperatorParameter {
104      get { return (IConstrainedValueParameter<IDiscreteDoubleValueModifier>)Parameters["ReinitializeCurveOperator"]; }
105    }
106    private ValueParameter<PercentValue> SplitProbabilityParameter {
107      get { return (ValueParameter<PercentValue>)Parameters["SplitProbability"]; }
108    }
109    private ValueParameter<PercentValue> MergeProbabilityParameter {
110      get { return (ValueParameter<PercentValue>)Parameters["MergeProbability"]; }
111    }
112    private ValueParameter<PercentValue> OneProbabilityParameter {
113      get { return (ValueParameter<PercentValue>)Parameters["OneProbability"]; }
114    }
115    private ValueParameter<IntValue> MaximumNumberOfIntervalsParameter {
116      get { return (ValueParameter<IntValue>)Parameters["MaximumNumberOfIntervals"]; }
117    }
118    private ValueParameter<IntValue> InitialNumberOfRulesParameter {
119      get { return (ValueParameter<IntValue>)Parameters["InitialNumberOfRules"]; }
120    }
121    private ValueParameter<ItemCollection<IDiscretizer>> DiscretizersParameter {
122      get { return (ValueParameter<ItemCollection<IDiscretizer>>)Parameters["Discretizers"]; }
123    }
124    #endregion
125
126    #region Properties
127    public IntValue Seed {
128      get { return SeedParameter.Value; }
129      set { SeedParameter.Value = value; }
130    }
131    public BoolValue SetSeedRandomly {
132      get { return SetSeedRandomlyParameter.Value; }
133      set { SetSeedRandomlyParameter.Value = value; }
134    }
135    public IntValue PopulationSize {
136      get { return PopulationSizeParameter.Value; }
137      set { PopulationSizeParameter.Value = value; }
138    }
139    public INichingSingleObjectiveSelector Selector {
140      get { return SelectorParameter.Value; }
141      set { SelectorParameter.Value = value; }
142    }
143    public PercentValue CrossoverProbability {
144      get { return CrossoverProbabilityParameter.Value; }
145      set { CrossoverProbabilityParameter.Value = value; }
146    }
147    public ICrossover Crossover {
148      get { return CrossoverParameter.Value; }
149      set { CrossoverParameter.Value = value; }
150    }
151    public PercentValue MutationProbability {
152      get { return MutationProbabilityParameter.Value; }
153      set { MutationProbabilityParameter.Value = value; }
154    }
155    public IManipulator Mutator {
156      get { return MutatorParameter.Value; }
157      set { MutatorParameter.Value = value; }
158    }
159    public IntValue Elites {
160      get { return ElitesParameter.Value; }
161      set { ElitesParameter.Value = value; }
162    }
163    public MultiAnalyzer Analyzer {
164      get { return AnalyzerParameter.Value; }
165      set { AnalyzerParameter.Value = value; }
166    }
167    public GAssistSpecialStageMultiOperator SpecialStages {
168      get { return SpecialStagesParameter.Value; }
169      set { SpecialStagesParameter.Value = value; }
170    }
171    public IDiscreteDoubleValueModifier ReinitializeCurveOperator {
172      get { return ReinitializeCurveOperatorParameter.Value; }
173      set { ReinitializeCurveOperatorParameter.Value = value; }
174    }
175    public IntValue MaximumGenerations {
176      get { return MaximumGenerationsParameter.Value; }
177      set { MaximumGenerationsParameter.Value = value; }
178    }
179    private RandomCreator RandomCreator {
180      get { return (RandomCreator)OperatorGraph.InitialOperator; }
181    }
182    private SolutionsCreator SolutionsCreator {
183      get { return (SolutionsCreator)RandomCreator.Successor; }
184    }
185    private GAssistMainLoop GeneticAlgorithmMainLoop {
186      get { return FindMainLoop(SolutionsCreator.Successor); }
187    }
188    [Storable]
189    private BestAverageWorstQualityAnalyzer qualityAnalyzer;
190    #endregion
191
192    public GAssist()
193      : base() {
194      Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
195      Parameters.Add(new ValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
196      Parameters.Add(new ValueParameter<IntValue>("PopulationSize", "The size of the population of solutions.", new IntValue(100)));
197      Parameters.Add(new ConstrainedValueParameter<INichingSingleObjectiveSelector>("Selector", "The operator used to select solutions for reproduction."));
198      Parameters.Add(new ValueParameter<PercentValue>("CrossoverProbability", "The probability that the Crossover operator is applied on a solution.", new PercentValue(0.9)));
199      Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions."));
200      Parameters.Add(new ValueParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution.", new PercentValue(0.05)));
201      Parameters.Add(new OptionalConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions."));
202      Parameters.Add(new ValueParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.", new IntValue(1)));
203      Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze each generation.", new MultiAnalyzer()));
204      Parameters.Add(new ValueParameter<GAssistSpecialStageMultiOperator>("SpecialStages", "", new GAssistSpecialStageMultiOperator()));
205      Parameters.Add(new ValueParameter<IntValue>("MaximumGenerations", "The maximum number of generations which should be processed.", new IntValue(1000)));
206      Parameters.Add(new FixedValueParameter<PercentValue>("SplitProbability", "", new PercentValue(0.05)));
207      Parameters.Add(new FixedValueParameter<PercentValue>("MergeProbability", "", new PercentValue(0.05)));
208      Parameters.Add(new FixedValueParameter<PercentValue>("StartReinitializeProbability", "", new PercentValue(0.05)));
209      Parameters.Add(new FixedValueParameter<PercentValue>("EndReinitializeProbability", "", new PercentValue(Double.Epsilon)));
210      Parameters.Add(new FixedValueParameter<PercentValue>("OneProbability", "", new PercentValue(0.75)));
211      Parameters.Add(new FixedValueParameter<IntValue>("MaximumNumberOfIntervals", "", new IntValue(5)));
212      Parameters.Add(new FixedValueParameter<IntValue>("InitialNumberOfRules", "", new IntValue(20)));
213      Parameters.Add(new ConstrainedValueParameter<IDefaultRuleOperator>("DefaultRule", ""));
214      Parameters.Add(new ConstrainedValueParameter<IDiscreteDoubleValueModifier>("ReinitializeCurveOperator", ""));
215      Parameters.Add(new ValueParameter<ItemCollection<IDiscretizer>>("Discretizers", "", new ItemCollection<IDiscretizer>()));
216
217      RandomCreator randomCreator = new RandomCreator();
218      SolutionsCreator solutionsCreator = new SolutionsCreator();
219      SubScopesCounter subScopesCounter = new SubScopesCounter();
220      ResultsCollector resultsCollector = new ResultsCollector();
221      GAssistMainLoop mainLoop = new GAssistMainLoop();
222      OperatorGraph.InitialOperator = randomCreator;
223
224      randomCreator.RandomParameter.ActualName = "Random";
225      randomCreator.SeedParameter.ActualName = SeedParameter.Name;
226      randomCreator.SeedParameter.Value = null;
227      randomCreator.SetSeedRandomlyParameter.ActualName = SetSeedRandomlyParameter.Name;
228      randomCreator.SetSeedRandomlyParameter.Value = null;
229      randomCreator.Successor = solutionsCreator;
230
231      solutionsCreator.NumberOfSolutionsParameter.ActualName = PopulationSizeParameter.Name;
232      solutionsCreator.Successor = subScopesCounter;
233
234      subScopesCounter.Name = "Initialize EvaluatedSolutions";
235      subScopesCounter.ValueParameter.ActualName = "EvaluatedSolutions";
236      subScopesCounter.Successor = resultsCollector;
237
238      resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Evaluated Solutions", null, "EvaluatedSolutions"));
239      resultsCollector.ResultsParameter.ActualName = "Results";
240      resultsCollector.Successor = mainLoop;
241
242      mainLoop.DefaultRuleParameter.ActualName = DefaultRuleParameter.Name;
243      mainLoop.SelectorParameter.ActualName = SelectorParameter.Name;
244      mainLoop.CrossoverParameter.ActualName = CrossoverParameter.Name;
245      mainLoop.CrossoverProbabilityParameter.ActualName = CrossoverProbabilityParameter.Name;
246      mainLoop.ElitesParameter.ActualName = ElitesParameter.Name;
247      mainLoop.MaximumGenerationsParameter.ActualName = MaximumGenerationsParameter.Name;
248      mainLoop.MutatorParameter.ActualName = MutatorParameter.Name;
249      mainLoop.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
250      mainLoop.RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
251      mainLoop.AnalyzerParameter.ActualName = AnalyzerParameter.Name;
252      mainLoop.SpecialStagesParameter.ActualName = SpecialStagesParameter.Name;
253      mainLoop.EvaluatedSolutionsParameter.ActualName = "EvaluatedSolutions";
254      mainLoop.PopulationSizeParameter.ActualName = PopulationSizeParameter.Name;
255      mainLoop.ResultsParameter.ActualName = "Results";
256      mainLoop.ReinitializationProbabilityOperatorParameter.ActualName = ReinitializeCurveOperatorParameter.Name;
257
258      foreach (INichingSingleObjectiveSelector selector in ApplicationManager.Manager.GetInstances<INichingSingleObjectiveSelector>().Where(x => !(x is IMultiObjectiveSelector)).OrderBy(x => x.Name))
259        SelectorParameter.ValidValues.Add(selector);
260      //INichingSingleObjectiveSelector proportionalSelector = SelectorParameter.ValidValues.FirstOrDefault(x => x.GetType().Name.Equals("ProportionalSelector"));
261      //if (proportionalSelector != null) SelectorParameter.Value = proportionalSelector;
262      ParameterizeSelectors();
263
264      qualityAnalyzer = new BestAverageWorstQualityAnalyzer();
265      ParameterizeAnalyzers();
266      UpdateAnalyzers();
267
268      foreach (IDiscreteDoubleValueModifier op in ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>().OrderBy(x => x.Name)) {
269        ReinitializeCurveOperatorParameter.ValidValues.Add(op);
270      }
271      ReinitializeCurveOperatorParameter.Value = ReinitializeCurveOperatorParameter.ValidValues.First(x => x.GetType().Equals(typeof(LinearDiscreteDoubleValueModifier)));
272      ParameterizeReinitializeCurveOperators();
273
274      InitializeSpecialStages();
275
276      UpdateDiscretizers();
277
278      Initialize();
279    }
280
281    private void UpdateDiscretizers() {
282      // change to add more
283      DiscretizersParameter.Value.AddRange(ApplicationManager.Manager.GetInstances<IDiscretizer>());
284    }
285
286    private void ParameterizeReinitializeCurveOperators() {
287      foreach (IDiscreteDoubleValueModifier op in ReinitializeCurveOperatorParameter.ValidValues) {
288        op.IndexParameter.ActualName = "Generations";
289        op.IndexParameter.Hidden = true;
290        op.StartIndexParameter.Value = new IntValue(0);
291        op.EndIndexParameter.ActualName = MaximumGenerationsParameter.Name;
292        op.ValueParameter.ActualName = "ReinitializeProbability";
293        op.ValueParameter.Hidden = true;
294        op.StartValueParameter.ActualName = StartReinitializeProbabilityParameter.Name;
295        op.StartValueParameter.Hidden = true;
296        op.EndValueParameter.ActualName = EndReinitializeProbabilityParameter.Name;
297        op.EndValueParameter.Hidden = true;
298        ParameterizeStochasticOperator(op);
299      }
300    }
301
302    private void InitializeSpecialStages() {
303      SpecialStages.Operators.Clear();
304      var splitOperator = new SplitOperator();
305      splitOperator.ProbabilityParameter.ActualName = "SplitProbability";
306      //change
307      splitOperator.IndividualParameter.ActualName = "DecisionList";
308      SpecialStages.Operators.Add(splitOperator);
309      var mergeOperator = new MergeOperator();
310      mergeOperator.ProbabilityParameter.ActualName = "MergeProbability";
311      //change
312      mergeOperator.IndividualParameter.ActualName = "DecisionList";
313      SpecialStages.Operators.Add(mergeOperator);
314      var reinitializeOperator = new ReinitializeOperator();
315      reinitializeOperator.ProbabilityParameter.ActualName = "ReinitializeProbability";
316      reinitializeOperator.DiscretizersParameter.ActualName = "Discretizers";
317      reinitializeOperator.OneProbabilityParameter.ActualName = "OneProbability";
318      //change
319      reinitializeOperator.IndividualParameter.ActualName = "DecisionList";
320      SpecialStages.Operators.Add(reinitializeOperator);
321      foreach (var op in SpecialStages.Operators) {
322        op.RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
323      }
324    }
325
326    [StorableConstructor]
327    private GAssist(bool deserializing) : base(deserializing) { }
328    [StorableHook(HookType.AfterDeserialization)]
329    private void AfterDeserialization() {
330      Initialize();
331    }
332
333    private GAssist(GAssist original, Cloner cloner)
334      : base(original, cloner) {
335      qualityAnalyzer = cloner.Clone(original.qualityAnalyzer);
336      Initialize();
337    }
338    public override IDeepCloneable Clone(Cloner cloner) {
339      return new GAssist(this, cloner);
340    }
341
342    public override void Prepare() {
343      if (Problem != null) base.Prepare();
344    }
345
346    #region Events
347    protected override void OnProblemChanged() {
348      ParameterizeStochasticOperator(Problem.SolutionCreator);
349      ParameterizeStochasticOperator(Problem.Evaluator);
350      foreach (IOperator op in Problem.Operators.OfType<IOperator>()) ParameterizeStochasticOperator(op);
351      ParameterizeSolutionsCreator();
352      ParameterizeGeneticAlgorithmMainLoop();
353      ParameterizeSelectors();
354      ParameterizeAnalyzers();
355      ParameterizeIterationBasedOperators();
356      UpdateDefaultRuleOperators();
357      UpdateCrossovers();
358      UpdateMutators();
359      UpdateAnalyzers();
360      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
361      base.OnProblemChanged();
362    }
363
364    protected override void Problem_SolutionCreatorChanged(object sender, EventArgs e) {
365      ParameterizeStochasticOperator(Problem.SolutionCreator);
366      ParameterizeSolutionsCreator();
367      base.Problem_SolutionCreatorChanged(sender, e);
368    }
369    protected override void Problem_EvaluatorChanged(object sender, EventArgs e) {
370      ParameterizeStochasticOperator(Problem.Evaluator);
371      ParameterizeSolutionsCreator();
372      ParameterizeGeneticAlgorithmMainLoop();
373      ParameterizeSelectors();
374      ParameterizeAnalyzers();
375      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
376      base.Problem_EvaluatorChanged(sender, e);
377    }
378    protected override void Problem_OperatorsChanged(object sender, EventArgs e) {
379      foreach (IOperator op in Problem.Operators.OfType<IOperator>()) ParameterizeStochasticOperator(op);
380      ParameterizeIterationBasedOperators();
381      UpdateCrossovers();
382      UpdateMutators();
383      UpdateAnalyzers();
384      base.Problem_OperatorsChanged(sender, e);
385    }
386    private void ElitesParameter_ValueChanged(object sender, EventArgs e) {
387      Elites.ValueChanged += new EventHandler(Elites_ValueChanged);
388      ParameterizeSelectors();
389    }
390    private void Elites_ValueChanged(object sender, EventArgs e) {
391      ParameterizeSelectors();
392    }
393
394    private void PopulationSizeParameter_ValueChanged(object sender, EventArgs e) {
395      PopulationSize.ValueChanged += new EventHandler(PopulationSize_ValueChanged);
396      ParameterizeSelectors();
397    }
398    private void PopulationSize_ValueChanged(object sender, EventArgs e) {
399      ParameterizeSelectors();
400    }
401    private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
402      ParameterizeGeneticAlgorithmMainLoop();
403      ParameterizeSelectors();
404      ParameterizeAnalyzers();
405    }
406    #endregion
407
408    #region Helpers
409    private void Initialize() {
410      PopulationSizeParameter.ValueChanged += new EventHandler(PopulationSizeParameter_ValueChanged);
411      PopulationSize.ValueChanged += new EventHandler(PopulationSize_ValueChanged);
412      ElitesParameter.ValueChanged += new EventHandler(ElitesParameter_ValueChanged);
413      Elites.ValueChanged += new EventHandler(Elites_ValueChanged);
414      if (Problem != null) {
415        Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
416      }
417    }
418
419    private void ParameterizeSolutionsCreator() {
420      SolutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
421      SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name;
422      // change!
423      ((IGAssistIndividualCreator)Problem.SolutionCreatorParameter.ActualValue).DiscretizersParameter.ActualName = "Discretizers";
424    }
425    private void ParameterizeGeneticAlgorithmMainLoop() {
426      GeneticAlgorithmMainLoop.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
427      GeneticAlgorithmMainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
428      GeneticAlgorithmMainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
429    }
430    private void ParameterizeStochasticOperator(IOperator op) {
431      IStochasticOperator stochasticOp = op as IStochasticOperator;
432      if (stochasticOp != null) {
433        stochasticOp.RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
434        stochasticOp.RandomParameter.Hidden = true;
435      }
436    }
437    private void ParameterizeSelectors() {
438      foreach (INichingSingleObjectiveSelector selector in SelectorParameter.ValidValues) {
439        selector.CopySelected = new BoolValue(true);
440        selector.NumberOfSelectedSubScopesParameter.Value = new IntValue(2 * (PopulationSizeParameter.Value.Value - ElitesParameter.Value.Value));
441        selector.NumberOfSelectedSubScopesParameter.Hidden = true;
442        selector.ParentsPerChildParameter.Value = new IntValue(2);
443        ParameterizeStochasticOperator(selector);
444      }
445      if (Problem != null) {
446        foreach (INichingSingleObjectiveSelector selector in SelectorParameter.ValidValues.OfType<INichingSingleObjectiveSelector>()) {
447          selector.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
448          selector.MaximizationParameter.Hidden = true;
449          selector.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
450          selector.QualityParameter.Hidden = true;
451          selector.NichingParameter.ActualName = Problem.NichingParameterName;
452          selector.GAssistNichesProblemDataParameter.ActualName = Problem.ProblemDataParameter.Name;
453          //change
454          selector.IndividualParameter.ActualName = "DecisionList";
455        }
456      }
457    }
458    private void ParameterizeAnalyzers() {
459      qualityAnalyzer.ResultsParameter.ActualName = "Results";
460      qualityAnalyzer.ResultsParameter.Hidden = true;
461      if (Problem != null) {
462        qualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
463        qualityAnalyzer.MaximizationParameter.Hidden = true;
464        qualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
465        qualityAnalyzer.QualityParameter.Depth = 1;
466        qualityAnalyzer.QualityParameter.Hidden = true;
467        qualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
468        qualityAnalyzer.BestKnownQualityParameter.Hidden = true;
469      }
470    }
471    private void ParameterizeIterationBasedOperators() {
472      if (Problem != null) {
473        foreach (IIterationBasedOperator op in Problem.Operators.OfType<IIterationBasedOperator>()) {
474          op.IterationsParameter.ActualName = "Generations";
475          op.IterationsParameter.Hidden = true;
476          op.MaximumIterationsParameter.ActualName = "MaximumGenerations";
477          op.MaximumIterationsParameter.Hidden = true;
478        }
479      }
480    }
481    private void UpdateDefaultRuleOperators() {
482      IDefaultRuleOperator oldDefaultRule = DefaultRuleParameter.Value;
483      DefaultRuleParameter.ValidValues.Clear();
484      IDefaultRuleOperator defaultdefaultRule = Problem.Operators.OfType<IDefaultRuleOperator>().FirstOrDefault();
485
486      foreach (IDefaultRuleOperator defaultRule in Problem.Operators.OfType<IDefaultRuleOperator>().OrderBy(x => x.Name))
487        DefaultRuleParameter.ValidValues.Add(defaultRule);
488
489      if (oldDefaultRule != null) {
490        IDefaultRuleOperator defaultRule = DefaultRuleParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldDefaultRule.GetType());
491        if (defaultRule != null) DefaultRuleParameter.Value = defaultRule;
492        else oldDefaultRule = null;
493      }
494      if (oldDefaultRule == null && defaultdefaultRule != null)
495        DefaultRuleParameter.Value = defaultdefaultRule;
496    }
497    private void UpdateCrossovers() {
498      ICrossover oldCrossover = CrossoverParameter.Value;
499      CrossoverParameter.ValidValues.Clear();
500      ICrossover defaultCrossover = Problem.Operators.OfType<ICrossover>().FirstOrDefault();
501
502      foreach (ICrossover crossover in Problem.Operators.OfType<ICrossover>().OrderBy(x => x.Name))
503        CrossoverParameter.ValidValues.Add(crossover);
504
505      if (oldCrossover != null) {
506        ICrossover crossover = CrossoverParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldCrossover.GetType());
507        if (crossover != null) CrossoverParameter.Value = crossover;
508        else oldCrossover = null;
509      }
510      if (oldCrossover == null && defaultCrossover != null)
511        CrossoverParameter.Value = defaultCrossover;
512    }
513    private void UpdateMutators() {
514      IManipulator oldMutator = MutatorParameter.Value;
515      MutatorParameter.ValidValues.Clear();
516      IManipulator defaultMutator = Problem.Operators.OfType<IManipulator>().FirstOrDefault();
517
518      foreach (IManipulator mutator in Problem.Operators.OfType<IManipulator>().OrderBy(x => x.Name))
519        MutatorParameter.ValidValues.Add(mutator);
520      if (oldMutator != null) {
521        IManipulator mutator = MutatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMutator.GetType());
522        if (mutator != null) MutatorParameter.Value = mutator;
523      }
524      if (oldMutator == null && defaultMutator != null)
525        MutatorParameter.Value = defaultMutator;
526    }
527    private void UpdateAnalyzers() {
528      Analyzer.Operators.Clear();
529      if (Problem != null) {
530        foreach (IAnalyzer analyzer in Problem.Operators.OfType<IAnalyzer>()) {
531          foreach (IScopeTreeLookupParameter param in analyzer.Parameters.OfType<IScopeTreeLookupParameter>())
532            param.Depth = 1;
533          Analyzer.Operators.Add(analyzer, analyzer.EnabledByDefault);
534        }
535      }
536      Analyzer.Operators.Add(qualityAnalyzer, qualityAnalyzer.EnabledByDefault);
537    }
538    private GAssistMainLoop FindMainLoop(IOperator start) {
539      IOperator mainLoop = start;
540      while (mainLoop != null && !(mainLoop is GAssistMainLoop))
541        mainLoop = ((SingleSuccessorOperator)mainLoop).Successor;
542      if (mainLoop == null) return null;
543      else return (GAssistMainLoop)mainLoop;
544    }
545    #endregion
546  }
547}
Note: See TracBrowser for help on using the repository browser.