Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Enhanced OSALPS/HeuristicLab.Algorithms.ALPS/3.3/AlpsOs2MainLoop.cs @ 15432

Last change on this file since 15432 was 15432, checked in by pfleck, 5 years ago

#2849: AlpsOs2 with a ContinuousMatingPoolCreator

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