Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 16796 was 15584, checked in by swagner, 7 years ago

#2640: Updated year of copyrights in license headers on stable

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