1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2015 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 |
|
---|
22 | using HeuristicLab.Common;
|
---|
23 | using HeuristicLab.Core;
|
---|
24 | using HeuristicLab.Data;
|
---|
25 | using HeuristicLab.Operators;
|
---|
26 | using HeuristicLab.Optimization;
|
---|
27 | using HeuristicLab.Optimization.Operators;
|
---|
28 | using HeuristicLab.Parameters;
|
---|
29 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
30 | using HeuristicLab.Selection;
|
---|
31 |
|
---|
32 | namespace HeuristicLab.Algorithms.RAPGA {
|
---|
33 | /// <summary>
|
---|
34 | /// An operator which represents the main loop of a relevant alleles preserving genetic algorithm.
|
---|
35 | /// </summary>
|
---|
36 | [Item("RAPGAMainLoop", "An operator which represents the main loop of a relevant alleles preserving genetic algorithm.")]
|
---|
37 | [StorableType("4F237A68-FCA8-4BBB-9095-F51595C57CB9")]
|
---|
38 | public sealed class RAPGAMainLoop : AlgorithmOperator {
|
---|
39 | #region Parameter properties
|
---|
40 | public ValueLookupParameter<IRandom> RandomParameter {
|
---|
41 | get { return (ValueLookupParameter<IRandom>)Parameters["Random"]; }
|
---|
42 | }
|
---|
43 | public ValueLookupParameter<BoolValue> MaximizationParameter {
|
---|
44 | get { return (ValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
|
---|
45 | }
|
---|
46 | public ScopeTreeLookupParameter<DoubleValue> QualityParameter {
|
---|
47 | get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
|
---|
48 | }
|
---|
49 | public ValueLookupParameter<IOperator> SelectorParameter {
|
---|
50 | get { return (ValueLookupParameter<IOperator>)Parameters["Selector"]; }
|
---|
51 | }
|
---|
52 | public ValueLookupParameter<IOperator> CrossoverParameter {
|
---|
53 | get { return (ValueLookupParameter<IOperator>)Parameters["Crossover"]; }
|
---|
54 | }
|
---|
55 | public ValueLookupParameter<PercentValue> MutationProbabilityParameter {
|
---|
56 | get { return (ValueLookupParameter<PercentValue>)Parameters["MutationProbability"]; }
|
---|
57 | }
|
---|
58 | public ValueLookupParameter<IOperator> MutatorParameter {
|
---|
59 | get { return (ValueLookupParameter<IOperator>)Parameters["Mutator"]; }
|
---|
60 | }
|
---|
61 | public ValueLookupParameter<IOperator> EvaluatorParameter {
|
---|
62 | get { return (ValueLookupParameter<IOperator>)Parameters["Evaluator"]; }
|
---|
63 | }
|
---|
64 | public ValueLookupParameter<IntValue> ElitesParameter {
|
---|
65 | get { return (ValueLookupParameter<IntValue>)Parameters["Elites"]; }
|
---|
66 | }
|
---|
67 | public IValueLookupParameter<BoolValue> ReevaluateElitesParameter {
|
---|
68 | get { return (IValueLookupParameter<BoolValue>)Parameters["ReevaluateElites"]; }
|
---|
69 | }
|
---|
70 | public ValueLookupParameter<IntValue> MaximumGenerationsParameter {
|
---|
71 | get { return (ValueLookupParameter<IntValue>)Parameters["MaximumGenerations"]; }
|
---|
72 | }
|
---|
73 | public ValueLookupParameter<VariableCollection> ResultsParameter {
|
---|
74 | get { return (ValueLookupParameter<VariableCollection>)Parameters["Results"]; }
|
---|
75 | }
|
---|
76 | public ValueLookupParameter<IOperator> AnalyzerParameter {
|
---|
77 | get { return (ValueLookupParameter<IOperator>)Parameters["Analyzer"]; }
|
---|
78 | }
|
---|
79 | public ValueLookupParameter<IntValue> EvaluatedSolutionsParameter {
|
---|
80 | get { return (ValueLookupParameter<IntValue>)Parameters["EvaluatedSolutions"]; }
|
---|
81 | }
|
---|
82 | public ValueLookupParameter<IntValue> PopulationSizeParameter {
|
---|
83 | get { return (ValueLookupParameter<IntValue>)Parameters["PopulationSize"]; }
|
---|
84 | }
|
---|
85 | public IValueLookupParameter<IntValue> MinimumPopulationSizeParameter {
|
---|
86 | get { return (IValueLookupParameter<IntValue>)Parameters["MinimumPopulationSize"]; }
|
---|
87 | }
|
---|
88 | public IValueLookupParameter<IntValue> MaximumPopulationSizeParameter {
|
---|
89 | get { return (IValueLookupParameter<IntValue>)Parameters["MaximumPopulationSize"]; }
|
---|
90 | }
|
---|
91 | public IValueLookupParameter<DoubleValue> ComparisonFactorParameter {
|
---|
92 | get { return (IValueLookupParameter<DoubleValue>)Parameters["ComparisonFactor"]; }
|
---|
93 | }
|
---|
94 | public IValueLookupParameter<IntValue> EffortParameter {
|
---|
95 | get { return (IValueLookupParameter<IntValue>)Parameters["Effort"]; }
|
---|
96 | }
|
---|
97 | public IValueLookupParameter<IntValue> BatchSizeParameter {
|
---|
98 | get { return (IValueLookupParameter<IntValue>)Parameters["BatchSize"]; }
|
---|
99 | }
|
---|
100 | public IValueLookupParameter<ISolutionSimilarityCalculator> SimilarityCalculatorParameter {
|
---|
101 | get { return (IValueLookupParameter<ISolutionSimilarityCalculator>)Parameters["SimilarityCalculator"]; }
|
---|
102 | }
|
---|
103 | private ScopeParameter CurrentScopeParameter {
|
---|
104 | get { return (ScopeParameter)Parameters["CurrentScope"]; }
|
---|
105 | }
|
---|
106 |
|
---|
107 | public IScope CurrentScope {
|
---|
108 | get { return CurrentScopeParameter.ActualValue; }
|
---|
109 | }
|
---|
110 | #endregion
|
---|
111 |
|
---|
112 | [StorableConstructor]
|
---|
113 | private RAPGAMainLoop(bool deserializing) : base(deserializing) { }
|
---|
114 | private RAPGAMainLoop(RAPGAMainLoop original, Cloner cloner) : base(original, cloner) { }
|
---|
115 | public RAPGAMainLoop()
|
---|
116 | : base() {
|
---|
117 | Initialize();
|
---|
118 | }
|
---|
119 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
120 | return new RAPGAMainLoop(this, cloner);
|
---|
121 | }
|
---|
122 |
|
---|
123 | [StorableHook(HookType.AfterDeserialization)]
|
---|
124 | private void AfterDeserialization() {
|
---|
125 | // BackwardsCompatibility3.3
|
---|
126 | #region Backwards compatible code, remove with 3.4
|
---|
127 | if (!Parameters.ContainsKey("ReevaluateElites")) {
|
---|
128 | Parameters.Add(new ValueLookupParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)"));
|
---|
129 | }
|
---|
130 | #endregion
|
---|
131 | }
|
---|
132 |
|
---|
133 | private void Initialize() {
|
---|
134 | #region Create parameters
|
---|
135 | Parameters.Add(new ValueLookupParameter<IRandom>("Random", "A pseudo random number generator."));
|
---|
136 | Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
|
---|
137 | Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution."));
|
---|
138 | Parameters.Add(new ValueLookupParameter<IOperator>("Selector", "The operator used to select solutions for reproduction."));
|
---|
139 | Parameters.Add(new ValueLookupParameter<IOperator>("Crossover", "The operator used to cross solutions."));
|
---|
140 | Parameters.Add(new ValueLookupParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution."));
|
---|
141 | Parameters.Add(new ValueLookupParameter<IOperator>("Mutator", "The operator used to mutate solutions."));
|
---|
142 | 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."));
|
---|
143 | Parameters.Add(new ValueLookupParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation."));
|
---|
144 | Parameters.Add(new ValueLookupParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)"));
|
---|
145 | Parameters.Add(new ValueLookupParameter<IntValue>("MaximumGenerations", "The maximum number of generations which should be processed."));
|
---|
146 | Parameters.Add(new ValueLookupParameter<VariableCollection>("Results", "The variable collection where results should be stored."));
|
---|
147 | Parameters.Add(new ValueLookupParameter<IOperator>("Analyzer", "The operator used to analyze each generation."));
|
---|
148 | Parameters.Add(new ValueLookupParameter<IntValue>("EvaluatedSolutions", "The number of times solutions have been evaluated."));
|
---|
149 | Parameters.Add(new ValueLookupParameter<IntValue>("PopulationSize", "The size of the population."));
|
---|
150 | Parameters.Add(new ValueLookupParameter<IntValue>("MinimumPopulationSize", "The minimum size of the population of solutions."));
|
---|
151 | Parameters.Add(new ValueLookupParameter<IntValue>("MaximumPopulationSize", "The maximum size of the population of solutions."));
|
---|
152 | Parameters.Add(new ValueLookupParameter<DoubleValue>("ComparisonFactor", "The comparison factor."));
|
---|
153 | Parameters.Add(new ValueLookupParameter<IntValue>("Effort", "The maximum number of offspring created in each generation."));
|
---|
154 | Parameters.Add(new ValueLookupParameter<IntValue>("BatchSize", "The number of children that should be created during one iteration of the offspring creation process."));
|
---|
155 | Parameters.Add(new ValueLookupParameter<ISolutionSimilarityCalculator>("SimilarityCalculator", "The operator used to calculate the similarity between two solutions."));
|
---|
156 | Parameters.Add(new ScopeParameter("CurrentScope", "The current scope which represents a population of solutions on which the genetic algorithm should be applied."));
|
---|
157 | #endregion
|
---|
158 |
|
---|
159 | #region Create operators
|
---|
160 | VariableCreator variableCreator = new VariableCreator();
|
---|
161 | Assigner assigner1 = new Assigner();
|
---|
162 | ResultsCollector resultsCollector = new ResultsCollector();
|
---|
163 | Placeholder analyzer1 = new Placeholder();
|
---|
164 | Placeholder selector = new Placeholder();
|
---|
165 | SubScopesProcessor subScopesProcessor1 = new SubScopesProcessor();
|
---|
166 | ChildrenCreator childrenCreator = new ChildrenCreator();
|
---|
167 | UniformSubScopesProcessor uniformSubScopesProcessor = new UniformSubScopesProcessor();
|
---|
168 | Placeholder crossover = new Placeholder();
|
---|
169 | StochasticBranch stochasticBranch = new StochasticBranch();
|
---|
170 | Placeholder mutator = new Placeholder();
|
---|
171 | Placeholder evaluator = new Placeholder();
|
---|
172 | WeightedParentsQualityComparator weightedParentsQualityComparator = new WeightedParentsQualityComparator();
|
---|
173 | SubScopesRemover subScopesRemover = new SubScopesRemover();
|
---|
174 | IntCounter intCounter1 = new IntCounter();
|
---|
175 | IntCounter intCounter2 = new IntCounter();
|
---|
176 | ConditionalSelector conditionalSelector = new ConditionalSelector();
|
---|
177 | RightReducer rightReducer1 = new RightReducer();
|
---|
178 | DuplicatesSelector duplicateSelector = new DuplicatesSelector();
|
---|
179 | LeftReducer leftReducer1 = new LeftReducer();
|
---|
180 | ProgressiveOffspringPreserver progressiveOffspringSelector = new ProgressiveOffspringPreserver();
|
---|
181 | SubScopesCounter subScopesCounter2 = new SubScopesCounter();
|
---|
182 | ExpressionCalculator calculator1 = new ExpressionCalculator();
|
---|
183 | ConditionalBranch conditionalBranch1 = new ConditionalBranch();
|
---|
184 | Comparator comparator1 = new Comparator();
|
---|
185 | ConditionalBranch conditionalBranch2 = new ConditionalBranch();
|
---|
186 | LeftReducer leftReducer2 = new LeftReducer();
|
---|
187 | SubScopesProcessor subScopesProcessor2 = new SubScopesProcessor();
|
---|
188 | BestSelector bestSelector = new BestSelector();
|
---|
189 | RightReducer rightReducer2 = new RightReducer();
|
---|
190 | ScopeCleaner scopeCleaner = new ScopeCleaner();
|
---|
191 | ScopeRestorer scopeRestorer = new ScopeRestorer();
|
---|
192 | MergingReducer mergingReducer = new MergingReducer();
|
---|
193 | IntCounter intCounter3 = new IntCounter();
|
---|
194 | SubScopesCounter subScopesCounter3 = new SubScopesCounter();
|
---|
195 | ExpressionCalculator calculator2 = new ExpressionCalculator();
|
---|
196 | Comparator comparator2 = new Comparator();
|
---|
197 | ConditionalBranch conditionalBranch3 = new ConditionalBranch();
|
---|
198 | Placeholder analyzer2 = new Placeholder();
|
---|
199 | Comparator comparator3 = new Comparator();
|
---|
200 | ConditionalBranch conditionalBranch4 = new ConditionalBranch();
|
---|
201 | Comparator comparator4 = new Comparator();
|
---|
202 | ConditionalBranch conditionalBranch5 = new ConditionalBranch();
|
---|
203 | Assigner assigner3 = new Assigner();
|
---|
204 | Assigner assigner4 = new Assigner();
|
---|
205 | Assigner assigner5 = new Assigner();
|
---|
206 | ConditionalBranch reevaluateElitesBranch = new ConditionalBranch();
|
---|
207 | UniformSubScopesProcessor uniformSubScopesProcessor2 = new UniformSubScopesProcessor();
|
---|
208 | Placeholder evaluator2 = new Placeholder();
|
---|
209 | SubScopesCounter subScopesCounter4 = new SubScopesCounter();
|
---|
210 |
|
---|
211 | variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Generations", new IntValue(0))); // Class RAPGA expects this to be called Generations
|
---|
212 | variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("CurrentPopulationSize", new IntValue(0)));
|
---|
213 | variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("NumberOfCreatedOffspring", new IntValue(0)));
|
---|
214 | variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("NumberOfSuccessfulOffspring", new IntValue(0)));
|
---|
215 | variableCreator.CollectedValues.Add(new ValueParameter<ScopeList>("OffspringList", new ScopeList()));
|
---|
216 |
|
---|
217 | assigner1.Name = "Initialize CurrentPopulationSize";
|
---|
218 | assigner1.LeftSideParameter.ActualName = "CurrentPopulationSize";
|
---|
219 | assigner1.RightSideParameter.ActualName = PopulationSizeParameter.Name;
|
---|
220 |
|
---|
221 | resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Generations"));
|
---|
222 | resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("CurrentPopulationSize"));
|
---|
223 | resultsCollector.ResultsParameter.ActualName = "Results";
|
---|
224 |
|
---|
225 | analyzer1.Name = "Analyzer";
|
---|
226 | analyzer1.OperatorParameter.ActualName = "Analyzer";
|
---|
227 |
|
---|
228 | selector.Name = "Selector";
|
---|
229 | selector.OperatorParameter.ActualName = "Selector";
|
---|
230 |
|
---|
231 | childrenCreator.ParentsPerChild = new IntValue(2);
|
---|
232 |
|
---|
233 | uniformSubScopesProcessor.Parallel.Value = true;
|
---|
234 |
|
---|
235 | crossover.Name = "Crossover";
|
---|
236 | crossover.OperatorParameter.ActualName = "Crossover";
|
---|
237 |
|
---|
238 | stochasticBranch.ProbabilityParameter.ActualName = "MutationProbability";
|
---|
239 | stochasticBranch.RandomParameter.ActualName = "Random";
|
---|
240 |
|
---|
241 | mutator.Name = "Mutator";
|
---|
242 | mutator.OperatorParameter.ActualName = "Mutator";
|
---|
243 |
|
---|
244 | evaluator.Name = "Evaluator";
|
---|
245 | evaluator.OperatorParameter.ActualName = "Evaluator";
|
---|
246 |
|
---|
247 | weightedParentsQualityComparator.ComparisonFactorParameter.ActualName = ComparisonFactorParameter.Name;
|
---|
248 | weightedParentsQualityComparator.LeftSideParameter.ActualName = QualityParameter.Name;
|
---|
249 | weightedParentsQualityComparator.MaximizationParameter.ActualName = MaximizationParameter.Name;
|
---|
250 | weightedParentsQualityComparator.RightSideParameter.ActualName = QualityParameter.Name;
|
---|
251 | weightedParentsQualityComparator.ResultParameter.ActualName = "SuccessfulOffspring";
|
---|
252 |
|
---|
253 | subScopesRemover.RemoveAllSubScopes = true;
|
---|
254 |
|
---|
255 | intCounter1.Name = "Increment NumberOfCreatedOffspring";
|
---|
256 | intCounter1.ValueParameter.ActualName = "NumberOfCreatedOffspring";
|
---|
257 | intCounter1.Increment = null;
|
---|
258 | intCounter1.IncrementParameter.ActualName = BatchSizeParameter.Name;
|
---|
259 |
|
---|
260 | intCounter2.Name = "Increment EvaluatedSolutions";
|
---|
261 | intCounter2.ValueParameter.ActualName = EvaluatedSolutionsParameter.Name;
|
---|
262 | intCounter2.Increment = null;
|
---|
263 | intCounter2.IncrementParameter.ActualName = BatchSizeParameter.Name;
|
---|
264 |
|
---|
265 | conditionalSelector.ConditionParameter.ActualName = "SuccessfulOffspring";
|
---|
266 | conditionalSelector.ConditionParameter.Depth = 1;
|
---|
267 | conditionalSelector.CopySelected.Value = false;
|
---|
268 |
|
---|
269 | duplicateSelector.CopySelected.Value = false;
|
---|
270 |
|
---|
271 | progressiveOffspringSelector.OffspringListParameter.ActualName = "OffspringList";
|
---|
272 | progressiveOffspringSelector.ElitesParameter.ActualName = ElitesParameter.Name;
|
---|
273 | progressiveOffspringSelector.MaximumPopulationSizeParameter.ActualName = MaximumPopulationSizeParameter.Name;
|
---|
274 |
|
---|
275 | subScopesCounter2.Name = "Count Successful Offspring";
|
---|
276 | subScopesCounter2.ValueParameter.ActualName = "NumberOfSuccessfulOffspring";
|
---|
277 |
|
---|
278 | calculator1.Name = "NumberOfSuccessfulOffspring == MaximumPopulationSize - Elites";
|
---|
279 | calculator1.CollectedValues.Add(new ValueLookupParameter<IntValue>("NumberOfSuccessfulOffspring"));
|
---|
280 | calculator1.CollectedValues.Add(new ValueLookupParameter<IntValue>("MaximumPopulationSize"));
|
---|
281 | calculator1.CollectedValues.Add(new ValueLookupParameter<IntValue>("Elites"));
|
---|
282 | calculator1.ExpressionParameter.Value = new StringValue("NumberOfSuccessfulOffspring MaximumPopulationSize Elites - ==");
|
---|
283 | calculator1.ExpressionResultParameter.ActualName = "Break";
|
---|
284 |
|
---|
285 | conditionalBranch1.Name = "Break?";
|
---|
286 | conditionalBranch1.ConditionParameter.ActualName = "Break";
|
---|
287 |
|
---|
288 | comparator1.Name = "NumberOfCreatedOffspring >= Effort";
|
---|
289 | comparator1.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
|
---|
290 | comparator1.LeftSideParameter.ActualName = "NumberOfCreatedOffspring";
|
---|
291 | comparator1.RightSideParameter.ActualName = EffortParameter.Name;
|
---|
292 | comparator1.ResultParameter.ActualName = "Break";
|
---|
293 |
|
---|
294 | conditionalBranch2.Name = "Break?";
|
---|
295 | conditionalBranch2.ConditionParameter.ActualName = "Break";
|
---|
296 |
|
---|
297 | bestSelector.CopySelected = new BoolValue(false);
|
---|
298 | bestSelector.MaximizationParameter.ActualName = MaximizationParameter.Name;
|
---|
299 | bestSelector.NumberOfSelectedSubScopesParameter.ActualName = "Elites";
|
---|
300 | bestSelector.QualityParameter.ActualName = QualityParameter.Name;
|
---|
301 |
|
---|
302 | intCounter3.Name = "Increment Generations";
|
---|
303 | intCounter3.Increment = new IntValue(1);
|
---|
304 | intCounter3.ValueParameter.ActualName = "Generations";
|
---|
305 |
|
---|
306 | subScopesCounter3.Name = "Update CurrentPopulationSize";
|
---|
307 | subScopesCounter3.ValueParameter.ActualName = "CurrentPopulationSize";
|
---|
308 | subScopesCounter3.AccumulateParameter.Value = new BoolValue(false);
|
---|
309 |
|
---|
310 | calculator2.Name = "Evaluate ActualSelectionPressure";
|
---|
311 | calculator2.CollectedValues.Add(new ValueLookupParameter<IntValue>("NumberOfCreatedOffspring"));
|
---|
312 | calculator2.CollectedValues.Add(new ValueLookupParameter<IntValue>("Elites"));
|
---|
313 | calculator2.CollectedValues.Add(new ValueLookupParameter<IntValue>("CurrentPopulationSize"));
|
---|
314 | calculator2.ExpressionParameter.Value = new StringValue("NumberOfCreatedOffspring Elites + CurrentPopulationSize /");
|
---|
315 | calculator2.ExpressionResultParameter.ActualName = "ActualSelectionPressure";
|
---|
316 |
|
---|
317 | comparator2.Name = "CurrentPopulationSize < 1";
|
---|
318 | comparator2.Comparison = new Comparison(ComparisonType.Less);
|
---|
319 | comparator2.LeftSideParameter.ActualName = "CurrentPopulationSize";
|
---|
320 | comparator2.RightSideParameter.Value = new IntValue(1);
|
---|
321 | comparator2.ResultParameter.ActualName = "Terminate";
|
---|
322 |
|
---|
323 | conditionalBranch3.Name = "Terminate?";
|
---|
324 | conditionalBranch3.ConditionParameter.ActualName = "Terminate";
|
---|
325 |
|
---|
326 | analyzer2.Name = "Analyzer";
|
---|
327 | analyzer2.OperatorParameter.ActualName = "Analyzer";
|
---|
328 |
|
---|
329 | comparator3.Name = "Generations >= MaximumGenerations";
|
---|
330 | comparator3.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
|
---|
331 | comparator3.LeftSideParameter.ActualName = "Generations";
|
---|
332 | comparator3.ResultParameter.ActualName = "Terminate";
|
---|
333 | comparator3.RightSideParameter.ActualName = MaximumGenerationsParameter.Name;
|
---|
334 |
|
---|
335 | conditionalBranch4.Name = "Terminate?";
|
---|
336 | conditionalBranch4.ConditionParameter.ActualName = "Terminate";
|
---|
337 |
|
---|
338 | comparator4.Name = "CurrentPopulationSize < MinimumPopulationSize";
|
---|
339 | comparator4.Comparison = new Comparison(ComparisonType.Less);
|
---|
340 | comparator4.LeftSideParameter.ActualName = "CurrentPopulationSize";
|
---|
341 | comparator4.RightSideParameter.ActualName = MinimumPopulationSizeParameter.Name;
|
---|
342 | comparator4.ResultParameter.ActualName = "Terminate";
|
---|
343 |
|
---|
344 | conditionalBranch5.Name = "Terminate?";
|
---|
345 | conditionalBranch5.ConditionParameter.ActualName = "Terminate";
|
---|
346 |
|
---|
347 | assigner3.Name = "Reset NumberOfCreatedOffspring";
|
---|
348 | assigner3.LeftSideParameter.ActualName = "NumberOfCreatedOffspring";
|
---|
349 | assigner3.RightSideParameter.Value = new IntValue(0);
|
---|
350 |
|
---|
351 | assigner4.Name = "Reset NumberOfSuccessfulOffspring";
|
---|
352 | assigner4.LeftSideParameter.ActualName = "NumberOfSuccessfulOffspring";
|
---|
353 | assigner4.RightSideParameter.Value = new IntValue(0);
|
---|
354 |
|
---|
355 | assigner5.Name = "Reset OffspringList";
|
---|
356 | assigner5.LeftSideParameter.ActualName = "OffspringList";
|
---|
357 | assigner5.RightSideParameter.Value = new ScopeList();
|
---|
358 |
|
---|
359 | reevaluateElitesBranch.ConditionParameter.ActualName = "ReevaluateElites";
|
---|
360 | reevaluateElitesBranch.Name = "Reevaluate elites ?";
|
---|
361 |
|
---|
362 | uniformSubScopesProcessor2.Parallel.Value = true;
|
---|
363 |
|
---|
364 | evaluator2.Name = "Evaluator (placeholder)";
|
---|
365 | evaluator2.OperatorParameter.ActualName = EvaluatorParameter.Name;
|
---|
366 |
|
---|
367 | subScopesCounter4.Name = "Increment EvaluatedSolutions";
|
---|
368 | subScopesCounter4.ValueParameter.ActualName = EvaluatedSolutionsParameter.Name;
|
---|
369 | #endregion
|
---|
370 |
|
---|
371 | #region Create operator graph
|
---|
372 | OperatorGraph.InitialOperator = variableCreator;
|
---|
373 | variableCreator.Successor = assigner1;
|
---|
374 | assigner1.Successor = resultsCollector;
|
---|
375 | resultsCollector.Successor = analyzer1;
|
---|
376 | analyzer1.Successor = selector;
|
---|
377 | selector.Successor = subScopesProcessor1;
|
---|
378 | subScopesProcessor1.Operators.Add(new EmptyOperator());
|
---|
379 | subScopesProcessor1.Operators.Add(childrenCreator);
|
---|
380 | subScopesProcessor1.Successor = calculator1;
|
---|
381 | childrenCreator.Successor = uniformSubScopesProcessor;
|
---|
382 | uniformSubScopesProcessor.Operator = crossover;
|
---|
383 | uniformSubScopesProcessor.Successor = intCounter1;
|
---|
384 | crossover.Successor = stochasticBranch;
|
---|
385 | stochasticBranch.FirstBranch = mutator;
|
---|
386 | stochasticBranch.SecondBranch = null;
|
---|
387 | mutator.Successor = null;
|
---|
388 | stochasticBranch.Successor = evaluator;
|
---|
389 | evaluator.Successor = weightedParentsQualityComparator;
|
---|
390 | weightedParentsQualityComparator.Successor = subScopesRemover;
|
---|
391 | intCounter1.Successor = intCounter2;
|
---|
392 | intCounter2.Successor = conditionalSelector;
|
---|
393 | conditionalSelector.Successor = rightReducer1;
|
---|
394 | rightReducer1.Successor = duplicateSelector;
|
---|
395 | duplicateSelector.Successor = leftReducer1;
|
---|
396 | leftReducer1.Successor = progressiveOffspringSelector;
|
---|
397 | progressiveOffspringSelector.Successor = subScopesCounter2;
|
---|
398 | calculator1.Successor = conditionalBranch1;
|
---|
399 | conditionalBranch1.FalseBranch = comparator1;
|
---|
400 | conditionalBranch1.TrueBranch = subScopesProcessor2;
|
---|
401 | comparator1.Successor = conditionalBranch2;
|
---|
402 | conditionalBranch2.FalseBranch = leftReducer2;
|
---|
403 | conditionalBranch2.TrueBranch = subScopesProcessor2;
|
---|
404 | leftReducer2.Successor = selector;
|
---|
405 | subScopesProcessor2.Operators.Add(bestSelector);
|
---|
406 | subScopesProcessor2.Operators.Add(scopeCleaner);
|
---|
407 | subScopesProcessor2.Successor = mergingReducer;
|
---|
408 | bestSelector.Successor = rightReducer2;
|
---|
409 | rightReducer2.Successor = reevaluateElitesBranch;
|
---|
410 | reevaluateElitesBranch.TrueBranch = uniformSubScopesProcessor2;
|
---|
411 | uniformSubScopesProcessor2.Operator = evaluator2;
|
---|
412 | uniformSubScopesProcessor2.Successor = subScopesCounter4;
|
---|
413 | evaluator2.Successor = null;
|
---|
414 | subScopesCounter4.Successor = null;
|
---|
415 | reevaluateElitesBranch.FalseBranch = null;
|
---|
416 | reevaluateElitesBranch.Successor = null;
|
---|
417 | scopeCleaner.Successor = scopeRestorer;
|
---|
418 | mergingReducer.Successor = intCounter3;
|
---|
419 | intCounter3.Successor = subScopesCounter3;
|
---|
420 | subScopesCounter3.Successor = calculator2;
|
---|
421 | calculator2.Successor = comparator2;
|
---|
422 | comparator2.Successor = conditionalBranch3;
|
---|
423 | conditionalBranch3.FalseBranch = analyzer2;
|
---|
424 | conditionalBranch3.TrueBranch = null;
|
---|
425 | analyzer2.Successor = comparator3;
|
---|
426 | comparator3.Successor = conditionalBranch4;
|
---|
427 | conditionalBranch4.FalseBranch = comparator4;
|
---|
428 | conditionalBranch4.TrueBranch = null;
|
---|
429 | conditionalBranch4.Successor = null;
|
---|
430 | comparator4.Successor = conditionalBranch5;
|
---|
431 | conditionalBranch5.FalseBranch = assigner3;
|
---|
432 | conditionalBranch5.TrueBranch = null;
|
---|
433 | conditionalBranch5.Successor = null;
|
---|
434 | assigner3.Successor = assigner4;
|
---|
435 | assigner4.Successor = assigner5;
|
---|
436 | assigner5.Successor = selector;
|
---|
437 |
|
---|
438 | #endregion
|
---|
439 | }
|
---|
440 |
|
---|
441 | public override IOperation Apply() {
|
---|
442 | if (CrossoverParameter.ActualName == null)
|
---|
443 | return null;
|
---|
444 | return base.Apply();
|
---|
445 | }
|
---|
446 | }
|
---|
447 | }
|
---|