Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataAnalysis.IslandAlgorithms/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3/IslandOffspringSelectionGeneticAlgorithmMainLoop.cs @ 13371

Last change on this file since 13371 was 11646, checked in by mkommend, 10 years ago

#1997: Merged trunk changes to data analysis island GA branch.

File size: 30.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2014 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;
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  [StorableClass]
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    public ValueLookupParameter<BoolValue> ReevaluateIndividualsAfterMigration {
136      get { return (ValueLookupParameter<BoolValue>)Parameters["ReevaluateIndividualsAfterMigration"]; }
137    }
138    #endregion
139
140    [StorableConstructor]
141    private IslandOffspringSelectionGeneticAlgorithmMainLoop(bool deserializing) : base(deserializing) { }
142    private IslandOffspringSelectionGeneticAlgorithmMainLoop(IslandOffspringSelectionGeneticAlgorithmMainLoop original, Cloner cloner)
143      : base(original, cloner) {
144    }
145    public override IDeepCloneable Clone(Cloner cloner) {
146      return new IslandOffspringSelectionGeneticAlgorithmMainLoop(this, cloner);
147    }
148    public IslandOffspringSelectionGeneticAlgorithmMainLoop()
149      : base() {
150      #region Create parameters
151      Parameters.Add(new ValueLookupParameter<IRandom>("Random", "A pseudo random number generator."));
152      Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
153      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution."));
154      Parameters.Add(new ValueLookupParameter<DoubleValue>("BestKnownQuality", "The best known quality value found so far."));
155      Parameters.Add(new ValueLookupParameter<IntValue>("NumberOfIslands", "The number of islands."));
156      Parameters.Add(new ValueLookupParameter<IntValue>("MigrationInterval", "The number of generations that should pass between migration phases."));
157      Parameters.Add(new ValueLookupParameter<PercentValue>("MigrationRate", "The proportion of individuals that should migrate between the islands."));
158      Parameters.Add(new ValueLookupParameter<IOperator>("Migrator", "The migration strategy."));
159      Parameters.Add(new ValueLookupParameter<IOperator>("EmigrantsSelector", "Selects the individuals that will be migrated."));
160      Parameters.Add(new ValueLookupParameter<IOperator>("ImmigrationReplacer", "Replaces part of the original population with the immigrants."));
161      Parameters.Add(new ValueLookupParameter<IntValue>("PopulationSize", "The size of the population of solutions."));
162      Parameters.Add(new ValueLookupParameter<IntValue>("MaximumGenerations", "The maximum number of generations that should be processed."));
163      Parameters.Add(new ValueLookupParameter<IOperator>("Selector", "The operator used to select solutions for reproduction."));
164      Parameters.Add(new ValueLookupParameter<IOperator>("Crossover", "The operator used to cross solutions."));
165      Parameters.Add(new ValueLookupParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution."));
166      Parameters.Add(new ValueLookupParameter<IOperator>("Mutator", "The operator used to mutate solutions."));
167      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."));
168      Parameters.Add(new ValueLookupParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation."));
169      Parameters.Add(new ValueLookupParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)"));
170      Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The results collection to store the results."));
171      Parameters.Add(new ValueLookupParameter<IOperator>("Visualizer", "The operator used to visualize solutions."));
172      Parameters.Add(new LookupParameter<IItem>("Visualization", "The item which represents the visualization of solutions."));
173      Parameters.Add(new ValueLookupParameter<DoubleValue>("SuccessRatio", "The ratio of successful to total children that should be achieved."));
174      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]."));
175      Parameters.Add(new ValueLookupParameter<DoubleValue>("ComparisonFactorStart", "The initial value for the comparison factor."));
176      Parameters.Add(new ValueLookupParameter<IOperator>("ComparisonFactorModifier", "The operator used to modify the comparison factor."));
177      Parameters.Add(new ValueLookupParameter<DoubleValue>("MaximumSelectionPressure", "The maximum selection pressure that terminates the algorithm."));
178      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."));
179      Parameters.Add(new ValueLookupParameter<IOperator>("Analyzer", "The operator used to the analyze the islands."));
180      Parameters.Add(new ValueLookupParameter<IOperator>("IslandAnalyzer", "The operator used to analyze each island."));
181      Parameters.Add(new LookupParameter<IntValue>("EvaluatedSolutions", "The number of times solutions have been evaluated."));
182      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."));
183      Parameters.Add(new ValueLookupParameter<BoolValue>("ReevaluateIndividualsAfterMigration", "Flag which indicates if inviduals should be reevaluated after migration."));
184      #endregion
185
186      #region Create operators
187      VariableCreator variableCreator = new VariableCreator();
188      UniformSubScopesProcessor uniformSubScopesProcessor0 = new UniformSubScopesProcessor();
189      VariableCreator islandVariableCreator = new VariableCreator();
190      Placeholder islandAnalyzer1 = new Placeholder();
191      ResultsCollector islandResultsCollector1 = new ResultsCollector();
192      Assigner comparisonFactorInitializer = new Assigner();
193      Placeholder analyzer1 = new Placeholder();
194      ResultsCollector resultsCollector1 = new ResultsCollector();
195      UniformSubScopesProcessor uniformSubScopesProcessor1 = new UniformSubScopesProcessor();
196      ConditionalBranch islandTerminatedBySelectionPressure1 = new ConditionalBranch();
197      OffspringSelectionGeneticAlgorithmMainOperator mainOperator = new OffspringSelectionGeneticAlgorithmMainOperator();
198      Placeholder islandAnalyzer2 = new Placeholder();
199      ResultsCollector islandResultsCollector2 = new ResultsCollector();
200      Comparator islandSelectionPressureComparator = new Comparator();
201      ConditionalBranch islandTerminatedBySelectionPressure2 = new ConditionalBranch();
202      IntCounter terminatedIslandsCounter = new IntCounter();
203      IntCounter generationsCounter = new IntCounter();
204      IntCounter generationsSinceLastMigrationCounter = new IntCounter();
205      Comparator migrationComparator = new Comparator();
206      ConditionalBranch migrationBranch = new ConditionalBranch();
207      Assigner resetTerminatedIslandsAssigner = new Assigner();
208      Assigner resetGenerationsSinceLastMigrationAssigner = new Assigner();
209      IntCounter migrationsCounter = new IntCounter();
210      UniformSubScopesProcessor uniformSubScopesProcessor2 = new UniformSubScopesProcessor();
211      Assigner reviveIslandAssigner = new Assigner();
212      Placeholder emigrantsSelector = new Placeholder();
213      Placeholder migrator = new Placeholder();
214      ConditionalBranch reevaluateImmigrantsBranch = new ConditionalBranch();
215      UniformSubScopesProcessor uniformSubScopesProcessor3 = new UniformSubScopesProcessor();
216      SubScopesProcessor subScopesProcessor = new SubScopesProcessor();
217      UniformSubScopesProcessor uniformSubScopesProcessor4 = new UniformSubScopesProcessor();
218      Placeholder evaluator = new Placeholder();
219      SubScopesCounter subScopesCounter = new SubScopesCounter();
220      UniformSubScopesProcessor uniformSubScopesProcessor5 = new UniformSubScopesProcessor();
221      Placeholder immigrationReplacer = new Placeholder();
222      Comparator generationsComparator = new Comparator();
223      Comparator terminatedIslandsComparator = new Comparator();
224      Comparator maxEvaluatedSolutionsComparator = new Comparator();
225      Placeholder comparisonFactorModifier = new Placeholder();
226      Placeholder analyzer2 = new Placeholder();
227      ConditionalBranch generationsTerminationCondition = new ConditionalBranch();
228      ConditionalBranch terminatedIslandsCondition = new ConditionalBranch();
229      ConditionalBranch evaluatedSolutionsTerminationCondition = new ConditionalBranch();
230
231      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Migrations", new IntValue(0)));
232      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Generations", new IntValue(0))); // Class IslandOffspringSelectionGeneticAlgorithm expects this to be called Generations
233      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("GenerationsSinceLastMigration", new IntValue(0)));
234      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("TerminatedIslands", new IntValue(0)));
235
236      islandVariableCreator.CollectedValues.Add(new ValueParameter<ResultCollection>(ResultsParameter.Name, new ResultCollection()));
237      islandVariableCreator.CollectedValues.Add(new ValueParameter<BoolValue>("TerminateSelectionPressure", new BoolValue(false)));
238      islandVariableCreator.CollectedValues.Add(new ValueParameter<DoubleValue>("SelectionPressure", new DoubleValue(0)));
239
240      islandAnalyzer1.Name = "Island Analyzer (placeholder)";
241      islandAnalyzer1.OperatorParameter.ActualName = IslandAnalyzerParameter.Name;
242
243      islandResultsCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Selection Pressure", "Displays the rising selection pressure during a generation.", "SelectionPressure"));
244      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"));
245      islandResultsCollector1.ResultsParameter.ActualName = ResultsParameter.Name;
246
247      comparisonFactorInitializer.Name = "Initialize Comparison Factor";
248      comparisonFactorInitializer.LeftSideParameter.ActualName = ComparisonFactorParameter.Name;
249      comparisonFactorInitializer.RightSideParameter.ActualName = ComparisonFactorStartParameter.Name;
250
251      analyzer1.Name = "Analyzer (placeholder)";
252      analyzer1.OperatorParameter.ActualName = AnalyzerParameter.Name;
253
254      resultsCollector1.CopyValue = new BoolValue(false);
255      resultsCollector1.CollectedValues.Add(new LookupParameter<IntValue>("Migrations"));
256      resultsCollector1.CollectedValues.Add(new LookupParameter<IntValue>("Generations"));
257      resultsCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Comparison Factor", null, ComparisonFactorParameter.Name));
258      resultsCollector1.CollectedValues.Add(new ScopeTreeLookupParameter<ResultCollection>("IslandResults", "Result set for each island", ResultsParameter.Name));
259      resultsCollector1.ResultsParameter.ActualName = ResultsParameter.Name;
260
261      islandTerminatedBySelectionPressure1.Name = "Island Terminated ?";
262      islandTerminatedBySelectionPressure1.ConditionParameter.ActualName = "TerminateSelectionPressure";
263
264      mainOperator.ComparisonFactorParameter.ActualName = ComparisonFactorParameter.Name;
265      mainOperator.CrossoverParameter.ActualName = CrossoverParameter.Name;
266      mainOperator.CurrentSuccessRatioParameter.ActualName = "CurrentSuccessRatio";
267      mainOperator.ElitesParameter.ActualName = ElitesParameter.Name;
268      mainOperator.ReevaluateElitesParameter.ActualName = ReevaluateElitesParameter.Name;
269      mainOperator.EvaluatedSolutionsParameter.ActualName = EvaluatedSolutionsParameter.Name;
270      mainOperator.EvaluatorParameter.ActualName = EvaluatorParameter.Name;
271      mainOperator.MaximizationParameter.ActualName = MaximizationParameter.Name;
272      mainOperator.MaximumSelectionPressureParameter.ActualName = MaximumSelectionPressureParameter.Name;
273      mainOperator.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
274      mainOperator.MutatorParameter.ActualName = MutatorParameter.Name;
275      mainOperator.OffspringSelectionBeforeMutationParameter.ActualName = OffspringSelectionBeforeMutationParameter.Name;
276      mainOperator.QualityParameter.ActualName = QualityParameter.Name;
277      mainOperator.RandomParameter.ActualName = RandomParameter.Name;
278      mainOperator.SelectionPressureParameter.ActualName = "SelectionPressure";
279      mainOperator.SelectorParameter.ActualName = SelectorParameter.Name;
280      mainOperator.SuccessRatioParameter.ActualName = SuccessRatioParameter.Name;
281      mainOperator.FillPopulationWithParentsParameter.ActualName = FillPopulationWithParentsParameter.Name;
282
283      islandAnalyzer2.Name = "Island Analyzer (placeholder)";
284      islandAnalyzer2.OperatorParameter.ActualName = IslandAnalyzerParameter.Name;
285
286      islandResultsCollector2.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Selection Pressure", "Displays the rising selection pressure during a generation.", "SelectionPressure"));
287      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"));
288      islandResultsCollector2.ResultsParameter.ActualName = "Results";
289
290      islandSelectionPressureComparator.Name = "SelectionPressure >= MaximumSelectionPressure ?";
291      islandSelectionPressureComparator.LeftSideParameter.ActualName = "SelectionPressure";
292      islandSelectionPressureComparator.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
293      islandSelectionPressureComparator.RightSideParameter.ActualName = MaximumSelectionPressureParameter.Name;
294      islandSelectionPressureComparator.ResultParameter.ActualName = "TerminateSelectionPressure";
295
296      islandTerminatedBySelectionPressure2.Name = "Island Terminated ?";
297      islandTerminatedBySelectionPressure2.ConditionParameter.ActualName = "TerminateSelectionPressure";
298
299      terminatedIslandsCounter.Name = "TerminatedIslands + 1";
300      terminatedIslandsCounter.ValueParameter.ActualName = "TerminatedIslands";
301      terminatedIslandsCounter.Increment = new IntValue(1);
302
303      generationsCounter.Name = "Generations + 1";
304      generationsCounter.ValueParameter.ActualName = "Generations";
305      generationsCounter.Increment = new IntValue(1);
306
307      generationsSinceLastMigrationCounter.Name = "GenerationsSinceLastMigration + 1";
308      generationsSinceLastMigrationCounter.ValueParameter.ActualName = "GenerationsSinceLastMigration";
309      generationsSinceLastMigrationCounter.Increment = new IntValue(1);
310
311      migrationComparator.Name = "GenerationsSinceLastMigration = MigrationInterval ?";
312      migrationComparator.LeftSideParameter.ActualName = "GenerationsSinceLastMigration";
313      migrationComparator.Comparison = new Comparison(ComparisonType.Equal);
314      migrationComparator.RightSideParameter.ActualName = MigrationIntervalParameter.Name;
315      migrationComparator.ResultParameter.ActualName = "Migrate";
316
317      migrationBranch.Name = "Migrate?";
318      migrationBranch.ConditionParameter.ActualName = "Migrate";
319
320      resetTerminatedIslandsAssigner.Name = "Reset TerminatedIslands";
321      resetTerminatedIslandsAssigner.LeftSideParameter.ActualName = "TerminatedIslands";
322      resetTerminatedIslandsAssigner.RightSideParameter.Value = new IntValue(0);
323
324      resetGenerationsSinceLastMigrationAssigner.Name = "Reset GenerationsSinceLastMigration";
325      resetGenerationsSinceLastMigrationAssigner.LeftSideParameter.ActualName = "GenerationsSinceLastMigration";
326      resetGenerationsSinceLastMigrationAssigner.RightSideParameter.Value = new IntValue(0);
327
328      migrationsCounter.Name = "Migrations + 1";
329      migrationsCounter.IncrementParameter.Value = new IntValue(1);
330      migrationsCounter.ValueParameter.ActualName = "Migrations";
331
332      reviveIslandAssigner.Name = "Revive Island";
333      reviveIslandAssigner.LeftSideParameter.ActualName = "TerminateSelectionPressure";
334      reviveIslandAssigner.RightSideParameter.Value = new BoolValue(false);
335
336      emigrantsSelector.Name = "Emigrants Selector (placeholder)";
337      emigrantsSelector.OperatorParameter.ActualName = EmigrantsSelectorParameter.Name;
338
339      migrator.Name = "Migrator (placeholder)";
340      migrator.OperatorParameter.ActualName = MigratorParameter.Name;
341
342      reevaluateImmigrantsBranch.ConditionParameter.ActualName = "ReevaluateImmigrants";
343      reevaluateImmigrantsBranch.Name = "Reevaluate Immigrants ?";
344
345      evaluator.Name = "Evaluator (placeholder)";
346      evaluator.OperatorParameter.ActualName = EvaluatorParameter.Name;
347
348      subScopesCounter.Name = "Increment EvaluatedSolutions";
349      subScopesCounter.ValueParameter.ActualName = EvaluatedSolutionsParameter.Name;
350
351      immigrationReplacer.Name = "Immigration Replacer (placeholder)";
352      immigrationReplacer.OperatorParameter.ActualName = ImmigrationReplacerParameter.Name;
353
354      generationsComparator.Name = "Generations >= MaximumGenerations ?";
355      generationsComparator.LeftSideParameter.ActualName = "Generations";
356      generationsComparator.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
357      generationsComparator.RightSideParameter.ActualName = MaximumGenerationsParameter.Name;
358      generationsComparator.ResultParameter.ActualName = "TerminateGenerations";
359
360      terminatedIslandsComparator.Name = "All Islands terminated ?";
361      terminatedIslandsComparator.LeftSideParameter.ActualName = "TerminatedIslands";
362      terminatedIslandsComparator.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
363      terminatedIslandsComparator.RightSideParameter.ActualName = NumberOfIslandsParameter.Name;
364      terminatedIslandsComparator.ResultParameter.ActualName = "TerminateTerminatedIslands";
365
366      maxEvaluatedSolutionsComparator.Name = "EvaluatedSolutions >= MaximumEvaluatedSolutions ?";
367      maxEvaluatedSolutionsComparator.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
368      maxEvaluatedSolutionsComparator.LeftSideParameter.ActualName = EvaluatedSolutionsParameter.Name;
369      maxEvaluatedSolutionsComparator.ResultParameter.ActualName = "TerminateEvaluatedSolutions";
370      maxEvaluatedSolutionsComparator.RightSideParameter.ActualName = "MaximumEvaluatedSolutions";
371
372      comparisonFactorModifier.Name = "Update Comparison Factor (Placeholder)";
373      comparisonFactorModifier.OperatorParameter.ActualName = ComparisonFactorModifierParameter.Name;
374
375      analyzer2.Name = "Analyzer (placeholder)";
376      analyzer2.OperatorParameter.ActualName = AnalyzerParameter.Name;
377
378      generationsTerminationCondition.Name = "Terminate (MaxGenerations) ?";
379      generationsTerminationCondition.ConditionParameter.ActualName = "TerminateGenerations";
380
381      terminatedIslandsCondition.Name = "Terminate (TerminatedIslands) ?";
382      terminatedIslandsCondition.ConditionParameter.ActualName = "TerminateTerminatedIslands";
383
384      evaluatedSolutionsTerminationCondition.Name = "Terminate (EvaluatedSolutions) ?";
385      evaluatedSolutionsTerminationCondition.ConditionParameter.ActualName = "TerminateEvaluatedSolutions";
386      #endregion
387
388      #region Create operator graph
389      OperatorGraph.InitialOperator = variableCreator;
390      variableCreator.Successor = uniformSubScopesProcessor0;
391      uniformSubScopesProcessor0.Operator = islandVariableCreator;
392      uniformSubScopesProcessor0.Successor = comparisonFactorInitializer;
393      islandVariableCreator.Successor = islandAnalyzer1;
394      islandAnalyzer1.Successor = islandResultsCollector1;
395      islandResultsCollector1.Successor = null;
396      comparisonFactorInitializer.Successor = analyzer1;
397      analyzer1.Successor = resultsCollector1;
398      resultsCollector1.Successor = uniformSubScopesProcessor1;
399      uniformSubScopesProcessor1.Operator = islandTerminatedBySelectionPressure1;
400      uniformSubScopesProcessor1.Successor = generationsCounter;
401      islandTerminatedBySelectionPressure1.TrueBranch = null;
402      islandTerminatedBySelectionPressure1.FalseBranch = mainOperator;
403      islandTerminatedBySelectionPressure1.Successor = null;
404      mainOperator.Successor = islandAnalyzer2;
405      islandAnalyzer2.Successor = islandResultsCollector2;
406      islandResultsCollector2.Successor = islandSelectionPressureComparator;
407      islandSelectionPressureComparator.Successor = islandTerminatedBySelectionPressure2;
408      islandTerminatedBySelectionPressure2.TrueBranch = terminatedIslandsCounter;
409      islandTerminatedBySelectionPressure2.FalseBranch = null;
410      islandTerminatedBySelectionPressure2.Successor = null;
411      generationsCounter.Successor = generationsSinceLastMigrationCounter;
412      generationsSinceLastMigrationCounter.Successor = migrationComparator;
413      migrationComparator.Successor = migrationBranch;
414      migrationBranch.TrueBranch = resetTerminatedIslandsAssigner;
415      migrationBranch.FalseBranch = null;
416      migrationBranch.Successor = generationsComparator;
417      resetTerminatedIslandsAssigner.Successor = resetGenerationsSinceLastMigrationAssigner;
418      resetGenerationsSinceLastMigrationAssigner.Successor = migrationsCounter;
419      migrationsCounter.Successor = uniformSubScopesProcessor2;
420      uniformSubScopesProcessor2.Operator = reviveIslandAssigner;
421      uniformSubScopesProcessor2.Successor = migrator;
422      reviveIslandAssigner.Successor = emigrantsSelector;
423      emigrantsSelector.Successor = null;
424      migrator.Successor = reevaluateImmigrantsBranch;
425      reevaluateImmigrantsBranch.FalseBranch = null;
426      reevaluateImmigrantsBranch.Successor = uniformSubScopesProcessor5;
427      reevaluateImmigrantsBranch.TrueBranch = uniformSubScopesProcessor3;
428      uniformSubScopesProcessor3.Operator = subScopesProcessor;
429      subScopesProcessor.Operators.Add(uniformSubScopesProcessor4);
430      subScopesProcessor.Operators.Add(uniformSubScopesProcessor4);
431      uniformSubScopesProcessor4.Operator = evaluator;
432      uniformSubScopesProcessor4.Successor = subScopesCounter;
433      evaluator.Successor = null;
434      uniformSubScopesProcessor5.Operator = immigrationReplacer;
435      uniformSubScopesProcessor5.Successor = null;
436      immigrationReplacer.Successor = null;
437      generationsComparator.Successor = terminatedIslandsComparator;
438      terminatedIslandsComparator.Successor = maxEvaluatedSolutionsComparator;
439      maxEvaluatedSolutionsComparator.Successor = comparisonFactorModifier;
440      comparisonFactorModifier.Successor = analyzer2;
441      analyzer2.Successor = generationsTerminationCondition;
442      generationsTerminationCondition.TrueBranch = null;
443      generationsTerminationCondition.FalseBranch = terminatedIslandsCondition;
444      generationsTerminationCondition.Successor = null;
445      terminatedIslandsCondition.TrueBranch = null;
446      terminatedIslandsCondition.FalseBranch = evaluatedSolutionsTerminationCondition;
447      terminatedIslandsCondition.Successor = null;
448      evaluatedSolutionsTerminationCondition.TrueBranch = null;
449      evaluatedSolutionsTerminationCondition.FalseBranch = uniformSubScopesProcessor1;
450      evaluatedSolutionsTerminationCondition.Successor = null;
451      #endregion
452    }
453
454    [StorableHook(HookType.AfterDeserialization)]
455    private void AfterDeserialization() {
456      // BackwardsCompatibility3.3
457      #region Backwards compatible code, remove with 3.4
458      if (!Parameters.ContainsKey("ReevaluateElites")) {
459        Parameters.Add(new ValueLookupParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)"));
460      }
461      if (!Parameters.ContainsKey("FillPopulationWithParents"))
462        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."));
463      #endregion
464    }
465
466    public override IOperation Apply() {
467      if (CrossoverParameter.ActualValue == null)
468        return null;
469      return base.Apply();
470    }
471  }
472}
Note: See TracBrowser for help on using the repository browser.