Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataAnalysis.IslandAlgorithms/HeuristicLab.Algorithms.GeneticAlgorithm/3.3/IslandGeneticAlgorithmMainLoop.cs @ 18183

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

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

File size: 29.2 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using HeuristicLab.Common;
23using HeuristicLab.Core;
24using HeuristicLab.Data;
25using HeuristicLab.Operators;
26using HeuristicLab.Optimization;
27using HeuristicLab.Optimization.Operators;
28using HeuristicLab.Parameters;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30using HeuristicLab.Selection;
31
32namespace HeuristicLab.Algorithms.GeneticAlgorithm {
33  /// <summary>
34  /// An island genetic algorithm main loop operator.
35  /// </summary>
36  [Item("IslandGeneticAlgorithmMainLoop", "An island genetic algorithm main loop operator.")]
37  [StorableClass]
38  public sealed class IslandGeneticAlgorithmMainLoop : AlgorithmOperator {
39    #region Parameter Properties
40    public ValueLookupParameter<IRandom> RandomParameter {
41      get { return (ValueLookupParameter<IRandom>)Parameters["Random"]; }
42    }
43    public ValueLookupParameter<BoolValue> MaximizationParameter {
44      get { return (ValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
45    }
46    public ScopeTreeLookupParameter<DoubleValue> QualityParameter {
47      get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
48    }
49    public ValueLookupParameter<DoubleValue> BestKnownQualityParameter {
50      get { return (ValueLookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
51    }
52    public ValueLookupParameter<IntValue> NumberOfIslandsParameter {
53      get { return (ValueLookupParameter<IntValue>)Parameters["NumberOfIslands"]; }
54    }
55    public ValueLookupParameter<IntValue> MigrationIntervalParameter {
56      get { return (ValueLookupParameter<IntValue>)Parameters["MigrationInterval"]; }
57    }
58    public IValueLookupParameter<IntValue> AnalysisIntervalParameter {
59      get { return (IValueLookupParameter<IntValue>)Parameters["AnalysisInterval"]; }
60    }
61    public ValueLookupParameter<PercentValue> MigrationRateParameter {
62      get { return (ValueLookupParameter<PercentValue>)Parameters["MigrationRate"]; }
63    }
64    public ValueLookupParameter<IOperator> MigratorParameter {
65      get { return (ValueLookupParameter<IOperator>)Parameters["Migrator"]; }
66    }
67    public ValueLookupParameter<IOperator> EmigrantsSelectorParameter {
68      get { return (ValueLookupParameter<IOperator>)Parameters["EmigrantsSelector"]; }
69    }
70    public ValueLookupParameter<IOperator> ImmigrationReplacerParameter {
71      get { return (ValueLookupParameter<IOperator>)Parameters["ImmigrationReplacer"]; }
72    }
73    public ValueLookupParameter<IntValue> PopulationSizeParameter {
74      get { return (ValueLookupParameter<IntValue>)Parameters["PopulationSize"]; }
75    }
76    public ValueLookupParameter<IntValue> MaximumGenerationsParameter {
77      get { return (ValueLookupParameter<IntValue>)Parameters["MaximumGenerations"]; }
78    }
79    public ValueLookupParameter<IOperator> SelectorParameter {
80      get { return (ValueLookupParameter<IOperator>)Parameters["Selector"]; }
81    }
82    public ValueLookupParameter<IOperator> CrossoverParameter {
83      get { return (ValueLookupParameter<IOperator>)Parameters["Crossover"]; }
84    }
85    public ValueLookupParameter<PercentValue> MutationProbabilityParameter {
86      get { return (ValueLookupParameter<PercentValue>)Parameters["MutationProbability"]; }
87    }
88    public ValueLookupParameter<IOperator> MutatorParameter {
89      get { return (ValueLookupParameter<IOperator>)Parameters["Mutator"]; }
90    }
91    public ValueLookupParameter<IOperator> EvaluatorParameter {
92      get { return (ValueLookupParameter<IOperator>)Parameters["Evaluator"]; }
93    }
94    public ValueLookupParameter<IntValue> ElitesParameter {
95      get { return (ValueLookupParameter<IntValue>)Parameters["Elites"]; }
96    }
97    public IValueLookupParameter<BoolValue> ReevaluateElitesParameter {
98      get { return (IValueLookupParameter<BoolValue>)Parameters["ReevaluateElites"]; }
99    }
100    public ValueLookupParameter<ResultCollection> ResultsParameter {
101      get { return (ValueLookupParameter<ResultCollection>)Parameters["Results"]; }
102    }
103    public ValueLookupParameter<IOperator> AnalyzerParameter {
104      get { return (ValueLookupParameter<IOperator>)Parameters["Analyzer"]; }
105    }
106    public ValueLookupParameter<IOperator> IslandAnalyzerParameter {
107      get { return (ValueLookupParameter<IOperator>)Parameters["IslandAnalyzer"]; }
108    }
109    public LookupParameter<IntValue> EvaluatedSolutionsParameter {
110      get { return (LookupParameter<IntValue>)Parameters["EvaluatedSolutions"]; }
111    }
112    public LookupParameter<IntValue> IslandGenerations {
113      get { return (LookupParameter<IntValue>)Parameters["IslandGenerations"]; }
114    }
115    public LookupParameter<IntValue> IslandEvaluatedSolutions {
116      get { return (LookupParameter<IntValue>)Parameters["IslandEvaluatedSolutions"]; }
117    }
118    public ValueLookupParameter<BoolValue> Migrate {
119      get { return (ValueLookupParameter<BoolValue>)Parameters["Migrate"]; }
120    }
121    public ILookupParameter<BoolValue> RunAnalysis {
122      get { return (ILookupParameter<BoolValue>)Parameters["RunAnalysis"]; }
123    }
124
125    public ValueLookupParameter<BoolValue> ReevaluateIndividualsAfterMigration {
126      get { return (ValueLookupParameter<BoolValue>)Parameters["ReevaluateIndividualsAfterMigration"]; }
127    }
128    #endregion
129
130    [StorableConstructor]
131    private IslandGeneticAlgorithmMainLoop(bool deserializing) : base(deserializing) { }
132    private IslandGeneticAlgorithmMainLoop(IslandGeneticAlgorithmMainLoop original, Cloner cloner)
133      : base(original, cloner) {
134    }
135    public override IDeepCloneable Clone(Cloner cloner) {
136      return new IslandGeneticAlgorithmMainLoop(this, cloner);
137    }
138    public IslandGeneticAlgorithmMainLoop()
139      : base() {
140      #region Create parameters
141      Parameters.Add(new ValueLookupParameter<IRandom>("Random", "A pseudo random number generator."));
142      Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
143      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution."));
144      Parameters.Add(new ValueLookupParameter<DoubleValue>("BestKnownQuality", "The best known quality value found so far."));
145      Parameters.Add(new ValueLookupParameter<IntValue>("NumberOfIslands", "The number of islands."));
146      Parameters.Add(new ValueLookupParameter<IntValue>("MigrationInterval", "The number of generations that should pass between migration phases."));
147      Parameters.Add(new ValueLookupParameter<IntValue>("AnalysisInterval", "The number of generations that should pass between the analyzers should be executed (should be <= MigrationInteval)."));
148      Parameters.Add(new ValueLookupParameter<PercentValue>("MigrationRate", "The proportion of individuals that should migrate between the islands."));
149      Parameters.Add(new ValueLookupParameter<IOperator>("Migrator", "The migration strategy."));
150      Parameters.Add(new ValueLookupParameter<IOperator>("EmigrantsSelector", "Selects the individuals that will be migrated."));
151      Parameters.Add(new ValueLookupParameter<IOperator>("ImmigrationReplacer", "Replaces some of the original population with the immigrants."));
152      Parameters.Add(new ValueLookupParameter<IntValue>("PopulationSize", "The size of the population of solutions."));
153      Parameters.Add(new ValueLookupParameter<IntValue>("MaximumGenerations", "The maximum number of generations that the algorithm should process."));
154      Parameters.Add(new ValueLookupParameter<IOperator>("Selector", "The operator used to select solutions for reproduction."));
155      Parameters.Add(new ValueLookupParameter<IOperator>("Crossover", "The operator used to cross solutions."));
156      Parameters.Add(new ValueLookupParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution."));
157      Parameters.Add(new ValueLookupParameter<IOperator>("Mutator", "The operator used to mutate solutions."));
158      Parameters.Add(new ValueLookupParameter<IOperator>("Evaluator", "The operator used to evaluate solutions."));
159      Parameters.Add(new ValueLookupParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation."));
160      Parameters.Add(new ValueLookupParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)"));
161      Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The results collection to store the results."));
162      Parameters.Add(new ValueLookupParameter<IOperator>("Analyzer", "The operator used to the analyze the islands."));
163      Parameters.Add(new ValueLookupParameter<IOperator>("IslandAnalyzer", "The operator used to analyze each island."));
164      Parameters.Add(new LookupParameter<IntValue>("EvaluatedSolutions", "The number of times a solution has been evaluated."));
165      Parameters.Add(new LookupParameter<IntValue>("IslandGenerations", "The number of generations calculated on one island."));
166      Parameters.Add(new LookupParameter<IntValue>("IslandEvaluatedSolutions", "The number of times a solution has been evaluated on one island."));
167      Parameters.Add(new ValueLookupParameter<BoolValue>("Migrate", "Migrate the island?"));
168      Parameters.Add(new LookupParameter<BoolValue>("RunAnalysis", "Run Analyzers?"));
169      Parameters.Add(new ValueLookupParameter<BoolValue>("ReevaluateIndividualsAfterMigration", "Flag which indicates if inviduals should be reevaluated after migration."));
170      #endregion
171
172      #region Create operators
173      VariableCreator variableCreator = new VariableCreator();
174      UniformSubScopesProcessor uniformSubScopesProcessor0 = new UniformSubScopesProcessor();
175      VariableCreator islandVariableCreator = new VariableCreator();
176      Placeholder islandAnalyzer1 = new Placeholder();
177      LocalRandomCreator localRandomCreator = new LocalRandomCreator();
178      Placeholder analyzer1 = new Placeholder();
179      ResultsCollector resultsCollector1 = new ResultsCollector();
180      UniformSubScopesProcessor uniformSubScopesProcessor1 = new UniformSubScopesProcessor();
181      Assigner generationsAssigner = new Assigner();
182      Assigner evaluatedSolutionsAssigner = new Assigner();
183      Placeholder selector = new Placeholder();
184      SubScopesProcessor subScopesProcessor1 = new SubScopesProcessor();
185      ChildrenCreator childrenCreator = new ChildrenCreator();
186      UniformSubScopesProcessor uniformSubScopesProcessor2 = new UniformSubScopesProcessor();
187      Placeholder crossover = new Placeholder();
188      StochasticBranch stochasticBranch = new StochasticBranch();
189      Placeholder mutator = new Placeholder();
190      SubScopesRemover subScopesRemover = new SubScopesRemover();
191      UniformSubScopesProcessor uniformSubScopesProcessor3 = new UniformSubScopesProcessor();
192      Placeholder evaluator = new Placeholder();
193      SubScopesCounter subScopesCounter = new SubScopesCounter();
194      SubScopesProcessor subScopesProcessor2 = new SubScopesProcessor();
195      BestSelector bestSelector = new BestSelector();
196      RightReducer rightReducer = new RightReducer();
197      MergingReducer mergingReducer = new MergingReducer();
198      IntCounter islandGenerationsCounter = new IntCounter();
199      IntCounter generationsSinceLastMigrationCounter = new IntCounter();
200      IntCounter generationsSinceLastAnalysisCounter = new IntCounter();
201      Comparator checkIslandGenerationsReachedMaximum = new Comparator();
202      ConditionalBranch checkContinueEvolution = new ConditionalBranch();
203      Assigner resetGenerationsSinceLastMigration = new Assigner();
204      Comparator checkIslandGenerationsForAnalysis = new Comparator();
205      ConditionalBranch checkRunAnalysis = new ConditionalBranch();
206      Assigner resetGenerationsSinceLastAnalysis = new Assigner();
207      DataReducer generationsReducer = new DataReducer();
208      DataReducer evaluatedSolutionsReducer = new DataReducer();
209      DataReducer migrationDataReducer = new DataReducer();
210      ConditionalBranch migrateIndividuals = new ConditionalBranch();
211      Placeholder islandAnalyzer2 = new Placeholder();
212      UniformSubScopesProcessor uniformSubScopesProcessor5 = new UniformSubScopesProcessor();
213      Placeholder emigrantsSelector = new Placeholder();
214      IntCounter migrationsCounter = new IntCounter();
215      Placeholder migrator = new Placeholder();
216      ConditionalBranch reevaluateImmigrantsBranch = new ConditionalBranch();
217      Assigner evaluatedSolutionsAssigner2 = new Assigner();
218      UniformSubScopesProcessor uniformSubScopesProcessor6 = new UniformSubScopesProcessor();
219      UniformSubScopesProcessor uniformSubScopesProcessor8 = new UniformSubScopesProcessor();
220      DataReducer evaluatedSolutionsReducer2 = new DataReducer();
221      UniformSubScopesProcessor uniformSubScopesProcessor7 = new UniformSubScopesProcessor();
222      Placeholder immigrationReplacer = new Placeholder();
223      Comparator generationsComparator = new Comparator();
224      Placeholder analyzer2 = new Placeholder();
225      ConditionalBranch generationsTerminationCondition = new ConditionalBranch();
226      ConditionalBranch reevaluateElitesBranch = new ConditionalBranch();
227
228      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Migrations", new IntValue(0)));
229      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Generations", new IntValue(0))); // Class IslandGeneticAlgorithm expects this to be called Generations
230
231      islandVariableCreator.CollectedValues.Add(new ValueParameter<ResultCollection>("Results", new ResultCollection()));
232      islandVariableCreator.CollectedValues.Add(new ValueParameter<IntValue>("IslandGenerations", new IntValue(0)));
233      islandVariableCreator.CollectedValues.Add(new ValueParameter<IntValue>("IslandEvaluatedSolutions", new IntValue(0)));
234      islandVariableCreator.CollectedValues.Add(new ValueParameter<IntValue>("IslandGenerationsSinceLastMigration", new IntValue(0)));
235      islandVariableCreator.CollectedValues.Add(new ValueParameter<IntValue>("IslandGenerationsSinceLastAnalysis", new IntValue(0)));
236
237      islandAnalyzer1.Name = "Island Analyzer (placeholder)";
238      islandAnalyzer1.OperatorParameter.ActualName = IslandAnalyzerParameter.Name;
239
240      analyzer1.Name = "Analyzer (placeholder)";
241      analyzer1.OperatorParameter.ActualName = AnalyzerParameter.Name;
242
243      resultsCollector1.CollectedValues.Add(new LookupParameter<IntValue>("Migrations"));
244      resultsCollector1.CollectedValues.Add(new LookupParameter<IntValue>("Generations"));
245      resultsCollector1.CollectedValues.Add(new ScopeTreeLookupParameter<ResultCollection>("IslandResults", "Result set for each island", "Results"));
246      resultsCollector1.ResultsParameter.ActualName = ResultsParameter.Name;
247
248      uniformSubScopesProcessor1.Parallel.Value = true;
249
250      generationsAssigner.Name = "Initialize Island Generations";
251      generationsAssigner.LeftSideParameter.ActualName = IslandGenerations.Name;
252      generationsAssigner.RightSideParameter.Value = new IntValue(0);
253
254      evaluatedSolutionsAssigner.Name = "Initialize Island evaluated solutions";
255      evaluatedSolutionsAssigner.LeftSideParameter.ActualName = IslandEvaluatedSolutions.Name;
256      evaluatedSolutionsAssigner.RightSideParameter.Value = new IntValue(0);
257
258      selector.Name = "Selector (placeholder)";
259      selector.OperatorParameter.ActualName = SelectorParameter.Name;
260
261      childrenCreator.ParentsPerChild = new IntValue(2);
262
263      crossover.Name = "Crossover (placeholder)";
264      crossover.OperatorParameter.ActualName = CrossoverParameter.Name;
265
266      stochasticBranch.ProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
267      //set it to the random number generator of the island
268      stochasticBranch.RandomParameter.ActualName = "LocalRandom";
269
270      mutator.Name = "Mutator (placeholder)";
271      mutator.OperatorParameter.ActualName = MutatorParameter.Name;
272
273      subScopesRemover.RemoveAllSubScopes = true;
274
275      evaluator.Name = "Evaluator (placeholder)";
276      evaluator.OperatorParameter.ActualName = EvaluatorParameter.Name;
277
278      subScopesCounter.Name = "Increment EvaluatedSolutions";
279      subScopesCounter.ValueParameter.ActualName = IslandEvaluatedSolutions.Name;
280
281      bestSelector.CopySelected = new BoolValue(false);
282      bestSelector.MaximizationParameter.ActualName = MaximizationParameter.Name;
283      bestSelector.NumberOfSelectedSubScopesParameter.ActualName = ElitesParameter.Name;
284      bestSelector.QualityParameter.ActualName = QualityParameter.Name;
285
286      islandGenerationsCounter.Name = "Increment island generatrions";
287      islandGenerationsCounter.ValueParameter.ActualName = IslandGenerations.Name;
288      islandGenerationsCounter.Increment = new IntValue(1);
289
290      generationsSinceLastMigrationCounter.Name = "Increment island generation since last migration";
291      generationsSinceLastMigrationCounter.ValueParameter.ActualName = "IslandGenerationsSinceLastMigration";
292      generationsSinceLastMigrationCounter.Increment = new IntValue(1);
293
294      generationsSinceLastAnalysisCounter.Name = "Increment island generation since last analysis";
295      generationsSinceLastAnalysisCounter.ValueParameter.ActualName = "IslandGenerationsSinceLastAnalysis";
296      generationsSinceLastAnalysisCounter.Increment = new IntValue(1);
297
298      checkIslandGenerationsReachedMaximum.LeftSideParameter.ActualName = "IslandGenerationsSinceLastMigration";
299      checkIslandGenerationsReachedMaximum.RightSideParameter.ActualName = MigrationIntervalParameter.Name;
300      checkIslandGenerationsReachedMaximum.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
301      checkIslandGenerationsReachedMaximum.ResultParameter.ActualName = Migrate.Name;
302
303      resetGenerationsSinceLastMigration.Name = "Reset generations since last migration";
304      resetGenerationsSinceLastMigration.LeftSideParameter.ActualName = "IslandGenerationsSinceLastMigration";
305      resetGenerationsSinceLastMigration.RightSideParameter.Value = new IntValue(0);
306      resetGenerationsSinceLastMigration.Successor = resetGenerationsSinceLastAnalysis;
307
308      checkContinueEvolution.Name = "Migrate?";
309      checkContinueEvolution.ConditionParameter.ActualName = Migrate.Name;
310      checkContinueEvolution.TrueBranch = resetGenerationsSinceLastMigration;
311      checkContinueEvolution.FalseBranch = checkIslandGenerationsForAnalysis;
312
313      checkIslandGenerationsForAnalysis.LeftSideParameter.ActualName = "IslandGenerationsSinceLastAnalysis";
314      checkIslandGenerationsForAnalysis.RightSideParameter.ActualName = AnalysisIntervalParameter.Name;
315      checkIslandGenerationsForAnalysis.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
316      checkIslandGenerationsForAnalysis.ResultParameter.ActualName = RunAnalysis.Name;
317
318      resetGenerationsSinceLastAnalysis.Name = "Reset generations since last analysis";
319      resetGenerationsSinceLastAnalysis.LeftSideParameter.ActualName = "IslandGenerationsSinceLastAnalysis";
320      resetGenerationsSinceLastAnalysis.RightSideParameter.Value = new IntValue(0);
321
322      checkRunAnalysis.Name = "Run Analyzers?";
323      checkRunAnalysis.ConditionParameter.ActualName = RunAnalysis.Name;
324      checkRunAnalysis.TrueBranch = resetGenerationsSinceLastAnalysis;
325      checkRunAnalysis.FalseBranch = selector;
326
327      islandAnalyzer2.Name = "Island Analyzer (placeholder)";
328      islandAnalyzer2.OperatorParameter.ActualName = IslandAnalyzerParameter.Name;
329
330      generationsReducer.Name = "Increment Generations";
331      generationsReducer.ParameterToReduce.ActualName = islandGenerationsCounter.ValueParameter.ActualName;
332      generationsReducer.TargetParameter.ActualName = "Generations";
333      generationsReducer.ReductionOperation.Value = new ReductionOperation(ReductionOperations.Min);
334      generationsReducer.TargetOperation.Value = new ReductionOperation(ReductionOperations.Sum);
335
336      evaluatedSolutionsReducer.Name = "Increment Evaluated Solutions";
337      evaluatedSolutionsReducer.ParameterToReduce.ActualName = IslandEvaluatedSolutions.Name;
338      evaluatedSolutionsReducer.TargetParameter.ActualName = EvaluatedSolutionsParameter.Name;
339      evaluatedSolutionsReducer.ReductionOperation.Value = new ReductionOperation(ReductionOperations.Sum);
340      evaluatedSolutionsReducer.TargetOperation.Value = new ReductionOperation(ReductionOperations.Sum);
341
342      migrationDataReducer.Name = "Collect Migration Flags";
343      migrationDataReducer.ParameterToReduce.ActualName = Migrate.Name;
344      migrationDataReducer.TargetParameter.ActualName = Migrate.Name;
345      migrationDataReducer.ReductionOperation.Value = new ReductionOperation(ReductionOperations.All);
346      migrationDataReducer.TargetOperation.Value = new ReductionOperation(ReductionOperations.Assign);
347
348      migrateIndividuals.Name = "Migrate?";
349      migrateIndividuals.ConditionParameter.ActualName = Migrate.Name;
350
351      emigrantsSelector.Name = "Emigrants Selector (placeholder)";
352      emigrantsSelector.OperatorParameter.ActualName = EmigrantsSelectorParameter.Name;
353
354      migrationsCounter.Name = "Increment number of Migrations";
355      migrationsCounter.ValueParameter.ActualName = "Migrations";
356      migrationsCounter.Increment = new IntValue(1);
357
358      migrator.Name = "Migrator (placeholder)";
359      migrator.OperatorParameter.ActualName = MigratorParameter.Name;
360
361      reevaluateImmigrantsBranch.ConditionParameter.ActualName = "ReevaluateImmigrants";
362      reevaluateImmigrantsBranch.Name = "Reevaluate Immigrants ?";
363
364      evaluatedSolutionsAssigner2.Name = "Reset Island evaluated solutions";
365      evaluatedSolutionsAssigner2.LeftSideParameter.ActualName = IslandEvaluatedSolutions.Name;
366      evaluatedSolutionsAssigner2.RightSideParameter.Value = new IntValue(0);
367
368      evaluatedSolutionsReducer2.Name = "Increment Evaluated Solutions";
369      evaluatedSolutionsReducer2.ParameterToReduce.ActualName = IslandEvaluatedSolutions.Name;
370      evaluatedSolutionsReducer2.TargetParameter.ActualName = EvaluatedSolutionsParameter.Name;
371      evaluatedSolutionsReducer2.ReductionOperation.Value = new ReductionOperation(ReductionOperations.Sum);
372      evaluatedSolutionsReducer2.TargetOperation.Value = new ReductionOperation(ReductionOperations.Sum);
373
374      immigrationReplacer.Name = "Immigration Replacer (placeholder)";
375      immigrationReplacer.OperatorParameter.ActualName = ImmigrationReplacerParameter.Name;
376
377      generationsComparator.Name = "Generations >= MaximumGenerations ?";
378      generationsComparator.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
379      generationsComparator.LeftSideParameter.ActualName = "Generations";
380      generationsComparator.ResultParameter.ActualName = "TerminateGenerations";
381      generationsComparator.RightSideParameter.ActualName = MaximumGenerationsParameter.Name;
382
383      analyzer2.Name = "Analyzer (placeholder)";
384      analyzer2.OperatorParameter.ActualName = AnalyzerParameter.Name;
385
386      generationsTerminationCondition.Name = "Terminate?";
387      generationsTerminationCondition.ConditionParameter.ActualName = "TerminateGenerations";
388
389      reevaluateElitesBranch.ConditionParameter.ActualName = "ReevaluateElites";
390      reevaluateElitesBranch.Name = "Reevaluate elites ?";
391      #endregion
392
393      #region Create operator graph
394      OperatorGraph.InitialOperator = variableCreator;
395      variableCreator.Successor = uniformSubScopesProcessor0;
396      uniformSubScopesProcessor0.Operator = islandVariableCreator;
397      uniformSubScopesProcessor0.Successor = analyzer1;
398      islandVariableCreator.Successor = islandAnalyzer1;
399      // BackwardsCompatibility3.3
400      //the local randoms are created by the island GA itself and are only here to ensure same algorithm results
401      #region Backwards compatible code, remove local random creator with 3.4 and rewire the operator graph
402      islandAnalyzer1.Successor = localRandomCreator;
403      localRandomCreator.Successor = null;
404      #endregion
405      analyzer1.Successor = resultsCollector1;
406      resultsCollector1.Successor = uniformSubScopesProcessor1;
407      uniformSubScopesProcessor1.Operator = generationsAssigner;
408      uniformSubScopesProcessor1.Successor = generationsReducer;
409      generationsReducer.Successor = evaluatedSolutionsReducer;
410      evaluatedSolutionsReducer.Successor = migrationDataReducer;
411      migrationDataReducer.Successor = migrateIndividuals;
412      migrateIndividuals.TrueBranch = migrationsCounter;
413      migrateIndividuals.FalseBranch = generationsComparator;
414      migrationsCounter.Successor = uniformSubScopesProcessor5;
415      generationsAssigner.Successor = evaluatedSolutionsAssigner;
416      evaluatedSolutionsAssigner.Successor = selector;
417      selector.Successor = subScopesProcessor1;
418      subScopesProcessor1.Operators.Add(new EmptyOperator());
419      subScopesProcessor1.Operators.Add(childrenCreator);
420      subScopesProcessor1.Successor = subScopesProcessor2;
421      childrenCreator.Successor = uniformSubScopesProcessor2;
422      uniformSubScopesProcessor2.Operator = crossover;
423      uniformSubScopesProcessor2.Successor = uniformSubScopesProcessor3;
424      crossover.Successor = stochasticBranch;
425      stochasticBranch.FirstBranch = mutator;
426      stochasticBranch.SecondBranch = null;
427      stochasticBranch.Successor = subScopesRemover;
428      mutator.Successor = null;
429      subScopesRemover.Successor = null;
430      uniformSubScopesProcessor3.Operator = evaluator;
431      uniformSubScopesProcessor3.Successor = subScopesCounter;
432      evaluator.Successor = null;
433      subScopesCounter.Successor = null;
434      subScopesProcessor2.Operators.Add(bestSelector);
435      subScopesProcessor2.Operators.Add(new EmptyOperator());
436      subScopesProcessor2.Successor = mergingReducer;
437      mergingReducer.Successor = islandAnalyzer2;
438      bestSelector.Successor = rightReducer;
439      rightReducer.Successor = reevaluateElitesBranch;
440      reevaluateElitesBranch.TrueBranch = uniformSubScopesProcessor3;
441      reevaluateElitesBranch.FalseBranch = null;
442      reevaluateElitesBranch.Successor = null;
443      islandAnalyzer2.Successor = islandGenerationsCounter;
444      islandGenerationsCounter.Successor = generationsSinceLastMigrationCounter;
445      generationsSinceLastMigrationCounter.Successor = generationsSinceLastAnalysisCounter;
446      generationsSinceLastAnalysisCounter.Successor = checkIslandGenerationsReachedMaximum;
447      checkIslandGenerationsReachedMaximum.Successor = checkContinueEvolution;
448      checkContinueEvolution.FalseBranch = checkIslandGenerationsForAnalysis;
449      checkIslandGenerationsForAnalysis.Successor = checkRunAnalysis;
450      uniformSubScopesProcessor5.Operator = emigrantsSelector;
451      emigrantsSelector.Successor = null;
452      uniformSubScopesProcessor5.Successor = migrator;
453      migrator.Successor = reevaluateImmigrantsBranch;
454      reevaluateImmigrantsBranch.FalseBranch = null;
455      reevaluateImmigrantsBranch.Successor = uniformSubScopesProcessor7;
456      reevaluateImmigrantsBranch.TrueBranch = uniformSubScopesProcessor6;
457      uniformSubScopesProcessor6.Successor = evaluatedSolutionsReducer2;
458      uniformSubScopesProcessor6.Operator = evaluatedSolutionsAssigner2;
459      evaluatedSolutionsAssigner2.Successor = uniformSubScopesProcessor8;
460      uniformSubScopesProcessor8.Operator = uniformSubScopesProcessor3;
461      uniformSubScopesProcessor8.Successor = null;
462      evaluatedSolutionsReducer2.Successor = null;
463      uniformSubScopesProcessor7.Operator = immigrationReplacer;
464      uniformSubScopesProcessor7.Successor = generationsComparator;
465      generationsComparator.Successor = analyzer2;
466      analyzer2.Successor = generationsTerminationCondition;
467      generationsTerminationCondition.TrueBranch = null;
468      generationsTerminationCondition.FalseBranch = uniformSubScopesProcessor1;
469      generationsTerminationCondition.Successor = null;
470      #endregion
471    }
472
473    [StorableHook(HookType.AfterDeserialization)]
474    private void AfterDeserialization() {
475      // BackwardsCompatibility3.3
476      #region Backwards compatible code, remove with 3.4
477      if (!Parameters.ContainsKey("ReevaluateElites")) {
478        Parameters.Add(new ValueLookupParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)"));
479      }
480      #endregion
481    }
482
483    public override IOperation Apply() {
484      if (CrossoverParameter.ActualValue == null)
485        return null;
486      return base.Apply();
487    }
488  }
489}
Note: See TracBrowser for help on using the repository browser.