Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3040_VectorBasedGP/HeuristicLab.Algorithms.ALPS/3.3/AlpsGeneticAlgorithmMainLoop.cs @ 17456

Last change on this file since 17456 was 17180, checked in by swagner, 5 years ago

#2875: Removed years in copyrights

File size: 24.9 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.ALPS {
33
34  [Item("AlpsGeneticAlgorithmMainLoop", "An ALPS genetic algorithm main loop operator.")]
35  [StorableType("3DDD5DE1-4ACF-4E85-9A4C-30D930C44B56")]
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(StorableConstructorFlag _) : base(_) { }
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() {
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."));
136      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution."));
137      Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
138
139      Parameters.Add(new ValueLookupParameter<IOperator>("Analyzer", "The operator used to analyze all individuals from all layers combined."));
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."));
143      Parameters.Add(new ValueLookupParameter<IntValue>("PopulationSize", "The size of the population of solutions in each layer."));
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."));
155      Parameters.Add(new ValueLookupParameter<IntValue>("AgeGap", "The frequency of reseeding the lowest layer and scaling factor for the age-limits for the layers."));
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."));
157      Parameters.Add(new ValueLookupParameter<IntArray>("AgeLimits", "The maximum age an individual is allowed to reach in a certain layer."));
158
159      Parameters.Add(new ValueLookupParameter<IntValue>("MatingPoolRange", "The range of sub - populations used for creating a mating pool. (1 = current + previous sub-population)"));
160      Parameters.Add(new ValueLookupParameter<BoolValue>("ReduceToPopulationSize", "Reduce the CurrentPopulationSize after elder migration to PopulationSize"));
161
162      Parameters.Add(new ValueLookupParameter<IOperator>("Terminator", "The termination criteria that defines if the algorithm should continue or stop"));
163
164
165      var variableCreator = new VariableCreator() { Name = "Initialize" };
166      var initLayerAnalyzerProcessor = new SubScopesProcessor();
167      var layerVariableCreator = new VariableCreator() { Name = "Initialize Layer" };
168      var initLayerAnalyzerPlaceholder = new Placeholder() { Name = "LayerAnalyzer (Placeholder)" };
169      var initAnalyzerPlaceholder = new Placeholder() { Name = "Analyzer (Placeholder)" };
170      var resultsCollector = new ResultsCollector();
171      var matingPoolCreator = new MatingPoolCreator() { Name = "Create Mating Pools" };
172      var matingPoolProcessor = new UniformSubScopesProcessor() { Name = "Process Mating Pools" };
173      var initializeLayer = new Assigner() { Name = "Reset LayerEvaluatedSolutions" };
174      var mainOperator = new AlpsGeneticAlgorithmMainOperator();
175      var generationsIcrementor = new IntCounter() { Name = "Increment Generations" };
176      var evaluatedSolutionsReducer = new DataReducer() { Name = "Increment EvaluatedSolutions" };
177      var eldersEmigrator = CreateEldersEmigrator();
178      var layerOpener = CreateLayerOpener();
179      var layerReseeder = CreateReseeder();
180      var layerAnalyzerProcessor = new UniformSubScopesProcessor();
181      var layerAnalyzerPlaceholder = new Placeholder() { Name = "LayerAnalyzer (Placeholder)" };
182      var analyzerPlaceholder = new Placeholder() { Name = "Analyzer (Placeholder)" };
183      var termination = new TerminationOperator();
184
185      OperatorGraph.InitialOperator = variableCreator;
186
187      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Generations", new IntValue(0)));
188      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("OpenLayers", new IntValue(1)));
189      variableCreator.Successor = initLayerAnalyzerProcessor;
190
191      initLayerAnalyzerProcessor.Operators.Add(layerVariableCreator);
192      initLayerAnalyzerProcessor.Successor = initAnalyzerPlaceholder;
193
194      layerVariableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Layer", new IntValue(0)));
195      layerVariableCreator.CollectedValues.Add(new ValueParameter<ResultCollection>("LayerResults"));
196      layerVariableCreator.Successor = initLayerAnalyzerPlaceholder;
197
198      initLayerAnalyzerPlaceholder.OperatorParameter.ActualName = LayerAnalyzerParameter.Name;
199      initLayerAnalyzerPlaceholder.Successor = null;
200
201      initAnalyzerPlaceholder.OperatorParameter.ActualName = AnalyzerParameter.Name;
202      initAnalyzerPlaceholder.Successor = resultsCollector;
203
204      resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Generations"));
205      resultsCollector.CollectedValues.Add(new ScopeTreeLookupParameter<ResultCollection>("LayerResults", "Result set for each Layer", "LayerResults"));
206      resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("OpenLayers"));
207      resultsCollector.CopyValue = new BoolValue(false);
208      resultsCollector.Successor = matingPoolCreator;
209
210      matingPoolCreator.MatingPoolRangeParameter.Value = null;
211      matingPoolCreator.MatingPoolRangeParameter.ActualName = MatingPoolRangeParameter.Name;
212      matingPoolCreator.Successor = matingPoolProcessor;
213
214      matingPoolProcessor.Parallel.Value = true;
215      matingPoolProcessor.Operator = initializeLayer;
216      matingPoolProcessor.Successor = generationsIcrementor;
217
218      initializeLayer.LeftSideParameter.ActualName = "LayerEvaluatedSolutions";
219      initializeLayer.RightSideParameter.Value = new IntValue(0);
220      initializeLayer.Successor = mainOperator;
221
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
240      generationsIcrementor.ValueParameter.ActualName = "Generations";
241      generationsIcrementor.Increment = new IntValue(1);
242      generationsIcrementor.Successor = evaluatedSolutionsReducer;
243
244      evaluatedSolutionsReducer.ParameterToReduce.ActualName = "LayerEvaluatedSolutions";
245      evaluatedSolutionsReducer.TargetParameter.ActualName = EvaluatedSolutionsParameter.Name;
246      evaluatedSolutionsReducer.ReductionOperation.Value = new ReductionOperation(ReductionOperations.Sum);
247      evaluatedSolutionsReducer.TargetOperation.Value = new ReductionOperation(ReductionOperations.Sum);
248      evaluatedSolutionsReducer.Successor = eldersEmigrator;
249
250      eldersEmigrator.Successor = layerOpener;
251
252      layerOpener.Successor = layerReseeder;
253
254      layerReseeder.Successor = layerAnalyzerProcessor;
255
256      layerAnalyzerProcessor.Operator = layerAnalyzerPlaceholder;
257      layerAnalyzerProcessor.Successor = analyzerPlaceholder;
258
259      layerAnalyzerPlaceholder.OperatorParameter.ActualName = LayerAnalyzerParameter.Name;
260
261      analyzerPlaceholder.OperatorParameter.ActualName = AnalyzerParameter.Name;
262      analyzerPlaceholder.Successor = termination;
263
264      termination.TerminatorParameter.ActualName = TerminatorParameter.Name;
265      termination.ContinueBranch = matingPoolCreator;
266    }
267
268    private CombinedOperator CreateEldersEmigrator() {
269      var eldersEmigrator = new CombinedOperator() { Name = "Emigrate Elders" };
270      var selectorProsessor = new UniformSubScopesProcessor();
271      var eldersSelector = new EldersSelector();
272      var shiftToRightMigrator = new UnidirectionalRingMigrator() { Name = "Shift elders to next layer" };
273      var mergingProsessor = new UniformSubScopesProcessor();
274      var mergingReducer = new MergingReducer();
275      var subScopesCounter = new SubScopesCounter();
276      var reduceToPopulationSizeBranch = new ConditionalBranch() { Name = "ReduceToPopulationSize?" };
277      var countCalculator = new ExpressionCalculator() { Name = "CurrentPopulationSize = Min(CurrentPopulationSize, PopulationSize)" };
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
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
292      shiftToRightMigrator.ClockwiseMigrationParameter.Value = new BoolValue(true);
293      shiftToRightMigrator.Successor = mergingProsessor;
294
295      mergingProsessor.Operator = mergingReducer;
296
297      mergingReducer.Successor = subScopesCounter;
298
299      subScopesCounter.ValueParameter.ActualName = CurrentPopulationSizeParameter.Name;
300      subScopesCounter.AccumulateParameter.Value = new BoolValue(false);
301      subScopesCounter.Successor = reduceToPopulationSizeBranch;
302
303      reduceToPopulationSizeBranch.ConditionParameter.ActualName = ReduceToPopulationSizeParameter.Name;
304      reduceToPopulationSizeBranch.TrueBranch = countCalculator;
305
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;
310      countCalculator.Successor = bestSelector;
311
312      bestSelector.NumberOfSelectedSubScopesParameter.ActualName = CurrentPopulationSizeParameter.Name;
313      bestSelector.CopySelected = new BoolValue(false);
314      bestSelector.Successor = rightReducer;
315
316      return eldersEmigrator;
317    }
318
319    private CombinedOperator CreateLayerOpener() {
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?" };
325      var layerCreator = new LastLayerCloner() { Name = "Create Layer" };
326      var updateLayerNumber = new Assigner() { Name = "Layer = OpenLayers" };
327      var historyWiper = new ResultsHistoryWiper() { Name = "Clear History in Results" };
328      var createChildrenViaCrossover = new AlpsGeneticAlgorithmMainOperator();
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";
336      maxLayerReached.RightSideParameter.ActualName = NumberOfLayersParameter.Name;
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
344      openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntArray>(AgeLimitsParameter.Name));
345      openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntValue>("Generations"));
346      openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntValue>(NumberOfLayersParameter.Name));
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
355      layerCreator.NewLayerOperator = updateLayerNumber;
356      layerCreator.Successor = incrOpenLayers;
357
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);
382      createChildrenViaCrossover.Successor = incrEvaluatedSolutionsForNewLayer;
383
384      incrEvaluatedSolutionsForNewLayer.ValueParameter.ActualName = EvaluatedSolutionsParameter.Name;
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
398    private CombinedOperator CreateReseeder() {
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
409      reseedingController.GenerationsParameter.ActualName = "Generations";
410      reseedingController.AgeGapParameter.ActualName = AgeGapParameter.Name;
411      reseedingController.FirstLayerOperator = removeIndividuals;
412      reseedingController.Successor = null;
413
414      removeIndividuals.Successor = createIndividuals;
415
416      createIndividuals.NumberOfSolutionsParameter.ActualName = PopulationSizeParameter.Name;
417      createIndividuals.Successor = initializeAgeProsessor;
418
419      initializeAgeProsessor.Operator = initializeAge;
420      initializeAgeProsessor.Successor = incrEvaluatedSolutionsAfterReseeding;
421
422      initializeAge.CollectedValues.Add(new ValueParameter<DoubleValue>(AgeParameter.Name, new DoubleValue(0)));
423
424      incrEvaluatedSolutionsAfterReseeding.ValueParameter.ActualName = EvaluatedSolutionsParameter.Name;
425      incrEvaluatedSolutionsAfterReseeding.AccumulateParameter.Value = new BoolValue(true);
426
427      return reseeder;
428    }
429  }
430}
Note: See TracBrowser for help on using the repository browser.