Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3/SASEGASAMainLoop.cs @ 15800

Last change on this file since 15800 was 15583, checked in by swagner, 7 years ago

#2640: Updated year of copyrights in license headers

File size: 30.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2018 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    public IValueLookupParameter<BoolValue> FillPopulationWithParentsParameter {
115      get { return (IValueLookupParameter<BoolValue>)Parameters["FillPopulationWithParents"]; }
116    }
117    #endregion
118
119    [StorableConstructor]
120    private SASEGASAMainLoop(bool deserializing) : base(deserializing) { }
121    private SASEGASAMainLoop(SASEGASAMainLoop original, Cloner cloner)
122      : base(original, cloner) {
123    }
124    public override IDeepCloneable Clone(Cloner cloner) {
125      return new SASEGASAMainLoop(this, cloner);
126    }
127    public SASEGASAMainLoop()
128      : base() {
129      #region Create parameters
130      Parameters.Add(new ValueLookupParameter<IRandom>("Random", "A pseudo random number generator."));
131      Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
132      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution."));
133      Parameters.Add(new ValueLookupParameter<DoubleValue>("BestKnownQuality", "The best known quality value found so far."));
134      Parameters.Add(new ValueLookupParameter<IntValue>("NumberOfVillages", "The initial number of villages."));
135      Parameters.Add(new ValueLookupParameter<IntValue>("MigrationInterval", "The fixed period after which migration occurs."));
136      Parameters.Add(new ValueLookupParameter<IOperator>("Selector", "The operator used to select solutions for reproduction."));
137      Parameters.Add(new ValueLookupParameter<IOperator>("Crossover", "The operator used to cross solutions."));
138      Parameters.Add(new ValueLookupParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution."));
139      Parameters.Add(new ValueLookupParameter<IOperator>("Mutator", "The operator used to mutate solutions."));
140      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."));
141      Parameters.Add(new ValueLookupParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation."));
142      Parameters.Add(new ValueLookupParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)"));
143      Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The results collection to store the results."));
144      Parameters.Add(new ValueLookupParameter<IOperator>("Analyzer", "The operator used to the analyze the villages."));
145      Parameters.Add(new ValueLookupParameter<IOperator>("VillageAnalyzer", "The operator used to analyze each village."));
146      Parameters.Add(new ValueLookupParameter<DoubleValue>("SuccessRatio", "The ratio of successful to total children that should be achieved."));
147      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]."));
148      Parameters.Add(new ValueLookupParameter<DoubleValue>("ComparisonFactorStart", "The lower bound of the comparison factor (start)."));
149      Parameters.Add(new ValueLookupParameter<IOperator>("ComparisonFactorModifier", "The operator used to modify the comparison factor."));
150      Parameters.Add(new ValueLookupParameter<DoubleValue>("MaximumSelectionPressure", "The maximum selection pressure that terminates the algorithm."));
151      Parameters.Add(new ValueLookupParameter<DoubleValue>("FinalMaximumSelectionPressure", "The maximum selection pressure used when there is only one village left."));
152      Parameters.Add(new ValueLookupParameter<IntValue>("MaximumGenerations", "The maximum genreation that terminates the algorithm."));
153      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."));
154      Parameters.Add(new LookupParameter<IntValue>("EvaluatedSolutions", "The number of times solutions have been evaluated."));
155      Parameters.Add(new ValueLookupParameter<BoolValue>("FillPopulationWithParents", "True if the population should be filled with parent individual or false if worse children should be used when the maximum selection pressure is exceeded."));
156      #endregion
157
158      #region Create operators
159      VariableCreator variableCreator = new VariableCreator();
160      Assigner maxSelPressAssigner = new Assigner();
161      Assigner villageCountAssigner = new Assigner();
162      Assigner comparisonFactorInitializer = new Assigner();
163      UniformSubScopesProcessor uniformSubScopesProcessor0 = new UniformSubScopesProcessor();
164      VariableCreator villageVariableCreator = new VariableCreator();
165      Placeholder villageAnalyzer1 = new Placeholder();
166      ResultsCollector villageResultsCollector1 = new ResultsCollector();
167      Placeholder analyzer1 = new Placeholder();
168      ResultsCollector resultsCollector1 = new ResultsCollector();
169      UniformSubScopesProcessor uniformSubScopesProcessor1 = new UniformSubScopesProcessor();
170      ConditionalBranch villageTerminatedBySelectionPressure1 = new ConditionalBranch();
171      OffspringSelectionGeneticAlgorithmMainOperator mainOperator = new OffspringSelectionGeneticAlgorithmMainOperator();
172      Placeholder villageAnalyzer2 = new Placeholder();
173      ResultsCollector villageResultsCollector2 = new ResultsCollector();
174      Comparator villageSelectionPressureComparator = new Comparator();
175      ConditionalBranch villageTerminatedBySelectionPressure2 = new ConditionalBranch();
176      IntCounter terminatedVillagesCounter = new IntCounter();
177      IntCounter generationsCounter = new IntCounter();
178      IntCounter generationsSinceLastReunificationCounter = new IntCounter();
179      Comparator reunificationComparator1 = new Comparator();
180      ConditionalBranch reunificationConditionalBranch1 = new ConditionalBranch();
181      Comparator reunificationComparator2 = new Comparator();
182      ConditionalBranch reunificationConditionalBranch2 = new ConditionalBranch();
183      Comparator reunificationComparator3 = new Comparator();
184      ConditionalBranch reunificationConditionalBranch3 = new ConditionalBranch();
185      Assigner resetTerminatedVillagesAssigner = new Assigner();
186      Assigner resetGenerationsSinceLastReunificationAssigner = new Assigner();
187      SASEGASAReunificator reunificator = new SASEGASAReunificator();
188      IntCounter reunificationCounter = new IntCounter();
189      Placeholder comparisonFactorModifier = new Placeholder();
190      UniformSubScopesProcessor uniformSubScopesProcessor2 = new UniformSubScopesProcessor();
191      Assigner villageReviver = new Assigner();
192      Comparator villageCountComparator = new Comparator();
193      ConditionalBranch villageCountConditionalBranch = new ConditionalBranch();
194      Assigner finalMaxSelPressAssigner = new Assigner();
195      Comparator maximumGenerationsComparator = new Comparator();
196      Comparator maximumEvaluatedSolutionsComparator = new Comparator();
197      Placeholder analyzer2 = new Placeholder();
198      ConditionalBranch terminationCondition = new ConditionalBranch();
199      ConditionalBranch maximumGenerationsTerminationCondition = new ConditionalBranch();
200      ConditionalBranch maximumEvaluatedSolutionsTerminationCondition = new ConditionalBranch();
201
202      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Reunifications", new IntValue(0)));
203      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Generations", new IntValue(0))); // Class SASEGASA expects this to be called Generations
204      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("GenerationsSinceLastReunification", new IntValue(0)));
205      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("TerminatedVillages", new IntValue(0)));
206
207      villageCountAssigner.LeftSideParameter.ActualName = "VillageCount";
208      villageCountAssigner.RightSideParameter.ActualName = NumberOfVillagesParameter.Name;
209
210      maxSelPressAssigner.LeftSideParameter.ActualName = "CurrentMaximumSelectionPressure";
211      maxSelPressAssigner.RightSideParameter.ActualName = MaximumSelectionPressureParameter.Name;
212
213      comparisonFactorInitializer.LeftSideParameter.ActualName = ComparisonFactorParameter.Name;
214      comparisonFactorInitializer.RightSideParameter.ActualName = ComparisonFactorStartParameter.Name;
215
216      villageVariableCreator.CollectedValues.Add(new ValueParameter<ResultCollection>("Results", new ResultCollection()));
217      villageVariableCreator.CollectedValues.Add(new ValueParameter<BoolValue>("TerminateSelectionPressure", new BoolValue(false)));
218      villageVariableCreator.CollectedValues.Add(new ValueParameter<DoubleValue>("SelectionPressure", new DoubleValue(0)));
219      villageVariableCreator.CollectedValues.Add(new ValueParameter<DoubleValue>("CurrentSuccessRatio", new DoubleValue(0)));
220
221      villageAnalyzer1.Name = "Village Analyzer (placeholder)";
222      villageAnalyzer1.OperatorParameter.ActualName = VillageAnalyzerParameter.Name;
223
224      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"));
225      villageResultsCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Selection Pressure", "Displays the rising selection pressure during a generation.", "SelectionPressure"));
226      villageResultsCollector1.ResultsParameter.ActualName = "Results";
227
228      analyzer1.Name = "Analyzer (placeholder)";
229      analyzer1.OperatorParameter.ActualName = AnalyzerParameter.Name;
230
231      resultsCollector1.CopyValue = new BoolValue(false);
232      resultsCollector1.CollectedValues.Add(new LookupParameter<IntValue>("Generations"));
233      resultsCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>("ComparisonFactor", null, ComparisonFactorParameter.Name));
234      resultsCollector1.CollectedValues.Add(new LookupParameter<IntValue>("Terminated Villages", null, "TerminatedVillages"));
235      resultsCollector1.CollectedValues.Add(new LookupParameter<IntValue>("Total Active Villages", null, "VillageCount"));
236      resultsCollector1.CollectedValues.Add(new ScopeTreeLookupParameter<ResultCollection>("VillageResults", "Result set for each village", "Results"));
237      resultsCollector1.ResultsParameter.ActualName = ResultsParameter.Name;
238
239      villageTerminatedBySelectionPressure1.Name = "Village Terminated ?";
240      villageTerminatedBySelectionPressure1.ConditionParameter.ActualName = "TerminateSelectionPressure";
241
242      mainOperator.ComparisonFactorParameter.ActualName = ComparisonFactorParameter.Name;
243      mainOperator.CrossoverParameter.ActualName = CrossoverParameter.Name;
244      mainOperator.CurrentSuccessRatioParameter.ActualName = "CurrentSuccessRatio";
245      mainOperator.ElitesParameter.ActualName = ElitesParameter.Name;
246      mainOperator.ReevaluateElitesParameter.ActualName = ReevaluateElitesParameter.Name;
247      mainOperator.EvaluatedSolutionsParameter.ActualName = EvaluatedSolutionsParameter.Name;
248      mainOperator.EvaluatorParameter.ActualName = EvaluatorParameter.Name;
249      mainOperator.MaximizationParameter.ActualName = MaximizationParameter.Name;
250      mainOperator.MaximumSelectionPressureParameter.ActualName = "CurrentMaximumSelectionPressure";
251      mainOperator.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
252      mainOperator.MutatorParameter.ActualName = MutatorParameter.Name;
253      mainOperator.OffspringSelectionBeforeMutationParameter.ActualName = OffspringSelectionBeforeMutationParameter.Name;
254      mainOperator.QualityParameter.ActualName = QualityParameter.Name;
255      mainOperator.RandomParameter.ActualName = RandomParameter.Name;
256      mainOperator.SelectionPressureParameter.ActualName = "SelectionPressure";
257      mainOperator.SelectorParameter.ActualName = SelectorParameter.Name;
258      mainOperator.SuccessRatioParameter.ActualName = SuccessRatioParameter.Name;
259      mainOperator.FillPopulationWithParentsParameter.ActualName = FillPopulationWithParentsParameter.Name;
260
261      villageAnalyzer2.Name = "Village Analyzer (placeholder)";
262      villageAnalyzer2.OperatorParameter.ActualName = VillageAnalyzerParameter.Name;
263
264      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"));
265      villageResultsCollector2.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Selection Pressure", "Displays the rising selection pressure during a generation.", "SelectionPressure"));
266      villageResultsCollector2.ResultsParameter.ActualName = "Results";
267
268      villageSelectionPressureComparator.Name = "SelectionPressure >= CurrentMaximumSelectionPressure ?";
269      villageSelectionPressureComparator.LeftSideParameter.ActualName = "SelectionPressure";
270      villageSelectionPressureComparator.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
271      villageSelectionPressureComparator.RightSideParameter.ActualName = "CurrentMaximumSelectionPressure";
272      villageSelectionPressureComparator.ResultParameter.ActualName = "TerminateSelectionPressure";
273
274      villageTerminatedBySelectionPressure2.Name = "Village Terminated ?";
275      villageTerminatedBySelectionPressure2.ConditionParameter.ActualName = "TerminateSelectionPressure";
276
277      terminatedVillagesCounter.Name = "TerminatedVillages + 1";
278      terminatedVillagesCounter.ValueParameter.ActualName = "TerminatedVillages";
279      terminatedVillagesCounter.Increment = new IntValue(1);
280
281      generationsCounter.Name = "Generations + 1";
282      generationsCounter.ValueParameter.ActualName = "Generations";
283      generationsCounter.Increment = new IntValue(1);
284
285      generationsSinceLastReunificationCounter.Name = "GenerationsSinceLastReunification + 1";
286      generationsSinceLastReunificationCounter.ValueParameter.ActualName = "GenerationsSinceLastReunification";
287      generationsSinceLastReunificationCounter.Increment = new IntValue(1);
288
289      reunificationComparator1.Name = "TerminatedVillages = VillageCount ?";
290      reunificationComparator1.LeftSideParameter.ActualName = "TerminatedVillages";
291      reunificationComparator1.Comparison = new Comparison(ComparisonType.Equal);
292      reunificationComparator1.RightSideParameter.ActualName = "VillageCount";
293      reunificationComparator1.ResultParameter.ActualName = "Reunificate";
294
295      reunificationConditionalBranch1.Name = "Reunificate ?";
296      reunificationConditionalBranch1.ConditionParameter.ActualName = "Reunificate";
297
298      reunificationComparator2.Name = "GenerationsSinceLastReunification = MigrationInterval ?";
299      reunificationComparator2.LeftSideParameter.ActualName = "GenerationsSinceLastReunification";
300      reunificationComparator2.Comparison = new Comparison(ComparisonType.Equal);
301      reunificationComparator2.RightSideParameter.ActualName = "MigrationInterval";
302      reunificationComparator2.ResultParameter.ActualName = "Reunificate";
303
304      reunificationConditionalBranch2.Name = "Reunificate ?";
305      reunificationConditionalBranch2.ConditionParameter.ActualName = "Reunificate";
306
307      // if there's just one village left and we're getting to this point SASEGASA terminates
308      reunificationComparator3.Name = "VillageCount <= 1 ?";
309      reunificationComparator3.LeftSideParameter.ActualName = "VillageCount";
310      reunificationComparator3.RightSideParameter.Value = new IntValue(1);
311      reunificationComparator3.Comparison.Value = ComparisonType.LessOrEqual;
312      reunificationComparator3.ResultParameter.ActualName = "TerminateSASEGASA";
313
314      reunificationConditionalBranch3.Name = "Skip reunification?";
315      reunificationConditionalBranch3.ConditionParameter.ActualName = "TerminateSASEGASA";
316
317      resetTerminatedVillagesAssigner.Name = "Reset TerminatedVillages";
318      resetTerminatedVillagesAssigner.LeftSideParameter.ActualName = "TerminatedVillages";
319      resetTerminatedVillagesAssigner.RightSideParameter.Value = new IntValue(0);
320
321      resetGenerationsSinceLastReunificationAssigner.Name = "Reset GenerationsSinceLastReunification";
322      resetGenerationsSinceLastReunificationAssigner.LeftSideParameter.ActualName = "GenerationsSinceLastReunification";
323      resetGenerationsSinceLastReunificationAssigner.RightSideParameter.Value = new IntValue(0);
324
325      reunificator.VillageCountParameter.ActualName = "VillageCount";
326
327      reunificationCounter.ValueParameter.ActualName = "Reunifications"; // this variable is referenced in SASEGASA, do not change!
328      reunificationCounter.IncrementParameter.Value = new IntValue(1);
329
330      comparisonFactorModifier.Name = "Update comparison factor (placeholder)";
331      comparisonFactorModifier.OperatorParameter.ActualName = ComparisonFactorModifierParameter.Name;
332
333      villageReviver.Name = "Village Reviver";
334      villageReviver.LeftSideParameter.ActualName = "TerminateSelectionPressure";
335      villageReviver.RightSideParameter.Value = new BoolValue(false);
336
337      villageCountComparator.Name = "VillageCount == 1 ?";
338      villageCountComparator.LeftSideParameter.ActualName = "VillageCount";
339      villageCountComparator.RightSideParameter.Value = new IntValue(1);
340      villageCountComparator.Comparison.Value = ComparisonType.Equal;
341      villageCountComparator.ResultParameter.ActualName = "ChangeMaxSelPress";
342
343      villageCountConditionalBranch.Name = "Change max selection pressure?";
344      villageCountConditionalBranch.ConditionParameter.ActualName = "ChangeMaxSelPress";
345
346      finalMaxSelPressAssigner.LeftSideParameter.ActualName = "CurrentMaximumSelectionPressure";
347      finalMaxSelPressAssigner.RightSideParameter.ActualName = FinalMaximumSelectionPressureParameter.Name;
348
349      // if Generations is reaching MaximumGenerations we're also terminating
350      maximumGenerationsComparator.LeftSideParameter.ActualName = "Generations";
351      maximumGenerationsComparator.RightSideParameter.ActualName = MaximumGenerationsParameter.Name;
352      maximumGenerationsComparator.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
353      maximumGenerationsComparator.ResultParameter.ActualName = "TerminateMaximumGenerations";
354
355      maximumEvaluatedSolutionsComparator.Name = "EvaluatedSolutions >= MaximumEvaluatedSolutions";
356      maximumEvaluatedSolutionsComparator.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
357      maximumEvaluatedSolutionsComparator.LeftSideParameter.ActualName = EvaluatedSolutionsParameter.Name;
358      maximumEvaluatedSolutionsComparator.ResultParameter.ActualName = "TerminateEvaluatedSolutions";
359      maximumEvaluatedSolutionsComparator.RightSideParameter.ActualName = "MaximumEvaluatedSolutions";
360
361      analyzer2.Name = "Analyzer (placeholder)";
362      analyzer2.OperatorParameter.ActualName = AnalyzerParameter.Name;
363
364      terminationCondition.ConditionParameter.ActualName = "TerminateSASEGASA";
365      maximumGenerationsTerminationCondition.ConditionParameter.ActualName = "TerminateMaximumGenerations";
366      maximumEvaluatedSolutionsTerminationCondition.ConditionParameter.ActualName = "TerminateEvaluatedSolutions";
367      #endregion
368
369      #region Create operator graph
370      OperatorGraph.InitialOperator = variableCreator;
371      variableCreator.Successor = maxSelPressAssigner;
372      maxSelPressAssigner.Successor = villageCountAssigner;
373      villageCountAssigner.Successor = comparisonFactorInitializer;
374      comparisonFactorInitializer.Successor = uniformSubScopesProcessor0;
375      uniformSubScopesProcessor0.Operator = villageVariableCreator;
376      uniformSubScopesProcessor0.Successor = analyzer1;
377      villageVariableCreator.Successor = villageAnalyzer1;
378      villageAnalyzer1.Successor = villageResultsCollector1;
379      analyzer1.Successor = resultsCollector1;
380      resultsCollector1.Successor = uniformSubScopesProcessor1;
381      uniformSubScopesProcessor1.Operator = villageTerminatedBySelectionPressure1;
382      uniformSubScopesProcessor1.Successor = generationsCounter;
383      villageTerminatedBySelectionPressure1.TrueBranch = null;
384      villageTerminatedBySelectionPressure1.FalseBranch = mainOperator;
385      villageTerminatedBySelectionPressure1.Successor = null;
386      mainOperator.Successor = villageAnalyzer2;
387      villageAnalyzer2.Successor = villageResultsCollector2;
388      villageResultsCollector2.Successor = villageSelectionPressureComparator;
389      villageSelectionPressureComparator.Successor = villageTerminatedBySelectionPressure2;
390      villageTerminatedBySelectionPressure2.TrueBranch = terminatedVillagesCounter;
391      villageTerminatedBySelectionPressure2.FalseBranch = null;
392      villageTerminatedBySelectionPressure2.Successor = null;
393      terminatedVillagesCounter.Successor = null;
394      generationsCounter.Successor = generationsSinceLastReunificationCounter;
395      generationsSinceLastReunificationCounter.Successor = reunificationComparator1;
396      reunificationComparator1.Successor = reunificationConditionalBranch1;
397      reunificationConditionalBranch1.TrueBranch = reunificationComparator3;
398      reunificationConditionalBranch1.FalseBranch = reunificationComparator2;
399      reunificationConditionalBranch1.Successor = maximumGenerationsComparator;
400      reunificationComparator2.Successor = reunificationConditionalBranch2;
401      reunificationConditionalBranch2.TrueBranch = reunificationComparator3;
402      reunificationConditionalBranch2.FalseBranch = null;
403      reunificationConditionalBranch2.Successor = null;
404      reunificationComparator3.Successor = reunificationConditionalBranch3;
405      reunificationConditionalBranch3.TrueBranch = null;
406      reunificationConditionalBranch3.FalseBranch = resetTerminatedVillagesAssigner;
407      reunificationConditionalBranch3.Successor = null;
408      resetTerminatedVillagesAssigner.Successor = resetGenerationsSinceLastReunificationAssigner;
409      resetGenerationsSinceLastReunificationAssigner.Successor = reunificator;
410      reunificator.Successor = reunificationCounter;
411      reunificationCounter.Successor = comparisonFactorModifier;
412      comparisonFactorModifier.Successor = uniformSubScopesProcessor2;
413      uniformSubScopesProcessor2.Operator = villageReviver;
414      uniformSubScopesProcessor2.Successor = villageCountComparator;
415      villageReviver.Successor = null;
416      villageCountComparator.Successor = villageCountConditionalBranch;
417      villageCountConditionalBranch.TrueBranch = finalMaxSelPressAssigner;
418      villageCountConditionalBranch.FalseBranch = null;
419      villageCountConditionalBranch.Successor = null;
420      finalMaxSelPressAssigner.Successor = null;
421      maximumGenerationsComparator.Successor = maximumEvaluatedSolutionsComparator;
422      maximumEvaluatedSolutionsComparator.Successor = analyzer2;
423      analyzer2.Successor = terminationCondition;
424      terminationCondition.TrueBranch = null;
425      terminationCondition.FalseBranch = maximumGenerationsTerminationCondition;
426      terminationCondition.Successor = null;
427      maximumGenerationsTerminationCondition.TrueBranch = null;
428      maximumGenerationsTerminationCondition.FalseBranch = maximumEvaluatedSolutionsTerminationCondition;
429      maximumGenerationsTerminationCondition.Successor = null;
430      maximumEvaluatedSolutionsTerminationCondition.TrueBranch = null;
431      maximumEvaluatedSolutionsTerminationCondition.FalseBranch = uniformSubScopesProcessor1;
432      maximumEvaluatedSolutionsTerminationCondition.Successor = null;
433      #endregion
434    }
435
436    [StorableHook(HookType.AfterDeserialization)]
437    private void AfterDeserialization() {
438      // BackwardsCompatibility3.3
439      #region Backwards compatible code, remove with 3.4
440      if (!Parameters.ContainsKey("ReevaluateElites")) {
441        Parameters.Add(new ValueLookupParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)"));
442      }
443      if (!Parameters.ContainsKey("FillPopulationWithParents"))
444        Parameters.Add(new ValueLookupParameter<BoolValue>("FillPopulationWithParents", "True if the population should be filled with parent individual or false if worse children should be used when the maximum selection pressure is exceeded."));
445      #endregion
446    }
447
448    public override IOperation Apply() {
449      if (CrossoverParameter.ActualValue == null)
450        return null;
451      return base.Apply();
452    }
453  }
454}
Note: See TracBrowser for help on using the repository browser.