Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3057_DynamicALPS/TestProblems/oesr-alps-master/HeuristicLab.Algorithms.OESRALPS/AlpsGeneticAlgorithmMainLoop.cs @ 17717

Last change on this file since 17717 was 17479, checked in by kyang, 5 years ago

#3057

  1. upload the latest version of ALPS with SMS-EMOA
  2. upload the related dynamic test problems (dynamic, single-objective symbolic regression), written by David Daninel.
File size: 25.6 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 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 HeuristicLab.Common;
23using HeuristicLab.Core;
24using HeuristicLab.Data;
25using HeuristicLab.Operators;
26using HeuristicLab.Optimization;
27using HeuristicLab.Optimization.Operators;
28using HeuristicLab.Parameters;
29using HEAL.Attic;
30using HeuristicLab.Selection;
31using HeuristicLab.Algorithms.OESRALPS.SlidingWindow.Operator;
32using HeuristicLab.PluginInfrastructure;
33using HeuristicLab.Algorithms.OESRALPS.Analyzers;
34using System.Linq;
35
36namespace HeuristicLab.Algorithms.OESRALPS {
37
38  [Item("AlpsGeneticAlgorithmMainLoop", "An open ended ALPS genetic algorithm main loop operator.")]
39  [StorableType("87678F8F-29BE-4A80-8976-084EE6C7041B")]
40    public sealed class AlpsGeneticAlgorithmMainLoop : AlgorithmOperator {
41    #region Parameter Properties
42    public IValueLookupParameter<IRandom> GlobalRandomParameter {
43      get { return (IValueLookupParameter<IRandom>)Parameters["GlobalRandom"]; }
44    }
45    public IValueLookupParameter<IRandom> LocalRandomParameter {
46      get { return (IValueLookupParameter<IRandom>)Parameters["LocalRandom"]; }
47    }
48
49    public IValueLookupParameter<IOperator> EvaluatorParameter {
50      get { return (IValueLookupParameter<IOperator>)Parameters["Evaluator"]; }
51    }
52    public IValueLookupParameter<IntValue> EvaluatedSolutionsParameter {
53      get { return (IValueLookupParameter<IntValue>)Parameters["EvaluatedSolutions"]; }
54    }
55    public IScopeTreeLookupParameter<DoubleValue> QualityParameter {
56      get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
57    }
58    public IValueLookupParameter<BoolValue> MaximizationParameter {
59      get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
60    }
61
62    public ILookupParameter<IOperator> AnalyzerParameter {
63      get { return (ILookupParameter<IOperator>)Parameters["Analyzer"]; }
64    }
65    public ILookupParameter<IOperator> LayerAnalyzerParameter {
66      get { return (ILookupParameter<IOperator>)Parameters["LayerAnalyzer"]; }
67    }
68
69    public IValueLookupParameter<IntValue> NumberOfLayersParameter {
70      get { return (IValueLookupParameter<IntValue>)Parameters["NumberOfLayers"]; }
71    }
72    public IValueLookupParameter<IntValue> PopulationSizeParameter {
73      get { return (IValueLookupParameter<IntValue>)Parameters["PopulationSize"]; }
74    }
75    public ILookupParameter<IntValue> CurrentPopulationSizeParameter {
76      get { return (ILookupParameter<IntValue>)Parameters["CurrentPopulationSize"]; }
77    }
78
79    public IValueLookupParameter<IOperator> SelectorParameter {
80      get { return (IValueLookupParameter<IOperator>)Parameters["Selector"]; }
81    }
82    public IValueLookupParameter<IOperator> CrossoverParameter {
83      get { return (IValueLookupParameter<IOperator>)Parameters["Crossover"]; }
84    }
85    public IValueLookupParameter<IOperator> MutatorParameter {
86      get { return (IValueLookupParameter<IOperator>)Parameters["Mutator"]; }
87    }
88    public IValueLookupParameter<PercentValue> MutationProbabilityParameter {
89      get { return (IValueLookupParameter<PercentValue>)Parameters["MutationProbability"]; }
90    }
91    public IValueLookupParameter<IntValue> ElitesParameter {
92      get { return (IValueLookupParameter<IntValue>)Parameters["Elites"]; }
93    }
94    public IValueLookupParameter<BoolValue> ReevaluateElitesParameter {
95      get { return (IValueLookupParameter<BoolValue>)Parameters["ReevaluateElites"]; }
96    }
97    public IValueLookupParameter<BoolValue> PlusSelectionParameter {
98      get { return (IValueLookupParameter<BoolValue>)Parameters["PlusSelection"]; }
99    }
100
101    public IScopeTreeLookupParameter<DoubleValue> AgeParameter {
102      get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["Age"]; }
103    }
104    public IValueLookupParameter<IntValue> AgeGapParameter {
105      get { return (IValueLookupParameter<IntValue>)Parameters["AgeGap"]; }
106    }
107    public IValueLookupParameter<DoubleValue> AgeInheritanceParameter {
108      get { return (IValueLookupParameter<DoubleValue>)Parameters["AgeInheritance"]; }
109    }
110    public IValueLookupParameter<IntArray> AgeLimitsParameter {
111      get { return (IValueLookupParameter<IntArray>)Parameters["AgeLimits"]; }
112    }
113
114    public IValueLookupParameter<IntValue> MatingPoolRangeParameter {
115      get { return (IValueLookupParameter<IntValue>)Parameters["MatingPoolRange"]; }
116    }
117    public IValueLookupParameter<BoolValue> ReduceToPopulationSizeParameter {
118      get { return (IValueLookupParameter<BoolValue>)Parameters["ReduceToPopulationSize"]; }
119    }
120
121    public IValueLookupParameter<IOperator> TerminatorParameter {
122      get { return (IValueLookupParameter<IOperator>)Parameters["Terminator"]; }
123    }
124
125    public IValueLookupParameter<IOperator> SlidingWindowParameter {
126      get { return (IValueLookupParameter<IOperator>)Parameters["SlidingWindow"]; }
127    }
128    #endregion
129
130    [StorableConstructor]
131    private AlpsGeneticAlgorithmMainLoop(StorableConstructorFlag _) : base(_) { }
132    private AlpsGeneticAlgorithmMainLoop(AlpsGeneticAlgorithmMainLoop original, Cloner cloner)
133      : base(original, cloner) { }
134    public override IDeepCloneable Clone(Cloner cloner) {
135      return new AlpsGeneticAlgorithmMainLoop(this, cloner);
136    }
137    public AlpsGeneticAlgorithmMainLoop()
138      : base() {
139      Parameters.Add(new ValueLookupParameter<IRandom>("GlobalRandom", "A pseudo random number generator."));
140      Parameters.Add(new ValueLookupParameter<IRandom>("LocalRandom", "A pseudo random number generator."));
141
142      Parameters.Add(new ValueLookupParameter<IOperator>("Evaluator", "The operator used to evaluate solutions. This operator is executed in parallel, if an engine is used which supports parallelization."));
143      Parameters.Add(new ValueLookupParameter<IntValue>("EvaluatedSolutions", "The number of times solutions have been evaluated."));
144      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution."));
145      Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
146
147      Parameters.Add(new ValueLookupParameter<IOperator>("Analyzer", "The operator used to analyze all individuals from all layers combined."));
148      Parameters.Add(new ValueLookupParameter<IOperator>("LayerAnalyzer", "The operator used to analyze each layer."));
149
150      Parameters.Add(new ValueLookupParameter<IntValue>("NumberOfLayers", "The number of layers."));
151      Parameters.Add(new ValueLookupParameter<IntValue>("PopulationSize", "The size of the population of solutions in each layer."));
152      Parameters.Add(new LookupParameter<IntValue>("CurrentPopulationSize", "The current size of the population."));
153
154      Parameters.Add(new ValueLookupParameter<IOperator>("Selector", "The operator used to select solutions for reproduction."));
155      Parameters.Add(new ValueLookupParameter<IOperator>("Crossover", "The operator used to cross solutions."));
156      Parameters.Add(new ValueLookupParameter<IOperator>("Mutator", "The operator used to mutate solutions."));
157      Parameters.Add(new ValueLookupParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution."));
158      Parameters.Add(new ValueLookupParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation."));
159      Parameters.Add(new ValueLookupParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)"));
160      Parameters.Add(new ValueLookupParameter<BoolValue>("PlusSelection", "Include the parents in the selection of the invividuals for the next generation."));
161
162      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Age", "The age of individuals."));
163      Parameters.Add(new ValueLookupParameter<IntValue>("AgeGap", "The frequency of reseeding the lowest layer and scaling factor for the age-limits for the layers."));
164      Parameters.Add(new ValueLookupParameter<DoubleValue>("AgeInheritance", "A weight that determines the age of a child after crossover based on the older (1.0) and younger (0.0) parent."));
165      Parameters.Add(new ValueLookupParameter<IntArray>("AgeLimits", "The maximum age an individual is allowed to reach in a certain layer."));
166
167      Parameters.Add(new ValueLookupParameter<IntValue>("MatingPoolRange", "The range of sub - populations used for creating a mating pool. (1 = current + previous sub-population)"));
168      Parameters.Add(new ValueLookupParameter<BoolValue>("ReduceToPopulationSize", "Reduce the CurrentPopulationSize after elder migration to PopulationSize"));
169
170      Parameters.Add(new ValueLookupParameter<IOperator>("Terminator", "The termination criteria that defines if the algorithm should continue or stop"));
171
172      Parameters.Add(new ValueLookupParameter<IOperator>("SlidingWindow", "Operator which moves a sliding window over the training data."));
173
174      var variableCreator = new VariableCreator() { Name = "Initialize" };
175      var slidingWindow = new Placeholder() { Name = "Sliding Window (Placeholder)" };
176      var initLayerAnalyzerProcessor = new SubScopesProcessor();
177      var layerVariableCreator = new VariableCreator() { Name = "Initialize Layer" };
178      var initLayerAnalyzerPlaceholder = new Placeholder() { Name = "LayerAnalyzer (Placeholder)" };
179      var initAnalyzerPlaceholder = new Placeholder() { Name = "Analyzer (Placeholder)" };
180      var resultsCollector = new ResultsCollector();
181      var matingPoolCreator = new MatingPoolCreator() { Name = "Create Mating Pools" };
182      var matingPoolProcessor = new UniformSubScopesProcessor() { Name = "Process Mating Pools" };
183      var initializeLayer = new Assigner() { Name = "Reset LayerEvaluatedSolutions" };
184      var mainOperator = new AlpsGeneticAlgorithmMainOperator();
185      var generationsIcrementor = new IntCounter() { Name = "Increment Generations" };
186      var evaluatedSolutionsReducer = new DataReducer() { Name = "Increment EvaluatedSolutions" };
187      var eldersEmigrator = CreateEldersEmigrator();
188      var layerOpener = CreateLayerOpener();
189      var layerReseeder = CreateReseeder();
190      var layerAnalyzerProcessor = new UniformSubScopesProcessor();
191      var layerAnalyzerPlaceholder = new Placeholder() { Name = "LayerAnalyzer (Placeholder)" };
192      var analyzerPlaceholder = new Placeholder() { Name = "Analyzer (Placeholder)" };
193      var termination = new TerminationOperator();
194
195      OperatorGraph.InitialOperator = variableCreator;
196
197      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Generations", new IntValue(0)));
198      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("OpenLayers", new IntValue(1)));
199      variableCreator.Successor = initLayerAnalyzerProcessor;
200
201      initLayerAnalyzerProcessor.Operators.Add(layerVariableCreator);
202      initLayerAnalyzerProcessor.Successor = initAnalyzerPlaceholder;
203
204      layerVariableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Layer", new IntValue(0)));
205      layerVariableCreator.CollectedValues.Add(new ValueParameter<ResultCollection>("LayerResults"));
206      layerVariableCreator.Successor = initLayerAnalyzerPlaceholder;
207
208      initLayerAnalyzerPlaceholder.OperatorParameter.ActualName = LayerAnalyzerParameter.Name;
209      initLayerAnalyzerPlaceholder.Successor = null;
210
211      initAnalyzerPlaceholder.OperatorParameter.ActualName = AnalyzerParameter.Name;
212      initAnalyzerPlaceholder.Successor = resultsCollector;
213
214      resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Generations"));
215      resultsCollector.CollectedValues.Add(new ScopeTreeLookupParameter<ResultCollection>("LayerResults", "Result set for each Layer", "LayerResults"));
216      resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("OpenLayers"));
217      resultsCollector.CopyValue = new BoolValue(false);
218      resultsCollector.Successor = slidingWindow;
219
220      slidingWindow.OperatorParameter.ActualName = SlidingWindowParameter.Name;
221      slidingWindow.Successor = matingPoolCreator;
222
223      matingPoolCreator.MatingPoolRangeParameter.Value = null;
224      matingPoolCreator.MatingPoolRangeParameter.ActualName = MatingPoolRangeParameter.Name;
225      matingPoolCreator.Successor = matingPoolProcessor;
226
227      matingPoolProcessor.Parallel.Value = true;
228      matingPoolProcessor.Operator = initializeLayer;
229      matingPoolProcessor.Successor = generationsIcrementor;
230
231      initializeLayer.LeftSideParameter.ActualName = "LayerEvaluatedSolutions";
232      initializeLayer.RightSideParameter.Value = new IntValue(0);
233      initializeLayer.Successor = mainOperator;
234
235      mainOperator.RandomParameter.ActualName = LocalRandomParameter.Name;
236      mainOperator.EvaluatorParameter.ActualName = EvaluatorParameter.Name;
237      mainOperator.EvaluatedSolutionsParameter.ActualName = "LayerEvaluatedSolutions";
238      mainOperator.QualityParameter.ActualName = QualityParameter.Name;
239      mainOperator.MaximizationParameter.ActualName = MaximizationParameter.Name;
240      mainOperator.PopulationSizeParameter.ActualName = PopulationSizeParameter.Name;
241      mainOperator.SelectorParameter.ActualName = SelectorParameter.Name;
242      mainOperator.CrossoverParameter.ActualName = CrossoverParameter.Name;
243      mainOperator.MutatorParameter.ActualName = MutatorParameter.ActualName;
244      mainOperator.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
245      mainOperator.ElitesParameter.ActualName = ElitesParameter.Name;
246      mainOperator.ReevaluateElitesParameter.ActualName = ReevaluateElitesParameter.Name;
247      mainOperator.PlusSelectionParameter.ActualName = PlusSelectionParameter.Name;
248      mainOperator.AgeParameter.ActualName = AgeParameter.Name;
249      mainOperator.AgeInheritanceParameter.ActualName = AgeInheritanceParameter.Name;
250      mainOperator.AgeIncrementParameter.Value = new DoubleValue(1.0);
251      mainOperator.Successor = null;
252
253      generationsIcrementor.ValueParameter.ActualName = "Generations";
254      generationsIcrementor.Increment = new IntValue(1);
255      generationsIcrementor.Successor = evaluatedSolutionsReducer;
256
257      evaluatedSolutionsReducer.ParameterToReduce.ActualName = "LayerEvaluatedSolutions";
258      evaluatedSolutionsReducer.TargetParameter.ActualName = EvaluatedSolutionsParameter.Name;
259      evaluatedSolutionsReducer.ReductionOperation.Value = new ReductionOperation(ReductionOperations.Sum);
260      evaluatedSolutionsReducer.TargetOperation.Value = new ReductionOperation(ReductionOperations.Sum);
261      evaluatedSolutionsReducer.Successor = eldersEmigrator;
262
263      eldersEmigrator.Successor = layerOpener;
264
265      layerOpener.Successor = layerReseeder;
266
267      layerReseeder.Successor = layerAnalyzerProcessor;
268
269      layerAnalyzerProcessor.Operator = layerAnalyzerPlaceholder;
270      layerAnalyzerProcessor.Successor = analyzerPlaceholder;
271
272      layerAnalyzerPlaceholder.OperatorParameter.ActualName = LayerAnalyzerParameter.Name;
273
274      analyzerPlaceholder.OperatorParameter.ActualName = AnalyzerParameter.Name;
275      analyzerPlaceholder.Successor = termination;
276
277      termination.TerminatorParameter.ActualName = TerminatorParameter.Name;
278      termination.ContinueBranch = slidingWindow;
279    }
280
281    private CombinedOperator CreateEldersEmigrator() {
282      var eldersEmigrator = new CombinedOperator() { Name = "Emigrate Elders" };
283      var selectorProsessor = new UniformSubScopesProcessor();
284      var eldersSelector = new EldersSelector();
285      var shiftToRightMigrator = new UnidirectionalRingMigrator() { Name = "Shift elders to next layer" };
286      var mergingProsessor = new UniformSubScopesProcessor();
287      var mergingReducer = new MergingReducer();
288      var subScopesCounter = new SubScopesCounter();
289      var reduceToPopulationSizeBranch = new ConditionalBranch() { Name = "ReduceToPopulationSize?" };
290      var countCalculator = new ExpressionCalculator() { Name = "CurrentPopulationSize = Min(CurrentPopulationSize, PopulationSize)" };
291      var bestSelector = new BestSelector();
292      var rightReducer = new RightReducer();
293
294      eldersEmigrator.OperatorGraph.InitialOperator = selectorProsessor;
295
296      selectorProsessor.Operator = eldersSelector;
297      selectorProsessor.Successor = shiftToRightMigrator;
298
299      eldersSelector.AgeParameter.ActualName = AgeParameter.Name;
300      eldersSelector.AgeLimitsParameter.ActualName = AgeLimitsParameter.Name;
301      eldersSelector.NumberOfLayersParameter.ActualName = NumberOfLayersParameter.Name;
302      eldersSelector.LayerParameter.ActualName = "Layer";
303      eldersSelector.Successor = null;
304
305      shiftToRightMigrator.ClockwiseMigrationParameter.Value = new BoolValue(true);
306      shiftToRightMigrator.Successor = mergingProsessor;
307
308      mergingProsessor.Operator = mergingReducer;
309
310      mergingReducer.Successor = subScopesCounter;
311
312      subScopesCounter.ValueParameter.ActualName = CurrentPopulationSizeParameter.Name;
313      subScopesCounter.AccumulateParameter.Value = new BoolValue(false);
314      subScopesCounter.Successor = reduceToPopulationSizeBranch;
315
316      reduceToPopulationSizeBranch.ConditionParameter.ActualName = ReduceToPopulationSizeParameter.Name;
317      reduceToPopulationSizeBranch.TrueBranch = countCalculator;
318
319      countCalculator.CollectedValues.Add(new LookupParameter<IntValue>(PopulationSizeParameter.Name));
320      countCalculator.CollectedValues.Add(new LookupParameter<IntValue>(CurrentPopulationSizeParameter.Name));
321      countCalculator.ExpressionParameter.Value = new StringValue("CurrentPopulationSize PopulationSize CurrentPopulationSize PopulationSize < if toint");
322      countCalculator.ExpressionResultParameter.ActualName = CurrentPopulationSizeParameter.Name;
323      countCalculator.Successor = bestSelector;
324
325      bestSelector.NumberOfSelectedSubScopesParameter.ActualName = CurrentPopulationSizeParameter.Name;
326      bestSelector.CopySelected = new BoolValue(false);
327      bestSelector.Successor = rightReducer;
328
329      return eldersEmigrator;
330    }
331
332    private CombinedOperator CreateLayerOpener() {
333      var layerOpener = new CombinedOperator() { Name = "Open new Layer if needed" };
334      var maxLayerReached = new Comparator() { Name = "MaxLayersReached = OpenLayers >= NumberOfLayers" };
335      var maxLayerReachedBranch = new ConditionalBranch() { Name = "MaxLayersReached?" };
336      var openNewLayerCalculator = new ExpressionCalculator() { Name = "OpenNewLayer = Generations >= AgeLimits[OpenLayers - 1]" };
337      var openNewLayerBranch = new ConditionalBranch() { Name = "OpenNewLayer?" };
338      var layerCreator = new LastLayerCloner() { Name = "Create Layer" };
339      var updateLayerNumber = new Assigner() { Name = "Layer = OpenLayers" };
340      var historyWiper = new ResultsHistoryWiper() { Name = "Clear History in Results" };
341      var createChildrenViaCrossover = new AlpsGeneticAlgorithmMainOperator();
342      var incrEvaluatedSolutionsForNewLayer = new SubScopesCounter() { Name = "Update EvaluatedSolutions" };
343      var incrOpenLayers = new IntCounter() { Name = "Incr. OpenLayers" };
344      var newLayerResultsCollector = new ResultsCollector() { Name = "Collect new Layer Results" };
345
346      layerOpener.OperatorGraph.InitialOperator = maxLayerReached;
347
348      maxLayerReached.LeftSideParameter.ActualName = "OpenLayers";
349      maxLayerReached.RightSideParameter.ActualName = NumberOfLayersParameter.Name;
350      maxLayerReached.ResultParameter.ActualName = "MaxLayerReached";
351      maxLayerReached.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
352      maxLayerReached.Successor = maxLayerReachedBranch;
353
354      maxLayerReachedBranch.ConditionParameter.ActualName = "MaxLayerReached";
355      maxLayerReachedBranch.FalseBranch = openNewLayerCalculator;
356
357      openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntArray>(AgeLimitsParameter.Name));
358      openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntValue>("Generations"));
359      openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntValue>(NumberOfLayersParameter.Name));
360      openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntValue>("OpenLayers"));
361      openNewLayerCalculator.ExpressionResultParameter.ActualName = "OpenNewLayer";
362      openNewLayerCalculator.ExpressionParameter.Value = new StringValue("Generations 1 + AgeLimits OpenLayers 1 - [] >");
363      openNewLayerCalculator.Successor = openNewLayerBranch;
364
365      openNewLayerBranch.ConditionParameter.ActualName = "OpenNewLayer";
366      openNewLayerBranch.TrueBranch = layerCreator;
367
368      layerCreator.NewLayerOperator = updateLayerNumber;
369      layerCreator.Successor = incrOpenLayers;
370
371      updateLayerNumber.LeftSideParameter.ActualName = "Layer";
372      updateLayerNumber.RightSideParameter.ActualName = "OpenLayers";
373      updateLayerNumber.Successor = historyWiper;
374
375      historyWiper.ResultsParameter.ActualName = "LayerResults";
376      historyWiper.Successor = createChildrenViaCrossover;
377
378      // Maybe use only crossover and no elitism instead of "default operator"
379      createChildrenViaCrossover.RandomParameter.ActualName = LocalRandomParameter.Name;
380      createChildrenViaCrossover.EvaluatorParameter.ActualName = EvaluatorParameter.Name;
381      createChildrenViaCrossover.EvaluatedSolutionsParameter.ActualName = "LayerEvaluatedSolutions";
382      createChildrenViaCrossover.QualityParameter.ActualName = QualityParameter.Name;
383      createChildrenViaCrossover.MaximizationParameter.ActualName = MaximizationParameter.Name;
384      createChildrenViaCrossover.PopulationSizeParameter.ActualName = PopulationSizeParameter.Name;
385      createChildrenViaCrossover.SelectorParameter.ActualName = SelectorParameter.Name;
386      createChildrenViaCrossover.CrossoverParameter.ActualName = CrossoverParameter.Name;
387      createChildrenViaCrossover.MutatorParameter.ActualName = MutatorParameter.Name;
388      createChildrenViaCrossover.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
389      createChildrenViaCrossover.ElitesParameter.ActualName = ElitesParameter.Name;
390      createChildrenViaCrossover.ReevaluateElitesParameter.ActualName = ReevaluateElitesParameter.Name;
391      createChildrenViaCrossover.PlusSelectionParameter.ActualName = PlusSelectionParameter.Name;
392      createChildrenViaCrossover.AgeParameter.ActualName = AgeParameter.Name;
393      createChildrenViaCrossover.AgeInheritanceParameter.ActualName = AgeInheritanceParameter.Name;
394      createChildrenViaCrossover.AgeIncrementParameter.Value = new DoubleValue(0.0);
395      createChildrenViaCrossover.Successor = incrEvaluatedSolutionsForNewLayer;
396
397      incrEvaluatedSolutionsForNewLayer.ValueParameter.ActualName = EvaluatedSolutionsParameter.Name;
398      incrEvaluatedSolutionsForNewLayer.AccumulateParameter.Value = new BoolValue(true);
399
400      incrOpenLayers.ValueParameter.ActualName = "OpenLayers";
401      incrOpenLayers.Increment = new IntValue(1);
402      incrOpenLayers.Successor = newLayerResultsCollector;
403
404      newLayerResultsCollector.CollectedValues.Add(new ScopeTreeLookupParameter<ResultCollection>("LayerResults", "Result set for each layer", "LayerResults"));
405      newLayerResultsCollector.CopyValue = new BoolValue(false);
406      newLayerResultsCollector.Successor = null;
407
408      return layerOpener;
409    }
410
411    private CombinedOperator CreateReseeder() {
412      var reseeder = new CombinedOperator() { Name = "Reseed Layer Zero if needed" };
413      var reseedingController = new ReseedingController() { Name = "Reseeding needed (Generation % AgeGap == 0)?" };
414      var removeIndividuals = new SubScopesRemover();
415      var createIndividuals = new SolutionsCreator();
416      var initializeAgeProsessor = new UniformSubScopesProcessor();
417      var initializeAge = new VariableCreator() { Name = "Initialize Age" };
418      var incrEvaluatedSolutionsAfterReseeding = new SubScopesCounter() { Name = "Update EvaluatedSolutions" };
419
420      reseeder.OperatorGraph.InitialOperator = reseedingController;
421
422      reseedingController.GenerationsParameter.ActualName = "Generations";
423      reseedingController.AgeGapParameter.ActualName = AgeGapParameter.Name;
424      reseedingController.FirstLayerOperator = removeIndividuals;
425      reseedingController.Successor = null;
426
427      removeIndividuals.Successor = createIndividuals;
428
429      createIndividuals.NumberOfSolutionsParameter.ActualName = PopulationSizeParameter.Name;
430      createIndividuals.Successor = initializeAgeProsessor;
431
432      initializeAgeProsessor.Operator = initializeAge;
433      initializeAgeProsessor.Successor = incrEvaluatedSolutionsAfterReseeding;
434
435      initializeAge.CollectedValues.Add(new ValueParameter<DoubleValue>(AgeParameter.Name, new DoubleValue(0)));
436
437      incrEvaluatedSolutionsAfterReseeding.ValueParameter.ActualName = EvaluatedSolutionsParameter.Name;
438      incrEvaluatedSolutionsAfterReseeding.AccumulateParameter.Value = new BoolValue(true);
439
440      return reseeder;
441    }
442  }
443}
Note: See TracBrowser for help on using the repository browser.