1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2014 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 System;
|
---|
23 | using System.Linq;
|
---|
24 | using HeuristicLab.Analysis;
|
---|
25 | using HeuristicLab.Common;
|
---|
26 | using HeuristicLab.Core;
|
---|
27 | using HeuristicLab.Data;
|
---|
28 | using HeuristicLab.Operators;
|
---|
29 | using HeuristicLab.Optimization;
|
---|
30 | using HeuristicLab.Optimization.Operators;
|
---|
31 | using HeuristicLab.Parameters;
|
---|
32 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
33 | using HeuristicLab.PluginInfrastructure;
|
---|
34 | using HeuristicLab.Random;
|
---|
35 | using HeuristicLab.Selection;
|
---|
36 |
|
---|
37 | namespace HeuristicLab.Algorithms.ALPS {
|
---|
38 | [Item("ALPS Genetic Algorithm", "A genetic algorithm with an age-layered population structure.")]
|
---|
39 | [Creatable("Algorithms")]
|
---|
40 | [StorableClass]
|
---|
41 | public class AlpsGeneticAlgorithm : HeuristicOptimizationEngineAlgorithm, IStorableContent {
|
---|
42 | public string Filename { get; set; }
|
---|
43 |
|
---|
44 | #region Problem Properties
|
---|
45 | public override Type ProblemType {
|
---|
46 | get { return typeof(ISingleObjectiveHeuristicOptimizationProblem); }
|
---|
47 | }
|
---|
48 | public new ISingleObjectiveHeuristicOptimizationProblem Problem {
|
---|
49 | get { return (ISingleObjectiveHeuristicOptimizationProblem)base.Problem; }
|
---|
50 | set { base.Problem = value; }
|
---|
51 | }
|
---|
52 | #endregion
|
---|
53 |
|
---|
54 | #region Parameter Properties
|
---|
55 | private IValueParameter<IntValue> SeedParameter {
|
---|
56 | get { return (IValueParameter<IntValue>)Parameters["Seed"]; }
|
---|
57 | }
|
---|
58 | private IValueParameter<BoolValue> SetSeedRandomlyParameter {
|
---|
59 | get { return (IValueParameter<BoolValue>)Parameters["SetSeedRandomly"]; }
|
---|
60 | }
|
---|
61 | private IValueParameter<MultiAnalyzer> AnalyzerParameter {
|
---|
62 | get { return (IValueParameter<MultiAnalyzer>)Parameters["Analyzer"]; }
|
---|
63 | }
|
---|
64 | private IValueParameter<MultiAnalyzer> LayerAnalyzerParameter {
|
---|
65 | get { return (IValueParameter<MultiAnalyzer>)Parameters["LayerAnalyzer"]; }
|
---|
66 | }
|
---|
67 | private IValueParameter<IntValue> NumberOfLayersParameter {
|
---|
68 | get { return (IValueParameter<IntValue>)Parameters["NumberOfLayers"]; }
|
---|
69 | }
|
---|
70 | private IValueParameter<IntValue> PopulationSizeParameter {
|
---|
71 | get { return (IValueParameter<IntValue>)Parameters["PopulationSize"]; }
|
---|
72 | }
|
---|
73 | private IValueParameter<IntValue> MaximumGenerationsParameter {
|
---|
74 | get { return (IValueParameter<IntValue>)Parameters["MaximumGenerations"]; }
|
---|
75 | }
|
---|
76 | private IValueParameter<AgingScheme> AgingSchemeParameter {
|
---|
77 | get { return (IValueParameter<AgingScheme>)Parameters["AgingScheme"]; }
|
---|
78 | }
|
---|
79 | private IValueParameter<IntValue> AgeGapParameter {
|
---|
80 | get { return (IValueParameter<IntValue>)Parameters["AgeGap"]; }
|
---|
81 | }
|
---|
82 | private IValueParameter<IntArray> AgeLimitsParameter {
|
---|
83 | get { return (IValueParameter<IntArray>)Parameters["AgeLimits"]; }
|
---|
84 | }
|
---|
85 | private IValueParameter<ReductionOperation> AgeInheritanceParameter {
|
---|
86 | get { return (IValueParameter<ReductionOperation>)Parameters["AgeInheritance"]; }
|
---|
87 | }
|
---|
88 | public IConstrainedValueParameter<ISelector> SelectorParameter {
|
---|
89 | get { return (IConstrainedValueParameter<ISelector>)Parameters["Selector"]; }
|
---|
90 | }
|
---|
91 | public IConstrainedValueParameter<ICrossover> CrossoverParameter {
|
---|
92 | get { return (IConstrainedValueParameter<ICrossover>)Parameters["Crossover"]; }
|
---|
93 | }
|
---|
94 | private IValueParameter<PercentValue> MutationProbabilityParameter {
|
---|
95 | get { return (IValueParameter<PercentValue>)Parameters["MutationProbability"]; }
|
---|
96 | }
|
---|
97 | public IConstrainedValueParameter<IManipulator> MutatorParameter {
|
---|
98 | get { return (IConstrainedValueParameter<IManipulator>)Parameters["Mutator"]; }
|
---|
99 | }
|
---|
100 | private IValueParameter<IntValue> ElitesParameter {
|
---|
101 | get { return (IValueParameter<IntValue>)Parameters["Elites"]; }
|
---|
102 | }
|
---|
103 | private IFixedValueParameter<BoolValue> ReevaluateElitesParameter {
|
---|
104 | get { return (IFixedValueParameter<BoolValue>)Parameters["ReevaluateElites"]; }
|
---|
105 | }
|
---|
106 | #endregion
|
---|
107 |
|
---|
108 | #region Properties
|
---|
109 | public IntValue Seed {
|
---|
110 | get { return SeedParameter.Value; }
|
---|
111 | set { SeedParameter.Value = value; }
|
---|
112 | }
|
---|
113 | public BoolValue SetSeedRandomly {
|
---|
114 | get { return SetSeedRandomlyParameter.Value; }
|
---|
115 | set { SetSeedRandomlyParameter.Value = value; }
|
---|
116 | }
|
---|
117 | public MultiAnalyzer Analyzer {
|
---|
118 | get { return AnalyzerParameter.Value; }
|
---|
119 | set { AnalyzerParameter.Value = value; }
|
---|
120 | }
|
---|
121 | public MultiAnalyzer LayerAnalyzer {
|
---|
122 | get { return LayerAnalyzerParameter.Value; }
|
---|
123 | set { LayerAnalyzerParameter.Value = value; }
|
---|
124 | }
|
---|
125 | public IntValue NumberOfLayers {
|
---|
126 | get { return NumberOfLayersParameter.Value; }
|
---|
127 | set { NumberOfLayersParameter.Value = value; }
|
---|
128 | }
|
---|
129 |
|
---|
130 | public IntValue PopulationSize {
|
---|
131 | get { return PopulationSizeParameter.Value; }
|
---|
132 | set { PopulationSizeParameter.Value = value; }
|
---|
133 | }
|
---|
134 | public IntValue MaximumGenerations {
|
---|
135 | get { return MaximumGenerationsParameter.Value; }
|
---|
136 | set { MaximumGenerationsParameter.Value = value; }
|
---|
137 | }
|
---|
138 | public AgingScheme AgingScheme {
|
---|
139 | get { return AgingSchemeParameter.Value; }
|
---|
140 | set { AgingSchemeParameter.Value = value; }
|
---|
141 | }
|
---|
142 | public IntValue AgeGap {
|
---|
143 | get { return AgeGapParameter.Value; }
|
---|
144 | set { AgeGapParameter.Value = value; }
|
---|
145 | }
|
---|
146 | public IntArray AgeLimits {
|
---|
147 | get { return AgeLimitsParameter.Value; }
|
---|
148 | set { AgeLimitsParameter.Value = value; }
|
---|
149 | }
|
---|
150 | public ReductionOperation AgeInheritance {
|
---|
151 | get { return AgeInheritanceParameter.Value; }
|
---|
152 | set { AgeInheritanceParameter.Value = value; }
|
---|
153 | }
|
---|
154 | public ISelector Selector {
|
---|
155 | get { return SelectorParameter.Value; }
|
---|
156 | set { SelectorParameter.Value = value; }
|
---|
157 | }
|
---|
158 | public ICrossover Crossover {
|
---|
159 | get { return CrossoverParameter.Value; }
|
---|
160 | set { CrossoverParameter.Value = value; }
|
---|
161 | }
|
---|
162 | public PercentValue MutationProbability {
|
---|
163 | get { return MutationProbabilityParameter.Value; }
|
---|
164 | set { MutationProbabilityParameter.Value = value; }
|
---|
165 | }
|
---|
166 | public IManipulator Mutator {
|
---|
167 | get { return MutatorParameter.Value; }
|
---|
168 | set { MutatorParameter.Value = value; }
|
---|
169 | }
|
---|
170 | public IntValue Elites {
|
---|
171 | get { return ElitesParameter.Value; }
|
---|
172 | set { ElitesParameter.Value = value; }
|
---|
173 | }
|
---|
174 | public bool ReevaluteElites {
|
---|
175 | get { return ReevaluateElitesParameter.Value.Value; }
|
---|
176 | set { ReevaluateElitesParameter.Value.Value = value; }
|
---|
177 | }
|
---|
178 |
|
---|
179 | private RandomCreator GlobalRandomCreator {
|
---|
180 | get { return (RandomCreator)OperatorGraph.InitialOperator; }
|
---|
181 | }
|
---|
182 | private SolutionsCreator SolutionsCreator {
|
---|
183 | get { return OperatorGraph.Iterate().OfType<SolutionsCreator>().First(); }
|
---|
184 | }
|
---|
185 |
|
---|
186 | private AlpsGeneticAlgorithmMainLoop MainLoop {
|
---|
187 | get { return OperatorGraph.Iterate().OfType<AlpsGeneticAlgorithmMainLoop>().First(); }
|
---|
188 | }
|
---|
189 |
|
---|
190 | [Storable]
|
---|
191 | private BestAverageWorstQualityAnalyzer qualityAnalyzer;
|
---|
192 | [Storable]
|
---|
193 | private BestAverageWorstQualityAnalyzer layerQualityAnalyzer;
|
---|
194 | #endregion
|
---|
195 |
|
---|
196 | [StorableConstructor]
|
---|
197 | private AlpsGeneticAlgorithm(bool deserializing)
|
---|
198 | : base(deserializing) { }
|
---|
199 | private AlpsGeneticAlgorithm(AlpsGeneticAlgorithm original, Cloner cloner)
|
---|
200 | : base(original, cloner) {
|
---|
201 | qualityAnalyzer = cloner.Clone(original.qualityAnalyzer);
|
---|
202 | layerQualityAnalyzer = cloner.Clone(original.layerQualityAnalyzer);
|
---|
203 | Initialize();
|
---|
204 | }
|
---|
205 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
206 | return new AlpsGeneticAlgorithm(this, cloner);
|
---|
207 | }
|
---|
208 | public AlpsGeneticAlgorithm()
|
---|
209 | : base() {
|
---|
210 | Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
|
---|
211 | Parameters.Add(new ValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
|
---|
212 | Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze the islands.", new MultiAnalyzer()));
|
---|
213 | Parameters.Add(new ValueParameter<MultiAnalyzer>("LayerAnalyzer", "The operator used to analyze each layer.", new MultiAnalyzer()));
|
---|
214 | Parameters.Add(new ValueParameter<IntValue>("NumberOfLayers", "The number of layers.", new IntValue(5)));
|
---|
215 | Parameters.Add(new ValueParameter<IntValue>("PopulationSize", "The size of the population of solutions each layer.", new IntValue(20)));
|
---|
216 | Parameters.Add(new ValueParameter<IntValue>("MaximumGenerations", "The maximum number of generations that should be processed.", new IntValue(1000)));
|
---|
217 | Parameters.Add(new ValueParameter<AgingScheme>("AgingScheme", "The aging scheme for setting the age-limits for the layers.", new AgingScheme(AgingSchemes.Polynomial)));
|
---|
218 | Parameters.Add(new ValueParameter<IntValue>("AgeGap", "The frequency of reseeding the lowest layer and scaling factor for the age-limits for the layers", new IntValue(5)));
|
---|
219 | Parameters.Add(new ValueParameter<IntArray>("AgeLimits", new IntArray(new[] { 1, 20, 45, 80, 125 })) { Hidden = true });
|
---|
220 | Parameters.Add(new ValueParameter<ReductionOperation>("AgeInheritance", "The operator for determining the age of an offspring based the parents' age.", new ReductionOperation(ReductionOperations.Max)) { Hidden = true });
|
---|
221 | Parameters.Add(new ConstrainedValueParameter<ISelector>("Selector", "The operator used to select solutions for reproduction."));
|
---|
222 | Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions."));
|
---|
223 | Parameters.Add(new ValueParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution.", new PercentValue(0.05)));
|
---|
224 | Parameters.Add(new OptionalConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions."));
|
---|
225 | Parameters.Add(new ValueParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.", new IntValue(1)));
|
---|
226 | Parameters.Add(new FixedValueParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)", new BoolValue(false)) { Hidden = true });
|
---|
227 |
|
---|
228 | var globalRandomCreator = new RandomCreator();
|
---|
229 | var layer0Creator = new SubScopesCreator() { Name = "Create Layer Zero" };
|
---|
230 | var layer0Processor = new SubScopesProcessor();
|
---|
231 | var localRandomCreator = new LocalRandomCreator();
|
---|
232 | var layerSolutionsCreator = new SolutionsCreator();
|
---|
233 | var initializeAgeProcessor = new UniformSubScopesProcessor();
|
---|
234 | var initializeAge = new VariableCreator() { Name = "Initialize Age" };
|
---|
235 | var initializeLocalEvaluatedSolutions = new SubScopesCounter();
|
---|
236 | var initializeGlobalEvaluatedSolutions = new DataReducer() { Name = "Initialize EvaluatedSolutions" };
|
---|
237 | var resultsCollector = new ResultsCollector();
|
---|
238 | var mainLoop = new AlpsGeneticAlgorithmMainLoop();
|
---|
239 |
|
---|
240 | OperatorGraph.InitialOperator = globalRandomCreator;
|
---|
241 |
|
---|
242 | globalRandomCreator.RandomParameter.ActualName = "GlobalRandom";
|
---|
243 | globalRandomCreator.SeedParameter.Value = null;
|
---|
244 | globalRandomCreator.SetSeedRandomlyParameter.Value = null;
|
---|
245 | globalRandomCreator.Successor = layer0Creator;
|
---|
246 |
|
---|
247 | layer0Creator.NumberOfSubScopesParameter.Value = new IntValue(1);
|
---|
248 | layer0Creator.Successor = layer0Processor;
|
---|
249 |
|
---|
250 | layer0Processor.Operators.Add(localRandomCreator);
|
---|
251 | layer0Processor.Successor = initializeGlobalEvaluatedSolutions;
|
---|
252 |
|
---|
253 | localRandomCreator.Successor = layerSolutionsCreator;
|
---|
254 |
|
---|
255 | layerSolutionsCreator.NumberOfSolutionsParameter.ActualName = PopulationSizeParameter.Name;
|
---|
256 | layerSolutionsCreator.Successor = initializeAgeProcessor;
|
---|
257 |
|
---|
258 | initializeAgeProcessor.Operator = initializeAge;
|
---|
259 | initializeAgeProcessor.Successor = initializeLocalEvaluatedSolutions;
|
---|
260 |
|
---|
261 | initializeAge.CollectedValues.Add(new ValueParameter<IntValue>("Age", new IntValue(0)));
|
---|
262 | initializeAge.Successor = null;
|
---|
263 |
|
---|
264 | initializeLocalEvaluatedSolutions.ValueParameter.ActualName = "EvaluatedSolutions";
|
---|
265 | initializeLocalEvaluatedSolutions.Successor = null;
|
---|
266 |
|
---|
267 | initializeGlobalEvaluatedSolutions.ReductionOperation.Value.Value = ReductionOperations.Sum;
|
---|
268 | initializeGlobalEvaluatedSolutions.TargetOperation.Value.Value = ReductionOperations.Assign;
|
---|
269 | initializeGlobalEvaluatedSolutions.ParameterToReduce.ActualName = "EvaluatedSolutions";
|
---|
270 | initializeGlobalEvaluatedSolutions.TargetParameter.ActualName = "EvaluatedSolutions";
|
---|
271 | initializeGlobalEvaluatedSolutions.Successor = resultsCollector;
|
---|
272 |
|
---|
273 | resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("EvaluatedSolutions"));
|
---|
274 | resultsCollector.Successor = mainLoop;
|
---|
275 |
|
---|
276 | foreach (var selector in ApplicationManager.Manager.GetInstances<ISelector>().Where(s => !(s is IMultiObjectiveSelector)).OrderBy(s => Name))
|
---|
277 | SelectorParameter.ValidValues.Add(selector);
|
---|
278 | var porportionalSelector = SelectorParameter.ValidValues.FirstOrDefault(s => s is ProportionalSelector);
|
---|
279 | if (porportionalSelector != null) SelectorParameter.Value = porportionalSelector;
|
---|
280 |
|
---|
281 | ParameterizeSelectors();
|
---|
282 |
|
---|
283 | qualityAnalyzer = new BestAverageWorstQualityAnalyzer();
|
---|
284 | layerQualityAnalyzer = new BestAverageWorstQualityAnalyzer();
|
---|
285 | ParameterizeAnalyzers();
|
---|
286 | UpdateAnalyzers();
|
---|
287 |
|
---|
288 | Initialize();
|
---|
289 | }
|
---|
290 |
|
---|
291 | public override void Prepare() {
|
---|
292 | if (Problem != null)
|
---|
293 | base.Prepare();
|
---|
294 | }
|
---|
295 |
|
---|
296 | #region Events
|
---|
297 | protected override void OnProblemChanged() {
|
---|
298 | ParameterizeStochasticOperator(Problem.SolutionCreator);
|
---|
299 | ParameterizeStochasticOperatorForLayer(Problem.Evaluator);
|
---|
300 | foreach (var @operator in Problem.Operators.OfType<IOperator>())
|
---|
301 | ParameterizeStochasticOperator(@operator);
|
---|
302 | ParameterizeSolutionsCreator();
|
---|
303 | ParameterizeMainLoop();
|
---|
304 | ParameterizeSelectors();
|
---|
305 | ParameterizeAnalyzers();
|
---|
306 | ParameterizeIterationBasedOperators();
|
---|
307 | UpdateCrossovers();
|
---|
308 | UpdateMutators();
|
---|
309 | UpdateAnalyzers();
|
---|
310 | Problem.Evaluator.QualityParameter.ActualNameChanged += Evaluator_QualityParameter_ActualNameChanged;
|
---|
311 | base.OnProblemChanged();
|
---|
312 | }
|
---|
313 |
|
---|
314 | protected override void Problem_SolutionCreatorChanged(object sender, EventArgs e) {
|
---|
315 | ParameterizeStochasticOperator(Problem.SolutionCreator);
|
---|
316 | ParameterizeSolutionsCreator();
|
---|
317 | base.Problem_SolutionCreatorChanged(sender, e);
|
---|
318 | }
|
---|
319 | protected override void Problem_EvaluatorChanged(object sender, EventArgs e) {
|
---|
320 | ParameterizeStochasticOperatorForLayer(Problem.Evaluator);
|
---|
321 | ParameterizeSolutionsCreator();
|
---|
322 | ParameterizeMainLoop();
|
---|
323 | ParameterizeSelectors();
|
---|
324 | ParameterizeAnalyzers();
|
---|
325 | Problem.Evaluator.QualityParameter.ActualNameChanged += Evaluator_QualityParameter_ActualNameChanged;
|
---|
326 | base.Problem_EvaluatorChanged(sender, e);
|
---|
327 | }
|
---|
328 | protected override void Problem_OperatorsChanged(object sender, EventArgs e) {
|
---|
329 | foreach (var @operator in Problem.Operators.OfType<IOperator>())
|
---|
330 | ParameterizeStochasticOperator(@operator);
|
---|
331 | ParameterizeIterationBasedOperators();
|
---|
332 | UpdateCrossovers();
|
---|
333 | UpdateMutators();
|
---|
334 | UpdateAnalyzers();
|
---|
335 | base.Problem_OperatorsChanged(sender, e);
|
---|
336 | }
|
---|
337 | private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
|
---|
338 | ParameterizeMainLoop();
|
---|
339 | ParameterizeSelectors();
|
---|
340 | ParameterizeAnalyzers();
|
---|
341 | }
|
---|
342 |
|
---|
343 | void PopulationSizeParameter_ValueChanged(object sender, EventArgs e) {
|
---|
344 | PopulationSizeParameter.ValueChanged += PopulationSize_ValueChanged;
|
---|
345 | ParameterizeSelectors();
|
---|
346 | }
|
---|
347 | void PopulationSize_ValueChanged(object sender, EventArgs e) {
|
---|
348 | ParameterizeSelectors();
|
---|
349 | }
|
---|
350 | void ElitesParameter_ValueChanged(object sender, EventArgs e) {
|
---|
351 | Elites.ValueChanged += ElitesParameter_ValueChanged;
|
---|
352 | ParameterizeSelectors();
|
---|
353 | }
|
---|
354 | void Elites_ValueChanged(object sender, EventArgs e) {
|
---|
355 | ParameterizeSelectors();
|
---|
356 | }
|
---|
357 | #endregion
|
---|
358 |
|
---|
359 | #region Parameterization
|
---|
360 | private void Initialize() {
|
---|
361 | PopulationSizeParameter.ValueChanged += PopulationSizeParameter_ValueChanged;
|
---|
362 | PopulationSize.ValueChanged += PopulationSize_ValueChanged;
|
---|
363 | ElitesParameter.ValueChanged += ElitesParameter_ValueChanged;
|
---|
364 | Elites.ValueChanged += Elites_ValueChanged;
|
---|
365 | if (Problem != null)
|
---|
366 | Problem.Evaluator.QualityParameter.ActualNameChanged += Evaluator_QualityParameter_ActualNameChanged;
|
---|
367 | }
|
---|
368 | private void ParameterizeSolutionsCreator() {
|
---|
369 | SolutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
|
---|
370 | SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name;
|
---|
371 | }
|
---|
372 | private void ParameterizeMainLoop() {
|
---|
373 | MainLoop.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
|
---|
374 | MainLoop.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
|
---|
375 | MainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
|
---|
376 | MainLoop.BestKnownQualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
377 | }
|
---|
378 | private void ParameterizeSelectors() {
|
---|
379 | foreach (var selector in SelectorParameter.ValidValues) {
|
---|
380 | selector.CopySelected = new BoolValue(true);
|
---|
381 | selector.NumberOfSelectedSubScopesParameter.Value = new IntValue(2 * (PopulationSize.Value - Elites.Value));
|
---|
382 | selector.NumberOfSelectedSubScopesParameter.Hidden = true;
|
---|
383 | ParameterizeStochasticOperatorForLayer(selector);
|
---|
384 | }
|
---|
385 | if (Problem != null) {
|
---|
386 | foreach (var selector in SelectorParameter.ValidValues.OfType<ISingleObjectiveSelector>()) {
|
---|
387 | selector.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
|
---|
388 | selector.MaximizationParameter.Hidden = true;
|
---|
389 | selector.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
390 | selector.QualityParameter.Hidden = true;
|
---|
391 | }
|
---|
392 | }
|
---|
393 | }
|
---|
394 | private void ParameterizeAnalyzers() {
|
---|
395 | qualityAnalyzer.ResultsParameter.ActualName = "Results";
|
---|
396 | qualityAnalyzer.ResultsParameter.Hidden = true;
|
---|
397 | qualityAnalyzer.QualityParameter.Depth = 2;
|
---|
398 | layerQualityAnalyzer.ResultsParameter.ActualName = "Results";
|
---|
399 | layerQualityAnalyzer.ResultsParameter.Hidden = true;
|
---|
400 | layerQualityAnalyzer.QualityParameter.Depth = 1;
|
---|
401 | if (Problem != null) {
|
---|
402 | qualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
|
---|
403 | qualityAnalyzer.MaximizationParameter.Hidden = true;
|
---|
404 | qualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
405 | qualityAnalyzer.QualityParameter.Hidden = true;
|
---|
406 | qualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
|
---|
407 | qualityAnalyzer.BestKnownQualityParameter.Hidden = true;
|
---|
408 | layerQualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
|
---|
409 | layerQualityAnalyzer.MaximizationParameter.Hidden = true;
|
---|
410 | layerQualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
411 | layerQualityAnalyzer.QualityParameter.Hidden = true;
|
---|
412 | layerQualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
|
---|
413 | layerQualityAnalyzer.BestKnownQualityParameter.Hidden = true;
|
---|
414 | }
|
---|
415 | }
|
---|
416 | private void ParameterizeIterationBasedOperators() {
|
---|
417 | if (Problem != null) {
|
---|
418 | foreach (var @operator in Problem.Operators.OfType<IIterationBasedOperator>()) {
|
---|
419 | @operator.IterationsParameter.ActualName = "Generations";
|
---|
420 | @operator.IterationsParameter.Hidden = true;
|
---|
421 | @operator.MaximumIterationsParameter.ActualName = "MaximumGenerations";
|
---|
422 | @operator.MaximumIterationsParameter.Hidden = true;
|
---|
423 | }
|
---|
424 | }
|
---|
425 | }
|
---|
426 | private void ParameterizeStochasticOperator(IOperator @operator) {
|
---|
427 | var stochasticOperator = @operator as IStochasticOperator;
|
---|
428 | if (stochasticOperator != null) {
|
---|
429 | stochasticOperator.RandomParameter.ActualName = GlobalRandomCreator.RandomParameter.ActualName;
|
---|
430 | stochasticOperator.RandomParameter.Hidden = true;
|
---|
431 | }
|
---|
432 | }
|
---|
433 | private void ParameterizeStochasticOperatorForLayer(IOperator @operator) {
|
---|
434 | var stochasticOperator = @operator as IStochasticOperator;
|
---|
435 | if (stochasticOperator != null) {
|
---|
436 | stochasticOperator.RandomParameter.ActualName = "LocalRandom";
|
---|
437 | stochasticOperator.RandomParameter.Hidden = true;
|
---|
438 | }
|
---|
439 | }
|
---|
440 |
|
---|
441 | #endregion
|
---|
442 |
|
---|
443 | #region Updates
|
---|
444 | private void UpdateCrossovers() {
|
---|
445 | var oldCrossover = CrossoverParameter.Value;
|
---|
446 | var defaultCrossover = Problem.Operators.OfType<ICrossover>().FirstOrDefault();
|
---|
447 | CrossoverParameter.ValidValues.Clear();
|
---|
448 | foreach (var crossover in Problem.Operators.OfType<ICrossover>().OrderBy(c => c.Name)) {
|
---|
449 | ParameterizeStochasticOperatorForLayer(crossover);
|
---|
450 | CrossoverParameter.ValidValues.Add(crossover);
|
---|
451 | }
|
---|
452 | if (oldCrossover != null) {
|
---|
453 | var crossover = CrossoverParameter.ValidValues.FirstOrDefault(c => c.GetType() == oldCrossover.GetType());
|
---|
454 | CrossoverParameter.Value = crossover;
|
---|
455 | }
|
---|
456 | if (oldCrossover == null && defaultCrossover != null)
|
---|
457 | CrossoverParameter.Value = defaultCrossover;
|
---|
458 | }
|
---|
459 | private void UpdateMutators() {
|
---|
460 | var oldMutator = MutatorParameter.Value;
|
---|
461 | MutatorParameter.ValidValues.Clear();
|
---|
462 | foreach (var mutator in Problem.Operators.OfType<IManipulator>().OrderBy(m => m.Name)) {
|
---|
463 | ParameterizeStochasticOperatorForLayer(mutator);
|
---|
464 | MutatorParameter.ValidValues.Add(mutator);
|
---|
465 | }
|
---|
466 | if (oldMutator != null) {
|
---|
467 | var mutator = MutatorParameter.ValidValues.FirstOrDefault(m => m.GetType() == oldMutator.GetType());
|
---|
468 | MutatorParameter.Value = mutator;
|
---|
469 | }
|
---|
470 | }
|
---|
471 | private void UpdateAnalyzers() {
|
---|
472 | Analyzer.Operators.Clear();
|
---|
473 | LayerAnalyzer.Operators.Clear();
|
---|
474 |
|
---|
475 | Analyzer.Operators.Add(qualityAnalyzer, qualityAnalyzer.EnabledByDefault);
|
---|
476 | LayerAnalyzer.Operators.Add(layerQualityAnalyzer, layerQualityAnalyzer.EnabledByDefault);
|
---|
477 |
|
---|
478 | if (Problem != null) {
|
---|
479 | foreach (var analyzer in Problem.Operators.OfType<IAnalyzer>()) {
|
---|
480 | foreach (var parameter in analyzer.Parameters.OfType<IScopeTreeLookupParameter>())
|
---|
481 | parameter.Depth = 2;
|
---|
482 | Analyzer.Operators.Add(analyzer, analyzer.EnabledByDefault);
|
---|
483 | }
|
---|
484 | }
|
---|
485 | }
|
---|
486 | #endregion
|
---|
487 | }
|
---|
488 | } |
---|