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

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

Changed Island GA in that it does not use the GAMainLoop anymore #971

File size: 31.1 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      // END GA mainloop
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      IntCounter generationsCounter = new IntCounter();
185      Comparator generationsComparator = new Comparator();
186      BestQualityMemorizer bestQualityMemorizer3 = new BestQualityMemorizer();
187      BestQualityMemorizer bestQualityMemorizer4 = new BestQualityMemorizer();
188      BestAverageWorstQualityCalculator bestAverageWorstQualityCalculator2 = new BestAverageWorstQualityCalculator();
189      DataTableValuesCollector dataTableValuesCollector2 = new DataTableValuesCollector();
190      QualityDifferenceCalculator qualityDifferenceCalculator2 = new QualityDifferenceCalculator();
191      ConditionalBranch generationsTerminationCondition = new ConditionalBranch();
192
193      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Migrations", new IntValue(0)));
194      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("GenerationsSinceLastMigration", new IntValue(0)));
195      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Generations", new IntValue(0)));
196
197      islandVariableCreator.CollectedValues.Add(new ValueParameter<ResultCollection>("IslandResults", new ResultCollection()));
198
199      islandBestQualityMemorizer1.BestQualityParameter.ActualName = "BestQuality";
200      islandBestQualityMemorizer1.MaximizationParameter.ActualName = MaximizationParameter.Name;
201      islandBestQualityMemorizer1.QualityParameter.ActualName = QualityParameter.Name;
202
203      islandBestAverageWorstQualityCalculator1.AverageQualityParameter.ActualName = "CurrentAverageQuality";
204      islandBestAverageWorstQualityCalculator1.BestQualityParameter.ActualName = "CurrentBestQuality";
205      islandBestAverageWorstQualityCalculator1.MaximizationParameter.ActualName = MaximizationParameter.Name;
206      islandBestAverageWorstQualityCalculator1.QualityParameter.ActualName = QualityParameter.Name;
207      islandBestAverageWorstQualityCalculator1.WorstQualityParameter.ActualName = "CurrentWorstQuality";
208
209      islandDataTableValuesCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Best Quality", null, "CurrentBestQuality"));
210      islandDataTableValuesCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Average Quality", null, "CurrentAverageQuality"));
211      islandDataTableValuesCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Worst Quality", null, "CurrentWorstQuality"));
212      islandDataTableValuesCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Quality", null, "BestQuality"));
213      islandDataTableValuesCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Known Quality", null, "BestKnownQuality"));
214      islandDataTableValuesCollector1.DataTableParameter.ActualName = "Qualities";
215
216      islandQualityDifferenceCalculator1.AbsoluteDifferenceParameter.ActualName = "AbsoluteDifferenceBestKnownToBest";
217      islandQualityDifferenceCalculator1.FirstQualityParameter.ActualName = BestKnownQualityParameter.Name;
218      islandQualityDifferenceCalculator1.RelativeDifferenceParameter.ActualName = "RelativeDifferenceBestKnownToBest";
219      islandQualityDifferenceCalculator1.SecondQualityParameter.ActualName = "BestQuality";
220
221      islandVisualizer1.Name = "Visualizer";
222      islandVisualizer1.OperatorParameter.ActualName = "Visualizer";
223
224      islandResultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Generations"));
225      islandResultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Best Quality", null, "CurrentBestQuality"));
226      islandResultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Average Quality", null, "CurrentAverageQuality"));
227      islandResultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Worst Quality", null, "CurrentWorstQuality"));
228      islandResultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Quality", null, "BestQuality"));
229      islandResultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Known Quality", null, "BestKnownQuality"));
230      islandResultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Absolute Difference of Best Known Quality to Best Quality", null, "AbsoluteDifferenceBestKnownToBest"));
231      islandResultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Relative Difference of Best Known Quality to Best Quality", null, "RelativeDifferenceBestKnownToBest"));
232      islandResultsCollector.CollectedValues.Add(new LookupParameter<IItem>("Solution Visualization", null, "Visualization"));
233      islandResultsCollector.CollectedValues.Add(new LookupParameter<DataTable>("Qualities"));
234      islandResultsCollector.ResultsParameter.ActualName = "IslandResults";
235
236      bestQualityMemorizer1.BestQualityParameter.ActualName = "BestQuality";
237      bestQualityMemorizer1.MaximizationParameter.ActualName = MaximizationParameter.Name;
238      bestQualityMemorizer1.QualityParameter.ActualName = "BestQuality";
239
240      bestQualityMemorizer2.BestQualityParameter.ActualName = BestKnownQualityParameter.Name;
241      bestQualityMemorizer2.MaximizationParameter.ActualName = MaximizationParameter.Name;
242      bestQualityMemorizer2.QualityParameter.ActualName = "BestQuality";
243
244      bestAverageWorstQualityCalculator1.AverageQualityParameter.ActualName = "CurrentAverageBestQuality";
245      bestAverageWorstQualityCalculator1.BestQualityParameter.ActualName = "CurrentBestBestQuality";
246      bestAverageWorstQualityCalculator1.MaximizationParameter.ActualName = MaximizationParameter.Name;
247      bestAverageWorstQualityCalculator1.QualityParameter.ActualName = "CurrentBestQuality";
248      bestAverageWorstQualityCalculator1.WorstQualityParameter.ActualName = "CurrentWorstBestQuality";
249
250      dataTableValuesCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Best BestQuality", null, "CurrentBestBestQuality"));
251      dataTableValuesCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Average BestQuality", null, "CurrentAverageBestQuality"));
252      dataTableValuesCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Worst BestQuality", null, "CurrentWorstBestQuality"));
253      dataTableValuesCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Quality", null, "BestQuality"));
254      dataTableValuesCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Known Quality", null, BestKnownQualityParameter.Name));
255      dataTableValuesCollector1.DataTableParameter.ActualName = "BestQualities";
256
257      qualityDifferenceCalculator1.AbsoluteDifferenceParameter.ActualName = "AbsoluteDifferenceBestKnownToBest";
258      qualityDifferenceCalculator1.FirstQualityParameter.ActualName = BestKnownQualityParameter.Name;
259      qualityDifferenceCalculator1.RelativeDifferenceParameter.ActualName = "RelativeDifferenceBestKnownToBest";
260      qualityDifferenceCalculator1.SecondQualityParameter.ActualName = "BestQuality";
261
262      resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Migrations"));
263      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Best BestQuality", null, "CurrentBestBestQuality"));
264      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Average BestQuality", null, "CurrentAverageBestQuality"));
265      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Worst BestQuality", null, "CurrentWorstBestQuality"));
266      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Quality", null, "BestQuality"));
267      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Known Quality", null, BestKnownQualityParameter.Name));
268      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Absolute Difference of Best Known Quality to Best Quality", null, "AbsoluteDifferenceBestKnownToBest"));
269      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Relative Difference of Best Known Quality to Best Quality", null, "RelativeDifferenceBestKnownToBest"));
270      resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>("BestQualities"));
271      resultsCollector.CollectedValues.Add(new SubScopesLookupParameter<ResultCollection>("IslandResults", "Result set for each island"));
272      resultsCollector.ResultsParameter.ActualName = ResultsParameter.Name;
273
274      // START GA mainloop
275      selector.Name = "Selector (placeholder)";
276      selector.OperatorParameter.ActualName = SelectorParameter.Name;
277
278      childrenCreator.ParentsPerChild = new IntValue(2);
279
280      crossover.Name = "Crossover (placeholder)";
281      crossover.OperatorParameter.ActualName = CrossoverParameter.Name;
282
283      stochasticBranch.ProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
284      stochasticBranch.RandomParameter.ActualName = RandomParameter.Name;
285
286      mutator.Name = "Mutator (placeholder)";
287      mutator.OperatorParameter.ActualName = MutatorParameter.Name;
288
289      evaluator.Name = "Evaluator (placeholder)";
290      evaluator.OperatorParameter.ActualName = EvaluatorParameter.Name;
291
292      subScopesRemover.RemoveAllSubScopes = true;
293
294      bestSelector.CopySelected = new BoolValue(false);
295      bestSelector.MaximizationParameter.ActualName = MaximizationParameter.Name;
296      bestSelector.NumberOfSelectedSubScopesParameter.ActualName = ElitesParameter.Name;
297      bestSelector.QualityParameter.ActualName = QualityParameter.Name;
298
299      islandBestQualityMemorizer2.BestQualityParameter.ActualName = "BestQuality";
300      islandBestQualityMemorizer2.MaximizationParameter.ActualName = MaximizationParameter.Name;
301      islandBestQualityMemorizer2.QualityParameter.ActualName = QualityParameter.Name;
302
303      islandBestAverageWorstQualityCalculator2.AverageQualityParameter.ActualName = "CurrentAverageQuality";
304      islandBestAverageWorstQualityCalculator2.BestQualityParameter.ActualName = "CurrentBestQuality";
305      islandBestAverageWorstQualityCalculator2.MaximizationParameter.ActualName = MaximizationParameter.Name;
306      islandBestAverageWorstQualityCalculator2.QualityParameter.ActualName = QualityParameter.Name;
307      islandBestAverageWorstQualityCalculator2.WorstQualityParameter.ActualName = "CurrentWorstQuality";
308
309      islandDataTableValuesCollector2.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Best Quality", null, "CurrentBestQuality"));
310      islandDataTableValuesCollector2.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Average Quality", null, "CurrentAverageQuality"));
311      islandDataTableValuesCollector2.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Worst Quality", null, "CurrentWorstQuality"));
312      islandDataTableValuesCollector2.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Quality", null, "BestQuality"));
313      islandDataTableValuesCollector2.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Known Quality", null, BestKnownQualityParameter.Name));
314      islandDataTableValuesCollector2.DataTableParameter.ActualName = "Qualities";
315
316      islandQualityDifferenceCalculator2.AbsoluteDifferenceParameter.ActualName = "AbsoluteDifferenceBestKnownToBest";
317      islandQualityDifferenceCalculator2.FirstQualityParameter.ActualName = BestKnownQualityParameter.Name;
318      islandQualityDifferenceCalculator2.RelativeDifferenceParameter.ActualName = "RelativeDifferenceBestKnownToBest";
319      islandQualityDifferenceCalculator2.SecondQualityParameter.ActualName = "BestQuality";
320
321      islandVisualizer2.Name = "Visualizer";
322      islandVisualizer2.OperatorParameter.ActualName = "Visualizer";
323      // END GA mainloop
324
325      generationsSinceLastMigrationCounter.ValueParameter.ActualName = "GenerationsSinceLastMigration";
326      generationsSinceLastMigrationCounter.Increment = new IntValue(1);
327
328      migrationComparator.LeftSideParameter.ActualName = "GenerationsSinceLastMigration";
329      migrationComparator.Comparison = new Comparison(ComparisonType.Equal);
330      migrationComparator.RightSideParameter.ActualName = MigrationIntervalParameter.Name;
331      migrationComparator.ResultParameter.ActualName = "Migrate";
332
333      migrationBranch.ConditionParameter.ActualName = "Migrate";
334
335      resetGenerationsSinceLastMigrationAssigner.Name = "Reset Counter";
336      resetGenerationsSinceLastMigrationAssigner.LeftSideParameter.ActualName = "GenerationsSinceLastMigration";
337      resetGenerationsSinceLastMigrationAssigner.RightSideParameter.Value = new IntValue(0);
338
339      migrationsCounter.Name = "Migrations + 1";
340      migrationsCounter.IncrementParameter.Value = new IntValue(1);
341      migrationsCounter.ValueParameter.ActualName = "Migrations";
342
343      emigrantsSelector.Name = "Emigrants Selector (placeholder)";
344      emigrantsSelector.OperatorParameter.ActualName = EmigrantsSelectorParameter.Name;
345
346      migrator.Name = "Migrator (placeholder)";
347      migrator.OperatorParameter.ActualName = MigratorParameter.Name;
348
349      immigrationReplacer.Name = "Immigration Replacer (placeholder)";
350      immigrationReplacer.OperatorParameter.ActualName = ImmigrationReplacerParameter.Name;
351
352      generationsCounter.Name = "Generations + 1";
353      generationsCounter.Increment = new IntValue(1);
354      generationsCounter.ValueParameter.ActualName = "Generations";
355
356      generationsComparator.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
357      generationsComparator.LeftSideParameter.ActualName = "Generations";
358      generationsComparator.ResultParameter.ActualName = "TerminateGenerations";
359      generationsComparator.RightSideParameter.ActualName = MaximumGenerationsParameter.Name;
360
361      bestQualityMemorizer3.BestQualityParameter.ActualName = "BestQuality";
362      bestQualityMemorizer3.MaximizationParameter.ActualName = MaximizationParameter.Name;
363      bestQualityMemorizer3.QualityParameter.ActualName = "BestQuality";
364
365      bestQualityMemorizer4.BestQualityParameter.ActualName = BestKnownQualityParameter.Name;
366      bestQualityMemorizer4.MaximizationParameter.ActualName = MaximizationParameter.Name;
367      bestQualityMemorizer4.QualityParameter.ActualName = "BestQuality";
368
369      bestAverageWorstQualityCalculator2.AverageQualityParameter.ActualName = "CurrentAverageBestQuality";
370      bestAverageWorstQualityCalculator2.BestQualityParameter.ActualName = "CurrentBestBestQuality";
371      bestAverageWorstQualityCalculator2.MaximizationParameter.ActualName = MaximizationParameter.Name;
372      bestAverageWorstQualityCalculator2.QualityParameter.ActualName = "CurrentBestQuality";
373      bestAverageWorstQualityCalculator2.WorstQualityParameter.ActualName = "CurrentWorstBestQuality";
374
375      dataTableValuesCollector2.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Best BestQuality", null, "CurrentBestBestQuality"));
376      dataTableValuesCollector2.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Average BestQuality", null, "CurrentAverageBestQuality"));
377      dataTableValuesCollector2.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Worst BestQuality", null, "CurrentWorstBestQuality"));
378      dataTableValuesCollector2.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Quality", null, "BestQuality"));
379      dataTableValuesCollector2.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Known Quality", null, BestKnownQualityParameter.Name));
380      dataTableValuesCollector2.DataTableParameter.ActualName = "BestQualities";
381
382      qualityDifferenceCalculator2.AbsoluteDifferenceParameter.ActualName = "AbsoluteDifferenceBestKnownToBest";
383      qualityDifferenceCalculator2.FirstQualityParameter.ActualName = BestKnownQualityParameter.Name;
384      qualityDifferenceCalculator2.RelativeDifferenceParameter.ActualName = "RelativeDifferenceBestKnownToBest";
385      qualityDifferenceCalculator2.SecondQualityParameter.ActualName = "BestQuality";
386
387      generationsTerminationCondition.ConditionParameter.ActualName = "TerminateGenerations";
388      #endregion
389
390      #region Create operator graph
391      OperatorGraph.InitialOperator = variableCreator;
392      variableCreator.Successor = uniformSubScopesProcessor0;
393      uniformSubScopesProcessor0.Operator = islandVariableCreator;
394      uniformSubScopesProcessor0.Successor = bestQualityMemorizer1;
395      islandVariableCreator.Successor = islandBestQualityMemorizer1;
396      islandBestQualityMemorizer1.Successor = islandBestAverageWorstQualityCalculator1;
397      islandBestAverageWorstQualityCalculator1.Successor = islandDataTableValuesCollector1;
398      islandDataTableValuesCollector1.Successor = islandQualityDifferenceCalculator1;
399      islandQualityDifferenceCalculator1.Successor = islandVisualizer1;
400      islandVisualizer1.Successor = islandResultsCollector;
401      bestQualityMemorizer1.Successor = bestQualityMemorizer2;
402      bestQualityMemorizer2.Successor = bestAverageWorstQualityCalculator1;
403      bestAverageWorstQualityCalculator1.Successor = dataTableValuesCollector1;
404      dataTableValuesCollector1.Successor = qualityDifferenceCalculator1;
405      qualityDifferenceCalculator1.Successor = resultsCollector;
406      resultsCollector.Successor = uniformSubScopesProcessor1;
407      uniformSubScopesProcessor1.Operator = selector;
408      uniformSubScopesProcessor1.Successor = generationsSinceLastMigrationCounter;
409      selector.Successor = subScopesProcessor1;
410      subScopesProcessor1.Operators.Add(new EmptyOperator());
411      subScopesProcessor1.Operators.Add(childrenCreator);
412      subScopesProcessor1.Successor = subScopesProcessor2;
413      childrenCreator.Successor = uniformSubScopesProcessor2;
414      uniformSubScopesProcessor2.Operator = crossover;
415      uniformSubScopesProcessor2.Successor = null;
416      crossover.Successor = stochasticBranch;
417      stochasticBranch.FirstBranch = mutator;
418      stochasticBranch.SecondBranch = null;
419      stochasticBranch.Successor = evaluator;
420      mutator.Successor = null;
421      evaluator.Successor = subScopesRemover;
422      subScopesRemover.Successor = null;
423      subScopesProcessor2.Operators.Add(bestSelector);
424      subScopesProcessor2.Operators.Add(new EmptyOperator());
425      subScopesProcessor2.Successor = mergingReducer;
426      bestSelector.Successor = rightReducer;
427      rightReducer.Successor = null;
428      mergingReducer.Successor = islandBestQualityMemorizer2;
429      islandBestQualityMemorizer2.Successor = islandBestAverageWorstQualityCalculator2;
430      islandBestAverageWorstQualityCalculator2.Successor = islandDataTableValuesCollector2;
431      islandDataTableValuesCollector2.Successor = islandQualityDifferenceCalculator2;
432      islandQualityDifferenceCalculator2.Successor = islandVisualizer2;
433      islandVisualizer2.Successor = null;
434      generationsSinceLastMigrationCounter.Successor = migrationComparator;
435      migrationComparator.Successor = migrationBranch;
436      migrationBranch.TrueBranch = resetGenerationsSinceLastMigrationAssigner;
437      migrationBranch.FalseBranch = null;
438      migrationBranch.Successor = generationsCounter;
439      resetGenerationsSinceLastMigrationAssigner.Successor = migrationsCounter;
440      migrationsCounter.Successor = uniformSubScopesProcessor3;
441      uniformSubScopesProcessor3.Operator = emigrantsSelector;
442      uniformSubScopesProcessor3.Successor = migrator;
443      migrator.Successor = uniformSubScopesProcessor4;
444      uniformSubScopesProcessor4.Operator = immigrationReplacer;
445      uniformSubScopesProcessor4.Successor = null;
446      generationsCounter.Successor = generationsComparator;
447      generationsComparator.Successor = bestQualityMemorizer3;
448      bestQualityMemorizer3.Successor = bestQualityMemorizer4;
449      bestQualityMemorizer4.Successor = bestAverageWorstQualityCalculator2;
450      bestAverageWorstQualityCalculator2.Successor = dataTableValuesCollector2;
451      dataTableValuesCollector2.Successor = qualityDifferenceCalculator2;
452      qualityDifferenceCalculator2.Successor = generationsTerminationCondition;
453      generationsTerminationCondition.TrueBranch = null;
454      generationsTerminationCondition.FalseBranch = uniformSubScopesProcessor1;
455      generationsTerminationCondition.Successor = null;
456      #endregion
457    }
458  }
459}
Note: See TracBrowser for help on using the repository browser.