Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.Algorithms.ALPS/3.3/AlpsGeneticAlgorithmMainLoop.cs @ 17982

Last change on this file since 17982 was 17181, checked in by swagner, 5 years ago

#2875: Merged r17180 from trunk to stable

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