Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HLScript/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3/SASEGASAMainLoop.cs @ 12289

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

#2038: Added tagging comment

File size: 29.2 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using HeuristicLab.Common;
23using HeuristicLab.Core;
24using HeuristicLab.Data;
25using HeuristicLab.Operators;
26using HeuristicLab.Optimization;
27using HeuristicLab.Optimization.Operators;
28using HeuristicLab.Parameters;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30
31namespace HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm {
32  /// <summary>
33  /// A SASEGASA main loop operator.
34  /// </summary>
35  [Item("SASEGASAMainLoop", "A SASEGASA main loop operator.")]
36  [StorableClass]
37  public sealed class SASEGASAMainLoop : AlgorithmOperator {
38    #region Parameter Properties
39    public ValueLookupParameter<IRandom> RandomParameter {
40      get { return (ValueLookupParameter<IRandom>)Parameters["Random"]; }
41    }
42    public ValueLookupParameter<IntValue> NumberOfVillagesParameter {
43      get { return (ValueLookupParameter<IntValue>)Parameters["NumberOfVillages"]; }
44    }
45    public ValueLookupParameter<IntValue> MigrationIntervalParameter {
46      get { return (ValueLookupParameter<IntValue>)Parameters["MigrationInterval"]; }
47    }
48    public ValueLookupParameter<BoolValue> MaximizationParameter {
49      get { return (ValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
50    }
51    public ScopeTreeLookupParameter<DoubleValue> QualityParameter {
52      get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
53    }
54    public ValueLookupParameter<DoubleValue> BestKnownQualityParameter {
55      get { return (ValueLookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
56    }
57    public ValueLookupParameter<IOperator> SelectorParameter {
58      get { return (ValueLookupParameter<IOperator>)Parameters["Selector"]; }
59    }
60    public ValueLookupParameter<IOperator> CrossoverParameter {
61      get { return (ValueLookupParameter<IOperator>)Parameters["Crossover"]; }
62    }
63    public ValueLookupParameter<PercentValue> MutationProbabilityParameter {
64      get { return (ValueLookupParameter<PercentValue>)Parameters["MutationProbability"]; }
65    }
66    public ValueLookupParameter<IOperator> MutatorParameter {
67      get { return (ValueLookupParameter<IOperator>)Parameters["Mutator"]; }
68    }
69    public ValueLookupParameter<IOperator> EvaluatorParameter {
70      get { return (ValueLookupParameter<IOperator>)Parameters["Evaluator"]; }
71    }
72    public ValueLookupParameter<IntValue> ElitesParameter {
73      get { return (ValueLookupParameter<IntValue>)Parameters["Elites"]; }
74    }
75    public IValueLookupParameter<BoolValue> ReevaluateElitesParameter {
76      get { return (IValueLookupParameter<BoolValue>)Parameters["ReevaluateElites"]; }
77    }
78    public ValueLookupParameter<ResultCollection> ResultsParameter {
79      get { return (ValueLookupParameter<ResultCollection>)Parameters["Results"]; }
80    }
81    public ValueLookupParameter<IOperator> AnalyzerParameter {
82      get { return (ValueLookupParameter<IOperator>)Parameters["Analyzer"]; }
83    }
84    public ValueLookupParameter<IOperator> VillageAnalyzerParameter {
85      get { return (ValueLookupParameter<IOperator>)Parameters["VillageAnalyzer"]; }
86    }
87    public ValueLookupParameter<DoubleValue> SuccessRatioParameter {
88      get { return (ValueLookupParameter<DoubleValue>)Parameters["SuccessRatio"]; }
89    }
90    public LookupParameter<DoubleValue> ComparisonFactorParameter {
91      get { return (LookupParameter<DoubleValue>)Parameters["ComparisonFactor"]; }
92    }
93    public ValueLookupParameter<DoubleValue> ComparisonFactorStartParameter {
94      get { return (ValueLookupParameter<DoubleValue>)Parameters["ComparisonFactorStart"]; }
95    }
96    public ValueLookupParameter<IOperator> ComparisonFactorModifierParameter {
97      get { return (ValueLookupParameter<IOperator>)Parameters["ComparisonFactorModifier"]; }
98    }
99    public ValueLookupParameter<DoubleValue> MaximumSelectionPressureParameter {
100      get { return (ValueLookupParameter<DoubleValue>)Parameters["MaximumSelectionPressure"]; }
101    }
102    public ValueLookupParameter<DoubleValue> FinalMaximumSelectionPressureParameter {
103      get { return (ValueLookupParameter<DoubleValue>)Parameters["FinalMaximumSelectionPressure"]; }
104    }
105    public ValueLookupParameter<IntValue> MaximumGenerationsParameter {
106      get { return (ValueLookupParameter<IntValue>)Parameters["MaximumGenerations"]; }
107    }
108    public ValueLookupParameter<BoolValue> OffspringSelectionBeforeMutationParameter {
109      get { return (ValueLookupParameter<BoolValue>)Parameters["OffspringSelectionBeforeMutation"]; }
110    }
111    public LookupParameter<IntValue> EvaluatedSolutionsParameter {
112      get { return (LookupParameter<IntValue>)Parameters["EvaluatedSolutions"]; }
113    }
114    #endregion
115
116    [StorableConstructor]
117    private SASEGASAMainLoop(bool deserializing) : base(deserializing) { }
118    private SASEGASAMainLoop(SASEGASAMainLoop original, Cloner cloner)
119      : base(original, cloner) {
120    }
121    public override IDeepCloneable Clone(Cloner cloner) {
122      return new SASEGASAMainLoop(this, cloner);
123    }
124    public SASEGASAMainLoop()
125      : base() {
126      #region Create parameters
127      Parameters.Add(new ValueLookupParameter<IRandom>("Random", "A pseudo random number generator."));
128      Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
129      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution."));
130      Parameters.Add(new ValueLookupParameter<DoubleValue>("BestKnownQuality", "The best known quality value found so far."));
131      Parameters.Add(new ValueLookupParameter<IntValue>("NumberOfVillages", "The initial number of villages."));
132      Parameters.Add(new ValueLookupParameter<IntValue>("MigrationInterval", "The fixed period after which migration occurs."));
133      Parameters.Add(new ValueLookupParameter<IOperator>("Selector", "The operator used to select solutions for reproduction."));
134      Parameters.Add(new ValueLookupParameter<IOperator>("Crossover", "The operator used to cross solutions."));
135      Parameters.Add(new ValueLookupParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution."));
136      Parameters.Add(new ValueLookupParameter<IOperator>("Mutator", "The operator used to mutate solutions."));
137      Parameters.Add(new ValueLookupParameter<IOperator>("Evaluator", "The operator used to evaluate solutions. This operator is executed in parallel, if an engine is used which supports parallelization."));
138      Parameters.Add(new ValueLookupParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation."));
139      Parameters.Add(new ValueLookupParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)"));
140      Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The results collection to store the results."));
141      Parameters.Add(new ValueLookupParameter<IOperator>("Analyzer", "The operator used to the analyze the villages."));
142      Parameters.Add(new ValueLookupParameter<IOperator>("VillageAnalyzer", "The operator used to analyze each village."));
143      Parameters.Add(new ValueLookupParameter<DoubleValue>("SuccessRatio", "The ratio of successful to total children that should be achieved."));
144      Parameters.Add(new LookupParameter<DoubleValue>("ComparisonFactor", "The comparison factor is used to determine whether the offspring should be compared to the better parent, the worse parent or a quality value linearly interpolated between them. It is in the range [0;1]."));
145      Parameters.Add(new ValueLookupParameter<DoubleValue>("ComparisonFactorStart", "The lower bound of the comparison factor (start)."));
146      Parameters.Add(new ValueLookupParameter<IOperator>("ComparisonFactorModifier", "The operator used to modify the comparison factor."));
147      Parameters.Add(new ValueLookupParameter<DoubleValue>("MaximumSelectionPressure", "The maximum selection pressure that terminates the algorithm."));
148      Parameters.Add(new ValueLookupParameter<DoubleValue>("FinalMaximumSelectionPressure", "The maximum selection pressure used when there is only one village left."));
149      Parameters.Add(new ValueLookupParameter<IntValue>("MaximumGenerations", "The maximum genreation that terminates the algorithm."));
150      Parameters.Add(new ValueLookupParameter<BoolValue>("OffspringSelectionBeforeMutation", "True if the offspring selection step should be applied before mutation, false if it should be applied after mutation."));
151      Parameters.Add(new LookupParameter<IntValue>("EvaluatedSolutions", "The number of times solutions have been evaluated."));
152      #endregion
153
154      #region Create operators
155      VariableCreator variableCreator = new VariableCreator();
156      Assigner maxSelPressAssigner = new Assigner();
157      Assigner villageCountAssigner = new Assigner();
158      Assigner comparisonFactorInitializer = new Assigner();
159      UniformSubScopesProcessor uniformSubScopesProcessor0 = new UniformSubScopesProcessor();
160      VariableCreator villageVariableCreator = new VariableCreator();
161      Placeholder villageAnalyzer1 = new Placeholder();
162      ResultsCollector villageResultsCollector1 = new ResultsCollector();
163      Placeholder analyzer1 = new Placeholder();
164      ResultsCollector resultsCollector1 = new ResultsCollector();
165      UniformSubScopesProcessor uniformSubScopesProcessor1 = new UniformSubScopesProcessor();
166      ConditionalBranch villageTerminatedBySelectionPressure1 = new ConditionalBranch();
167      OffspringSelectionGeneticAlgorithmMainOperator mainOperator = new OffspringSelectionGeneticAlgorithmMainOperator();
168      Placeholder villageAnalyzer2 = new Placeholder();
169      ResultsCollector villageResultsCollector2 = new ResultsCollector();
170      Comparator villageSelectionPressureComparator = new Comparator();
171      ConditionalBranch villageTerminatedBySelectionPressure2 = new ConditionalBranch();
172      IntCounter terminatedVillagesCounter = new IntCounter();
173      IntCounter generationsCounter = new IntCounter();
174      IntCounter generationsSinceLastReunificationCounter = new IntCounter();
175      Comparator reunificationComparator1 = new Comparator();
176      ConditionalBranch reunificationConditionalBranch1 = new ConditionalBranch();
177      Comparator reunificationComparator2 = new Comparator();
178      ConditionalBranch reunificationConditionalBranch2 = new ConditionalBranch();
179      Comparator reunificationComparator3 = new Comparator();
180      ConditionalBranch reunificationConditionalBranch3 = new ConditionalBranch();
181      Assigner resetTerminatedVillagesAssigner = new Assigner();
182      Assigner resetGenerationsSinceLastReunificationAssigner = new Assigner();
183      SASEGASAReunificator reunificator = new SASEGASAReunificator();
184      IntCounter reunificationCounter = new IntCounter();
185      Placeholder comparisonFactorModifier = new Placeholder();
186      UniformSubScopesProcessor uniformSubScopesProcessor2 = new UniformSubScopesProcessor();
187      Assigner villageReviver = new Assigner();
188      Comparator villageCountComparator = new Comparator();
189      ConditionalBranch villageCountConditionalBranch = new ConditionalBranch();
190      Assigner finalMaxSelPressAssigner = new Assigner();
191      Comparator maximumGenerationsComparator = new Comparator();
192      Comparator maximumEvaluatedSolutionsComparator = new Comparator();
193      Placeholder analyzer2 = new Placeholder();
194      ConditionalBranch terminationCondition = new ConditionalBranch();
195      ConditionalBranch maximumGenerationsTerminationCondition = new ConditionalBranch();
196      ConditionalBranch maximumEvaluatedSolutionsTerminationCondition = new ConditionalBranch();
197
198      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Reunifications", new IntValue(0)));
199      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Generations", new IntValue(0))); // Class SASEGASA expects this to be called Generations
200      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("GenerationsSinceLastReunification", new IntValue(0)));
201      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("TerminatedVillages", new IntValue(0)));
202
203      villageCountAssigner.LeftSideParameter.ActualName = "VillageCount";
204      villageCountAssigner.RightSideParameter.ActualName = NumberOfVillagesParameter.Name;
205
206      maxSelPressAssigner.LeftSideParameter.ActualName = "CurrentMaximumSelectionPressure";
207      maxSelPressAssigner.RightSideParameter.ActualName = MaximumSelectionPressureParameter.Name;
208
209      comparisonFactorInitializer.LeftSideParameter.ActualName = ComparisonFactorParameter.Name;
210      comparisonFactorInitializer.RightSideParameter.ActualName = ComparisonFactorStartParameter.Name;
211
212      villageVariableCreator.CollectedValues.Add(new ValueParameter<ResultCollection>("Results", new ResultCollection()));
213      villageVariableCreator.CollectedValues.Add(new ValueParameter<BoolValue>("TerminateSelectionPressure", new BoolValue(false)));
214      villageVariableCreator.CollectedValues.Add(new ValueParameter<DoubleValue>("SelectionPressure", new DoubleValue(0)));
215      villageVariableCreator.CollectedValues.Add(new ValueParameter<DoubleValue>("CurrentSuccessRatio", new DoubleValue(0)));
216
217      villageAnalyzer1.Name = "Village Analyzer (placeholder)";
218      villageAnalyzer1.OperatorParameter.ActualName = VillageAnalyzerParameter.Name;
219
220      villageResultsCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Success Ratio", "Indicates how many successful children were already found during a generation (relative to the population size).", "CurrentSuccessRatio"));
221      villageResultsCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Selection Pressure", "Displays the rising selection pressure during a generation.", "SelectionPressure"));
222      villageResultsCollector1.ResultsParameter.ActualName = "Results";
223
224      analyzer1.Name = "Analyzer (placeholder)";
225      analyzer1.OperatorParameter.ActualName = AnalyzerParameter.Name;
226
227      resultsCollector1.CopyValue = new BoolValue(false);
228      resultsCollector1.CollectedValues.Add(new LookupParameter<IntValue>("Generations"));
229      resultsCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>("ComparisonFactor", null, ComparisonFactorParameter.Name));
230      resultsCollector1.CollectedValues.Add(new LookupParameter<IntValue>("Terminated Villages", null, "TerminatedVillages"));
231      resultsCollector1.CollectedValues.Add(new LookupParameter<IntValue>("Total Active Villages", null, "VillageCount"));
232      resultsCollector1.CollectedValues.Add(new ScopeTreeLookupParameter<ResultCollection>("VillageResults", "Result set for each village", "Results"));
233      resultsCollector1.ResultsParameter.ActualName = ResultsParameter.Name;
234
235      villageTerminatedBySelectionPressure1.Name = "Village Terminated ?";
236      villageTerminatedBySelectionPressure1.ConditionParameter.ActualName = "TerminateSelectionPressure";
237
238      mainOperator.ComparisonFactorParameter.ActualName = ComparisonFactorParameter.Name;
239      mainOperator.CrossoverParameter.ActualName = CrossoverParameter.Name;
240      mainOperator.CurrentSuccessRatioParameter.ActualName = "CurrentSuccessRatio";
241      mainOperator.ElitesParameter.ActualName = ElitesParameter.Name;
242      mainOperator.ReevaluateElitesParameter.ActualName = ReevaluateElitesParameter.Name;
243      mainOperator.EvaluatedSolutionsParameter.ActualName = EvaluatedSolutionsParameter.Name;
244      mainOperator.EvaluatorParameter.ActualName = EvaluatorParameter.Name;
245      mainOperator.MaximizationParameter.ActualName = MaximizationParameter.Name;
246      mainOperator.MaximumSelectionPressureParameter.ActualName = "CurrentMaximumSelectionPressure";
247      mainOperator.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
248      mainOperator.MutatorParameter.ActualName = MutatorParameter.Name;
249      mainOperator.OffspringSelectionBeforeMutationParameter.ActualName = OffspringSelectionBeforeMutationParameter.Name;
250      mainOperator.QualityParameter.ActualName = QualityParameter.Name;
251      mainOperator.RandomParameter.ActualName = RandomParameter.Name;
252      mainOperator.SelectionPressureParameter.ActualName = "SelectionPressure";
253      mainOperator.SelectorParameter.ActualName = SelectorParameter.Name;
254      mainOperator.SuccessRatioParameter.ActualName = SuccessRatioParameter.Name;
255
256      villageAnalyzer2.Name = "Village Analyzer (placeholder)";
257      villageAnalyzer2.OperatorParameter.ActualName = VillageAnalyzerParameter.Name;
258
259      villageResultsCollector2.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Success Ratio", "Indicates how many successful children were already found during a generation (relative to the population size).", "CurrentSuccessRatio"));
260      villageResultsCollector2.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Selection Pressure", "Displays the rising selection pressure during a generation.", "SelectionPressure"));
261      villageResultsCollector2.ResultsParameter.ActualName = "Results";
262
263      villageSelectionPressureComparator.Name = "SelectionPressure >= MaximumSelectionPressure ?";
264      villageSelectionPressureComparator.LeftSideParameter.ActualName = "SelectionPressure";
265      villageSelectionPressureComparator.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
266      villageSelectionPressureComparator.RightSideParameter.ActualName = MaximumSelectionPressureParameter.Name;
267      villageSelectionPressureComparator.ResultParameter.ActualName = "TerminateSelectionPressure";
268
269      villageTerminatedBySelectionPressure2.Name = "Village Terminated ?";
270      villageTerminatedBySelectionPressure2.ConditionParameter.ActualName = "TerminateSelectionPressure";
271
272      terminatedVillagesCounter.Name = "TerminatedVillages + 1";
273      terminatedVillagesCounter.ValueParameter.ActualName = "TerminatedVillages";
274      terminatedVillagesCounter.Increment = new IntValue(1);
275
276      generationsCounter.Name = "Generations + 1";
277      generationsCounter.ValueParameter.ActualName = "Generations";
278      generationsCounter.Increment = new IntValue(1);
279
280      generationsSinceLastReunificationCounter.Name = "GenerationsSinceLastReunification + 1";
281      generationsSinceLastReunificationCounter.ValueParameter.ActualName = "GenerationsSinceLastReunification";
282      generationsSinceLastReunificationCounter.Increment = new IntValue(1);
283
284      reunificationComparator1.Name = "TerminatedVillages = VillageCount ?";
285      reunificationComparator1.LeftSideParameter.ActualName = "TerminatedVillages";
286      reunificationComparator1.Comparison = new Comparison(ComparisonType.Equal);
287      reunificationComparator1.RightSideParameter.ActualName = "VillageCount";
288      reunificationComparator1.ResultParameter.ActualName = "Reunificate";
289
290      reunificationConditionalBranch1.Name = "Reunificate ?";
291      reunificationConditionalBranch1.ConditionParameter.ActualName = "Reunificate";
292
293      reunificationComparator2.Name = "GenerationsSinceLastReunification = MigrationInterval ?";
294      reunificationComparator2.LeftSideParameter.ActualName = "GenerationsSinceLastReunification";
295      reunificationComparator2.Comparison = new Comparison(ComparisonType.Equal);
296      reunificationComparator2.RightSideParameter.ActualName = "MigrationInterval";
297      reunificationComparator2.ResultParameter.ActualName = "Reunificate";
298
299      reunificationConditionalBranch2.Name = "Reunificate ?";
300      reunificationConditionalBranch2.ConditionParameter.ActualName = "Reunificate";
301
302      // if there's just one village left and we're getting to this point SASEGASA terminates
303      reunificationComparator3.Name = "VillageCount <= 1 ?";
304      reunificationComparator3.LeftSideParameter.ActualName = "VillageCount";
305      reunificationComparator3.RightSideParameter.Value = new IntValue(1);
306      reunificationComparator3.Comparison.Value = ComparisonType.LessOrEqual;
307      reunificationComparator3.ResultParameter.ActualName = "TerminateSASEGASA";
308
309      reunificationConditionalBranch3.Name = "Skip reunification?";
310      reunificationConditionalBranch3.ConditionParameter.ActualName = "TerminateSASEGASA";
311
312      resetTerminatedVillagesAssigner.Name = "Reset TerminatedVillages";
313      resetTerminatedVillagesAssigner.LeftSideParameter.ActualName = "TerminatedVillages";
314      resetTerminatedVillagesAssigner.RightSideParameter.Value = new IntValue(0);
315
316      resetGenerationsSinceLastReunificationAssigner.Name = "Reset GenerationsSinceLastReunification";
317      resetGenerationsSinceLastReunificationAssigner.LeftSideParameter.ActualName = "GenerationsSinceLastReunification";
318      resetGenerationsSinceLastReunificationAssigner.RightSideParameter.Value = new IntValue(0);
319
320      reunificator.VillageCountParameter.ActualName = "VillageCount";
321
322      reunificationCounter.ValueParameter.ActualName = "Reunifications"; // this variable is referenced in SASEGASA, do not change!
323      reunificationCounter.IncrementParameter.Value = new IntValue(1);
324
325      comparisonFactorModifier.Name = "Update comparison factor (placeholder)";
326      comparisonFactorModifier.OperatorParameter.ActualName = ComparisonFactorModifierParameter.Name;
327
328      villageReviver.Name = "Village Reviver";
329      villageReviver.LeftSideParameter.ActualName = "TerminateSelectionPressure";
330      villageReviver.RightSideParameter.Value = new BoolValue(false);
331
332      villageCountComparator.Name = "VillageCount == 1 ?";
333      villageCountComparator.LeftSideParameter.ActualName = "VillageCount";
334      villageCountComparator.RightSideParameter.Value = new IntValue(1);
335      villageCountComparator.Comparison.Value = ComparisonType.Equal;
336      villageCountComparator.ResultParameter.ActualName = "ChangeMaxSelPress";
337
338      villageCountConditionalBranch.Name = "Change max selection pressure?";
339      villageCountConditionalBranch.ConditionParameter.ActualName = "ChangeMaxSelPress";
340
341      finalMaxSelPressAssigner.LeftSideParameter.ActualName = "CurrentMaximumSelectionPressure";
342      finalMaxSelPressAssigner.RightSideParameter.ActualName = FinalMaximumSelectionPressureParameter.Name;
343
344      // if Generations is reaching MaximumGenerations we're also terminating
345      maximumGenerationsComparator.LeftSideParameter.ActualName = "Generations";
346      maximumGenerationsComparator.RightSideParameter.ActualName = MaximumGenerationsParameter.Name;
347      maximumGenerationsComparator.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
348      maximumGenerationsComparator.ResultParameter.ActualName = "TerminateMaximumGenerations";
349
350      maximumEvaluatedSolutionsComparator.Name = "EvaluatedSolutions >= MaximumEvaluatedSolutions";
351      maximumEvaluatedSolutionsComparator.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
352      maximumEvaluatedSolutionsComparator.LeftSideParameter.ActualName = EvaluatedSolutionsParameter.Name;
353      maximumEvaluatedSolutionsComparator.ResultParameter.ActualName = "TerminateEvaluatedSolutions";
354      maximumEvaluatedSolutionsComparator.RightSideParameter.ActualName = "MaximumEvaluatedSolutions";
355
356      analyzer2.Name = "Analyzer (placeholder)";
357      analyzer2.OperatorParameter.ActualName = AnalyzerParameter.Name;
358
359      terminationCondition.ConditionParameter.ActualName = "TerminateSASEGASA";
360      maximumGenerationsTerminationCondition.ConditionParameter.ActualName = "TerminateMaximumGenerations";
361      maximumEvaluatedSolutionsTerminationCondition.ConditionParameter.ActualName = "TerminateEvaluatedSolutions";
362      #endregion
363
364      #region Create operator graph
365      OperatorGraph.InitialOperator = variableCreator;
366      variableCreator.Successor = maxSelPressAssigner;
367      maxSelPressAssigner.Successor = villageCountAssigner;
368      villageCountAssigner.Successor = comparisonFactorInitializer;
369      comparisonFactorInitializer.Successor = uniformSubScopesProcessor0;
370      uniformSubScopesProcessor0.Operator = villageVariableCreator;
371      uniformSubScopesProcessor0.Successor = analyzer1;
372      villageVariableCreator.Successor = villageAnalyzer1;
373      villageAnalyzer1.Successor = villageResultsCollector1;
374      analyzer1.Successor = resultsCollector1;
375      resultsCollector1.Successor = uniformSubScopesProcessor1;
376      uniformSubScopesProcessor1.Operator = villageTerminatedBySelectionPressure1;
377      uniformSubScopesProcessor1.Successor = generationsCounter;
378      villageTerminatedBySelectionPressure1.TrueBranch = null;
379      villageTerminatedBySelectionPressure1.FalseBranch = mainOperator;
380      villageTerminatedBySelectionPressure1.Successor = null;
381      mainOperator.Successor = villageAnalyzer2;
382      villageAnalyzer2.Successor = villageResultsCollector2;
383      villageResultsCollector2.Successor = villageSelectionPressureComparator;
384      villageSelectionPressureComparator.Successor = villageTerminatedBySelectionPressure2;
385      villageTerminatedBySelectionPressure2.TrueBranch = terminatedVillagesCounter;
386      villageTerminatedBySelectionPressure2.FalseBranch = null;
387      villageTerminatedBySelectionPressure2.Successor = null;
388      terminatedVillagesCounter.Successor = null;
389      generationsCounter.Successor = generationsSinceLastReunificationCounter;
390      generationsSinceLastReunificationCounter.Successor = reunificationComparator1;
391      reunificationComparator1.Successor = reunificationConditionalBranch1;
392      reunificationConditionalBranch1.TrueBranch = reunificationComparator3;
393      reunificationConditionalBranch1.FalseBranch = reunificationComparator2;
394      reunificationConditionalBranch1.Successor = maximumGenerationsComparator;
395      reunificationComparator2.Successor = reunificationConditionalBranch2;
396      reunificationConditionalBranch2.TrueBranch = reunificationComparator3;
397      reunificationConditionalBranch2.FalseBranch = null;
398      reunificationConditionalBranch2.Successor = null;
399      reunificationComparator3.Successor = reunificationConditionalBranch3;
400      reunificationConditionalBranch3.TrueBranch = null;
401      reunificationConditionalBranch3.FalseBranch = resetTerminatedVillagesAssigner;
402      reunificationConditionalBranch3.Successor = null;
403      resetTerminatedVillagesAssigner.Successor = resetGenerationsSinceLastReunificationAssigner;
404      resetGenerationsSinceLastReunificationAssigner.Successor = reunificator;
405      reunificator.Successor = reunificationCounter;
406      reunificationCounter.Successor = comparisonFactorModifier;
407      comparisonFactorModifier.Successor = uniformSubScopesProcessor2;
408      uniformSubScopesProcessor2.Operator = villageReviver;
409      uniformSubScopesProcessor2.Successor = villageCountComparator;
410      villageReviver.Successor = null;
411      villageCountComparator.Successor = villageCountConditionalBranch;
412      villageCountConditionalBranch.TrueBranch = finalMaxSelPressAssigner;
413      villageCountConditionalBranch.FalseBranch = null;
414      villageCountConditionalBranch.Successor = null;
415      finalMaxSelPressAssigner.Successor = null;
416      maximumGenerationsComparator.Successor = maximumEvaluatedSolutionsComparator;
417      maximumEvaluatedSolutionsComparator.Successor = analyzer2;
418      analyzer2.Successor = terminationCondition;
419      terminationCondition.TrueBranch = null;
420      terminationCondition.FalseBranch = maximumGenerationsTerminationCondition;
421      terminationCondition.Successor = null;
422      maximumGenerationsTerminationCondition.TrueBranch = null;
423      maximumGenerationsTerminationCondition.FalseBranch = maximumEvaluatedSolutionsTerminationCondition;
424      maximumGenerationsTerminationCondition.Successor = null;
425      maximumEvaluatedSolutionsTerminationCondition.TrueBranch = null;
426      maximumEvaluatedSolutionsTerminationCondition.FalseBranch = uniformSubScopesProcessor1;
427      maximumEvaluatedSolutionsTerminationCondition.Successor = null;
428      #endregion
429    }
430
431    [StorableHook(HookType.AfterDeserialization)]
432    private void AfterDeserialization() {
433      // BackwardsCompatibility3.3
434      #region Backwards compatible code, remove with 3.4
435      if (!Parameters.ContainsKey("ReevaluateElites")) {
436        Parameters.Add(new ValueLookupParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)"));
437      }
438      #endregion
439    }
440
441    public override IOperation Apply() {
442      if (CrossoverParameter.ActualValue == null)
443        return null;
444      return base.Apply();
445    }
446  }
447}
Note: See TracBrowser for help on using the repository browser.