Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ParameterBinding/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3/SASEGASAMainLoop.cs @ 7624

Last change on this file since 7624 was 4722, checked in by swagner, 14 years ago

Merged cloning refactoring branch back into trunk (#922)

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