Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3/IslandOffspringSelectionGeneticAlgorithmMainLoop.cs @ 16568

Last change on this file since 16568 was 16565, checked in by gkronber, 6 years ago

#2520: merged changes from PersistenceOverhaul branch (r16451:16564) into trunk

File size: 29.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2019 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;
30
31namespace HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm {
32  /// <summary>
33  /// An island offspring selection genetic algorithm main loop operator.
34  /// </summary>
35  [Item("IslandOffspringSelectionGeneticAlgorithmMainLoop", "An island offspring selection genetic algorithm main loop operator.")]
36  [StorableType("C7F1B472-A58A-46DA-AF59-C9D971AF9F3A")]
37  public sealed class IslandOffspringSelectionGeneticAlgorithmMainLoop : AlgorithmOperator {
38    #region Parameter Properties
39    public ValueLookupParameter<IRandom> RandomParameter {
40      get { return (ValueLookupParameter<IRandom>)Parameters["Random"]; }
41    }
42    public ValueLookupParameter<BoolValue> MaximizationParameter {
43      get { return (ValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
44    }
45    public ScopeTreeLookupParameter<DoubleValue> QualityParameter {
46      get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
47    }
48    public ValueLookupParameter<DoubleValue> BestKnownQualityParameter {
49      get { return (ValueLookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
50    }
51    public ValueLookupParameter<IntValue> NumberOfIslandsParameter {
52      get { return (ValueLookupParameter<IntValue>)Parameters["NumberOfIslands"]; }
53    }
54    public ValueLookupParameter<IntValue> MigrationIntervalParameter {
55      get { return (ValueLookupParameter<IntValue>)Parameters["MigrationInterval"]; }
56    }
57    public ValueLookupParameter<PercentValue> MigrationRateParameter {
58      get { return (ValueLookupParameter<PercentValue>)Parameters["MigrationRate"]; }
59    }
60    public ValueLookupParameter<IOperator> MigratorParameter {
61      get { return (ValueLookupParameter<IOperator>)Parameters["Migrator"]; }
62    }
63    public ValueLookupParameter<IOperator> EmigrantsSelectorParameter {
64      get { return (ValueLookupParameter<IOperator>)Parameters["EmigrantsSelector"]; }
65    }
66    public ValueLookupParameter<IOperator> ImmigrationReplacerParameter {
67      get { return (ValueLookupParameter<IOperator>)Parameters["ImmigrationReplacer"]; }
68    }
69    public ValueLookupParameter<IntValue> PopulationSizeParameter {
70      get { return (ValueLookupParameter<IntValue>)Parameters["PopulationSize"]; }
71    }
72    public ValueLookupParameter<IntValue> MaximumGenerationsParameter {
73      get { return (ValueLookupParameter<IntValue>)Parameters["MaximumGenerations"]; }
74    }
75    public ValueLookupParameter<IOperator> SelectorParameter {
76      get { return (ValueLookupParameter<IOperator>)Parameters["Selector"]; }
77    }
78    public ValueLookupParameter<IOperator> CrossoverParameter {
79      get { return (ValueLookupParameter<IOperator>)Parameters["Crossover"]; }
80    }
81    public ValueLookupParameter<PercentValue> MutationProbabilityParameter {
82      get { return (ValueLookupParameter<PercentValue>)Parameters["MutationProbability"]; }
83    }
84    public ValueLookupParameter<IOperator> MutatorParameter {
85      get { return (ValueLookupParameter<IOperator>)Parameters["Mutator"]; }
86    }
87    public ValueLookupParameter<IOperator> EvaluatorParameter {
88      get { return (ValueLookupParameter<IOperator>)Parameters["Evaluator"]; }
89    }
90    public ValueLookupParameter<IntValue> ElitesParameter {
91      get { return (ValueLookupParameter<IntValue>)Parameters["Elites"]; }
92    }
93    public IValueLookupParameter<BoolValue> ReevaluateElitesParameter {
94      get { return (IValueLookupParameter<BoolValue>)Parameters["ReevaluateElites"]; }
95    }
96    public ValueLookupParameter<ResultCollection> ResultsParameter {
97      get { return (ValueLookupParameter<ResultCollection>)Parameters["Results"]; }
98    }
99    public ValueLookupParameter<IOperator> VisualizerParameter {
100      get { return (ValueLookupParameter<IOperator>)Parameters["Visualizer"]; }
101    }
102    public LookupParameter<IItem> VisualizationParameter {
103      get { return (LookupParameter<IItem>)Parameters["Visualization"]; }
104    }
105    public ValueLookupParameter<DoubleValue> SuccessRatioParameter {
106      get { return (ValueLookupParameter<DoubleValue>)Parameters["SuccessRatio"]; }
107    }
108    public LookupParameter<DoubleValue> ComparisonFactorParameter {
109      get { return (LookupParameter<DoubleValue>)Parameters["ComparisonFactor"]; }
110    }
111    public ValueLookupParameter<DoubleValue> ComparisonFactorStartParameter {
112      get { return (ValueLookupParameter<DoubleValue>)Parameters["ComparisonFactorStart"]; }
113    }
114    public ValueLookupParameter<IOperator> ComparisonFactorModifierParameter {
115      get { return (ValueLookupParameter<IOperator>)Parameters["ComparisonFactorModifier"]; }
116    }
117    public ValueLookupParameter<DoubleValue> MaximumSelectionPressureParameter {
118      get { return (ValueLookupParameter<DoubleValue>)Parameters["MaximumSelectionPressure"]; }
119    }
120    public ValueLookupParameter<BoolValue> OffspringSelectionBeforeMutationParameter {
121      get { return (ValueLookupParameter<BoolValue>)Parameters["OffspringSelectionBeforeMutation"]; }
122    }
123    public ValueLookupParameter<IOperator> AnalyzerParameter {
124      get { return (ValueLookupParameter<IOperator>)Parameters["Analyzer"]; }
125    }
126    public ValueLookupParameter<IOperator> IslandAnalyzerParameter {
127      get { return (ValueLookupParameter<IOperator>)Parameters["IslandAnalyzer"]; }
128    }
129    public LookupParameter<IntValue> EvaluatedSolutionsParameter {
130      get { return (LookupParameter<IntValue>)Parameters["EvaluatedSolutions"]; }
131    }
132    public IValueLookupParameter<BoolValue> FillPopulationWithParentsParameter {
133      get { return (IValueLookupParameter<BoolValue>)Parameters["FillPopulationWithParents"]; }
134    }
135    #endregion
136
137    [StorableConstructor]
138    private IslandOffspringSelectionGeneticAlgorithmMainLoop(StorableConstructorFlag _) : base(_) { }
139    private IslandOffspringSelectionGeneticAlgorithmMainLoop(IslandOffspringSelectionGeneticAlgorithmMainLoop original, Cloner cloner)
140      : base(original, cloner) {
141    }
142    public override IDeepCloneable Clone(Cloner cloner) {
143      return new IslandOffspringSelectionGeneticAlgorithmMainLoop(this, cloner);
144    }
145    public IslandOffspringSelectionGeneticAlgorithmMainLoop()
146      : base() {
147      #region Create parameters
148      Parameters.Add(new ValueLookupParameter<IRandom>("Random", "A pseudo random number generator."));
149      Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
150      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution."));
151      Parameters.Add(new ValueLookupParameter<DoubleValue>("BestKnownQuality", "The best known quality value found so far."));
152      Parameters.Add(new ValueLookupParameter<IntValue>("NumberOfIslands", "The number of islands."));
153      Parameters.Add(new ValueLookupParameter<IntValue>("MigrationInterval", "The number of generations that should pass between migration phases."));
154      Parameters.Add(new ValueLookupParameter<PercentValue>("MigrationRate", "The proportion of individuals that should migrate between the islands."));
155      Parameters.Add(new ValueLookupParameter<IOperator>("Migrator", "The migration strategy."));
156      Parameters.Add(new ValueLookupParameter<IOperator>("EmigrantsSelector", "Selects the individuals that will be migrated."));
157      Parameters.Add(new ValueLookupParameter<IOperator>("ImmigrationReplacer", "Replaces part of the original population with the immigrants."));
158      Parameters.Add(new ValueLookupParameter<IntValue>("PopulationSize", "The size of the population of solutions."));
159      Parameters.Add(new ValueLookupParameter<IntValue>("MaximumGenerations", "The maximum number of generations that should be processed."));
160      Parameters.Add(new ValueLookupParameter<IOperator>("Selector", "The operator used to select solutions for reproduction."));
161      Parameters.Add(new ValueLookupParameter<IOperator>("Crossover", "The operator used to cross solutions."));
162      Parameters.Add(new ValueLookupParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution."));
163      Parameters.Add(new ValueLookupParameter<IOperator>("Mutator", "The operator used to mutate solutions."));
164      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."));
165      Parameters.Add(new ValueLookupParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation."));
166      Parameters.Add(new ValueLookupParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)"));
167      Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The results collection to store the results."));
168      Parameters.Add(new ValueLookupParameter<IOperator>("Visualizer", "The operator used to visualize solutions."));
169      Parameters.Add(new LookupParameter<IItem>("Visualization", "The item which represents the visualization of solutions."));
170      Parameters.Add(new ValueLookupParameter<DoubleValue>("SuccessRatio", "The ratio of successful to total children that should be achieved."));
171      Parameters.Add(new LookupParameter<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]."));
172      Parameters.Add(new ValueLookupParameter<DoubleValue>("ComparisonFactorStart", "The initial value for the comparison factor."));
173      Parameters.Add(new ValueLookupParameter<IOperator>("ComparisonFactorModifier", "The operator used to modify the comparison factor."));
174      Parameters.Add(new ValueLookupParameter<DoubleValue>("MaximumSelectionPressure", "The maximum selection pressure that terminates the algorithm."));
175      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."));
176      Parameters.Add(new ValueLookupParameter<IOperator>("Analyzer", "The operator used to the analyze the islands."));
177      Parameters.Add(new ValueLookupParameter<IOperator>("IslandAnalyzer", "The operator used to analyze each island."));
178      Parameters.Add(new LookupParameter<IntValue>("EvaluatedSolutions", "The number of times solutions have been evaluated."));
179      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."));
180      #endregion
181
182      #region Create operators
183      VariableCreator variableCreator = new VariableCreator();
184      UniformSubScopesProcessor uniformSubScopesProcessor0 = new UniformSubScopesProcessor();
185      VariableCreator islandVariableCreator = new VariableCreator();
186      Placeholder islandAnalyzer1 = new Placeholder();
187      ResultsCollector islandResultsCollector1 = new ResultsCollector();
188      Assigner comparisonFactorInitializer = new Assigner();
189      Placeholder analyzer1 = new Placeholder();
190      ResultsCollector resultsCollector1 = new ResultsCollector();
191      UniformSubScopesProcessor uniformSubScopesProcessor1 = new UniformSubScopesProcessor();
192      ConditionalBranch islandTerminatedBySelectionPressure1 = new ConditionalBranch();
193      OffspringSelectionGeneticAlgorithmMainOperator mainOperator = new OffspringSelectionGeneticAlgorithmMainOperator();
194      Placeholder islandAnalyzer2 = new Placeholder();
195      ResultsCollector islandResultsCollector2 = new ResultsCollector();
196      Comparator islandSelectionPressureComparator = new Comparator();
197      ConditionalBranch islandTerminatedBySelectionPressure2 = new ConditionalBranch();
198      IntCounter terminatedIslandsCounter = new IntCounter();
199      IntCounter generationsCounter = new IntCounter();
200      IntCounter generationsSinceLastMigrationCounter = new IntCounter();
201      Comparator migrationComparator = new Comparator();
202      ConditionalBranch migrationBranch = new ConditionalBranch();
203      Assigner resetTerminatedIslandsAssigner = new Assigner();
204      Assigner resetGenerationsSinceLastMigrationAssigner = new Assigner();
205      IntCounter migrationsCounter = new IntCounter();
206      UniformSubScopesProcessor uniformSubScopesProcessor2 = new UniformSubScopesProcessor();
207      Assigner reviveIslandAssigner = new Assigner();
208      Placeholder emigrantsSelector = new Placeholder();
209      Placeholder migrator = new Placeholder();
210      UniformSubScopesProcessor uniformSubScopesProcessor3 = new UniformSubScopesProcessor();
211      Placeholder immigrationReplacer = new Placeholder();
212      Comparator generationsComparator = new Comparator();
213      Comparator terminatedIslandsComparator = new Comparator();
214      Comparator maxEvaluatedSolutionsComparator = new Comparator();
215      Placeholder comparisonFactorModifier = new Placeholder();
216      Placeholder analyzer2 = new Placeholder();
217      ConditionalBranch generationsTerminationCondition = new ConditionalBranch();
218      ConditionalBranch terminatedIslandsCondition = new ConditionalBranch();
219      ConditionalBranch evaluatedSolutionsTerminationCondition = new ConditionalBranch();
220
221      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Migrations", new IntValue(0)));
222      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Generations", new IntValue(0))); // Class IslandOffspringSelectionGeneticAlgorithm expects this to be called Generations
223      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("GenerationsSinceLastMigration", new IntValue(0)));
224      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("TerminatedIslands", new IntValue(0)));
225
226      islandVariableCreator.CollectedValues.Add(new ValueParameter<ResultCollection>(ResultsParameter.Name, new ResultCollection()));
227      islandVariableCreator.CollectedValues.Add(new ValueParameter<BoolValue>("TerminateSelectionPressure", new BoolValue(false)));
228      islandVariableCreator.CollectedValues.Add(new ValueParameter<DoubleValue>("SelectionPressure", new DoubleValue(0)));
229
230      islandAnalyzer1.Name = "Island Analyzer (placeholder)";
231      islandAnalyzer1.OperatorParameter.ActualName = IslandAnalyzerParameter.Name;
232
233      islandResultsCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Selection Pressure", "Displays the rising selection pressure during a generation.", "SelectionPressure"));
234      islandResultsCollector1.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"));
235      islandResultsCollector1.ResultsParameter.ActualName = ResultsParameter.Name;
236
237      comparisonFactorInitializer.Name = "Initialize Comparison Factor";
238      comparisonFactorInitializer.LeftSideParameter.ActualName = ComparisonFactorParameter.Name;
239      comparisonFactorInitializer.RightSideParameter.ActualName = ComparisonFactorStartParameter.Name;
240
241      analyzer1.Name = "Analyzer (placeholder)";
242      analyzer1.OperatorParameter.ActualName = AnalyzerParameter.Name;
243
244      resultsCollector1.CopyValue = new BoolValue(false);
245      resultsCollector1.CollectedValues.Add(new LookupParameter<IntValue>("Migrations"));
246      resultsCollector1.CollectedValues.Add(new LookupParameter<IntValue>("Generations"));
247      resultsCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Comparison Factor", null, ComparisonFactorParameter.Name));
248      resultsCollector1.CollectedValues.Add(new ScopeTreeLookupParameter<ResultCollection>("IslandResults", "Result set for each island", ResultsParameter.Name));
249      resultsCollector1.ResultsParameter.ActualName = ResultsParameter.Name;
250
251      islandTerminatedBySelectionPressure1.Name = "Island Terminated ?";
252      islandTerminatedBySelectionPressure1.ConditionParameter.ActualName = "TerminateSelectionPressure";
253
254      mainOperator.ComparisonFactorParameter.ActualName = ComparisonFactorParameter.Name;
255      mainOperator.CrossoverParameter.ActualName = CrossoverParameter.Name;
256      mainOperator.CurrentSuccessRatioParameter.ActualName = "CurrentSuccessRatio";
257      mainOperator.ElitesParameter.ActualName = ElitesParameter.Name;
258      mainOperator.ReevaluateElitesParameter.ActualName = ReevaluateElitesParameter.Name;
259      mainOperator.EvaluatedSolutionsParameter.ActualName = EvaluatedSolutionsParameter.Name;
260      mainOperator.EvaluatorParameter.ActualName = EvaluatorParameter.Name;
261      mainOperator.MaximizationParameter.ActualName = MaximizationParameter.Name;
262      mainOperator.MaximumSelectionPressureParameter.ActualName = MaximumSelectionPressureParameter.Name;
263      mainOperator.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
264      mainOperator.MutatorParameter.ActualName = MutatorParameter.Name;
265      mainOperator.OffspringSelectionBeforeMutationParameter.ActualName = OffspringSelectionBeforeMutationParameter.Name;
266      mainOperator.QualityParameter.ActualName = QualityParameter.Name;
267      mainOperator.RandomParameter.ActualName = RandomParameter.Name;
268      mainOperator.SelectionPressureParameter.ActualName = "SelectionPressure";
269      mainOperator.SelectorParameter.ActualName = SelectorParameter.Name;
270      mainOperator.SuccessRatioParameter.ActualName = SuccessRatioParameter.Name;
271      mainOperator.FillPopulationWithParentsParameter.ActualName = FillPopulationWithParentsParameter.Name;
272
273      islandAnalyzer2.Name = "Island Analyzer (placeholder)";
274      islandAnalyzer2.OperatorParameter.ActualName = IslandAnalyzerParameter.Name;
275
276      islandResultsCollector2.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Selection Pressure", "Displays the rising selection pressure during a generation.", "SelectionPressure"));
277      islandResultsCollector2.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"));
278      islandResultsCollector2.ResultsParameter.ActualName = "Results";
279
280      islandSelectionPressureComparator.Name = "SelectionPressure >= MaximumSelectionPressure ?";
281      islandSelectionPressureComparator.LeftSideParameter.ActualName = "SelectionPressure";
282      islandSelectionPressureComparator.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
283      islandSelectionPressureComparator.RightSideParameter.ActualName = MaximumSelectionPressureParameter.Name;
284      islandSelectionPressureComparator.ResultParameter.ActualName = "TerminateSelectionPressure";
285
286      islandTerminatedBySelectionPressure2.Name = "Island Terminated ?";
287      islandTerminatedBySelectionPressure2.ConditionParameter.ActualName = "TerminateSelectionPressure";
288
289      terminatedIslandsCounter.Name = "TerminatedIslands + 1";
290      terminatedIslandsCounter.ValueParameter.ActualName = "TerminatedIslands";
291      terminatedIslandsCounter.Increment = new IntValue(1);
292
293      generationsCounter.Name = "Generations + 1";
294      generationsCounter.ValueParameter.ActualName = "Generations";
295      generationsCounter.Increment = new IntValue(1);
296
297      generationsSinceLastMigrationCounter.Name = "GenerationsSinceLastMigration + 1";
298      generationsSinceLastMigrationCounter.ValueParameter.ActualName = "GenerationsSinceLastMigration";
299      generationsSinceLastMigrationCounter.Increment = new IntValue(1);
300
301      migrationComparator.Name = "GenerationsSinceLastMigration = MigrationInterval ?";
302      migrationComparator.LeftSideParameter.ActualName = "GenerationsSinceLastMigration";
303      migrationComparator.Comparison = new Comparison(ComparisonType.Equal);
304      migrationComparator.RightSideParameter.ActualName = MigrationIntervalParameter.Name;
305      migrationComparator.ResultParameter.ActualName = "Migrate";
306
307      migrationBranch.Name = "Migrate?";
308      migrationBranch.ConditionParameter.ActualName = "Migrate";
309
310      resetTerminatedIslandsAssigner.Name = "Reset TerminatedIslands";
311      resetTerminatedIslandsAssigner.LeftSideParameter.ActualName = "TerminatedIslands";
312      resetTerminatedIslandsAssigner.RightSideParameter.Value = new IntValue(0);
313
314      resetGenerationsSinceLastMigrationAssigner.Name = "Reset GenerationsSinceLastMigration";
315      resetGenerationsSinceLastMigrationAssigner.LeftSideParameter.ActualName = "GenerationsSinceLastMigration";
316      resetGenerationsSinceLastMigrationAssigner.RightSideParameter.Value = new IntValue(0);
317
318      migrationsCounter.Name = "Migrations + 1";
319      migrationsCounter.IncrementParameter.Value = new IntValue(1);
320      migrationsCounter.ValueParameter.ActualName = "Migrations";
321
322      reviveIslandAssigner.Name = "Revive Island";
323      reviveIslandAssigner.LeftSideParameter.ActualName = "TerminateSelectionPressure";
324      reviveIslandAssigner.RightSideParameter.Value = new BoolValue(false);
325
326      emigrantsSelector.Name = "Emigrants Selector (placeholder)";
327      emigrantsSelector.OperatorParameter.ActualName = EmigrantsSelectorParameter.Name;
328
329      migrator.Name = "Migrator (placeholder)";
330      migrator.OperatorParameter.ActualName = MigratorParameter.Name;
331
332      immigrationReplacer.Name = "Immigration Replacer (placeholder)";
333      immigrationReplacer.OperatorParameter.ActualName = ImmigrationReplacerParameter.Name;
334
335      generationsComparator.Name = "Generations >= MaximumGenerations ?";
336      generationsComparator.LeftSideParameter.ActualName = "Generations";
337      generationsComparator.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
338      generationsComparator.RightSideParameter.ActualName = MaximumGenerationsParameter.Name;
339      generationsComparator.ResultParameter.ActualName = "TerminateGenerations";
340
341      terminatedIslandsComparator.Name = "All Islands terminated ?";
342      terminatedIslandsComparator.LeftSideParameter.ActualName = "TerminatedIslands";
343      terminatedIslandsComparator.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
344      terminatedIslandsComparator.RightSideParameter.ActualName = NumberOfIslandsParameter.Name;
345      terminatedIslandsComparator.ResultParameter.ActualName = "TerminateTerminatedIslands";
346
347      maxEvaluatedSolutionsComparator.Name = "EvaluatedSolutions >= MaximumEvaluatedSolutions ?";
348      maxEvaluatedSolutionsComparator.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
349      maxEvaluatedSolutionsComparator.LeftSideParameter.ActualName = EvaluatedSolutionsParameter.Name;
350      maxEvaluatedSolutionsComparator.ResultParameter.ActualName = "TerminateEvaluatedSolutions";
351      maxEvaluatedSolutionsComparator.RightSideParameter.ActualName = "MaximumEvaluatedSolutions";
352
353      comparisonFactorModifier.Name = "Update Comparison Factor (Placeholder)";
354      comparisonFactorModifier.OperatorParameter.ActualName = ComparisonFactorModifierParameter.Name;
355
356      analyzer2.Name = "Analyzer (placeholder)";
357      analyzer2.OperatorParameter.ActualName = AnalyzerParameter.Name;
358
359      generationsTerminationCondition.Name = "Terminate (MaxGenerations) ?";
360      generationsTerminationCondition.ConditionParameter.ActualName = "TerminateGenerations";
361
362      terminatedIslandsCondition.Name = "Terminate (TerminatedIslands) ?";
363      terminatedIslandsCondition.ConditionParameter.ActualName = "TerminateTerminatedIslands";
364
365      evaluatedSolutionsTerminationCondition.Name = "Terminate (EvaluatedSolutions) ?";
366      evaluatedSolutionsTerminationCondition.ConditionParameter.ActualName = "TerminateEvaluatedSolutions";
367      #endregion
368
369      #region Create operator graph
370      OperatorGraph.InitialOperator = variableCreator;
371      variableCreator.Successor = uniformSubScopesProcessor0;
372      uniformSubScopesProcessor0.Operator = islandVariableCreator;
373      uniformSubScopesProcessor0.Successor = comparisonFactorInitializer;
374      islandVariableCreator.Successor = islandAnalyzer1;
375      islandAnalyzer1.Successor = islandResultsCollector1;
376      islandResultsCollector1.Successor = null;
377      comparisonFactorInitializer.Successor = analyzer1;
378      analyzer1.Successor = resultsCollector1;
379      resultsCollector1.Successor = uniformSubScopesProcessor1;
380      uniformSubScopesProcessor1.Operator = islandTerminatedBySelectionPressure1;
381      uniformSubScopesProcessor1.Successor = generationsCounter;
382      islandTerminatedBySelectionPressure1.TrueBranch = null;
383      islandTerminatedBySelectionPressure1.FalseBranch = mainOperator;
384      islandTerminatedBySelectionPressure1.Successor = null;
385      mainOperator.Successor = islandAnalyzer2;
386      islandAnalyzer2.Successor = islandResultsCollector2;
387      islandResultsCollector2.Successor = islandSelectionPressureComparator;
388      islandSelectionPressureComparator.Successor = islandTerminatedBySelectionPressure2;
389      islandTerminatedBySelectionPressure2.TrueBranch = terminatedIslandsCounter;
390      islandTerminatedBySelectionPressure2.FalseBranch = null;
391      islandTerminatedBySelectionPressure2.Successor = null;
392      generationsCounter.Successor = generationsSinceLastMigrationCounter;
393      generationsSinceLastMigrationCounter.Successor = migrationComparator;
394      migrationComparator.Successor = migrationBranch;
395      migrationBranch.TrueBranch = resetTerminatedIslandsAssigner;
396      migrationBranch.FalseBranch = null;
397      migrationBranch.Successor = generationsComparator;
398      resetTerminatedIslandsAssigner.Successor = resetGenerationsSinceLastMigrationAssigner;
399      resetGenerationsSinceLastMigrationAssigner.Successor = migrationsCounter;
400      migrationsCounter.Successor = uniformSubScopesProcessor2;
401      uniformSubScopesProcessor2.Operator = reviveIslandAssigner;
402      uniformSubScopesProcessor2.Successor = migrator;
403      reviveIslandAssigner.Successor = emigrantsSelector;
404      emigrantsSelector.Successor = null;
405      migrator.Successor = uniformSubScopesProcessor3;
406      uniformSubScopesProcessor3.Operator = immigrationReplacer;
407      uniformSubScopesProcessor3.Successor = null;
408      immigrationReplacer.Successor = null;
409      generationsComparator.Successor = terminatedIslandsComparator;
410      terminatedIslandsComparator.Successor = maxEvaluatedSolutionsComparator;
411      maxEvaluatedSolutionsComparator.Successor = comparisonFactorModifier;
412      comparisonFactorModifier.Successor = analyzer2;
413      analyzer2.Successor = generationsTerminationCondition;
414      generationsTerminationCondition.TrueBranch = null;
415      generationsTerminationCondition.FalseBranch = terminatedIslandsCondition;
416      generationsTerminationCondition.Successor = null;
417      terminatedIslandsCondition.TrueBranch = null;
418      terminatedIslandsCondition.FalseBranch = evaluatedSolutionsTerminationCondition;
419      terminatedIslandsCondition.Successor = null;
420      evaluatedSolutionsTerminationCondition.TrueBranch = null;
421      evaluatedSolutionsTerminationCondition.FalseBranch = uniformSubScopesProcessor1;
422      evaluatedSolutionsTerminationCondition.Successor = null;
423      #endregion
424    }
425
426    [StorableHook(HookType.AfterDeserialization)]
427    private void AfterDeserialization() {
428      // BackwardsCompatibility3.3
429      #region Backwards compatible code, remove with 3.4
430      if (!Parameters.ContainsKey("ReevaluateElites")) {
431        Parameters.Add(new ValueLookupParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)"));
432      }
433      if (!Parameters.ContainsKey("FillPopulationWithParents"))
434        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."));
435      #endregion
436    }
437
438    public override IOperation Apply() {
439      if (CrossoverParameter.ActualValue == null)
440        return null;
441      return base.Apply();
442    }
443  }
444}
Note: See TracBrowser for help on using the repository browser.