Free cookie consent management tool by TermsFeed Policy Generator

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

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