Free cookie consent management tool by TermsFeed Policy Generator

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

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

#2038: Added tagging comment

File size: 29.2 KB
RevLine 
[3479]1#region License Information
2/* HeuristicLab
[9456]3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[3479]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
[4722]22using HeuristicLab.Common;
[3479]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    }
[3659]51    public ScopeTreeLookupParameter<DoubleValue> QualityParameter {
52      get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
[3479]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    }
[9569]75    public IValueLookupParameter<BoolValue> ReevaluateElitesParameter {
76      get { return (IValueLookupParameter<BoolValue>)Parameters["ReevaluateElites"]; }
77    }
[3479]78    public ValueLookupParameter<ResultCollection> ResultsParameter {
79      get { return (ValueLookupParameter<ResultCollection>)Parameters["Results"]; }
80    }
[3656]81    public ValueLookupParameter<IOperator> AnalyzerParameter {
82      get { return (ValueLookupParameter<IOperator>)Parameters["Analyzer"]; }
[3479]83    }
[3656]84    public ValueLookupParameter<IOperator> VillageAnalyzerParameter {
85      get { return (ValueLookupParameter<IOperator>)Parameters["VillageAnalyzer"]; }
[3479]86    }
87    public ValueLookupParameter<DoubleValue> SuccessRatioParameter {
88      get { return (ValueLookupParameter<DoubleValue>)Parameters["SuccessRatio"]; }
89    }
[3615]90    public LookupParameter<DoubleValue> ComparisonFactorParameter {
91      get { return (LookupParameter<DoubleValue>)Parameters["ComparisonFactor"]; }
92    }
[3744]93    public ValueLookupParameter<DoubleValue> ComparisonFactorStartParameter {
94      get { return (ValueLookupParameter<DoubleValue>)Parameters["ComparisonFactorStart"]; }
[3479]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    }
[3490]102    public ValueLookupParameter<DoubleValue> FinalMaximumSelectionPressureParameter {
103      get { return (ValueLookupParameter<DoubleValue>)Parameters["FinalMaximumSelectionPressure"]; }
104    }
[3479]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    }
[5356]111    public LookupParameter<IntValue> EvaluatedSolutionsParameter {
112      get { return (LookupParameter<IntValue>)Parameters["EvaluatedSolutions"]; }
113    }
[3479]114    #endregion
115
116    [StorableConstructor]
[4722]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    }
[3479]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."));
[3659]129      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution."));
[3479]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."));
[5208]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."));
[3479]138      Parameters.Add(new ValueLookupParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation."));
[9569]139      Parameters.Add(new ValueLookupParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)"));
[3479]140      Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The results collection to store the results."));
[3656]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."));
[3479]143      Parameters.Add(new ValueLookupParameter<DoubleValue>("SuccessRatio", "The ratio of successful to total children that should be achieved."));
[3615]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]."));
[3744]145      Parameters.Add(new ValueLookupParameter<DoubleValue>("ComparisonFactorStart", "The lower bound of the comparison factor (start)."));
[3479]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."));
[3490]148      Parameters.Add(new ValueLookupParameter<DoubleValue>("FinalMaximumSelectionPressure", "The maximum selection pressure used when there is only one village left."));
[3479]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."));
[5356]151      Parameters.Add(new LookupParameter<IntValue>("EvaluatedSolutions", "The number of times solutions have been evaluated."));
[3479]152      #endregion
153
154      #region Create operators
155      VariableCreator variableCreator = new VariableCreator();
[3490]156      Assigner maxSelPressAssigner = new Assigner();
[3479]157      Assigner villageCountAssigner = new Assigner();
158      Assigner comparisonFactorInitializer = new Assigner();
[3615]159      UniformSubScopesProcessor uniformSubScopesProcessor0 = new UniformSubScopesProcessor();
160      VariableCreator villageVariableCreator = new VariableCreator();
[3656]161      Placeholder villageAnalyzer1 = new Placeholder();
162      ResultsCollector villageResultsCollector1 = new ResultsCollector();
163      Placeholder analyzer1 = new Placeholder();
164      ResultsCollector resultsCollector1 = new ResultsCollector();
[3615]165      UniformSubScopesProcessor uniformSubScopesProcessor1 = new UniformSubScopesProcessor();
166      ConditionalBranch villageTerminatedBySelectionPressure1 = new ConditionalBranch();
167      OffspringSelectionGeneticAlgorithmMainOperator mainOperator = new OffspringSelectionGeneticAlgorithmMainOperator();
[3656]168      Placeholder villageAnalyzer2 = new Placeholder();
169      ResultsCollector villageResultsCollector2 = new ResultsCollector();
[3615]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();
[3479]183      SASEGASAReunificator reunificator = new SASEGASAReunificator();
184      IntCounter reunificationCounter = new IntCounter();
185      Placeholder comparisonFactorModifier = new Placeholder();
[3615]186      UniformSubScopesProcessor uniformSubScopesProcessor2 = new UniformSubScopesProcessor();
187      Assigner villageReviver = new Assigner();
188      Comparator villageCountComparator = new Comparator();
189      ConditionalBranch villageCountConditionalBranch = new ConditionalBranch();
[3490]190      Assigner finalMaxSelPressAssigner = new Assigner();
[3479]191      Comparator maximumGenerationsComparator = new Comparator();
[3891]192      Comparator maximumEvaluatedSolutionsComparator = new Comparator();
[3656]193      Placeholder analyzer2 = new Placeholder();
[3615]194      ConditionalBranch terminationCondition = new ConditionalBranch();
[3479]195      ConditionalBranch maximumGenerationsTerminationCondition = new ConditionalBranch();
[3891]196      ConditionalBranch maximumEvaluatedSolutionsTerminationCondition = new ConditionalBranch();
[3479]197
[3615]198      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Reunifications", new IntValue(0)));
[3750]199      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Generations", new IntValue(0))); // Class SASEGASA expects this to be called Generations
[3615]200      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("GenerationsSinceLastReunification", new IntValue(0)));
201      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("TerminatedVillages", new IntValue(0)));
[3479]202
203      villageCountAssigner.LeftSideParameter.ActualName = "VillageCount";
204      villageCountAssigner.RightSideParameter.ActualName = NumberOfVillagesParameter.Name;
205
[3490]206      maxSelPressAssigner.LeftSideParameter.ActualName = "CurrentMaximumSelectionPressure";
207      maxSelPressAssigner.RightSideParameter.ActualName = MaximumSelectionPressureParameter.Name;
208
[3744]209      comparisonFactorInitializer.LeftSideParameter.ActualName = ComparisonFactorParameter.Name;
210      comparisonFactorInitializer.RightSideParameter.ActualName = ComparisonFactorStartParameter.Name;
[3479]211
[3656]212      villageVariableCreator.CollectedValues.Add(new ValueParameter<ResultCollection>("Results", new ResultCollection()));
[3615]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)));
[3479]216
[3656]217      villageAnalyzer1.Name = "Village Analyzer (placeholder)";
218      villageAnalyzer1.OperatorParameter.ActualName = VillageAnalyzerParameter.Name;
[3479]219
[6630]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"));
[3656]222      villageResultsCollector1.ResultsParameter.ActualName = "Results";
[3615]223
[3656]224      analyzer1.Name = "Analyzer (placeholder)";
225      analyzer1.OperatorParameter.ActualName = AnalyzerParameter.Name;
[3615]226
[3673]227      resultsCollector1.CopyValue = new BoolValue(false);
[3656]228      resultsCollector1.CollectedValues.Add(new LookupParameter<IntValue>("Generations"));
[3744]229      resultsCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>("ComparisonFactor", null, ComparisonFactorParameter.Name));
[3656]230      resultsCollector1.CollectedValues.Add(new LookupParameter<IntValue>("Terminated Villages", null, "TerminatedVillages"));
231      resultsCollector1.CollectedValues.Add(new LookupParameter<IntValue>("Total Active Villages", null, "VillageCount"));
[3673]232      resultsCollector1.CollectedValues.Add(new ScopeTreeLookupParameter<ResultCollection>("VillageResults", "Result set for each village", "Results"));
[3656]233      resultsCollector1.ResultsParameter.ActualName = ResultsParameter.Name;
[3615]234
235      villageTerminatedBySelectionPressure1.Name = "Village Terminated ?";
236      villageTerminatedBySelectionPressure1.ConditionParameter.ActualName = "TerminateSelectionPressure";
[3489]237
[3615]238      mainOperator.ComparisonFactorParameter.ActualName = ComparisonFactorParameter.Name;
239      mainOperator.CrossoverParameter.ActualName = CrossoverParameter.Name;
240      mainOperator.CurrentSuccessRatioParameter.ActualName = "CurrentSuccessRatio";
241      mainOperator.ElitesParameter.ActualName = ElitesParameter.Name;
[9569]242      mainOperator.ReevaluateElitesParameter.ActualName = ReevaluateElitesParameter.Name;
[5356]243      mainOperator.EvaluatedSolutionsParameter.ActualName = EvaluatedSolutionsParameter.Name;
[3615]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;
[3479]255
[3656]256      villageAnalyzer2.Name = "Village Analyzer (placeholder)";
257      villageAnalyzer2.OperatorParameter.ActualName = VillageAnalyzerParameter.Name;
[3479]258
[6630]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"));
[3656]261      villageResultsCollector2.ResultsParameter.ActualName = "Results";
[3479]262
[3615]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";
[3489]268
[3615]269      villageTerminatedBySelectionPressure2.Name = "Village Terminated ?";
270      villageTerminatedBySelectionPressure2.ConditionParameter.ActualName = "TerminateSelectionPressure";
[3479]271
[3615]272      terminatedVillagesCounter.Name = "TerminatedVillages + 1";
273      terminatedVillagesCounter.ValueParameter.ActualName = "TerminatedVillages";
274      terminatedVillagesCounter.Increment = new IntValue(1);
[3489]275
[3615]276      generationsCounter.Name = "Generations + 1";
277      generationsCounter.ValueParameter.ActualName = "Generations";
278      generationsCounter.Increment = new IntValue(1);
[3479]279
[3615]280      generationsSinceLastReunificationCounter.Name = "GenerationsSinceLastReunification + 1";
281      generationsSinceLastReunificationCounter.ValueParameter.ActualName = "GenerationsSinceLastReunification";
282      generationsSinceLastReunificationCounter.Increment = new IntValue(1);
[3479]283
[3615]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
[3479]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
[3744]325      comparisonFactorModifier.Name = "Update comparison factor (placeholder)";
[3479]326      comparisonFactorModifier.OperatorParameter.ActualName = ComparisonFactorModifierParameter.Name;
327
[3615]328      villageReviver.Name = "Village Reviver";
329      villageReviver.LeftSideParameter.ActualName = "TerminateSelectionPressure";
330      villageReviver.RightSideParameter.Value = new BoolValue(false);
[3490]331
[3615]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";
[3490]337
[3615]338      villageCountConditionalBranch.Name = "Change max selection pressure?";
339      villageCountConditionalBranch.ConditionParameter.ActualName = "ChangeMaxSelPress";
340
[3490]341      finalMaxSelPressAssigner.LeftSideParameter.ActualName = "CurrentMaximumSelectionPressure";
342      finalMaxSelPressAssigner.RightSideParameter.ActualName = FinalMaximumSelectionPressureParameter.Name;
343
[3615]344      // if Generations is reaching MaximumGenerations we're also terminating
345      maximumGenerationsComparator.LeftSideParameter.ActualName = "Generations";
[3479]346      maximumGenerationsComparator.RightSideParameter.ActualName = MaximumGenerationsParameter.Name;
347      maximumGenerationsComparator.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
348      maximumGenerationsComparator.ResultParameter.ActualName = "TerminateMaximumGenerations";
349
[3891]350      maximumEvaluatedSolutionsComparator.Name = "EvaluatedSolutions >= MaximumEvaluatedSolutions";
351      maximumEvaluatedSolutionsComparator.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
[5356]352      maximumEvaluatedSolutionsComparator.LeftSideParameter.ActualName = EvaluatedSolutionsParameter.Name;
[3891]353      maximumEvaluatedSolutionsComparator.ResultParameter.ActualName = "TerminateEvaluatedSolutions";
354      maximumEvaluatedSolutionsComparator.RightSideParameter.ActualName = "MaximumEvaluatedSolutions";
355
[3656]356      analyzer2.Name = "Analyzer (placeholder)";
357      analyzer2.OperatorParameter.ActualName = AnalyzerParameter.Name;
[3479]358
[3615]359      terminationCondition.ConditionParameter.ActualName = "TerminateSASEGASA";
360      maximumGenerationsTerminationCondition.ConditionParameter.ActualName = "TerminateMaximumGenerations";
[3891]361      maximumEvaluatedSolutionsTerminationCondition.ConditionParameter.ActualName = "TerminateEvaluatedSolutions";
[3479]362      #endregion
363
364      #region Create operator graph
365      OperatorGraph.InitialOperator = variableCreator;
[3615]366      variableCreator.Successor = maxSelPressAssigner;
367      maxSelPressAssigner.Successor = villageCountAssigner;
368      villageCountAssigner.Successor = comparisonFactorInitializer;
369      comparisonFactorInitializer.Successor = uniformSubScopesProcessor0;
370      uniformSubScopesProcessor0.Operator = villageVariableCreator;
[3656]371      uniformSubScopesProcessor0.Successor = analyzer1;
372      villageVariableCreator.Successor = villageAnalyzer1;
373      villageAnalyzer1.Successor = villageResultsCollector1;
374      analyzer1.Successor = resultsCollector1;
[5356]375      resultsCollector1.Successor = uniformSubScopesProcessor1;
[3615]376      uniformSubScopesProcessor1.Operator = villageTerminatedBySelectionPressure1;
377      uniformSubScopesProcessor1.Successor = generationsCounter;
378      villageTerminatedBySelectionPressure1.TrueBranch = null;
379      villageTerminatedBySelectionPressure1.FalseBranch = mainOperator;
380      villageTerminatedBySelectionPressure1.Successor = null;
[3656]381      mainOperator.Successor = villageAnalyzer2;
382      villageAnalyzer2.Successor = villageResultsCollector2;
[5356]383      villageResultsCollector2.Successor = villageSelectionPressureComparator;
[3615]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;
[3479]405      reunificator.Successor = reunificationCounter;
406      reunificationCounter.Successor = comparisonFactorModifier;
[3615]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;
[3490]415      finalMaxSelPressAssigner.Successor = null;
[3891]416      maximumGenerationsComparator.Successor = maximumEvaluatedSolutionsComparator;
417      maximumEvaluatedSolutionsComparator.Successor = analyzer2;
[5356]418      analyzer2.Successor = terminationCondition;
[3615]419      terminationCondition.TrueBranch = null;
420      terminationCondition.FalseBranch = maximumGenerationsTerminationCondition;
421      terminationCondition.Successor = null;
[3479]422      maximumGenerationsTerminationCondition.TrueBranch = null;
[3891]423      maximumGenerationsTerminationCondition.FalseBranch = maximumEvaluatedSolutionsTerminationCondition;
[3479]424      maximumGenerationsTerminationCondition.Successor = null;
[3891]425      maximumEvaluatedSolutionsTerminationCondition.TrueBranch = null;
426      maximumEvaluatedSolutionsTerminationCondition.FalseBranch = uniformSubScopesProcessor1;
427      maximumEvaluatedSolutionsTerminationCondition.Successor = null;
[3479]428      #endregion
429    }
[3715]430
[9569]431    [StorableHook(HookType.AfterDeserialization)]
432    private void AfterDeserialization() {
[9592]433      // BackwardsCompatibility3.3
[9591]434      #region Backwards compatible code, remove with 3.4
[9569]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      }
[9591]438      #endregion
[9569]439    }
440
[3715]441    public override IOperation Apply() {
442      if (CrossoverParameter.ActualValue == null)
443        return null;
444      return base.Apply();
445    }
[3479]446  }
447}
Note: See TracBrowser for help on using the repository browser.