Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 10640 was 10640, checked in by mkommend, 11 years ago

#1997: Merged trunk changes regarding offspring selector in the symbolic island algorithms branch.

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