[11567] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[14185] | 3 | * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[11567] | 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;
|
---|
[12531] | 23 | using System.Collections.Generic;
|
---|
[11578] | 24 | using System.Linq;
|
---|
[12993] | 25 | using HeuristicLab.Analysis;
|
---|
| 26 | using HeuristicLab.Collections;
|
---|
[11567] | 27 | using HeuristicLab.Common;
|
---|
| 28 | using HeuristicLab.Core;
|
---|
[11568] | 29 | using HeuristicLab.Data;
|
---|
| 30 | using HeuristicLab.Operators;
|
---|
[11567] | 31 | using HeuristicLab.Optimization;
|
---|
[11578] | 32 | using HeuristicLab.Optimization.Operators;
|
---|
[11568] | 33 | using HeuristicLab.Parameters;
|
---|
[11567] | 34 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
[11578] | 35 | using HeuristicLab.PluginInfrastructure;
|
---|
| 36 | using HeuristicLab.Random;
|
---|
| 37 | using HeuristicLab.Selection;
|
---|
[11567] | 38 |
|
---|
| 39 | namespace HeuristicLab.Algorithms.ALPS {
|
---|
[12994] | 40 | [Item("ALPS Genetic Algorithm", "A genetic algorithm within an age-layered population structure as described in Gregory S. Hornby. 2006. ALPS: the age-layered population structure for reducing the problem of premature convergence. In Proceedings of the 8th annual conference on Genetic and evolutionary computation (GECCO '06). 815-822.")]
|
---|
| 41 | [Creatable(CreatableAttribute.Categories.PopulationBasedAlgorithms, Priority = 160)]
|
---|
[11567] | 42 | [StorableClass]
|
---|
[12993] | 43 | public sealed class AlpsGeneticAlgorithm : HeuristicOptimizationEngineAlgorithm, IStorableContent {
|
---|
| 44 | public string Filename { get; set; }
|
---|
| 45 |
|
---|
| 46 | #region Problem Properties
|
---|
| 47 | public override Type ProblemType {
|
---|
| 48 | get { return typeof(ISingleObjectiveHeuristicOptimizationProblem); }
|
---|
| 49 | }
|
---|
| 50 | public new ISingleObjectiveHeuristicOptimizationProblem Problem {
|
---|
| 51 | get { return (ISingleObjectiveHeuristicOptimizationProblem)base.Problem; }
|
---|
| 52 | set { base.Problem = value; }
|
---|
| 53 | }
|
---|
| 54 | #endregion
|
---|
| 55 |
|
---|
[11567] | 56 | #region Parameter Properties
|
---|
[12993] | 57 | private IValueParameter<IntValue> SeedParameter {
|
---|
| 58 | get { return (IValueParameter<IntValue>)Parameters["Seed"]; }
|
---|
| 59 | }
|
---|
| 60 | private IValueParameter<BoolValue> SetSeedRandomlyParameter {
|
---|
| 61 | get { return (IValueParameter<BoolValue>)Parameters["SetSeedRandomly"]; }
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | private IFixedValueParameter<MultiAnalyzer> AnalyzerParameter {
|
---|
| 65 | get { return (IFixedValueParameter<MultiAnalyzer>)Parameters["Analyzer"]; }
|
---|
| 66 | }
|
---|
| 67 | private IFixedValueParameter<MultiAnalyzer> LayerAnalyzerParameter {
|
---|
| 68 | get { return (IFixedValueParameter<MultiAnalyzer>)Parameters["LayerAnalyzer"]; }
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | private IValueParameter<IntValue> NumberOfLayersParameter {
|
---|
| 72 | get { return (IValueParameter<IntValue>)Parameters["NumberOfLayers"]; }
|
---|
| 73 | }
|
---|
[12992] | 74 | private IValueParameter<IntValue> PopulationSizeParameter {
|
---|
| 75 | get { return (IValueParameter<IntValue>)Parameters["PopulationSize"]; }
|
---|
[11568] | 76 | }
|
---|
[12993] | 77 |
|
---|
[11568] | 78 | public IConstrainedValueParameter<ISelector> SelectorParameter {
|
---|
| 79 | get { return (IConstrainedValueParameter<ISelector>)Parameters["Selector"]; }
|
---|
| 80 | }
|
---|
| 81 | public IConstrainedValueParameter<ICrossover> CrossoverParameter {
|
---|
| 82 | get { return (IConstrainedValueParameter<ICrossover>)Parameters["Crossover"]; }
|
---|
| 83 | }
|
---|
[12993] | 84 | public IConstrainedValueParameter<IManipulator> MutatorParameter {
|
---|
| 85 | get { return (IConstrainedValueParameter<IManipulator>)Parameters["Mutator"]; }
|
---|
| 86 | }
|
---|
[11568] | 87 | private IValueParameter<PercentValue> MutationProbabilityParameter {
|
---|
| 88 | get { return (IValueParameter<PercentValue>)Parameters["MutationProbability"]; }
|
---|
| 89 | }
|
---|
| 90 | private IValueParameter<IntValue> ElitesParameter {
|
---|
| 91 | get { return (IValueParameter<IntValue>)Parameters["Elites"]; }
|
---|
| 92 | }
|
---|
| 93 | private IFixedValueParameter<BoolValue> ReevaluateElitesParameter {
|
---|
| 94 | get { return (IFixedValueParameter<BoolValue>)Parameters["ReevaluateElites"]; }
|
---|
| 95 | }
|
---|
[12186] | 96 | private IValueParameter<BoolValue> PlusSelectionParameter {
|
---|
| 97 | get { return (IValueParameter<BoolValue>)Parameters["PlusSelection"]; }
|
---|
| 98 | }
|
---|
[12993] | 99 |
|
---|
| 100 | private IValueParameter<EnumValue<AgingScheme>> AgingSchemeParameter {
|
---|
| 101 | get { return (IValueParameter<EnumValue<AgingScheme>>)Parameters["AgingScheme"]; }
|
---|
| 102 | }
|
---|
| 103 | private IValueParameter<IntValue> AgeGapParameter {
|
---|
| 104 | get { return (IValueParameter<IntValue>)Parameters["AgeGap"]; }
|
---|
| 105 | }
|
---|
[12997] | 106 | private IValueParameter<DoubleValue> AgeInheritanceParameter {
|
---|
| 107 | get { return (IValueParameter<DoubleValue>)Parameters["AgeInheritance"]; }
|
---|
[12993] | 108 | }
|
---|
| 109 | private IValueParameter<IntArray> AgeLimitsParameter {
|
---|
| 110 | get { return (IValueParameter<IntArray>)Parameters["AgeLimits"]; }
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 | private IValueParameter<IntValue> MatingPoolRangeParameter {
|
---|
| 114 | get { return (IValueParameter<IntValue>)Parameters["MatingPoolRange"]; }
|
---|
| 115 | }
|
---|
[13124] | 116 | private IValueParameter<BoolValue> ReduceToPopulationSizeParameter {
|
---|
| 117 | get { return (IValueParameter<BoolValue>)Parameters["ReduceToPopulationSize"]; }
|
---|
| 118 | }
|
---|
[12993] | 119 |
|
---|
| 120 | private IValueParameter<MultiTerminator> TerminatorParameter {
|
---|
| 121 | get { return (IValueParameter<MultiTerminator>)Parameters["Terminator"]; }
|
---|
| 122 | }
|
---|
[11567] | 123 | #endregion
|
---|
| 124 |
|
---|
| 125 | #region Properties
|
---|
[12993] | 126 | public IntValue Seed {
|
---|
| 127 | get { return SeedParameter.Value; }
|
---|
| 128 | set { SeedParameter.Value = value; }
|
---|
| 129 | }
|
---|
| 130 | public BoolValue SetSeedRandomly {
|
---|
| 131 | get { return SetSeedRandomlyParameter.Value; }
|
---|
| 132 | set { SetSeedRandomlyParameter.Value = value; }
|
---|
| 133 | }
|
---|
| 134 |
|
---|
| 135 | public MultiAnalyzer Analyzer {
|
---|
| 136 | get { return AnalyzerParameter.Value; }
|
---|
| 137 | }
|
---|
| 138 | public MultiAnalyzer LayerAnalyzer {
|
---|
| 139 | get { return LayerAnalyzerParameter.Value; }
|
---|
| 140 | }
|
---|
| 141 |
|
---|
| 142 | public IntValue NumberOfLayers {
|
---|
| 143 | get { return NumberOfLayersParameter.Value; }
|
---|
| 144 | set { NumberOfLayersParameter.Value = value; }
|
---|
| 145 | }
|
---|
[12992] | 146 | public IntValue PopulationSize {
|
---|
[11568] | 147 | get { return PopulationSizeParameter.Value; }
|
---|
| 148 | set { PopulationSizeParameter.Value = value; }
|
---|
| 149 | }
|
---|
[12993] | 150 |
|
---|
[11568] | 151 | public ISelector Selector {
|
---|
| 152 | get { return SelectorParameter.Value; }
|
---|
| 153 | set { SelectorParameter.Value = value; }
|
---|
| 154 | }
|
---|
| 155 | public ICrossover Crossover {
|
---|
| 156 | get { return CrossoverParameter.Value; }
|
---|
| 157 | set { CrossoverParameter.Value = value; }
|
---|
| 158 | }
|
---|
[12993] | 159 | public IManipulator Mutator {
|
---|
| 160 | get { return MutatorParameter.Value; }
|
---|
| 161 | set { MutatorParameter.Value = value; }
|
---|
| 162 | }
|
---|
[11568] | 163 | public PercentValue MutationProbability {
|
---|
| 164 | get { return MutationProbabilityParameter.Value; }
|
---|
| 165 | set { MutationProbabilityParameter.Value = value; }
|
---|
| 166 | }
|
---|
| 167 | public IntValue Elites {
|
---|
| 168 | get { return ElitesParameter.Value; }
|
---|
| 169 | set { ElitesParameter.Value = value; }
|
---|
| 170 | }
|
---|
| 171 | public bool ReevaluteElites {
|
---|
| 172 | get { return ReevaluateElitesParameter.Value.Value; }
|
---|
| 173 | set { ReevaluateElitesParameter.Value.Value = value; }
|
---|
| 174 | }
|
---|
[12186] | 175 | public bool PlusSelection {
|
---|
| 176 | get { return PlusSelectionParameter.Value.Value; }
|
---|
| 177 | set { PlusSelectionParameter.Value.Value = value; }
|
---|
| 178 | }
|
---|
[11578] | 179 |
|
---|
[12993] | 180 | public EnumValue<AgingScheme> AgingScheme {
|
---|
| 181 | get { return AgingSchemeParameter.Value; }
|
---|
| 182 | set { AgingSchemeParameter.Value = value; }
|
---|
| 183 | }
|
---|
| 184 | public IntValue AgeGap {
|
---|
| 185 | get { return AgeGapParameter.Value; }
|
---|
| 186 | set { AgeGapParameter.Value = value; }
|
---|
| 187 | }
|
---|
[12997] | 188 | public DoubleValue AgeInheritance {
|
---|
[12993] | 189 | get { return AgeInheritanceParameter.Value; }
|
---|
| 190 | set { AgeInheritanceParameter.Value = value; }
|
---|
| 191 | }
|
---|
| 192 | public IntArray AgeLimits {
|
---|
| 193 | get { return AgeLimitsParameter.Value; }
|
---|
| 194 | set { AgeLimitsParameter.Value = value; }
|
---|
| 195 | }
|
---|
| 196 |
|
---|
| 197 | public IntValue MatingPoolRange {
|
---|
| 198 | get { return MatingPoolRangeParameter.Value; }
|
---|
| 199 | set { MatingPoolRangeParameter.Value = value; }
|
---|
| 200 | }
|
---|
| 201 |
|
---|
| 202 | public MultiTerminator Terminators {
|
---|
| 203 | get { return TerminatorParameter.Value; }
|
---|
| 204 | }
|
---|
| 205 |
|
---|
| 206 | public int MaximumGenerations {
|
---|
| 207 | get { return generationsTerminator.Threshold.Value; }
|
---|
| 208 | set { generationsTerminator.Threshold.Value = value; }
|
---|
| 209 | }
|
---|
| 210 | #endregion
|
---|
| 211 |
|
---|
| 212 | #region Helper Properties
|
---|
| 213 | private SolutionsCreator SolutionsCreator {
|
---|
| 214 | get { return OperatorGraph.Iterate().OfType<SolutionsCreator>().First(); }
|
---|
| 215 | }
|
---|
[11580] | 216 | private AlpsGeneticAlgorithmMainLoop MainLoop {
|
---|
| 217 | get { return OperatorGraph.Iterate().OfType<AlpsGeneticAlgorithmMainLoop>().First(); }
|
---|
| 218 | }
|
---|
[11676] | 219 | #endregion
|
---|
| 220 |
|
---|
[12993] | 221 | #region Preconfigured Analyzers
|
---|
[12531] | 222 | [Storable]
|
---|
[12993] | 223 | private BestAverageWorstQualityAnalyzer qualityAnalyzer;
|
---|
| 224 | [Storable]
|
---|
| 225 | private BestAverageWorstQualityAnalyzer layerQualityAnalyzer;
|
---|
[12996] | 226 | [Storable]
|
---|
| 227 | private OldestAverageYoungestAgeAnalyzer ageAnalyzer;
|
---|
| 228 | [Storable]
|
---|
| 229 | private OldestAverageYoungestAgeAnalyzer layerAgeAnalyzer;
|
---|
| 230 | [Storable]
|
---|
| 231 | private AgeDistributionAnalyzer ageDistributionAnalyzer;
|
---|
| 232 | [Storable]
|
---|
| 233 | private AgeDistributionAnalyzer layerAgeDistributionAnalyzer;
|
---|
[12993] | 234 | #endregion
|
---|
| 235 |
|
---|
| 236 | #region Preconfigured Terminators
|
---|
| 237 | [Storable]
|
---|
[12531] | 238 | private ComparisonTerminator<IntValue> generationsTerminator;
|
---|
[12993] | 239 | [Storable]
|
---|
| 240 | private ComparisonTerminator<IntValue> evaluationsTerminator;
|
---|
| 241 | [Storable]
|
---|
| 242 | private SingleObjectiveQualityTerminator qualityTerminator;
|
---|
| 243 | [Storable]
|
---|
| 244 | private ExecutionTimeTerminator executionTimeTerminator;
|
---|
| 245 | #endregion
|
---|
[12531] | 246 |
|
---|
[12996] | 247 | #region Constructors
|
---|
[11567] | 248 | [StorableConstructor]
|
---|
| 249 | private AlpsGeneticAlgorithm(bool deserializing)
|
---|
| 250 | : base(deserializing) { }
|
---|
[12570] | 251 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 252 | private void AfterDeserialization() {
|
---|
| 253 | Initialize();
|
---|
| 254 | }
|
---|
[11567] | 255 | private AlpsGeneticAlgorithm(AlpsGeneticAlgorithm original, Cloner cloner)
|
---|
| 256 | : base(original, cloner) {
|
---|
[12993] | 257 | qualityAnalyzer = cloner.Clone(original.qualityAnalyzer);
|
---|
| 258 | layerQualityAnalyzer = cloner.Clone(original.layerQualityAnalyzer);
|
---|
[12996] | 259 | ageAnalyzer = cloner.Clone(original.ageAnalyzer);
|
---|
| 260 | layerAgeAnalyzer = cloner.Clone(original.layerAgeAnalyzer);
|
---|
| 261 | ageDistributionAnalyzer = cloner.Clone(original.ageDistributionAnalyzer);
|
---|
| 262 | layerAgeDistributionAnalyzer = cloner.Clone(original.layerAgeDistributionAnalyzer);
|
---|
[12531] | 263 | generationsTerminator = cloner.Clone(original.generationsTerminator);
|
---|
[12993] | 264 | evaluationsTerminator = cloner.Clone(original.evaluationsTerminator);
|
---|
| 265 | qualityTerminator = cloner.Clone(original.qualityTerminator);
|
---|
| 266 | executionTimeTerminator = cloner.Clone(original.executionTimeTerminator);
|
---|
[11578] | 267 | Initialize();
|
---|
[11567] | 268 | }
|
---|
| 269 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 270 | return new AlpsGeneticAlgorithm(this, cloner);
|
---|
| 271 | }
|
---|
| 272 | public AlpsGeneticAlgorithm()
|
---|
| 273 | : base() {
|
---|
[12993] | 274 | #region Add parameters
|
---|
| 275 | Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
|
---|
| 276 | Parameters.Add(new ValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
|
---|
| 277 |
|
---|
[13128] | 278 | Parameters.Add(new FixedValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze all individuals from all layers combined.", new MultiAnalyzer()));
|
---|
[12993] | 279 | Parameters.Add(new FixedValueParameter<MultiAnalyzer>("LayerAnalyzer", "The operator used to analyze each layer.", new MultiAnalyzer()));
|
---|
| 280 |
|
---|
| 281 | Parameters.Add(new ValueParameter<IntValue>("NumberOfLayers", "The number of layers.", new IntValue(10)));
|
---|
[13206] | 282 | Parameters.Add(new ValueParameter<IntValue>("PopulationSize", "The size of the population of solutions in each layer.", new IntValue(100)));
|
---|
[12993] | 283 |
|
---|
[11568] | 284 | Parameters.Add(new ConstrainedValueParameter<ISelector>("Selector", "The operator used to select solutions for reproduction."));
|
---|
| 285 | Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions."));
|
---|
[12993] | 286 | Parameters.Add(new OptionalConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions."));
|
---|
[11568] | 287 | Parameters.Add(new ValueParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution.", new PercentValue(0.05)));
|
---|
| 288 | Parameters.Add(new ValueParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.", new IntValue(1)));
|
---|
| 289 | 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 });
|
---|
[12998] | 290 | Parameters.Add(new ValueParameter<BoolValue>("PlusSelection", "Include the parents in the selection of the invividuals for the next generation.", new BoolValue(false)));
|
---|
[11578] | 291 |
|
---|
[12993] | 292 | Parameters.Add(new ValueParameter<EnumValue<AgingScheme>>("AgingScheme", "The aging scheme for setting the age-limits for the layers.", new EnumValue<AgingScheme>(ALPS.AgingScheme.Polynomial)));
|
---|
[13127] | 293 | 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(20)));
|
---|
[12997] | 294 | Parameters.Add(new ValueParameter<DoubleValue>("AgeInheritance", "A weight that determines the age of a child after crossover based on the older (1.0) and younger (0.0) parent.", new DoubleValue(1.0)) { Hidden = true });
|
---|
[13206] | 295 | Parameters.Add(new ValueParameter<IntArray>("AgeLimits", "The maximum age an individual is allowed to reach in a certain layer.", new IntArray(new int[0])) { Hidden = true });
|
---|
[12993] | 296 |
|
---|
| 297 | Parameters.Add(new ValueParameter<IntValue>("MatingPoolRange", "The range of layers used for creating a mating pool. (1 = current + previous layer)", new IntValue(1)) { Hidden = true });
|
---|
[13127] | 298 | Parameters.Add(new ValueParameter<BoolValue>("ReduceToPopulationSize", "Reduce the CurrentPopulationSize after elder migration to PopulationSize", new BoolValue(true)) { Hidden = true });
|
---|
[12993] | 299 |
|
---|
[13127] | 300 | Parameters.Add(new ValueParameter<MultiTerminator>("Terminator", "The termination criteria that defines if the algorithm should continue or stop.", new MultiTerminator()));
|
---|
[12993] | 301 | #endregion
|
---|
| 302 |
|
---|
| 303 | #region Create operators
|
---|
[11578] | 304 | var globalRandomCreator = new RandomCreator();
|
---|
| 305 | var layer0Creator = new SubScopesCreator() { Name = "Create Layer Zero" };
|
---|
[13113] | 306 | var layer0Processor = new SubScopesProcessor();
|
---|
[11578] | 307 | var localRandomCreator = new LocalRandomCreator();
|
---|
| 308 | var layerSolutionsCreator = new SolutionsCreator();
|
---|
| 309 | var initializeAgeProcessor = new UniformSubScopesProcessor();
|
---|
| 310 | var initializeAge = new VariableCreator() { Name = "Initialize Age" };
|
---|
[13206] | 311 | var initializeCurrentPopulationSize = new SubScopesCounter() { Name = "Initialize CurrentPopulationCounter" };
|
---|
[11676] | 312 | var initializeLocalEvaluatedSolutions = new Assigner() { Name = "Initialize LayerEvaluatedSolutions" };
|
---|
[11578] | 313 | var initializeGlobalEvaluatedSolutions = new DataReducer() { Name = "Initialize EvaluatedSolutions" };
|
---|
| 314 | var resultsCollector = new ResultsCollector();
|
---|
[11580] | 315 | var mainLoop = new AlpsGeneticAlgorithmMainLoop();
|
---|
[12993] | 316 | #endregion
|
---|
[11580] | 317 |
|
---|
[12993] | 318 | #region Create and parameterize operator graph
|
---|
[11578] | 319 | OperatorGraph.InitialOperator = globalRandomCreator;
|
---|
| 320 |
|
---|
| 321 | globalRandomCreator.RandomParameter.ActualName = "GlobalRandom";
|
---|
| 322 | globalRandomCreator.SeedParameter.Value = null;
|
---|
[13128] | 323 | globalRandomCreator.SeedParameter.ActualName = SeedParameter.Name;
|
---|
[11578] | 324 | globalRandomCreator.SetSeedRandomlyParameter.Value = null;
|
---|
[13128] | 325 | globalRandomCreator.SetSeedRandomlyParameter.ActualName = SetSeedRandomlyParameter.Name;
|
---|
[11578] | 326 | globalRandomCreator.Successor = layer0Creator;
|
---|
| 327 |
|
---|
| 328 | layer0Creator.NumberOfSubScopesParameter.Value = new IntValue(1);
|
---|
| 329 | layer0Creator.Successor = layer0Processor;
|
---|
| 330 |
|
---|
[13113] | 331 | layer0Processor.Operators.Add(localRandomCreator);
|
---|
[11578] | 332 | layer0Processor.Successor = initializeGlobalEvaluatedSolutions;
|
---|
| 333 |
|
---|
[13127] | 334 | localRandomCreator.Successor = layerSolutionsCreator;
|
---|
[11578] | 335 |
|
---|
| 336 | layerSolutionsCreator.NumberOfSolutionsParameter.ActualName = PopulationSizeParameter.Name;
|
---|
| 337 | layerSolutionsCreator.Successor = initializeAgeProcessor;
|
---|
| 338 |
|
---|
| 339 | initializeAgeProcessor.Operator = initializeAge;
|
---|
[13127] | 340 | initializeAgeProcessor.Successor = initializeCurrentPopulationSize;
|
---|
[11578] | 341 |
|
---|
[13127] | 342 | initializeCurrentPopulationSize.ValueParameter.ActualName = "CurrentPopulationSize";
|
---|
| 343 | initializeCurrentPopulationSize.Successor = initializeLocalEvaluatedSolutions;
|
---|
[11676] | 344 |
|
---|
[13046] | 345 | initializeAge.CollectedValues.Add(new ValueParameter<DoubleValue>("Age", new DoubleValue(0)));
|
---|
[11578] | 346 | initializeAge.Successor = null;
|
---|
| 347 |
|
---|
[11676] | 348 | initializeLocalEvaluatedSolutions.LeftSideParameter.ActualName = "LayerEvaluatedSolutions";
|
---|
[13127] | 349 | initializeLocalEvaluatedSolutions.RightSideParameter.ActualName = "CurrentPopulationSize";
|
---|
[11578] | 350 | initializeLocalEvaluatedSolutions.Successor = null;
|
---|
| 351 |
|
---|
| 352 | initializeGlobalEvaluatedSolutions.ReductionOperation.Value.Value = ReductionOperations.Sum;
|
---|
| 353 | initializeGlobalEvaluatedSolutions.TargetOperation.Value.Value = ReductionOperations.Assign;
|
---|
[11590] | 354 | initializeGlobalEvaluatedSolutions.ParameterToReduce.ActualName = "LayerEvaluatedSolutions";
|
---|
[11578] | 355 | initializeGlobalEvaluatedSolutions.TargetParameter.ActualName = "EvaluatedSolutions";
|
---|
| 356 | initializeGlobalEvaluatedSolutions.Successor = resultsCollector;
|
---|
| 357 |
|
---|
[11609] | 358 | resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Evaluated Solutions", null, "EvaluatedSolutions"));
|
---|
[11578] | 359 | resultsCollector.Successor = mainLoop;
|
---|
[13124] | 360 |
|
---|
| 361 | mainLoop.GlobalRandomParameter.ActualName = "GlobalRandom";
|
---|
[13127] | 362 | mainLoop.LocalRandomParameter.ActualName = localRandomCreator.LocalRandomParameter.Name;
|
---|
[13124] | 363 | mainLoop.EvaluatedSolutionsParameter.ActualName = "EvaluatedSolutions";
|
---|
| 364 | mainLoop.AnalyzerParameter.ActualName = AnalyzerParameter.Name;
|
---|
| 365 | mainLoop.LayerAnalyzerParameter.ActualName = LayerAnalyzerParameter.Name;
|
---|
| 366 | mainLoop.NumberOfLayersParameter.ActualName = NumberOfLayersParameter.Name;
|
---|
| 367 | mainLoop.PopulationSizeParameter.ActualName = PopulationSizeParameter.Name;
|
---|
| 368 | mainLoop.CurrentPopulationSizeParameter.ActualName = "CurrentPopulationSize";
|
---|
| 369 | mainLoop.SelectorParameter.ActualName = SelectorParameter.Name;
|
---|
| 370 | mainLoop.CrossoverParameter.ActualName = CrossoverParameter.Name;
|
---|
| 371 | mainLoop.MutatorParameter.ActualName = MutatorParameter.Name;
|
---|
| 372 | mainLoop.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
|
---|
| 373 | mainLoop.ElitesParameter.ActualName = ElitesParameter.Name;
|
---|
| 374 | mainLoop.ReevaluateElitesParameter.ActualName = ReevaluateElitesParameter.Name;
|
---|
| 375 | mainLoop.PlusSelectionParameter.ActualName = PlusSelectionParameter.Name;
|
---|
| 376 | mainLoop.AgeParameter.ActualName = "Age";
|
---|
[13127] | 377 | mainLoop.AgeGapParameter.ActualName = AgeGapParameter.Name;
|
---|
[13124] | 378 | mainLoop.AgeInheritanceParameter.ActualName = AgeInheritanceParameter.Name;
|
---|
| 379 | mainLoop.AgeLimitsParameter.ActualName = AgeLimitsParameter.Name;
|
---|
| 380 | mainLoop.MatingPoolRangeParameter.ActualName = MatingPoolRangeParameter.Name;
|
---|
| 381 | mainLoop.ReduceToPopulationSizeParameter.ActualName = ReduceToPopulationSizeParameter.Name;
|
---|
[13127] | 382 | mainLoop.TerminatorParameter.ActualName = TerminatorParameter.Name;
|
---|
[12993] | 383 | #endregion
|
---|
[11578] | 384 |
|
---|
[12993] | 385 | #region Set selectors
|
---|
[11578] | 386 | foreach (var selector in ApplicationManager.Manager.GetInstances<ISelector>().Where(s => !(s is IMultiObjectiveSelector)).OrderBy(s => Name))
|
---|
| 387 | SelectorParameter.ValidValues.Add(selector);
|
---|
[12993] | 388 | var defaultSelector = SelectorParameter.ValidValues.OfType<GeneralizedRankSelector>().FirstOrDefault();
|
---|
| 389 | if (defaultSelector != null) {
|
---|
[13124] | 390 | defaultSelector.PressureParameter.Value = new DoubleValue(4.0);
|
---|
[12993] | 391 | SelectorParameter.Value = defaultSelector;
|
---|
[12119] | 392 | }
|
---|
[12993] | 393 | #endregion
|
---|
[11578] | 394 |
|
---|
[12993] | 395 | #region Create analyzers
|
---|
| 396 | qualityAnalyzer = new BestAverageWorstQualityAnalyzer();
|
---|
| 397 | layerQualityAnalyzer = new BestAverageWorstQualityAnalyzer();
|
---|
[12996] | 398 | ageAnalyzer = new OldestAverageYoungestAgeAnalyzer();
|
---|
| 399 | layerAgeAnalyzer = new OldestAverageYoungestAgeAnalyzer();
|
---|
| 400 | ageDistributionAnalyzer = new AgeDistributionAnalyzer();
|
---|
| 401 | layerAgeDistributionAnalyzer = new AgeDistributionAnalyzer();
|
---|
[12993] | 402 | #endregion
|
---|
| 403 |
|
---|
| 404 | #region Create terminators
|
---|
[12548] | 405 | generationsTerminator = new ComparisonTerminator<IntValue>("Generations", ComparisonType.Less, new IntValue(1000)) { Name = "Generations" };
|
---|
[12993] | 406 | evaluationsTerminator = new ComparisonTerminator<IntValue>("EvaluatedSolutions", ComparisonType.Less, new IntValue(int.MaxValue)) { Name = "Evaluations" };
|
---|
| 407 | qualityTerminator = new SingleObjectiveQualityTerminator() { Name = "Quality" };
|
---|
| 408 | executionTimeTerminator = new ExecutionTimeTerminator(this, new TimeSpanValue(TimeSpan.FromMinutes(5)));
|
---|
| 409 | #endregion
|
---|
[12548] | 410 |
|
---|
[12993] | 411 | #region Parameterize
|
---|
[12997] | 412 | UpdateAnalyzers();
|
---|
[12993] | 413 | ParameterizeAnalyzers();
|
---|
| 414 |
|
---|
[11578] | 415 | ParameterizeSelectors();
|
---|
[12548] | 416 |
|
---|
| 417 | UpdateTerminators();
|
---|
| 418 |
|
---|
[12993] | 419 | ParameterizeAgeLimits();
|
---|
| 420 | #endregion
|
---|
| 421 |
|
---|
[11578] | 422 | Initialize();
|
---|
[11567] | 423 | }
|
---|
[12996] | 424 | #endregion
|
---|
[11578] | 425 |
|
---|
| 426 | #region Events
|
---|
[12993] | 427 | public override void Prepare() {
|
---|
| 428 | if (Problem != null)
|
---|
| 429 | base.Prepare();
|
---|
| 430 | }
|
---|
[11578] | 431 | protected override void OnProblemChanged() {
|
---|
[12119] | 432 | base.OnProblemChanged();
|
---|
[12993] | 433 | ParameterizeStochasticOperator(Problem.SolutionCreator);
|
---|
| 434 | ParameterizeStochasticOperatorForLayer(Problem.Evaluator);
|
---|
| 435 | foreach (var @operator in Problem.Operators.OfType<IOperator>())
|
---|
| 436 | ParameterizeStochasticOperator(@operator);
|
---|
| 437 |
|
---|
| 438 | ParameterizeIterationBasedOperators();
|
---|
| 439 |
|
---|
[11578] | 440 | ParameterizeSolutionsCreator();
|
---|
| 441 | ParameterizeMainLoop();
|
---|
[12993] | 442 | ParameterizeAnalyzers();
|
---|
[11578] | 443 | ParameterizeSelectors();
|
---|
[12993] | 444 | ParameterizeTerminators();
|
---|
| 445 |
|
---|
| 446 | Problem.Evaluator.QualityParameter.ActualNameChanged += Evaluator_QualityParameter_ActualNameChanged;
|
---|
| 447 |
|
---|
| 448 | UpdateAnalyzers();
|
---|
[11578] | 449 | UpdateCrossovers();
|
---|
| 450 | UpdateMutators();
|
---|
[12548] | 451 | UpdateTerminators();
|
---|
[11578] | 452 | }
|
---|
[12993] | 453 |
|
---|
| 454 | protected override void RegisterProblemEvents() {
|
---|
| 455 | base.RegisterProblemEvents();
|
---|
| 456 | var maximizationParameter = (IValueParameter<BoolValue>)Problem.MaximizationParameter;
|
---|
| 457 | if (maximizationParameter != null) maximizationParameter.ValueChanged += new EventHandler(MaximizationParameter_ValueChanged);
|
---|
| 458 | }
|
---|
| 459 | protected override void DeregisterProblemEvents() {
|
---|
| 460 | var maximizationParameter = (IValueParameter<BoolValue>)Problem.MaximizationParameter;
|
---|
| 461 | if (maximizationParameter != null) maximizationParameter.ValueChanged -= new EventHandler(MaximizationParameter_ValueChanged);
|
---|
| 462 | base.DeregisterProblemEvents();
|
---|
| 463 | }
|
---|
| 464 |
|
---|
[11578] | 465 | protected override void Problem_SolutionCreatorChanged(object sender, EventArgs e) {
|
---|
[12119] | 466 | base.Problem_SolutionCreatorChanged(sender, e);
|
---|
[12993] | 467 | ParameterizeStochasticOperator(Problem.SolutionCreator);
|
---|
| 468 | ParameterizeStochasticOperatorForLayer(Problem.Evaluator);
|
---|
| 469 |
|
---|
| 470 | Problem.Evaluator.QualityParameter.ActualNameChanged += Evaluator_QualityParameter_ActualNameChanged;
|
---|
| 471 |
|
---|
[11578] | 472 | ParameterizeSolutionsCreator();
|
---|
[12993] | 473 | ParameterizeAnalyzers();
|
---|
[11578] | 474 | }
|
---|
| 475 | protected override void Problem_EvaluatorChanged(object sender, EventArgs e) {
|
---|
[12119] | 476 | base.Problem_EvaluatorChanged(sender, e);
|
---|
[14774] | 477 |
|
---|
| 478 | ParameterizeStochasticOperatorForLayer(Problem.Evaluator);
|
---|
| 479 |
|
---|
[12993] | 480 | foreach (var @operator in Problem.Operators.OfType<IOperator>())
|
---|
| 481 | ParameterizeStochasticOperator(@operator);
|
---|
| 482 |
|
---|
| 483 | UpdateAnalyzers();
|
---|
| 484 |
|
---|
[11578] | 485 | ParameterizeSolutionsCreator();
|
---|
| 486 | ParameterizeMainLoop();
|
---|
| 487 | ParameterizeSelectors();
|
---|
| 488 | }
|
---|
| 489 | protected override void Problem_OperatorsChanged(object sender, EventArgs e) {
|
---|
[12119] | 490 | base.Problem_OperatorsChanged(sender, e);
|
---|
[12120] | 491 | ParameterizeIterationBasedOperators();
|
---|
[11578] | 492 | UpdateCrossovers();
|
---|
| 493 | UpdateMutators();
|
---|
[12548] | 494 | UpdateTerminators();
|
---|
[11578] | 495 | }
|
---|
[12993] | 496 | private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
|
---|
[11578] | 497 | ParameterizeMainLoop();
|
---|
[12993] | 498 | ParameterizeAnalyzers();
|
---|
[11578] | 499 | ParameterizeSelectors();
|
---|
| 500 | }
|
---|
[12993] | 501 | private void MaximizationParameter_ValueChanged(object sender, EventArgs e) {
|
---|
| 502 | ParameterizeTerminators();
|
---|
| 503 | }
|
---|
| 504 | private void QualityAnalyzer_CurrentBestQualityParameter_NameChanged(object sender, EventArgs e) {
|
---|
| 505 | ParameterizeTerminators();
|
---|
| 506 | }
|
---|
| 507 |
|
---|
| 508 | private void AgeGapParameter_ValueChanged(object sender, EventArgs e) {
|
---|
| 509 | AgeGap.ValueChanged += AgeGap_ValueChanged;
|
---|
| 510 | ParameterizeAgeLimits();
|
---|
| 511 | }
|
---|
| 512 | private void AgeGap_ValueChanged(object sender, EventArgs e) {
|
---|
| 513 | ParameterizeAgeLimits();
|
---|
| 514 | }
|
---|
| 515 | private void AgingSchemeParameter_ValueChanged(object sender, EventArgs e) {
|
---|
| 516 | AgingScheme.ValueChanged += AgingScheme_ValueChanged;
|
---|
| 517 | ParameterizeAgeLimits();
|
---|
| 518 | }
|
---|
| 519 | private void AgingScheme_ValueChanged(object sender, EventArgs e) {
|
---|
| 520 | ParameterizeAgeLimits();
|
---|
| 521 | }
|
---|
| 522 | private void NumberOfLayersParameter_ValueChanged(object sender, EventArgs e) {
|
---|
| 523 | NumberOfLayers.ValueChanged += NumberOfLayers_ValueChanged;
|
---|
| 524 | ParameterizeAgeLimits();
|
---|
| 525 | }
|
---|
| 526 | private void NumberOfLayers_ValueChanged(object sender, EventArgs e) {
|
---|
| 527 | ParameterizeAgeLimits();
|
---|
| 528 | }
|
---|
| 529 |
|
---|
| 530 | private void AnalyzerOperators_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<IAnalyzer>> e) {
|
---|
| 531 | foreach (var analyzer in e.Items) {
|
---|
| 532 | foreach (var parameter in analyzer.Value.Parameters.OfType<IScopeTreeLookupParameter>()) {
|
---|
| 533 | parameter.Depth = 2;
|
---|
| 534 | }
|
---|
| 535 | }
|
---|
| 536 | }
|
---|
| 537 | private void LayerAnalyzerOperators_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<IAnalyzer>> e) {
|
---|
| 538 | foreach (var analyzer in e.Items) {
|
---|
| 539 | IParameter resultParameter;
|
---|
| 540 | if (analyzer.Value.Parameters.TryGetValue("Results", out resultParameter)) {
|
---|
| 541 | var lookupParameter = resultParameter as ILookupParameter;
|
---|
| 542 | if (lookupParameter != null)
|
---|
| 543 | lookupParameter.ActualName = "LayerResults";
|
---|
| 544 | }
|
---|
| 545 | foreach (var parameter in analyzer.Value.Parameters.OfType<IScopeTreeLookupParameter>()) {
|
---|
| 546 | parameter.Depth = 1;
|
---|
| 547 | }
|
---|
| 548 | }
|
---|
| 549 | }
|
---|
[11578] | 550 | #endregion
|
---|
| 551 |
|
---|
| 552 | #region Parameterization
|
---|
| 553 | private void Initialize() {
|
---|
[12993] | 554 | if (Problem != null)
|
---|
| 555 | Problem.Evaluator.QualityParameter.ActualNameChanged += Evaluator_QualityParameter_ActualNameChanged;
|
---|
| 556 |
|
---|
| 557 | NumberOfLayersParameter.ValueChanged += NumberOfLayersParameter_ValueChanged;
|
---|
| 558 | NumberOfLayers.ValueChanged += NumberOfLayers_ValueChanged;
|
---|
| 559 |
|
---|
| 560 | Analyzer.Operators.ItemsAdded += AnalyzerOperators_ItemsAdded;
|
---|
| 561 | LayerAnalyzer.Operators.ItemsAdded += LayerAnalyzerOperators_ItemsAdded;
|
---|
| 562 |
|
---|
| 563 | AgeGapParameter.ValueChanged += AgeGapParameter_ValueChanged;
|
---|
| 564 | AgeGap.ValueChanged += AgeGap_ValueChanged;
|
---|
| 565 | AgingSchemeParameter.ValueChanged += AgingSchemeParameter_ValueChanged;
|
---|
| 566 | AgingScheme.ValueChanged += AgingScheme_ValueChanged;
|
---|
| 567 |
|
---|
| 568 | qualityAnalyzer.CurrentBestQualityParameter.NameChanged += new EventHandler(QualityAnalyzer_CurrentBestQualityParameter_NameChanged);
|
---|
[11578] | 569 | }
|
---|
| 570 | private void ParameterizeSolutionsCreator() {
|
---|
[12993] | 571 | SolutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
|
---|
| 572 | SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name;
|
---|
[11578] | 573 | }
|
---|
| 574 | private void ParameterizeMainLoop() {
|
---|
[13124] | 575 | MainLoop.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
|
---|
| 576 | MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
[12045] | 577 | MainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
|
---|
[11578] | 578 | }
|
---|
[12993] | 579 | private void ParameterizeAnalyzers() {
|
---|
| 580 | qualityAnalyzer.ResultsParameter.ActualName = "Results";
|
---|
| 581 | qualityAnalyzer.ResultsParameter.Hidden = true;
|
---|
| 582 | qualityAnalyzer.QualityParameter.Depth = 2;
|
---|
[12996] | 583 | layerQualityAnalyzer.ResultsParameter.ActualName = "LayerResults";
|
---|
[12993] | 584 | layerQualityAnalyzer.ResultsParameter.Hidden = true;
|
---|
| 585 | layerQualityAnalyzer.QualityParameter.Depth = 1;
|
---|
| 586 | if (Problem != null) {
|
---|
| 587 | qualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
|
---|
| 588 | qualityAnalyzer.MaximizationParameter.Hidden = true;
|
---|
| 589 | qualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
| 590 | qualityAnalyzer.QualityParameter.Hidden = true;
|
---|
| 591 | qualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
|
---|
| 592 | qualityAnalyzer.BestKnownQualityParameter.Hidden = true;
|
---|
| 593 | layerQualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
|
---|
| 594 | layerQualityAnalyzer.MaximizationParameter.Hidden = true;
|
---|
| 595 | layerQualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
| 596 | layerQualityAnalyzer.QualityParameter.Hidden = true;
|
---|
| 597 | layerQualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
|
---|
| 598 | layerQualityAnalyzer.BestKnownQualityParameter.Hidden = true;
|
---|
| 599 | }
|
---|
| 600 | }
|
---|
[11578] | 601 | private void ParameterizeSelectors() {
|
---|
| 602 | foreach (var selector in SelectorParameter.ValidValues) {
|
---|
| 603 | selector.CopySelected = new BoolValue(true);
|
---|
| 604 | selector.NumberOfSelectedSubScopesParameter.Hidden = true;
|
---|
| 605 | ParameterizeStochasticOperatorForLayer(selector);
|
---|
| 606 | }
|
---|
| 607 | if (Problem != null) {
|
---|
| 608 | foreach (var selector in SelectorParameter.ValidValues.OfType<ISingleObjectiveSelector>()) {
|
---|
| 609 | selector.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
|
---|
| 610 | selector.MaximizationParameter.Hidden = true;
|
---|
| 611 | selector.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
| 612 | selector.QualityParameter.Hidden = true;
|
---|
| 613 | }
|
---|
| 614 | }
|
---|
| 615 | }
|
---|
[12993] | 616 | private void ParameterizeTerminators() {
|
---|
| 617 | qualityTerminator.Parameterize(qualityAnalyzer.CurrentBestQualityParameter, Problem);
|
---|
| 618 | }
|
---|
[12120] | 619 | private void ParameterizeIterationBasedOperators() {
|
---|
| 620 | if (Problem != null) {
|
---|
| 621 | foreach (var @operator in Problem.Operators.OfType<IIterationBasedOperator>()) {
|
---|
| 622 | @operator.IterationsParameter.ActualName = "Generations";
|
---|
| 623 | @operator.IterationsParameter.Hidden = true;
|
---|
[12531] | 624 | @operator.MaximumIterationsParameter.ActualName = generationsTerminator.ThresholdParameter.Name;
|
---|
[12120] | 625 | @operator.MaximumIterationsParameter.Hidden = true;
|
---|
| 626 | }
|
---|
| 627 | }
|
---|
| 628 | }
|
---|
[12993] | 629 | private void ParameterizeAgeLimits() {
|
---|
| 630 | var scheme = AgingScheme.Value;
|
---|
| 631 | int ageGap = AgeGap.Value;
|
---|
| 632 | int numberOfLayers = NumberOfLayers.Value;
|
---|
| 633 | AgeLimits = scheme.CalculateAgeLimits(ageGap, numberOfLayers);
|
---|
| 634 | }
|
---|
[12271] | 635 |
|
---|
[12993] | 636 | private void ParameterizeStochasticOperator(IOperator @operator) {
|
---|
| 637 | var stochasticOperator = @operator as IStochasticOperator;
|
---|
| 638 | if (stochasticOperator != null) {
|
---|
| 639 | stochasticOperator.RandomParameter.ActualName = "GlobalRandom";
|
---|
| 640 | stochasticOperator.RandomParameter.Hidden = true;
|
---|
| 641 | }
|
---|
| 642 | }
|
---|
| 643 |
|
---|
| 644 | private void ParameterizeStochasticOperatorForLayer(IOperator @operator) {
|
---|
| 645 | var stochasticOperator = @operator as IStochasticOperator;
|
---|
| 646 | if (stochasticOperator != null) {
|
---|
| 647 | stochasticOperator.RandomParameter.ActualName = "LocalRandom";
|
---|
| 648 | stochasticOperator.RandomParameter.Hidden = true;
|
---|
| 649 | }
|
---|
| 650 | }
|
---|
| 651 |
|
---|
[11578] | 652 | #endregion
|
---|
| 653 |
|
---|
| 654 | #region Updates
|
---|
[12993] | 655 | private void UpdateAnalyzers() {
|
---|
| 656 | Analyzer.Operators.Clear();
|
---|
| 657 | LayerAnalyzer.Operators.Clear();
|
---|
| 658 |
|
---|
| 659 | Analyzer.Operators.Add(qualityAnalyzer, qualityAnalyzer.EnabledByDefault);
|
---|
[12996] | 660 | Analyzer.Operators.Add(ageAnalyzer, ageAnalyzer.EnabledByDefault);
|
---|
| 661 | Analyzer.Operators.Add(ageDistributionAnalyzer, ageDistributionAnalyzer.EnabledByDefault);
|
---|
| 662 | LayerAnalyzer.Operators.Add(layerQualityAnalyzer, false);
|
---|
| 663 | LayerAnalyzer.Operators.Add(layerAgeAnalyzer, false);
|
---|
| 664 | LayerAnalyzer.Operators.Add(layerAgeDistributionAnalyzer, false);
|
---|
[12993] | 665 |
|
---|
[12548] | 666 | if (Problem != null) {
|
---|
[12993] | 667 | foreach (var analyzer in Problem.Operators.OfType<IAnalyzer>()) {
|
---|
| 668 | Analyzer.Operators.Add(analyzer, analyzer.EnabledByDefault);
|
---|
[12996] | 669 | LayerAnalyzer.Operators.Add((IAnalyzer)analyzer.Clone(), false);
|
---|
[12993] | 670 | }
|
---|
[12548] | 671 | }
|
---|
[12531] | 672 | }
|
---|
[11578] | 673 | private void UpdateCrossovers() {
|
---|
| 674 | var oldCrossover = CrossoverParameter.Value;
|
---|
| 675 | var defaultCrossover = Problem.Operators.OfType<ICrossover>().FirstOrDefault();
|
---|
| 676 | CrossoverParameter.ValidValues.Clear();
|
---|
| 677 | foreach (var crossover in Problem.Operators.OfType<ICrossover>().OrderBy(c => c.Name)) {
|
---|
| 678 | ParameterizeStochasticOperatorForLayer(crossover);
|
---|
| 679 | CrossoverParameter.ValidValues.Add(crossover);
|
---|
| 680 | }
|
---|
| 681 | if (oldCrossover != null) {
|
---|
| 682 | var crossover = CrossoverParameter.ValidValues.FirstOrDefault(c => c.GetType() == oldCrossover.GetType());
|
---|
[11678] | 683 | if (crossover != null)
|
---|
| 684 | CrossoverParameter.Value = crossover;
|
---|
| 685 | else
|
---|
| 686 | oldCrossover = null;
|
---|
[11578] | 687 | }
|
---|
| 688 | if (oldCrossover == null && defaultCrossover != null)
|
---|
| 689 | CrossoverParameter.Value = defaultCrossover;
|
---|
| 690 | }
|
---|
| 691 | private void UpdateMutators() {
|
---|
| 692 | var oldMutator = MutatorParameter.Value;
|
---|
| 693 | MutatorParameter.ValidValues.Clear();
|
---|
| 694 | foreach (var mutator in Problem.Operators.OfType<IManipulator>().OrderBy(m => m.Name)) {
|
---|
| 695 | ParameterizeStochasticOperatorForLayer(mutator);
|
---|
| 696 | MutatorParameter.ValidValues.Add(mutator);
|
---|
| 697 | }
|
---|
| 698 | if (oldMutator != null) {
|
---|
| 699 | var mutator = MutatorParameter.ValidValues.FirstOrDefault(m => m.GetType() == oldMutator.GetType());
|
---|
[11678] | 700 | if (mutator != null)
|
---|
| 701 | MutatorParameter.Value = mutator;
|
---|
[11578] | 702 | }
|
---|
| 703 | }
|
---|
[12993] | 704 | private void UpdateTerminators() {
|
---|
| 705 | var newTerminators = new Dictionary<ITerminator, bool> {
|
---|
| 706 | {generationsTerminator, !Terminators.Operators.Contains(generationsTerminator) || Terminators.Operators.ItemChecked(generationsTerminator)},
|
---|
| 707 | {evaluationsTerminator, Terminators.Operators.Contains(evaluationsTerminator) && Terminators.Operators.ItemChecked(evaluationsTerminator)},
|
---|
| 708 | {qualityTerminator, Terminators.Operators.Contains(qualityTerminator) && Terminators.Operators.ItemChecked(qualityTerminator) },
|
---|
| 709 | {executionTimeTerminator, Terminators.Operators.Contains(executionTimeTerminator) && Terminators.Operators.ItemChecked(executionTimeTerminator)}
|
---|
| 710 | };
|
---|
| 711 | if (Problem != null) {
|
---|
| 712 | foreach (var terminator in Problem.Operators.OfType<ITerminator>())
|
---|
| 713 | newTerminators.Add(terminator, !Terminators.Operators.Contains(terminator) || Terminators.Operators.ItemChecked(terminator));
|
---|
| 714 | }
|
---|
| 715 |
|
---|
| 716 | Terminators.Operators.Clear();
|
---|
| 717 |
|
---|
| 718 | foreach (var newTerminator in newTerminators)
|
---|
| 719 | Terminators.Operators.Add(newTerminator.Key, newTerminator.Value);
|
---|
| 720 | }
|
---|
[11578] | 721 | #endregion
|
---|
[11567] | 722 | }
|
---|
| 723 | } |
---|