Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 13810 was 13206, checked in by pfleck, 9 years ago

#2269 Fixed typos and renamed some stuff suggested by ascheibe and adapted project for mono.

  • The initialization of layer 0 is done similar to other algorithms where general initialization is done in the algorithm itself and variables used and produced during the main-loop is initialized in the main-loop-operator.
  • The GeneralizedRankSelector is used as default selector because it generally works the best (rank compensates the large quality range of multiple layers and high selection pressure via pressure-parameter). Proportional selection performs very badly because the selection pressure is too low for ALPS.
  • Concerning ReduceToPopulationSize in the EldersEmigrator, the behavior it is not completely clear in the original paper. Reducing the population to the population size seems the more logical way, therefore it is default. An empty layer could happen in extremely rare situations, but it never happens to me so far.
  • Concerning opening a new layer, when taking a closer look at the ages, all individual tends to be as old as possible, in the standard version with AgeInheritance==1. That means they usually get too old in exactly after the generation the AgeLimits for the current last layer states. This way it is not necessary to check if any individual becomes too old for the current last layer. For AgeInheritance<1 it can happen that there would actually be no need to open a new layer; however, it will be opened anyway.
File size: 24.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 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 HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30using HeuristicLab.Selection;
31
32namespace HeuristicLab.Algorithms.ALPS {
33
34  [Item("AlpsGeneticAlgorithmMainLoop", "An ALPS genetic algorithm main loop operator.")]
35  [StorableClass]
36  public sealed class AlpsGeneticAlgorithmMainLoop : AlgorithmOperator {
37    #region Parameter Properties
38    public IValueLookupParameter<IRandom> GlobalRandomParameter {
39      get { return (IValueLookupParameter<IRandom>)Parameters["GlobalRandom"]; }
40    }
41    public IValueLookupParameter<IRandom> LocalRandomParameter {
42      get { return (IValueLookupParameter<IRandom>)Parameters["LocalRandom"]; }
43    }
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
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
65    public IValueLookupParameter<IntValue> NumberOfLayersParameter {
66      get { return (IValueLookupParameter<IntValue>)Parameters["NumberOfLayers"]; }
67    }
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    }
74
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    }
100    public IValueLookupParameter<IntValue> AgeGapParameter {
101      get { return (IValueLookupParameter<IntValue>)Parameters["AgeGap"]; }
102    }
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    }
116
117    public IValueLookupParameter<IOperator> TerminatorParameter {
118      get { return (IValueLookupParameter<IOperator>)Parameters["Terminator"]; }
119    }
120    #endregion
121
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() {
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."));
137      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution."));
138      Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
139
140      Parameters.Add(new ValueLookupParameter<IOperator>("Analyzer", "The operator used to analyze all individuals from all layers combined."));
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."));
144      Parameters.Add(new ValueLookupParameter<IntValue>("PopulationSize", "The size of the population of solutions in each layer."));
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."));
156      Parameters.Add(new ValueLookupParameter<IntValue>("AgeGap", "The frequency of reseeding the lowest layer and scaling factor for the age-limits for the layers."));
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."));
158      Parameters.Add(new ValueLookupParameter<IntArray>("AgeLimits", "The maximum age an individual is allowed to reach in a certain layer."));
159
160      Parameters.Add(new ValueLookupParameter<IntValue>("MatingPoolRange", "The range of sub - populations used for creating a mating pool. (1 = current + previous sub-population)"));
161      Parameters.Add(new ValueLookupParameter<BoolValue>("ReduceToPopulationSize", "Reduce the CurrentPopulationSize after elder migration to PopulationSize"));
162
163      Parameters.Add(new ValueLookupParameter<IOperator>("Terminator", "The termination criteria that defines if the algorithm should continue or stop"));
164
165
166      var variableCreator = new VariableCreator() { Name = "Initialize" };
167      var initLayerAnalyzerProcessor = new SubScopesProcessor();
168      var layerVariableCreator = new VariableCreator() { Name = "Initialize Layer" };
169      var initLayerAnalyzerPlaceholder = new Placeholder() { Name = "LayerAnalyzer (Placeholder)" };
170      var initAnalyzerPlaceholder = new Placeholder() { Name = "Analyzer (Placeholder)" };
171      var resultsCollector = new ResultsCollector();
172      var matingPoolCreator = new MatingPoolCreator() { Name = "Create Mating Pools" };
173      var matingPoolProcessor = new UniformSubScopesProcessor() { Name = "Process Mating Pools" };
174      var initializeLayer = new Assigner() { Name = "Reset LayerEvaluatedSolutions" };
175      var mainOperator = new AlpsGeneticAlgorithmMainOperator();
176      var generationsIcrementor = new IntCounter() { Name = "Increment Generations" };
177      var evaluatedSolutionsReducer = new DataReducer() { Name = "Increment EvaluatedSolutions" };
178      var eldersEmigrator = CreateEldersEmigrator();
179      var layerOpener = CreateLayerOpener();
180      var layerReseeder = CreateReseeder();
181      var layerAnalyzerProcessor = new UniformSubScopesProcessor();
182      var layerAnalyzerPlaceholder = new Placeholder() { Name = "LayerAnalyzer (Placeholder)" };
183      var analyzerPlaceholder = new Placeholder() { Name = "Analyzer (Placeholder)" };
184      var termination = new TerminationOperator();
185
186      OperatorGraph.InitialOperator = variableCreator;
187
188      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Generations", new IntValue(0)));
189      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("OpenLayers", new IntValue(1)));
190      variableCreator.Successor = initLayerAnalyzerProcessor;
191
192      initLayerAnalyzerProcessor.Operators.Add(layerVariableCreator);
193      initLayerAnalyzerProcessor.Successor = initAnalyzerPlaceholder;
194
195      layerVariableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Layer", new IntValue(0)));
196      layerVariableCreator.CollectedValues.Add(new ValueParameter<ResultCollection>("LayerResults"));
197      layerVariableCreator.Successor = initLayerAnalyzerPlaceholder;
198
199      initLayerAnalyzerPlaceholder.OperatorParameter.ActualName = LayerAnalyzerParameter.Name;
200      initLayerAnalyzerPlaceholder.Successor = null;
201
202      initAnalyzerPlaceholder.OperatorParameter.ActualName = AnalyzerParameter.Name;
203      initAnalyzerPlaceholder.Successor = resultsCollector;
204
205      resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Generations"));
206      resultsCollector.CollectedValues.Add(new ScopeTreeLookupParameter<ResultCollection>("LayerResults", "Result set for each Layer", "LayerResults"));
207      resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("OpenLayers"));
208      resultsCollector.CopyValue = new BoolValue(false);
209      resultsCollector.Successor = matingPoolCreator;
210
211      matingPoolCreator.MatingPoolRangeParameter.Value = null;
212      matingPoolCreator.MatingPoolRangeParameter.ActualName = MatingPoolRangeParameter.Name;
213      matingPoolCreator.Successor = matingPoolProcessor;
214
215      matingPoolProcessor.Parallel.Value = true;
216      matingPoolProcessor.Operator = initializeLayer;
217      matingPoolProcessor.Successor = generationsIcrementor;
218
219      initializeLayer.LeftSideParameter.ActualName = "LayerEvaluatedSolutions";
220      initializeLayer.RightSideParameter.Value = new IntValue(0);
221      initializeLayer.Successor = mainOperator;
222
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
241      generationsIcrementor.ValueParameter.ActualName = "Generations";
242      generationsIcrementor.Increment = new IntValue(1);
243      generationsIcrementor.Successor = evaluatedSolutionsReducer;
244
245      evaluatedSolutionsReducer.ParameterToReduce.ActualName = "LayerEvaluatedSolutions";
246      evaluatedSolutionsReducer.TargetParameter.ActualName = EvaluatedSolutionsParameter.Name;
247      evaluatedSolutionsReducer.ReductionOperation.Value = new ReductionOperation(ReductionOperations.Sum);
248      evaluatedSolutionsReducer.TargetOperation.Value = new ReductionOperation(ReductionOperations.Sum);
249      evaluatedSolutionsReducer.Successor = eldersEmigrator;
250
251      eldersEmigrator.Successor = layerOpener;
252
253      layerOpener.Successor = layerReseeder;
254
255      layerReseeder.Successor = layerAnalyzerProcessor;
256
257      layerAnalyzerProcessor.Operator = layerAnalyzerPlaceholder;
258      layerAnalyzerProcessor.Successor = analyzerPlaceholder;
259
260      layerAnalyzerPlaceholder.OperatorParameter.ActualName = LayerAnalyzerParameter.Name;
261
262      analyzerPlaceholder.OperatorParameter.ActualName = AnalyzerParameter.Name;
263      analyzerPlaceholder.Successor = termination;
264
265      termination.TerminatorParameter.ActualName = TerminatorParameter.Name;
266      termination.ContinueBranch = matingPoolCreator;
267    }
268
269    private CombinedOperator CreateEldersEmigrator() {
270      var eldersEmigrator = new CombinedOperator() { Name = "Emigrate Elders" };
271      var selectorProsessor = new UniformSubScopesProcessor();
272      var eldersSelector = new EldersSelector();
273      var shiftToRightMigrator = new UnidirectionalRingMigrator() { Name = "Shift elders to next layer" };
274      var mergingProsessor = new UniformSubScopesProcessor();
275      var mergingReducer = new MergingReducer();
276      var subScopesCounter = new SubScopesCounter();
277      var reduceToPopulationSizeBranch = new ConditionalBranch() { Name = "ReduceToPopulationSize?" };
278      var countCalculator = new ExpressionCalculator() { Name = "CurrentPopulationSize = Min(CurrentPopulationSize, PopulationSize)" };
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
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
293      shiftToRightMigrator.ClockwiseMigrationParameter.Value = new BoolValue(true);
294      shiftToRightMigrator.Successor = mergingProsessor;
295
296      mergingProsessor.Operator = mergingReducer;
297
298      mergingReducer.Successor = subScopesCounter;
299
300      subScopesCounter.ValueParameter.ActualName = CurrentPopulationSizeParameter.Name;
301      subScopesCounter.AccumulateParameter.Value = new BoolValue(false);
302      subScopesCounter.Successor = reduceToPopulationSizeBranch;
303
304      reduceToPopulationSizeBranch.ConditionParameter.ActualName = ReduceToPopulationSizeParameter.Name;
305      reduceToPopulationSizeBranch.TrueBranch = countCalculator;
306
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;
311      countCalculator.Successor = bestSelector;
312
313      bestSelector.NumberOfSelectedSubScopesParameter.ActualName = CurrentPopulationSizeParameter.Name;
314      bestSelector.CopySelected = new BoolValue(false);
315      bestSelector.Successor = rightReducer;
316
317      return eldersEmigrator;
318    }
319
320    private CombinedOperator CreateLayerOpener() {
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?" };
326      var layerCreator = new LastLayerCloner() { Name = "Create Layer" };
327      var updateLayerNumber = new Assigner() { Name = "Layer = OpenLayers" };
328      var historyWiper = new ResultsHistoryWiper() { Name = "Clear History in Results" };
329      var createChildrenViaCrossover = new AlpsGeneticAlgorithmMainOperator();
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";
337      maxLayerReached.RightSideParameter.ActualName = NumberOfLayersParameter.Name;
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
345      openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntArray>(AgeLimitsParameter.Name));
346      openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntValue>("Generations"));
347      openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntValue>(NumberOfLayersParameter.Name));
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
356      layerCreator.NewLayerOperator = updateLayerNumber;
357      layerCreator.Successor = incrOpenLayers;
358
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);
383      createChildrenViaCrossover.Successor = incrEvaluatedSolutionsForNewLayer;
384
385      incrEvaluatedSolutionsForNewLayer.ValueParameter.ActualName = EvaluatedSolutionsParameter.Name;
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
399    private CombinedOperator CreateReseeder() {
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
410      reseedingController.GenerationsParameter.ActualName = "Generations";
411      reseedingController.AgeGapParameter.ActualName = AgeGapParameter.Name;
412      reseedingController.FirstLayerOperator = removeIndividuals;
413      reseedingController.Successor = null;
414
415      removeIndividuals.Successor = createIndividuals;
416
417      createIndividuals.NumberOfSolutionsParameter.ActualName = PopulationSizeParameter.Name;
418      createIndividuals.Successor = initializeAgeProsessor;
419
420      initializeAgeProsessor.Operator = initializeAge;
421      initializeAgeProsessor.Successor = incrEvaluatedSolutionsAfterReseeding;
422
423      initializeAge.CollectedValues.Add(new ValueParameter<DoubleValue>(AgeParameter.Name, new DoubleValue(0)));
424
425      incrEvaluatedSolutionsAfterReseeding.ValueParameter.ActualName = EvaluatedSolutionsParameter.Name;
426      incrEvaluatedSolutionsAfterReseeding.AccumulateParameter.Value = new BoolValue(true);
427
428      return reseeder;
429    }
430  }
431}
Note: See TracBrowser for help on using the repository browser.