source: trunk/sources/HeuristicLab.Algorithms.GeneticAlgorithm/3.3/IslandGeneticAlgorithmMainLoop.cs @ 3611

Last change on this file since 3611 was 3611, checked in by abeham, 11 years ago

Changed Island OSGA #976

  • removed mainloop
  • added mainoperator
File size: 31.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 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;
23using System.Collections.Generic;
24using System.Linq;
25using HeuristicLab.Analysis;
26using HeuristicLab.Common;
27using HeuristicLab.Core;
28using HeuristicLab.Data;
29using HeuristicLab.Operators;
30using HeuristicLab.Optimization;
31using HeuristicLab.Optimization.Operators;
32using HeuristicLab.Parameters;
33using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
34using HeuristicLab.PluginInfrastructure;
35using HeuristicLab.Selection;
36
37namespace HeuristicLab.Algorithms.GeneticAlgorithm {
38  /// <summary>
39  /// An island genetic algorithm main loop operator.
40  /// </summary>
41  [Item("IslandGeneticAlgorithmMainLoop", "An island genetic algorithm main loop operator.")]
42  [StorableClass]
43  public sealed class IslandGeneticAlgorithmMainLoop : AlgorithmOperator {
44    #region Parameter Properties
45    public ValueLookupParameter<IRandom> RandomParameter {
46      get { return (ValueLookupParameter<IRandom>)Parameters["Random"]; }
47    }
48    public ValueLookupParameter<BoolValue> MaximizationParameter {
49      get { return (ValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
50    }
51    public SubScopesLookupParameter<DoubleValue> QualityParameter {
52      get { return (SubScopesLookupParameter<DoubleValue>)Parameters["Quality"]; }
53    }
54    public ValueLookupParameter<DoubleValue> BestKnownQualityParameter {
55      get { return (ValueLookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
56    }
57    public ValueLookupParameter<IntValue> NumberOfIslandsParameter {
58      get { return (ValueLookupParameter<IntValue>)Parameters["NumberOfIslands"]; }
59    }
60    public ValueLookupParameter<IntValue> MigrationIntervalParameter {
61      get { return (ValueLookupParameter<IntValue>)Parameters["MigrationInterval"]; }
62    }
63    public ValueLookupParameter<PercentValue> MigrationRateParameter {
64      get { return (ValueLookupParameter<PercentValue>)Parameters["MigrationRate"]; }
65    }
66    public ValueLookupParameter<IOperator> MigratorParameter {
67      get { return (ValueLookupParameter<IOperator>)Parameters["Migrator"]; }
68    }
69    public ValueLookupParameter<IOperator> EmigrantsSelectorParameter {
70      get { return (ValueLookupParameter<IOperator>)Parameters["EmigrantsSelector"]; }
71    }
72    public ValueLookupParameter<IOperator> ImmigrationReplacerParameter {
73      get { return (ValueLookupParameter<IOperator>)Parameters["ImmigrationReplacer"]; }
74    }
75    public ValueLookupParameter<IntValue> PopulationSizeParameter {
76      get { return (ValueLookupParameter<IntValue>)Parameters["PopulationSize"]; }
77    }
78    public ValueLookupParameter<IntValue> MaximumGenerationsParameter {
79      get { return (ValueLookupParameter<IntValue>)Parameters["MaximumGenerations"]; }
80    }
81    public ValueLookupParameter<IOperator> SelectorParameter {
82      get { return (ValueLookupParameter<IOperator>)Parameters["Selector"]; }
83    }
84    public ValueLookupParameter<IOperator> CrossoverParameter {
85      get { return (ValueLookupParameter<IOperator>)Parameters["Crossover"]; }
86    }
87    public ValueLookupParameter<PercentValue> MutationProbabilityParameter {
88      get { return (ValueLookupParameter<PercentValue>)Parameters["MutationProbability"]; }
89    }
90    public ValueLookupParameter<IOperator> MutatorParameter {
91      get { return (ValueLookupParameter<IOperator>)Parameters["Mutator"]; }
92    }
93    public ValueLookupParameter<IOperator> EvaluatorParameter {
94      get { return (ValueLookupParameter<IOperator>)Parameters["Evaluator"]; }
95    }
96    public ValueLookupParameter<IntValue> ElitesParameter {
97      get { return (ValueLookupParameter<IntValue>)Parameters["Elites"]; }
98    }
99    public ValueLookupParameter<ResultCollection> ResultsParameter {
100      get { return (ValueLookupParameter<ResultCollection>)Parameters["Results"]; }
101    }
102    public ValueLookupParameter<IOperator> VisualizerParameter {
103      get { return (ValueLookupParameter<IOperator>)Parameters["Visualizer"]; }
104    }
105    public LookupParameter<IItem> VisualizationParameter {
106      get { return (LookupParameter<IItem>)Parameters["Visualization"]; }
107    }
108    #endregion
109
110    [StorableConstructor]
111    private IslandGeneticAlgorithmMainLoop(bool deserializing) : base() { }
112    public IslandGeneticAlgorithmMainLoop()
113      : base() {
114      #region Create parameters
115      Parameters.Add(new ValueLookupParameter<IRandom>("Random", "A pseudo random number generator."));
116      Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
117      Parameters.Add(new SubScopesLookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution."));
118      Parameters.Add(new ValueLookupParameter<DoubleValue>("BestKnownQuality", "The best known quality value found so far."));
119      Parameters.Add(new ValueLookupParameter<IntValue>("NumberOfIslands", "The number of islands."));
120      Parameters.Add(new ValueLookupParameter<IntValue>("MigrationInterval", "The number of generations that should pass between migration phases."));
121      Parameters.Add(new ValueLookupParameter<PercentValue>("MigrationRate", "The proportion of individuals that should migrate between the islands."));
122      Parameters.Add(new ValueLookupParameter<IOperator>("Migrator", "The migration strategy."));
123      Parameters.Add(new ValueLookupParameter<IOperator>("EmigrantsSelector", "Selects the individuals that will be migrated."));
124      Parameters.Add(new ValueLookupParameter<IOperator>("ImmigrationReplacer", "Replaces some of the original population with the immigrants."));
125      Parameters.Add(new ValueLookupParameter<IntValue>("PopulationSize", "The size of the population of solutions."));
126      Parameters.Add(new ValueLookupParameter<IntValue>("MaximumGenerations", "The maximum number of generations that the algorithm should process."));
127      Parameters.Add(new ValueLookupParameter<IOperator>("Selector", "The operator used to select solutions for reproduction."));
128      Parameters.Add(new ValueLookupParameter<IOperator>("Crossover", "The operator used to cross solutions."));
129      Parameters.Add(new ValueLookupParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution."));
130      Parameters.Add(new ValueLookupParameter<IOperator>("Mutator", "The operator used to mutate solutions."));
131      Parameters.Add(new ValueLookupParameter<IOperator>("Evaluator", "The operator used to evaluate solutions."));
132      Parameters.Add(new ValueLookupParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation."));
133      Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The results collection to store the results."));
134      Parameters.Add(new ValueLookupParameter<IOperator>("Visualizer", "The operator used to visualize solutions."));
135      Parameters.Add(new LookupParameter<IItem>("Visualization", "The item which represents the visualization of solutions."));
136      #endregion
137
138      #region Create operators
139      VariableCreator variableCreator = new VariableCreator();
140      UniformSubScopesProcessor uniformSubScopesProcessor0 = new UniformSubScopesProcessor();
141      VariableCreator islandVariableCreator = new VariableCreator();
142      BestQualityMemorizer islandBestQualityMemorizer1 = new BestQualityMemorizer();
143      BestAverageWorstQualityCalculator islandBestAverageWorstQualityCalculator1 = new BestAverageWorstQualityCalculator();
144      DataTableValuesCollector islandDataTableValuesCollector1 = new DataTableValuesCollector();
145      QualityDifferenceCalculator islandQualityDifferenceCalculator1 = new QualityDifferenceCalculator();
146      Placeholder islandVisualizer1 = new Placeholder();
147      ResultsCollector islandResultsCollector = new ResultsCollector();
148      BestQualityMemorizer bestQualityMemorizer1 = new BestQualityMemorizer();
149      BestQualityMemorizer bestQualityMemorizer2 = new BestQualityMemorizer();
150      BestAverageWorstQualityCalculator bestAverageWorstQualityCalculator1 = new BestAverageWorstQualityCalculator();
151      DataTableValuesCollector dataTableValuesCollector1 = new DataTableValuesCollector();
152      QualityDifferenceCalculator qualityDifferenceCalculator1 = new QualityDifferenceCalculator();
153      ResultsCollector resultsCollector = new ResultsCollector();
154      UniformSubScopesProcessor uniformSubScopesProcessor1 = new UniformSubScopesProcessor();
155      Placeholder selector = new Placeholder();
156      SubScopesProcessor subScopesProcessor1 = new SubScopesProcessor();
157      ChildrenCreator childrenCreator = new ChildrenCreator();
158      UniformSubScopesProcessor uniformSubScopesProcessor2 = new UniformSubScopesProcessor();
159      Placeholder crossover = new Placeholder();
160      StochasticBranch stochasticBranch = new StochasticBranch();
161      Placeholder mutator = new Placeholder();
162      Placeholder evaluator = new Placeholder();
163      SubScopesRemover subScopesRemover = new SubScopesRemover();
164      SubScopesProcessor subScopesProcessor2 = new SubScopesProcessor();
165      BestSelector bestSelector = new BestSelector();
166      RightReducer rightReducer = new RightReducer();
167      MergingReducer mergingReducer = new MergingReducer();
168      BestQualityMemorizer islandBestQualityMemorizer2 = new BestQualityMemorizer();
169      BestAverageWorstQualityCalculator islandBestAverageWorstQualityCalculator2 = new BestAverageWorstQualityCalculator();
170      DataTableValuesCollector islandDataTableValuesCollector2 = new DataTableValuesCollector();
171      QualityDifferenceCalculator islandQualityDifferenceCalculator2 = new QualityDifferenceCalculator();
172      Placeholder islandVisualizer2 = new Placeholder();
173      IntCounter generationsCounter = new IntCounter();
174      IntCounter generationsSinceLastMigrationCounter = new IntCounter();
175      Comparator migrationComparator = new Comparator();
176      ConditionalBranch migrationBranch = new ConditionalBranch();
177      Assigner resetGenerationsSinceLastMigrationAssigner = new Assigner();
178      IntCounter migrationsCounter = new IntCounter();
179      UniformSubScopesProcessor uniformSubScopesProcessor3 = new UniformSubScopesProcessor();
180      Placeholder emigrantsSelector = new Placeholder();
181      Placeholder migrator = new Placeholder();
182      UniformSubScopesProcessor uniformSubScopesProcessor4 = new UniformSubScopesProcessor();
183      Placeholder immigrationReplacer = new Placeholder();
184      Comparator generationsComparator = new Comparator();
185      BestQualityMemorizer bestQualityMemorizer3 = new BestQualityMemorizer();
186      BestQualityMemorizer bestQualityMemorizer4 = new BestQualityMemorizer();
187      BestAverageWorstQualityCalculator bestAverageWorstQualityCalculator2 = new BestAverageWorstQualityCalculator();
188      DataTableValuesCollector dataTableValuesCollector2 = new DataTableValuesCollector();
189      QualityDifferenceCalculator qualityDifferenceCalculator2 = new QualityDifferenceCalculator();
190      ConditionalBranch generationsTerminationCondition = new ConditionalBranch();
191
192      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Migrations", new IntValue(0)));
193      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("GenerationsSinceLastMigration", new IntValue(0)));
194      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Generations", new IntValue(0)));
195
196      islandVariableCreator.CollectedValues.Add(new ValueParameter<ResultCollection>("IslandResults", new ResultCollection()));
197
198      islandBestQualityMemorizer1.BestQualityParameter.ActualName = "BestQuality";
199      islandBestQualityMemorizer1.MaximizationParameter.ActualName = MaximizationParameter.Name;
200      islandBestQualityMemorizer1.QualityParameter.ActualName = QualityParameter.Name;
201
202      islandBestAverageWorstQualityCalculator1.AverageQualityParameter.ActualName = "CurrentAverageQuality";
203      islandBestAverageWorstQualityCalculator1.BestQualityParameter.ActualName = "CurrentBestQuality";
204      islandBestAverageWorstQualityCalculator1.MaximizationParameter.ActualName = MaximizationParameter.Name;
205      islandBestAverageWorstQualityCalculator1.QualityParameter.ActualName = QualityParameter.Name;
206      islandBestAverageWorstQualityCalculator1.WorstQualityParameter.ActualName = "CurrentWorstQuality";
207
208      islandDataTableValuesCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Best Quality", null, "CurrentBestQuality"));
209      islandDataTableValuesCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Average Quality", null, "CurrentAverageQuality"));
210      islandDataTableValuesCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Worst Quality", null, "CurrentWorstQuality"));
211      islandDataTableValuesCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Quality", null, "BestQuality"));
212      islandDataTableValuesCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Known Quality", null, "BestKnownQuality"));
213      islandDataTableValuesCollector1.DataTableParameter.ActualName = "Qualities";
214
215      islandQualityDifferenceCalculator1.AbsoluteDifferenceParameter.ActualName = "AbsoluteDifferenceBestKnownToBest";
216      islandQualityDifferenceCalculator1.FirstQualityParameter.ActualName = BestKnownQualityParameter.Name;
217      islandQualityDifferenceCalculator1.RelativeDifferenceParameter.ActualName = "RelativeDifferenceBestKnownToBest";
218      islandQualityDifferenceCalculator1.SecondQualityParameter.ActualName = "BestQuality";
219
220      islandVisualizer1.Name = "Visualizer";
221      islandVisualizer1.OperatorParameter.ActualName = "Visualizer";
222
223      islandResultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Generations"));
224      islandResultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Best Quality", null, "CurrentBestQuality"));
225      islandResultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Average Quality", null, "CurrentAverageQuality"));
226      islandResultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Worst Quality", null, "CurrentWorstQuality"));
227      islandResultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Quality", null, "BestQuality"));
228      islandResultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Known Quality", null, "BestKnownQuality"));
229      islandResultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Absolute Difference of Best Known Quality to Best Quality", null, "AbsoluteDifferenceBestKnownToBest"));
230      islandResultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Relative Difference of Best Known Quality to Best Quality", null, "RelativeDifferenceBestKnownToBest"));
231      islandResultsCollector.CollectedValues.Add(new LookupParameter<IItem>("Solution Visualization", null, "Visualization"));
232      islandResultsCollector.CollectedValues.Add(new LookupParameter<DataTable>("Qualities"));
233      islandResultsCollector.ResultsParameter.ActualName = "IslandResults";
234
235      bestQualityMemorizer1.BestQualityParameter.ActualName = "BestQuality";
236      bestQualityMemorizer1.MaximizationParameter.ActualName = MaximizationParameter.Name;
237      bestQualityMemorizer1.QualityParameter.ActualName = "BestQuality";
238
239      bestQualityMemorizer2.BestQualityParameter.ActualName = BestKnownQualityParameter.Name;
240      bestQualityMemorizer2.MaximizationParameter.ActualName = MaximizationParameter.Name;
241      bestQualityMemorizer2.QualityParameter.ActualName = "BestQuality";
242
243      bestAverageWorstQualityCalculator1.AverageQualityParameter.ActualName = "CurrentAverageBestQuality";
244      bestAverageWorstQualityCalculator1.BestQualityParameter.ActualName = "CurrentBestBestQuality";
245      bestAverageWorstQualityCalculator1.MaximizationParameter.ActualName = MaximizationParameter.Name;
246      bestAverageWorstQualityCalculator1.QualityParameter.ActualName = "CurrentBestQuality";
247      bestAverageWorstQualityCalculator1.WorstQualityParameter.ActualName = "CurrentWorstBestQuality";
248
249      dataTableValuesCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Best BestQuality", null, "CurrentBestBestQuality"));
250      dataTableValuesCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Average BestQuality", null, "CurrentAverageBestQuality"));
251      dataTableValuesCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Worst BestQuality", null, "CurrentWorstBestQuality"));
252      dataTableValuesCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Quality", null, "BestQuality"));
253      dataTableValuesCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Known Quality", null, BestKnownQualityParameter.Name));
254      dataTableValuesCollector1.DataTableParameter.ActualName = "BestQualities";
255
256      qualityDifferenceCalculator1.AbsoluteDifferenceParameter.ActualName = "AbsoluteDifferenceBestKnownToBest";
257      qualityDifferenceCalculator1.FirstQualityParameter.ActualName = BestKnownQualityParameter.Name;
258      qualityDifferenceCalculator1.RelativeDifferenceParameter.ActualName = "RelativeDifferenceBestKnownToBest";
259      qualityDifferenceCalculator1.SecondQualityParameter.ActualName = "BestQuality";
260
261      resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Migrations"));
262      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Best BestQuality", null, "CurrentBestBestQuality"));
263      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Average BestQuality", null, "CurrentAverageBestQuality"));
264      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Worst BestQuality", null, "CurrentWorstBestQuality"));
265      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Quality", null, "BestQuality"));
266      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Known Quality", null, BestKnownQualityParameter.Name));
267      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Absolute Difference of Best Known Quality to Best Quality", null, "AbsoluteDifferenceBestKnownToBest"));
268      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Relative Difference of Best Known Quality to Best Quality", null, "RelativeDifferenceBestKnownToBest"));
269      resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>("BestQualities"));
270      resultsCollector.CollectedValues.Add(new SubScopesLookupParameter<ResultCollection>("IslandResults", "Result set for each island"));
271      resultsCollector.ResultsParameter.ActualName = ResultsParameter.Name;
272
273      selector.Name = "Selector (placeholder)";
274      selector.OperatorParameter.ActualName = SelectorParameter.Name;
275
276      childrenCreator.ParentsPerChild = new IntValue(2);
277
278      crossover.Name = "Crossover (placeholder)";
279      crossover.OperatorParameter.ActualName = CrossoverParameter.Name;
280
281      stochasticBranch.ProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
282      stochasticBranch.RandomParameter.ActualName = RandomParameter.Name;
283
284      mutator.Name = "Mutator (placeholder)";
285      mutator.OperatorParameter.ActualName = MutatorParameter.Name;
286
287      evaluator.Name = "Evaluator (placeholder)";
288      evaluator.OperatorParameter.ActualName = EvaluatorParameter.Name;
289
290      subScopesRemover.RemoveAllSubScopes = true;
291
292      bestSelector.CopySelected = new BoolValue(false);
293      bestSelector.MaximizationParameter.ActualName = MaximizationParameter.Name;
294      bestSelector.NumberOfSelectedSubScopesParameter.ActualName = ElitesParameter.Name;
295      bestSelector.QualityParameter.ActualName = QualityParameter.Name;
296
297      islandBestQualityMemorizer2.BestQualityParameter.ActualName = "BestQuality";
298      islandBestQualityMemorizer2.MaximizationParameter.ActualName = MaximizationParameter.Name;
299      islandBestQualityMemorizer2.QualityParameter.ActualName = QualityParameter.Name;
300
301      islandBestAverageWorstQualityCalculator2.AverageQualityParameter.ActualName = "CurrentAverageQuality";
302      islandBestAverageWorstQualityCalculator2.BestQualityParameter.ActualName = "CurrentBestQuality";
303      islandBestAverageWorstQualityCalculator2.MaximizationParameter.ActualName = MaximizationParameter.Name;
304      islandBestAverageWorstQualityCalculator2.QualityParameter.ActualName = QualityParameter.Name;
305      islandBestAverageWorstQualityCalculator2.WorstQualityParameter.ActualName = "CurrentWorstQuality";
306
307      islandDataTableValuesCollector2.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Best Quality", null, "CurrentBestQuality"));
308      islandDataTableValuesCollector2.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Average Quality", null, "CurrentAverageQuality"));
309      islandDataTableValuesCollector2.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Worst Quality", null, "CurrentWorstQuality"));
310      islandDataTableValuesCollector2.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Quality", null, "BestQuality"));
311      islandDataTableValuesCollector2.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Known Quality", null, BestKnownQualityParameter.Name));
312      islandDataTableValuesCollector2.DataTableParameter.ActualName = "Qualities";
313
314      islandQualityDifferenceCalculator2.AbsoluteDifferenceParameter.ActualName = "AbsoluteDifferenceBestKnownToBest";
315      islandQualityDifferenceCalculator2.FirstQualityParameter.ActualName = BestKnownQualityParameter.Name;
316      islandQualityDifferenceCalculator2.RelativeDifferenceParameter.ActualName = "RelativeDifferenceBestKnownToBest";
317      islandQualityDifferenceCalculator2.SecondQualityParameter.ActualName = "BestQuality";
318
319      islandVisualizer2.Name = "Visualizer";
320      islandVisualizer2.OperatorParameter.ActualName = "Visualizer";
321
322      generationsCounter.Name = "Generations + 1";
323      generationsCounter.Increment = new IntValue(1);
324      generationsCounter.ValueParameter.ActualName = "Generations";
325
326      generationsSinceLastMigrationCounter.Name = "GenerationsSinceLastMigration + 1";
327      generationsSinceLastMigrationCounter.ValueParameter.ActualName = "GenerationsSinceLastMigration";
328      generationsSinceLastMigrationCounter.Increment = new IntValue(1);
329
330      migrationComparator.Name = "GenerationsSinceLastMigration = MigrationInterval ?";
331      migrationComparator.LeftSideParameter.ActualName = "GenerationsSinceLastMigration";
332      migrationComparator.Comparison = new Comparison(ComparisonType.Equal);
333      migrationComparator.RightSideParameter.ActualName = MigrationIntervalParameter.Name;
334      migrationComparator.ResultParameter.ActualName = "Migrate";
335
336      migrationBranch.Name = "Migrate?";
337      migrationBranch.ConditionParameter.ActualName = "Migrate";
338
339      resetGenerationsSinceLastMigrationAssigner.Name = "Reset GenerationsSinceLastMigration";
340      resetGenerationsSinceLastMigrationAssigner.LeftSideParameter.ActualName = "GenerationsSinceLastMigration";
341      resetGenerationsSinceLastMigrationAssigner.RightSideParameter.Value = new IntValue(0);
342
343      migrationsCounter.Name = "Migrations + 1";
344      migrationsCounter.IncrementParameter.Value = new IntValue(1);
345      migrationsCounter.ValueParameter.ActualName = "Migrations";
346
347      emigrantsSelector.Name = "Emigrants Selector (placeholder)";
348      emigrantsSelector.OperatorParameter.ActualName = EmigrantsSelectorParameter.Name;
349
350      migrator.Name = "Migrator (placeholder)";
351      migrator.OperatorParameter.ActualName = MigratorParameter.Name;
352
353      immigrationReplacer.Name = "Immigration Replacer (placeholder)";
354      immigrationReplacer.OperatorParameter.ActualName = ImmigrationReplacerParameter.Name;
355
356      generationsComparator.Name = "Generations >= MaximumGenerations ?";
357      generationsComparator.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
358      generationsComparator.LeftSideParameter.ActualName = "Generations";
359      generationsComparator.ResultParameter.ActualName = "TerminateGenerations";
360      generationsComparator.RightSideParameter.ActualName = MaximumGenerationsParameter.Name;
361
362      bestQualityMemorizer3.BestQualityParameter.ActualName = "BestQuality";
363      bestQualityMemorizer3.MaximizationParameter.ActualName = MaximizationParameter.Name;
364      bestQualityMemorizer3.QualityParameter.ActualName = "BestQuality";
365
366      bestQualityMemorizer4.BestQualityParameter.ActualName = BestKnownQualityParameter.Name;
367      bestQualityMemorizer4.MaximizationParameter.ActualName = MaximizationParameter.Name;
368      bestQualityMemorizer4.QualityParameter.ActualName = "BestQuality";
369
370      bestAverageWorstQualityCalculator2.AverageQualityParameter.ActualName = "CurrentAverageBestQuality";
371      bestAverageWorstQualityCalculator2.BestQualityParameter.ActualName = "CurrentBestBestQuality";
372      bestAverageWorstQualityCalculator2.MaximizationParameter.ActualName = MaximizationParameter.Name;
373      bestAverageWorstQualityCalculator2.QualityParameter.ActualName = "CurrentBestQuality";
374      bestAverageWorstQualityCalculator2.WorstQualityParameter.ActualName = "CurrentWorstBestQuality";
375
376      dataTableValuesCollector2.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Best BestQuality", null, "CurrentBestBestQuality"));
377      dataTableValuesCollector2.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Average BestQuality", null, "CurrentAverageBestQuality"));
378      dataTableValuesCollector2.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Worst BestQuality", null, "CurrentWorstBestQuality"));
379      dataTableValuesCollector2.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Quality", null, "BestQuality"));
380      dataTableValuesCollector2.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Known Quality", null, BestKnownQualityParameter.Name));
381      dataTableValuesCollector2.DataTableParameter.ActualName = "BestQualities";
382
383      qualityDifferenceCalculator2.AbsoluteDifferenceParameter.ActualName = "AbsoluteDifferenceBestKnownToBest";
384      qualityDifferenceCalculator2.FirstQualityParameter.ActualName = BestKnownQualityParameter.Name;
385      qualityDifferenceCalculator2.RelativeDifferenceParameter.ActualName = "RelativeDifferenceBestKnownToBest";
386      qualityDifferenceCalculator2.SecondQualityParameter.ActualName = "BestQuality";
387
388      generationsTerminationCondition.Name = "Terminate?";
389      generationsTerminationCondition.ConditionParameter.ActualName = "TerminateGenerations";
390      #endregion
391
392      #region Create operator graph
393      OperatorGraph.InitialOperator = variableCreator;
394      variableCreator.Successor = uniformSubScopesProcessor0;
395      uniformSubScopesProcessor0.Operator = islandVariableCreator;
396      uniformSubScopesProcessor0.Successor = bestQualityMemorizer1;
397      islandVariableCreator.Successor = islandBestQualityMemorizer1;
398      islandBestQualityMemorizer1.Successor = islandBestAverageWorstQualityCalculator1;
399      islandBestAverageWorstQualityCalculator1.Successor = islandDataTableValuesCollector1;
400      islandDataTableValuesCollector1.Successor = islandQualityDifferenceCalculator1;
401      islandQualityDifferenceCalculator1.Successor = islandVisualizer1;
402      islandVisualizer1.Successor = islandResultsCollector;
403      bestQualityMemorizer1.Successor = bestQualityMemorizer2;
404      bestQualityMemorizer2.Successor = bestAverageWorstQualityCalculator1;
405      bestAverageWorstQualityCalculator1.Successor = dataTableValuesCollector1;
406      dataTableValuesCollector1.Successor = qualityDifferenceCalculator1;
407      qualityDifferenceCalculator1.Successor = resultsCollector;
408      resultsCollector.Successor = uniformSubScopesProcessor1;
409      uniformSubScopesProcessor1.Operator = selector;
410      uniformSubScopesProcessor1.Successor = generationsCounter;
411      selector.Successor = subScopesProcessor1;
412      subScopesProcessor1.Operators.Add(new EmptyOperator());
413      subScopesProcessor1.Operators.Add(childrenCreator);
414      subScopesProcessor1.Successor = subScopesProcessor2;
415      childrenCreator.Successor = uniformSubScopesProcessor2;
416      uniformSubScopesProcessor2.Operator = crossover;
417      uniformSubScopesProcessor2.Successor = null;
418      crossover.Successor = stochasticBranch;
419      stochasticBranch.FirstBranch = mutator;
420      stochasticBranch.SecondBranch = null;
421      stochasticBranch.Successor = evaluator;
422      mutator.Successor = null;
423      evaluator.Successor = subScopesRemover;
424      subScopesRemover.Successor = null;
425      subScopesProcessor2.Operators.Add(bestSelector);
426      subScopesProcessor2.Operators.Add(new EmptyOperator());
427      subScopesProcessor2.Successor = mergingReducer;
428      bestSelector.Successor = rightReducer;
429      rightReducer.Successor = null;
430      mergingReducer.Successor = islandBestQualityMemorizer2;
431      islandBestQualityMemorizer2.Successor = islandBestAverageWorstQualityCalculator2;
432      islandBestAverageWorstQualityCalculator2.Successor = islandDataTableValuesCollector2;
433      islandDataTableValuesCollector2.Successor = islandQualityDifferenceCalculator2;
434      islandQualityDifferenceCalculator2.Successor = islandVisualizer2;
435      islandVisualizer2.Successor = null;
436      generationsCounter.Successor = generationsSinceLastMigrationCounter;
437      generationsSinceLastMigrationCounter.Successor = migrationComparator;
438      migrationComparator.Successor = migrationBranch;
439      migrationBranch.TrueBranch = resetGenerationsSinceLastMigrationAssigner;
440      migrationBranch.FalseBranch = null;
441      migrationBranch.Successor = generationsComparator;
442      resetGenerationsSinceLastMigrationAssigner.Successor = migrationsCounter;
443      migrationsCounter.Successor = uniformSubScopesProcessor3;
444      uniformSubScopesProcessor3.Operator = emigrantsSelector;
445      uniformSubScopesProcessor3.Successor = migrator;
446      migrator.Successor = uniformSubScopesProcessor4;
447      uniformSubScopesProcessor4.Operator = immigrationReplacer;
448      uniformSubScopesProcessor4.Successor = null;
449      generationsComparator.Successor = bestQualityMemorizer3;
450      bestQualityMemorizer3.Successor = bestQualityMemorizer4;
451      bestQualityMemorizer4.Successor = bestAverageWorstQualityCalculator2;
452      bestAverageWorstQualityCalculator2.Successor = dataTableValuesCollector2;
453      dataTableValuesCollector2.Successor = qualityDifferenceCalculator2;
454      qualityDifferenceCalculator2.Successor = generationsTerminationCondition;
455      generationsTerminationCondition.TrueBranch = null;
456      generationsTerminationCondition.FalseBranch = uniformSubScopesProcessor1;
457      generationsTerminationCondition.Successor = null;
458      #endregion
459    }
460  }
461}
Note: See TracBrowser for help on using the repository browser.