[11567] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[17181] | 3 | * Copyright (C) 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;
|
---|
[17111] | 25 | using HEAL.Attic;
|
---|
[12993] | 26 | using HeuristicLab.Analysis;
|
---|
| 27 | using HeuristicLab.Collections;
|
---|
[11567] | 28 | using HeuristicLab.Common;
|
---|
| 29 | using HeuristicLab.Core;
|
---|
[11568] | 30 | using HeuristicLab.Data;
|
---|
| 31 | using HeuristicLab.Operators;
|
---|
[11567] | 32 | using HeuristicLab.Optimization;
|
---|
[11578] | 33 | using HeuristicLab.Optimization.Operators;
|
---|
[11568] | 34 | using HeuristicLab.Parameters;
|
---|
[11578] | 35 | using HeuristicLab.PluginInfrastructure;
|
---|
| 36 | using HeuristicLab.Random;
|
---|
| 37 | using HeuristicLab.Selection;
|
---|
[11567] | 38 |
|
---|
| 39 | namespace HeuristicLab.Algorithms.ALPS {
|
---|
[13402] | 40 | [Item("ALPS OffspringSelection Genetic Algorithm", "An offspring selection genetic algorithm within an age-layered population structure.")]
|
---|
| 41 | [Creatable(CreatableAttribute.Categories.PopulationBasedAlgorithms, Priority = 162)]
|
---|
[17097] | 42 | [StorableType("4CA6AFE2-8EE9-4724-AA5C-624C734703FD")]
|
---|
[13402] | 43 | public sealed class AlpsOffspringSelectionGeneticAlgorithm : HeuristicOptimizationEngineAlgorithm, IStorableContent {
|
---|
[12993] | 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
|
---|
[13402] | 57 | private IFixedValueParameter<IntValue> SeedParameter {
|
---|
| 58 | get { return (IFixedValueParameter<IntValue>)Parameters["Seed"]; }
|
---|
[12993] | 59 | }
|
---|
[13402] | 60 | private IFixedValueParameter<BoolValue> SetSeedRandomlyParameter {
|
---|
| 61 | get { return (IFixedValueParameter<BoolValue>)Parameters["SetSeedRandomly"]; }
|
---|
[12993] | 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 |
|
---|
[13402] | 71 | private IFixedValueParameter<IntValue> NumberOfLayersParameter {
|
---|
| 72 | get { return (IFixedValueParameter<IntValue>)Parameters["NumberOfLayers"]; }
|
---|
[12993] | 73 | }
|
---|
[13402] | 74 | private IFixedValueParameter<IntValue> PopulationSizeParameter {
|
---|
| 75 | get { return (IFixedValueParameter<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 | }
|
---|
[13402] | 87 | private IFixedValueParameter<PercentValue> MutationProbabilityParameter {
|
---|
| 88 | get { return (IFixedValueParameter<PercentValue>)Parameters["MutationProbability"]; }
|
---|
[11568] | 89 | }
|
---|
[13402] | 90 | private IFixedValueParameter<IntValue> ElitesParameter {
|
---|
| 91 | get { return (IFixedValueParameter<IntValue>)Parameters["Elites"]; }
|
---|
[11568] | 92 | }
|
---|
| 93 | private IFixedValueParameter<BoolValue> ReevaluateElitesParameter {
|
---|
| 94 | get { return (IFixedValueParameter<BoolValue>)Parameters["ReevaluateElites"]; }
|
---|
| 95 | }
|
---|
[13402] | 96 |
|
---|
| 97 | private IFixedValueParameter<DoubleValue> SuccessRatioParameter {
|
---|
| 98 | get { return (IFixedValueParameter<DoubleValue>)Parameters["SuccessRatio"]; }
|
---|
[12186] | 99 | }
|
---|
[13402] | 100 | private IFixedValueParameter<DoubleValue> ComparisonFactorParameter {
|
---|
| 101 | get { return (IFixedValueParameter<DoubleValue>)Parameters["ComparisonFactor"]; }
|
---|
| 102 | }
|
---|
| 103 | private IFixedValueParameter<DoubleValue> MaximumSelectionPressureParameter {
|
---|
| 104 | get { return (IFixedValueParameter<DoubleValue>)Parameters["MaximumSelectionPressure"]; }
|
---|
| 105 | }
|
---|
| 106 | private IFixedValueParameter<BoolValue> OffspringSelectionBeforeMutationParameter {
|
---|
| 107 | get { return (IFixedValueParameter<BoolValue>)Parameters["OffspringSelectionBeforeMutation"]; }
|
---|
| 108 | }
|
---|
| 109 | private IFixedValueParameter<IntValue> SelectedParentsParameter {
|
---|
| 110 | get { return (IFixedValueParameter<IntValue>)Parameters["SelectedParents"]; }
|
---|
| 111 | }
|
---|
| 112 | private IFixedValueParameter<BoolValue> FillPopulationWithParentsParameter {
|
---|
| 113 | get { return (IFixedValueParameter<BoolValue>)Parameters["FillPopulationWithParents"]; }
|
---|
| 114 | }
|
---|
[12993] | 115 |
|
---|
[13402] | 116 | private IFixedValueParameter<EnumValue<AgingScheme>> AgingSchemeParameter {
|
---|
| 117 | get { return (IFixedValueParameter<EnumValue<AgingScheme>>)Parameters["AgingScheme"]; }
|
---|
[12993] | 118 | }
|
---|
[13402] | 119 | private IFixedValueParameter<IntValue> AgeGapParameter {
|
---|
| 120 | get { return (IFixedValueParameter<IntValue>)Parameters["AgeGap"]; }
|
---|
[12993] | 121 | }
|
---|
[13402] | 122 | private IFixedValueParameter<DoubleValue> AgeInheritanceParameter {
|
---|
| 123 | get { return (IFixedValueParameter<DoubleValue>)Parameters["AgeInheritance"]; }
|
---|
[12993] | 124 | }
|
---|
[13402] | 125 | private IFixedValueParameter<IntArray> AgeLimitsParameter {
|
---|
| 126 | get { return (IFixedValueParameter<IntArray>)Parameters["AgeLimits"]; }
|
---|
[12993] | 127 | }
|
---|
| 128 |
|
---|
[13402] | 129 | private IFixedValueParameter<IntValue> MatingPoolRangeParameter {
|
---|
| 130 | get { return (IFixedValueParameter<IntValue>)Parameters["MatingPoolRange"]; }
|
---|
[12993] | 131 | }
|
---|
[13402] | 132 | private IFixedValueParameter<BoolValue> ReduceToPopulationSizeParameter {
|
---|
| 133 | get { return (IFixedValueParameter<BoolValue>)Parameters["ReduceToPopulationSize"]; }
|
---|
[13124] | 134 | }
|
---|
[12993] | 135 |
|
---|
[13402] | 136 | private IFixedValueParameter<MultiTerminator> TerminatorParameter {
|
---|
| 137 | get { return (IFixedValueParameter<MultiTerminator>)Parameters["Terminator"]; }
|
---|
[12993] | 138 | }
|
---|
[11567] | 139 | #endregion
|
---|
| 140 |
|
---|
| 141 | #region Properties
|
---|
[13402] | 142 | public int Seed {
|
---|
| 143 | get { return SeedParameter.Value.Value; }
|
---|
| 144 | set { SeedParameter.Value.Value = value; }
|
---|
[12993] | 145 | }
|
---|
[13402] | 146 | public bool SetSeedRandomly {
|
---|
| 147 | get { return SetSeedRandomlyParameter.Value.Value; }
|
---|
| 148 | set { SetSeedRandomlyParameter.Value.Value = value; }
|
---|
[12993] | 149 | }
|
---|
| 150 |
|
---|
| 151 | public MultiAnalyzer Analyzer {
|
---|
| 152 | get { return AnalyzerParameter.Value; }
|
---|
| 153 | }
|
---|
| 154 | public MultiAnalyzer LayerAnalyzer {
|
---|
| 155 | get { return LayerAnalyzerParameter.Value; }
|
---|
| 156 | }
|
---|
| 157 |
|
---|
[13402] | 158 | public int NumberOfLayers {
|
---|
| 159 | get { return NumberOfLayersParameter.Value.Value; }
|
---|
| 160 | set { NumberOfLayersParameter.Value.Value = value; }
|
---|
[12993] | 161 | }
|
---|
[13402] | 162 | public int PopulationSize {
|
---|
| 163 | get { return PopulationSizeParameter.Value.Value; }
|
---|
| 164 | set { PopulationSizeParameter.Value.Value = value; }
|
---|
[11568] | 165 | }
|
---|
[12993] | 166 |
|
---|
[11568] | 167 | public ISelector Selector {
|
---|
| 168 | get { return SelectorParameter.Value; }
|
---|
| 169 | set { SelectorParameter.Value = value; }
|
---|
| 170 | }
|
---|
| 171 | public ICrossover Crossover {
|
---|
| 172 | get { return CrossoverParameter.Value; }
|
---|
| 173 | set { CrossoverParameter.Value = value; }
|
---|
| 174 | }
|
---|
[12993] | 175 | public IManipulator Mutator {
|
---|
| 176 | get { return MutatorParameter.Value; }
|
---|
| 177 | set { MutatorParameter.Value = value; }
|
---|
| 178 | }
|
---|
[13402] | 179 | public double MutationProbability {
|
---|
| 180 | get { return MutationProbabilityParameter.Value.Value; }
|
---|
| 181 | set { MutationProbabilityParameter.Value.Value = value; }
|
---|
[11568] | 182 | }
|
---|
[13402] | 183 | public int Elites {
|
---|
| 184 | get { return ElitesParameter.Value.Value; }
|
---|
| 185 | set { ElitesParameter.Value.Value = value; }
|
---|
[11568] | 186 | }
|
---|
| 187 | public bool ReevaluteElites {
|
---|
| 188 | get { return ReevaluateElitesParameter.Value.Value; }
|
---|
| 189 | set { ReevaluateElitesParameter.Value.Value = value; }
|
---|
| 190 | }
|
---|
[13402] | 191 |
|
---|
| 192 | public double SuccessRatio {
|
---|
| 193 | get { return SuccessRatioParameter.Value.Value; }
|
---|
| 194 | set { SuccessRatioParameter.Value.Value = value; }
|
---|
[12186] | 195 | }
|
---|
[13402] | 196 | public double ComparisonFactor {
|
---|
| 197 | get { return ComparisonFactorParameter.Value.Value; }
|
---|
| 198 | set { ComparisonFactorParameter.Value.Value = value; }
|
---|
| 199 | }
|
---|
| 200 | public double MaximumSelectionPressure {
|
---|
| 201 | get { return MaximumSelectionPressureParameter.Value.Value; }
|
---|
| 202 | set { MaximumSelectionPressureParameter.Value.Value = value; }
|
---|
| 203 | }
|
---|
| 204 | public bool OffspringSelectionBeforeMutation {
|
---|
| 205 | get { return OffspringSelectionBeforeMutationParameter.Value.Value; }
|
---|
| 206 | set { OffspringSelectionBeforeMutationParameter.Value.Value = value; }
|
---|
| 207 | }
|
---|
| 208 | public int SelectedParents {
|
---|
| 209 | get { return SelectedParentsParameter.Value.Value; }
|
---|
| 210 | set { SelectedParentsParameter.Value.Value = value; }
|
---|
| 211 | }
|
---|
| 212 | public bool FillPopulationWithParents {
|
---|
| 213 | get { return FillPopulationWithParentsParameter.Value.Value; }
|
---|
| 214 | set { FillPopulationWithParentsParameter.Value.Value = value; }
|
---|
| 215 | }
|
---|
[11578] | 216 |
|
---|
[13402] | 217 | public AgingScheme AgingScheme {
|
---|
| 218 | get { return AgingSchemeParameter.Value.Value; }
|
---|
| 219 | set { AgingSchemeParameter.Value.Value = value; }
|
---|
[12993] | 220 | }
|
---|
[13402] | 221 | public int AgeGap {
|
---|
| 222 | get { return AgeGapParameter.Value.Value; }
|
---|
| 223 | set { AgeGapParameter.Value.Value = value; }
|
---|
[12993] | 224 | }
|
---|
[13402] | 225 | public double AgeInheritance {
|
---|
| 226 | get { return AgeInheritanceParameter.Value.Value; }
|
---|
| 227 | set { AgeInheritanceParameter.Value.Value = value; }
|
---|
[12993] | 228 | }
|
---|
| 229 | public IntArray AgeLimits {
|
---|
| 230 | get { return AgeLimitsParameter.Value; }
|
---|
[13402] | 231 | set {
|
---|
| 232 | AgeLimits.Length = value.Length;
|
---|
| 233 | for (int i = 0; i < value.Length; i++)
|
---|
| 234 | AgeLimits[i] = value[i];
|
---|
| 235 | }
|
---|
[12993] | 236 | }
|
---|
| 237 |
|
---|
[13402] | 238 | public int MatingPoolRange {
|
---|
| 239 | get { return MatingPoolRangeParameter.Value.Value; }
|
---|
| 240 | set { MatingPoolRangeParameter.Value.Value = value; }
|
---|
[12993] | 241 | }
|
---|
| 242 |
|
---|
| 243 | public MultiTerminator Terminators {
|
---|
| 244 | get { return TerminatorParameter.Value; }
|
---|
| 245 | }
|
---|
| 246 |
|
---|
| 247 | public int MaximumGenerations {
|
---|
| 248 | get { return generationsTerminator.Threshold.Value; }
|
---|
| 249 | set { generationsTerminator.Threshold.Value = value; }
|
---|
| 250 | }
|
---|
| 251 | #endregion
|
---|
| 252 |
|
---|
| 253 | #region Helper Properties
|
---|
| 254 | private SolutionsCreator SolutionsCreator {
|
---|
| 255 | get { return OperatorGraph.Iterate().OfType<SolutionsCreator>().First(); }
|
---|
| 256 | }
|
---|
[13402] | 257 | private AlpsOffspringSelectionGeneticAlgorithmMainLoop MainLoop {
|
---|
| 258 | get { return OperatorGraph.Iterate().OfType<AlpsOffspringSelectionGeneticAlgorithmMainLoop>().First(); }
|
---|
[11580] | 259 | }
|
---|
[11676] | 260 | #endregion
|
---|
| 261 |
|
---|
[12993] | 262 | #region Preconfigured Analyzers
|
---|
[12531] | 263 | [Storable]
|
---|
[12993] | 264 | private BestAverageWorstQualityAnalyzer qualityAnalyzer;
|
---|
| 265 | [Storable]
|
---|
| 266 | private BestAverageWorstQualityAnalyzer layerQualityAnalyzer;
|
---|
[12996] | 267 | [Storable]
|
---|
| 268 | private OldestAverageYoungestAgeAnalyzer ageAnalyzer;
|
---|
| 269 | [Storable]
|
---|
| 270 | private OldestAverageYoungestAgeAnalyzer layerAgeAnalyzer;
|
---|
| 271 | [Storable]
|
---|
| 272 | private AgeDistributionAnalyzer ageDistributionAnalyzer;
|
---|
| 273 | [Storable]
|
---|
| 274 | private AgeDistributionAnalyzer layerAgeDistributionAnalyzer;
|
---|
[13402] | 275 | [Storable]
|
---|
| 276 | private ValueAnalyzer selectionPressureAnalyzer;
|
---|
| 277 | [Storable]
|
---|
| 278 | private ValueAnalyzer layerSelectionPressureAnalyzer;
|
---|
| 279 | [Storable]
|
---|
| 280 | private ValueAnalyzer currentSuccessRatioAnalyzer;
|
---|
[12993] | 281 | #endregion
|
---|
| 282 |
|
---|
| 283 | #region Preconfigured Terminators
|
---|
| 284 | [Storable]
|
---|
[12531] | 285 | private ComparisonTerminator<IntValue> generationsTerminator;
|
---|
[12993] | 286 | [Storable]
|
---|
| 287 | private ComparisonTerminator<IntValue> evaluationsTerminator;
|
---|
| 288 | [Storable]
|
---|
| 289 | private SingleObjectiveQualityTerminator qualityTerminator;
|
---|
| 290 | [Storable]
|
---|
| 291 | private ExecutionTimeTerminator executionTimeTerminator;
|
---|
| 292 | #endregion
|
---|
[12531] | 293 |
|
---|
[12996] | 294 | #region Constructors
|
---|
[11567] | 295 | [StorableConstructor]
|
---|
[17097] | 296 | private AlpsOffspringSelectionGeneticAlgorithm(StorableConstructorFlag _) : base(_) { }
|
---|
[12570] | 297 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 298 | private void AfterDeserialization() {
|
---|
[15238] | 299 | // BackwardsCompatibility3.3
|
---|
| 300 | #region Backwards compatible code, remove with 3.4
|
---|
| 301 | var optionalMutatorParameter = MutatorParameter as OptionalConstrainedValueParameter<IManipulator>;
|
---|
[17352] | 302 | var mutatorParameter = MutatorParameter as ConstrainedValueParameter<IManipulator>;
|
---|
| 303 | if (mutatorParameter == null && optionalMutatorParameter != null) {
|
---|
[15238] | 304 | Parameters.Remove(optionalMutatorParameter);
|
---|
| 305 | Parameters.Add(new ConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions."));
|
---|
| 306 | foreach (var m in optionalMutatorParameter.ValidValues)
|
---|
| 307 | MutatorParameter.ValidValues.Add(m);
|
---|
| 308 | if (optionalMutatorParameter.Value == null) MutationProbability = 0; // to guarantee that the old configuration results in the same behavior
|
---|
| 309 | else Mutator = optionalMutatorParameter.Value;
|
---|
| 310 | optionalMutatorParameter.ValidValues.Clear(); // to avoid dangling references to the old parameter its valid values are cleared
|
---|
| 311 | }
|
---|
| 312 | #endregion
|
---|
[12570] | 313 | Initialize();
|
---|
| 314 | }
|
---|
[13402] | 315 | private AlpsOffspringSelectionGeneticAlgorithm(AlpsOffspringSelectionGeneticAlgorithm original, Cloner cloner)
|
---|
[11567] | 316 | : base(original, cloner) {
|
---|
[12993] | 317 | qualityAnalyzer = cloner.Clone(original.qualityAnalyzer);
|
---|
| 318 | layerQualityAnalyzer = cloner.Clone(original.layerQualityAnalyzer);
|
---|
[12996] | 319 | ageAnalyzer = cloner.Clone(original.ageAnalyzer);
|
---|
| 320 | layerAgeAnalyzer = cloner.Clone(original.layerAgeAnalyzer);
|
---|
| 321 | ageDistributionAnalyzer = cloner.Clone(original.ageDistributionAnalyzer);
|
---|
| 322 | layerAgeDistributionAnalyzer = cloner.Clone(original.layerAgeDistributionAnalyzer);
|
---|
[13402] | 323 | selectionPressureAnalyzer = cloner.Clone(original.selectionPressureAnalyzer);
|
---|
| 324 | layerSelectionPressureAnalyzer = cloner.Clone(original.layerSelectionPressureAnalyzer);
|
---|
| 325 | currentSuccessRatioAnalyzer = cloner.Clone(original.currentSuccessRatioAnalyzer);
|
---|
[12531] | 326 | generationsTerminator = cloner.Clone(original.generationsTerminator);
|
---|
[12993] | 327 | evaluationsTerminator = cloner.Clone(original.evaluationsTerminator);
|
---|
| 328 | qualityTerminator = cloner.Clone(original.qualityTerminator);
|
---|
| 329 | executionTimeTerminator = cloner.Clone(original.executionTimeTerminator);
|
---|
[11578] | 330 | Initialize();
|
---|
[11567] | 331 | }
|
---|
| 332 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
[13402] | 333 | return new AlpsOffspringSelectionGeneticAlgorithm(this, cloner);
|
---|
[11567] | 334 | }
|
---|
[13402] | 335 | public AlpsOffspringSelectionGeneticAlgorithm()
|
---|
[11567] | 336 | : base() {
|
---|
[12993] | 337 | #region Add parameters
|
---|
[13402] | 338 | Parameters.Add(new FixedValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
|
---|
| 339 | Parameters.Add(new FixedValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
|
---|
[12993] | 340 |
|
---|
[13128] | 341 | Parameters.Add(new FixedValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze all individuals from all layers combined.", new MultiAnalyzer()));
|
---|
[12993] | 342 | Parameters.Add(new FixedValueParameter<MultiAnalyzer>("LayerAnalyzer", "The operator used to analyze each layer.", new MultiAnalyzer()));
|
---|
| 343 |
|
---|
[13402] | 344 | Parameters.Add(new FixedValueParameter<IntValue>("NumberOfLayers", "The number of layers.", new IntValue(10)));
|
---|
| 345 | Parameters.Add(new FixedValueParameter<IntValue>("PopulationSize", "The size of the population of solutions in each layer.", new IntValue(100)));
|
---|
[12993] | 346 |
|
---|
[11568] | 347 | Parameters.Add(new ConstrainedValueParameter<ISelector>("Selector", "The operator used to select solutions for reproduction."));
|
---|
| 348 | Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions."));
|
---|
[15238] | 349 | Parameters.Add(new ConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions."));
|
---|
[13402] | 350 | Parameters.Add(new FixedValueParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution.", new PercentValue(0.05)));
|
---|
| 351 | Parameters.Add(new FixedValueParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.", new IntValue(1)));
|
---|
[11568] | 352 | 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 });
|
---|
[11578] | 353 |
|
---|
[13402] | 354 | Parameters.Add(new FixedValueParameter<DoubleValue>("SuccessRatio", "The ratio of successful to total children that should be achieved.", new DoubleValue(1)));
|
---|
| 355 | Parameters.Add(new FixedValueParameter<DoubleValue>("ComparisonFactor", "The comparison factor is used to determine whether the offspring should be compared to the better parent, the worse parent or a quality value linearly interpolated between them. It is in the range [0;1].", new DoubleValue(1)));
|
---|
| 356 | Parameters.Add(new FixedValueParameter<DoubleValue>("MaximumSelectionPressure", "The maximum selection pressure that terminates the algorithm.", new DoubleValue(100)));
|
---|
| 357 | Parameters.Add(new FixedValueParameter<BoolValue>("OffspringSelectionBeforeMutation", "True if the offspring selection step should be applied before mutation, false if it should be applied after mutation.", new BoolValue(false)));
|
---|
| 358 | Parameters.Add(new FixedValueParameter<IntValue>("SelectedParents", "How much parents should be selected each time the offspring selection step is performed until the population is filled. This parameter should be about the same or twice the size of PopulationSize for smaller problems, and less for large problems.", new IntValue(200)));
|
---|
| 359 | Parameters.Add(new FixedValueParameter<BoolValue>("FillPopulationWithParents", "True if the population should be filled with parent individual or false if worse children should be used when the maximum selection pressure is exceeded.", new BoolValue(false)) { Hidden = true });
|
---|
[12993] | 360 |
|
---|
[13402] | 361 | Parameters.Add(new FixedValueParameter<EnumValue<AgingScheme>>("AgingScheme", "The aging scheme for setting the age-limits for the layers.", new EnumValue<AgingScheme>(ALPS.AgingScheme.Polynomial)));
|
---|
| 362 | Parameters.Add(new FixedValueParameter<IntValue>("AgeGap", "The frequency of reseeding the lowest layer and scaling factor for the age-limits for the layers.", new IntValue(20)));
|
---|
| 363 | Parameters.Add(new FixedValueParameter<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 });
|
---|
| 364 | Parameters.Add(new FixedValueParameter<IntArray>("AgeLimits", "The maximum age an individual is allowed to reach in a certain layer.", new IntArray(new int[0])) { Hidden = true });
|
---|
[12993] | 365 |
|
---|
[13402] | 366 | Parameters.Add(new FixedValueParameter<IntValue>("MatingPoolRange", "The range of layers used for creating a mating pool. (1 = current + previous layer)", new IntValue(1)) { Hidden = true });
|
---|
| 367 | Parameters.Add(new FixedValueParameter<BoolValue>("ReduceToPopulationSize", "Reduce the CurrentPopulationSize after elder migration to PopulationSize", new BoolValue(true)) { Hidden = true });
|
---|
| 368 |
|
---|
| 369 | Parameters.Add(new FixedValueParameter<MultiTerminator>("Terminator", "The termination criteria that defines if the algorithm should continue or stop.", new MultiTerminator()));
|
---|
[12993] | 370 | #endregion
|
---|
| 371 |
|
---|
| 372 | #region Create operators
|
---|
[11578] | 373 | var globalRandomCreator = new RandomCreator();
|
---|
| 374 | var layer0Creator = new SubScopesCreator() { Name = "Create Layer Zero" };
|
---|
[13113] | 375 | var layer0Processor = new SubScopesProcessor();
|
---|
[11578] | 376 | var localRandomCreator = new LocalRandomCreator();
|
---|
| 377 | var layerSolutionsCreator = new SolutionsCreator();
|
---|
| 378 | var initializeAgeProcessor = new UniformSubScopesProcessor();
|
---|
| 379 | var initializeAge = new VariableCreator() { Name = "Initialize Age" };
|
---|
[13206] | 380 | var initializeCurrentPopulationSize = new SubScopesCounter() { Name = "Initialize CurrentPopulationCounter" };
|
---|
[11676] | 381 | var initializeLocalEvaluatedSolutions = new Assigner() { Name = "Initialize LayerEvaluatedSolutions" };
|
---|
[11578] | 382 | var initializeGlobalEvaluatedSolutions = new DataReducer() { Name = "Initialize EvaluatedSolutions" };
|
---|
| 383 | var resultsCollector = new ResultsCollector();
|
---|
[13402] | 384 | var mainLoop = new AlpsOffspringSelectionGeneticAlgorithmMainLoop();
|
---|
[12993] | 385 | #endregion
|
---|
[11580] | 386 |
|
---|
[12993] | 387 | #region Create and parameterize operator graph
|
---|
[11578] | 388 | OperatorGraph.InitialOperator = globalRandomCreator;
|
---|
| 389 |
|
---|
| 390 | globalRandomCreator.RandomParameter.ActualName = "GlobalRandom";
|
---|
| 391 | globalRandomCreator.SeedParameter.Value = null;
|
---|
[13128] | 392 | globalRandomCreator.SeedParameter.ActualName = SeedParameter.Name;
|
---|
[11578] | 393 | globalRandomCreator.SetSeedRandomlyParameter.Value = null;
|
---|
[13128] | 394 | globalRandomCreator.SetSeedRandomlyParameter.ActualName = SetSeedRandomlyParameter.Name;
|
---|
[11578] | 395 | globalRandomCreator.Successor = layer0Creator;
|
---|
| 396 |
|
---|
| 397 | layer0Creator.NumberOfSubScopesParameter.Value = new IntValue(1);
|
---|
| 398 | layer0Creator.Successor = layer0Processor;
|
---|
| 399 |
|
---|
[13113] | 400 | layer0Processor.Operators.Add(localRandomCreator);
|
---|
[11578] | 401 | layer0Processor.Successor = initializeGlobalEvaluatedSolutions;
|
---|
| 402 |
|
---|
[13127] | 403 | localRandomCreator.Successor = layerSolutionsCreator;
|
---|
[11578] | 404 |
|
---|
| 405 | layerSolutionsCreator.NumberOfSolutionsParameter.ActualName = PopulationSizeParameter.Name;
|
---|
| 406 | layerSolutionsCreator.Successor = initializeAgeProcessor;
|
---|
| 407 |
|
---|
| 408 | initializeAgeProcessor.Operator = initializeAge;
|
---|
[13127] | 409 | initializeAgeProcessor.Successor = initializeCurrentPopulationSize;
|
---|
[11578] | 410 |
|
---|
[13127] | 411 | initializeCurrentPopulationSize.ValueParameter.ActualName = "CurrentPopulationSize";
|
---|
| 412 | initializeCurrentPopulationSize.Successor = initializeLocalEvaluatedSolutions;
|
---|
[11676] | 413 |
|
---|
[13046] | 414 | initializeAge.CollectedValues.Add(new ValueParameter<DoubleValue>("Age", new DoubleValue(0)));
|
---|
[11578] | 415 | initializeAge.Successor = null;
|
---|
| 416 |
|
---|
[11676] | 417 | initializeLocalEvaluatedSolutions.LeftSideParameter.ActualName = "LayerEvaluatedSolutions";
|
---|
[13127] | 418 | initializeLocalEvaluatedSolutions.RightSideParameter.ActualName = "CurrentPopulationSize";
|
---|
[11578] | 419 | initializeLocalEvaluatedSolutions.Successor = null;
|
---|
| 420 |
|
---|
| 421 | initializeGlobalEvaluatedSolutions.ReductionOperation.Value.Value = ReductionOperations.Sum;
|
---|
| 422 | initializeGlobalEvaluatedSolutions.TargetOperation.Value.Value = ReductionOperations.Assign;
|
---|
[11590] | 423 | initializeGlobalEvaluatedSolutions.ParameterToReduce.ActualName = "LayerEvaluatedSolutions";
|
---|
[11578] | 424 | initializeGlobalEvaluatedSolutions.TargetParameter.ActualName = "EvaluatedSolutions";
|
---|
| 425 | initializeGlobalEvaluatedSolutions.Successor = resultsCollector;
|
---|
| 426 |
|
---|
[11609] | 427 | resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Evaluated Solutions", null, "EvaluatedSolutions"));
|
---|
[11578] | 428 | resultsCollector.Successor = mainLoop;
|
---|
[13124] | 429 |
|
---|
| 430 | mainLoop.GlobalRandomParameter.ActualName = "GlobalRandom";
|
---|
[13127] | 431 | mainLoop.LocalRandomParameter.ActualName = localRandomCreator.LocalRandomParameter.Name;
|
---|
[13124] | 432 | mainLoop.EvaluatedSolutionsParameter.ActualName = "EvaluatedSolutions";
|
---|
| 433 | mainLoop.AnalyzerParameter.ActualName = AnalyzerParameter.Name;
|
---|
| 434 | mainLoop.LayerAnalyzerParameter.ActualName = LayerAnalyzerParameter.Name;
|
---|
| 435 | mainLoop.NumberOfLayersParameter.ActualName = NumberOfLayersParameter.Name;
|
---|
| 436 | mainLoop.PopulationSizeParameter.ActualName = PopulationSizeParameter.Name;
|
---|
| 437 | mainLoop.CurrentPopulationSizeParameter.ActualName = "CurrentPopulationSize";
|
---|
| 438 | mainLoop.SelectorParameter.ActualName = SelectorParameter.Name;
|
---|
| 439 | mainLoop.CrossoverParameter.ActualName = CrossoverParameter.Name;
|
---|
| 440 | mainLoop.MutatorParameter.ActualName = MutatorParameter.Name;
|
---|
| 441 | mainLoop.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
|
---|
| 442 | mainLoop.ElitesParameter.ActualName = ElitesParameter.Name;
|
---|
| 443 | mainLoop.ReevaluateElitesParameter.ActualName = ReevaluateElitesParameter.Name;
|
---|
[13402] | 444 | mainLoop.SuccessRatioParameter.ActualName = SuccessRatioParameter.Name;
|
---|
| 445 | mainLoop.ComparisonFactorParameter.ActualName = ComparisonFactorParameter.Name;
|
---|
| 446 | mainLoop.MaximumSelectionPressureParameter.ActualName = MaximumSelectionPressureParameter.Name;
|
---|
| 447 | mainLoop.OffspringSelectionBeforeMutationParameter.ActualName = OffspringSelectionBeforeMutationParameter.Name;
|
---|
| 448 | mainLoop.FillPopulationWithParentsParameter.ActualName = FillPopulationWithParentsParameter.Name;
|
---|
[13124] | 449 | mainLoop.AgeParameter.ActualName = "Age";
|
---|
[13127] | 450 | mainLoop.AgeGapParameter.ActualName = AgeGapParameter.Name;
|
---|
[13124] | 451 | mainLoop.AgeInheritanceParameter.ActualName = AgeInheritanceParameter.Name;
|
---|
| 452 | mainLoop.AgeLimitsParameter.ActualName = AgeLimitsParameter.Name;
|
---|
| 453 | mainLoop.MatingPoolRangeParameter.ActualName = MatingPoolRangeParameter.Name;
|
---|
| 454 | mainLoop.ReduceToPopulationSizeParameter.ActualName = ReduceToPopulationSizeParameter.Name;
|
---|
[13127] | 455 | mainLoop.TerminatorParameter.ActualName = TerminatorParameter.Name;
|
---|
[12993] | 456 | #endregion
|
---|
[11578] | 457 |
|
---|
[13402] | 458 | #region Set operators
|
---|
[11578] | 459 | foreach (var selector in ApplicationManager.Manager.GetInstances<ISelector>().Where(s => !(s is IMultiObjectiveSelector)).OrderBy(s => Name))
|
---|
| 460 | SelectorParameter.ValidValues.Add(selector);
|
---|
[12993] | 461 | var defaultSelector = SelectorParameter.ValidValues.OfType<GeneralizedRankSelector>().FirstOrDefault();
|
---|
| 462 | if (defaultSelector != null) {
|
---|
[13124] | 463 | defaultSelector.PressureParameter.Value = new DoubleValue(4.0);
|
---|
[12993] | 464 | SelectorParameter.Value = defaultSelector;
|
---|
[12119] | 465 | }
|
---|
[12993] | 466 | #endregion
|
---|
[11578] | 467 |
|
---|
[12993] | 468 | #region Create analyzers
|
---|
| 469 | qualityAnalyzer = new BestAverageWorstQualityAnalyzer();
|
---|
| 470 | layerQualityAnalyzer = new BestAverageWorstQualityAnalyzer();
|
---|
[12996] | 471 | ageAnalyzer = new OldestAverageYoungestAgeAnalyzer();
|
---|
| 472 | layerAgeAnalyzer = new OldestAverageYoungestAgeAnalyzer();
|
---|
| 473 | ageDistributionAnalyzer = new AgeDistributionAnalyzer();
|
---|
| 474 | layerAgeDistributionAnalyzer = new AgeDistributionAnalyzer();
|
---|
[13402] | 475 | selectionPressureAnalyzer = new ValueAnalyzer();
|
---|
| 476 | layerSelectionPressureAnalyzer = new ValueAnalyzer();
|
---|
| 477 | currentSuccessRatioAnalyzer = new ValueAnalyzer();
|
---|
[12993] | 478 | #endregion
|
---|
| 479 |
|
---|
| 480 | #region Create terminators
|
---|
[12548] | 481 | generationsTerminator = new ComparisonTerminator<IntValue>("Generations", ComparisonType.Less, new IntValue(1000)) { Name = "Generations" };
|
---|
[12993] | 482 | evaluationsTerminator = new ComparisonTerminator<IntValue>("EvaluatedSolutions", ComparisonType.Less, new IntValue(int.MaxValue)) { Name = "Evaluations" };
|
---|
| 483 | qualityTerminator = new SingleObjectiveQualityTerminator() { Name = "Quality" };
|
---|
| 484 | executionTimeTerminator = new ExecutionTimeTerminator(this, new TimeSpanValue(TimeSpan.FromMinutes(5)));
|
---|
| 485 | #endregion
|
---|
[12548] | 486 |
|
---|
[12993] | 487 | #region Parameterize
|
---|
[12997] | 488 | UpdateAnalyzers();
|
---|
[12993] | 489 | ParameterizeAnalyzers();
|
---|
| 490 |
|
---|
[11578] | 491 | ParameterizeSelectors();
|
---|
[12548] | 492 |
|
---|
| 493 | UpdateTerminators();
|
---|
| 494 |
|
---|
[12993] | 495 | ParameterizeAgeLimits();
|
---|
| 496 | #endregion
|
---|
| 497 |
|
---|
[11578] | 498 | Initialize();
|
---|
[11567] | 499 | }
|
---|
[12996] | 500 | #endregion
|
---|
[11578] | 501 |
|
---|
| 502 | #region Events
|
---|
[12993] | 503 | public override void Prepare() {
|
---|
| 504 | if (Problem != null)
|
---|
| 505 | base.Prepare();
|
---|
| 506 | }
|
---|
[11578] | 507 | protected override void OnProblemChanged() {
|
---|
[12119] | 508 | base.OnProblemChanged();
|
---|
[12993] | 509 | ParameterizeStochasticOperator(Problem.SolutionCreator);
|
---|
| 510 | foreach (var @operator in Problem.Operators.OfType<IOperator>())
|
---|
| 511 | ParameterizeStochasticOperator(@operator);
|
---|
[17114] | 512 | ParameterizeStochasticOperatorForLayer(Problem.Evaluator);
|
---|
[12993] | 513 |
|
---|
| 514 | ParameterizeIterationBasedOperators();
|
---|
| 515 |
|
---|
[11578] | 516 | ParameterizeSolutionsCreator();
|
---|
| 517 | ParameterizeMainLoop();
|
---|
[12993] | 518 | ParameterizeAnalyzers();
|
---|
[11578] | 519 | ParameterizeSelectors();
|
---|
[12993] | 520 | ParameterizeTerminators();
|
---|
| 521 |
|
---|
| 522 | Problem.Evaluator.QualityParameter.ActualNameChanged += Evaluator_QualityParameter_ActualNameChanged;
|
---|
| 523 |
|
---|
| 524 | UpdateAnalyzers();
|
---|
[11578] | 525 | UpdateCrossovers();
|
---|
| 526 | UpdateMutators();
|
---|
[12548] | 527 | UpdateTerminators();
|
---|
[11578] | 528 | }
|
---|
[12993] | 529 |
|
---|
| 530 | protected override void RegisterProblemEvents() {
|
---|
| 531 | base.RegisterProblemEvents();
|
---|
| 532 | var maximizationParameter = (IValueParameter<BoolValue>)Problem.MaximizationParameter;
|
---|
| 533 | if (maximizationParameter != null) maximizationParameter.ValueChanged += new EventHandler(MaximizationParameter_ValueChanged);
|
---|
| 534 | }
|
---|
| 535 | protected override void DeregisterProblemEvents() {
|
---|
| 536 | var maximizationParameter = (IValueParameter<BoolValue>)Problem.MaximizationParameter;
|
---|
| 537 | if (maximizationParameter != null) maximizationParameter.ValueChanged -= new EventHandler(MaximizationParameter_ValueChanged);
|
---|
| 538 | base.DeregisterProblemEvents();
|
---|
| 539 | }
|
---|
| 540 |
|
---|
[11578] | 541 | protected override void Problem_SolutionCreatorChanged(object sender, EventArgs e) {
|
---|
[12119] | 542 | base.Problem_SolutionCreatorChanged(sender, e);
|
---|
[12993] | 543 | ParameterizeStochasticOperator(Problem.SolutionCreator);
|
---|
| 544 |
|
---|
| 545 | Problem.Evaluator.QualityParameter.ActualNameChanged += Evaluator_QualityParameter_ActualNameChanged;
|
---|
| 546 |
|
---|
[11578] | 547 | ParameterizeSolutionsCreator();
|
---|
[12993] | 548 | ParameterizeAnalyzers();
|
---|
[11578] | 549 | }
|
---|
| 550 | protected override void Problem_EvaluatorChanged(object sender, EventArgs e) {
|
---|
[12119] | 551 | base.Problem_EvaluatorChanged(sender, e);
|
---|
[17114] | 552 | ParameterizeStochasticOperatorForLayer(Problem.Evaluator);
|
---|
[12993] | 553 |
|
---|
| 554 | UpdateAnalyzers();
|
---|
| 555 |
|
---|
[11578] | 556 | ParameterizeSolutionsCreator();
|
---|
| 557 | ParameterizeMainLoop();
|
---|
| 558 | ParameterizeSelectors();
|
---|
| 559 | }
|
---|
| 560 | protected override void Problem_OperatorsChanged(object sender, EventArgs e) {
|
---|
[12119] | 561 | base.Problem_OperatorsChanged(sender, e);
|
---|
[17111] | 562 | foreach (IOperator op in Problem.Operators.OfType<IOperator>()) ParameterizeStochasticOperator(op);
|
---|
[17114] | 563 | ParameterizeStochasticOperatorForLayer(Problem.Evaluator);
|
---|
[12120] | 564 | ParameterizeIterationBasedOperators();
|
---|
[11578] | 565 | UpdateCrossovers();
|
---|
| 566 | UpdateMutators();
|
---|
[12548] | 567 | UpdateTerminators();
|
---|
[11578] | 568 | }
|
---|
[12993] | 569 | private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
|
---|
[11578] | 570 | ParameterizeMainLoop();
|
---|
[12993] | 571 | ParameterizeAnalyzers();
|
---|
[11578] | 572 | ParameterizeSelectors();
|
---|
| 573 | }
|
---|
[12993] | 574 | private void MaximizationParameter_ValueChanged(object sender, EventArgs e) {
|
---|
| 575 | ParameterizeTerminators();
|
---|
| 576 | }
|
---|
| 577 | private void QualityAnalyzer_CurrentBestQualityParameter_NameChanged(object sender, EventArgs e) {
|
---|
| 578 | ParameterizeTerminators();
|
---|
| 579 | }
|
---|
| 580 |
|
---|
| 581 | private void AgeGap_ValueChanged(object sender, EventArgs e) {
|
---|
| 582 | ParameterizeAgeLimits();
|
---|
| 583 | }
|
---|
| 584 | private void AgingScheme_ValueChanged(object sender, EventArgs e) {
|
---|
| 585 | ParameterizeAgeLimits();
|
---|
| 586 | }
|
---|
| 587 | private void NumberOfLayers_ValueChanged(object sender, EventArgs e) {
|
---|
| 588 | ParameterizeAgeLimits();
|
---|
| 589 | }
|
---|
| 590 |
|
---|
| 591 | private void AnalyzerOperators_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<IAnalyzer>> e) {
|
---|
| 592 | foreach (var analyzer in e.Items) {
|
---|
| 593 | foreach (var parameter in analyzer.Value.Parameters.OfType<IScopeTreeLookupParameter>()) {
|
---|
| 594 | parameter.Depth = 2;
|
---|
| 595 | }
|
---|
| 596 | }
|
---|
| 597 | }
|
---|
| 598 | private void LayerAnalyzerOperators_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<IAnalyzer>> e) {
|
---|
| 599 | foreach (var analyzer in e.Items) {
|
---|
| 600 | IParameter resultParameter;
|
---|
| 601 | if (analyzer.Value.Parameters.TryGetValue("Results", out resultParameter)) {
|
---|
| 602 | var lookupParameter = resultParameter as ILookupParameter;
|
---|
| 603 | if (lookupParameter != null)
|
---|
| 604 | lookupParameter.ActualName = "LayerResults";
|
---|
| 605 | }
|
---|
| 606 | foreach (var parameter in analyzer.Value.Parameters.OfType<IScopeTreeLookupParameter>()) {
|
---|
| 607 | parameter.Depth = 1;
|
---|
| 608 | }
|
---|
| 609 | }
|
---|
| 610 | }
|
---|
[11578] | 611 | #endregion
|
---|
| 612 |
|
---|
| 613 | #region Parameterization
|
---|
| 614 | private void Initialize() {
|
---|
[12993] | 615 | if (Problem != null)
|
---|
| 616 | Problem.Evaluator.QualityParameter.ActualNameChanged += Evaluator_QualityParameter_ActualNameChanged;
|
---|
| 617 |
|
---|
[13402] | 618 | NumberOfLayersParameter.Value.ValueChanged += NumberOfLayers_ValueChanged;
|
---|
[12993] | 619 |
|
---|
| 620 | Analyzer.Operators.ItemsAdded += AnalyzerOperators_ItemsAdded;
|
---|
| 621 | LayerAnalyzer.Operators.ItemsAdded += LayerAnalyzerOperators_ItemsAdded;
|
---|
| 622 |
|
---|
[13402] | 623 | AgeGapParameter.Value.ValueChanged += AgeGap_ValueChanged;
|
---|
| 624 | AgingSchemeParameter.Value.ValueChanged += AgingScheme_ValueChanged;
|
---|
[12993] | 625 |
|
---|
[13402] | 626 | qualityAnalyzer.CurrentBestQualityParameter.NameChanged += QualityAnalyzer_CurrentBestQualityParameter_NameChanged;
|
---|
[11578] | 627 | }
|
---|
| 628 | private void ParameterizeSolutionsCreator() {
|
---|
[12993] | 629 | SolutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
|
---|
| 630 | SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name;
|
---|
[11578] | 631 | }
|
---|
| 632 | private void ParameterizeMainLoop() {
|
---|
[13124] | 633 | MainLoop.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
|
---|
| 634 | MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
[12045] | 635 | MainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
|
---|
[11578] | 636 | }
|
---|
[12993] | 637 | private void ParameterizeAnalyzers() {
|
---|
| 638 | qualityAnalyzer.ResultsParameter.ActualName = "Results";
|
---|
| 639 | qualityAnalyzer.ResultsParameter.Hidden = true;
|
---|
| 640 | qualityAnalyzer.QualityParameter.Depth = 2;
|
---|
[12996] | 641 | layerQualityAnalyzer.ResultsParameter.ActualName = "LayerResults";
|
---|
[12993] | 642 | layerQualityAnalyzer.ResultsParameter.Hidden = true;
|
---|
| 643 | layerQualityAnalyzer.QualityParameter.Depth = 1;
|
---|
[13402] | 644 | selectionPressureAnalyzer.Name = "SelectionPressure Analyzer";
|
---|
| 645 | selectionPressureAnalyzer.ResultsParameter.ActualName = "Results";
|
---|
| 646 | selectionPressureAnalyzer.ValueParameter.ActualName = "SelectionPressure";
|
---|
| 647 | selectionPressureAnalyzer.ValueParameter.Depth = 1;
|
---|
| 648 | selectionPressureAnalyzer.ValuesParameter.ActualName = "Selection Pressure History";
|
---|
| 649 | layerSelectionPressureAnalyzer.Name = "SelectionPressure Analyzer";
|
---|
| 650 | layerSelectionPressureAnalyzer.ResultsParameter.ActualName = "LayerResults";
|
---|
| 651 | layerSelectionPressureAnalyzer.ValueParameter.ActualName = "SelectionPressure";
|
---|
| 652 | layerSelectionPressureAnalyzer.ValueParameter.Depth = 0;
|
---|
| 653 | layerSelectionPressureAnalyzer.ValuesParameter.ActualName = "Selection Pressure History";
|
---|
| 654 | currentSuccessRatioAnalyzer.Name = "CurrentSuccessRatio Analyzer";
|
---|
| 655 | currentSuccessRatioAnalyzer.ResultsParameter.ActualName = "Results";
|
---|
| 656 | currentSuccessRatioAnalyzer.ValueParameter.ActualName = "CurrentSuccessRatio";
|
---|
| 657 | currentSuccessRatioAnalyzer.ValueParameter.Depth = 1;
|
---|
| 658 | currentSuccessRatioAnalyzer.ValuesParameter.ActualName = "Success Ratio History";
|
---|
[12993] | 659 | if (Problem != null) {
|
---|
| 660 | qualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
|
---|
| 661 | qualityAnalyzer.MaximizationParameter.Hidden = true;
|
---|
| 662 | qualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
| 663 | qualityAnalyzer.QualityParameter.Hidden = true;
|
---|
| 664 | qualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
|
---|
| 665 | qualityAnalyzer.BestKnownQualityParameter.Hidden = true;
|
---|
| 666 | layerQualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
|
---|
| 667 | layerQualityAnalyzer.MaximizationParameter.Hidden = true;
|
---|
| 668 | layerQualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
| 669 | layerQualityAnalyzer.QualityParameter.Hidden = true;
|
---|
| 670 | layerQualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
|
---|
| 671 | layerQualityAnalyzer.BestKnownQualityParameter.Hidden = true;
|
---|
| 672 | }
|
---|
| 673 | }
|
---|
[11578] | 674 | private void ParameterizeSelectors() {
|
---|
| 675 | foreach (var selector in SelectorParameter.ValidValues) {
|
---|
| 676 | selector.CopySelected = new BoolValue(true);
|
---|
| 677 | selector.NumberOfSelectedSubScopesParameter.Hidden = true;
|
---|
[13402] | 678 | selector.NumberOfSelectedSubScopesParameter.ActualName = SelectedParentsParameter.Name;
|
---|
[11578] | 679 | ParameterizeStochasticOperatorForLayer(selector);
|
---|
| 680 | }
|
---|
| 681 | if (Problem != null) {
|
---|
| 682 | foreach (var selector in SelectorParameter.ValidValues.OfType<ISingleObjectiveSelector>()) {
|
---|
| 683 | selector.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
|
---|
| 684 | selector.MaximizationParameter.Hidden = true;
|
---|
| 685 | selector.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
| 686 | selector.QualityParameter.Hidden = true;
|
---|
| 687 | }
|
---|
| 688 | }
|
---|
| 689 | }
|
---|
[12993] | 690 | private void ParameterizeTerminators() {
|
---|
| 691 | qualityTerminator.Parameterize(qualityAnalyzer.CurrentBestQualityParameter, Problem);
|
---|
| 692 | }
|
---|
[12120] | 693 | private void ParameterizeIterationBasedOperators() {
|
---|
| 694 | if (Problem != null) {
|
---|
| 695 | foreach (var @operator in Problem.Operators.OfType<IIterationBasedOperator>()) {
|
---|
| 696 | @operator.IterationsParameter.ActualName = "Generations";
|
---|
| 697 | @operator.IterationsParameter.Hidden = true;
|
---|
[12531] | 698 | @operator.MaximumIterationsParameter.ActualName = generationsTerminator.ThresholdParameter.Name;
|
---|
[12120] | 699 | @operator.MaximumIterationsParameter.Hidden = true;
|
---|
| 700 | }
|
---|
| 701 | }
|
---|
| 702 | }
|
---|
[12993] | 703 | private void ParameterizeAgeLimits() {
|
---|
[13402] | 704 | AgeLimits = AgingScheme.CalculateAgeLimits(AgeGap, NumberOfLayers);
|
---|
[12993] | 705 | }
|
---|
[12271] | 706 |
|
---|
[12993] | 707 | private void ParameterizeStochasticOperator(IOperator @operator) {
|
---|
| 708 | var stochasticOperator = @operator as IStochasticOperator;
|
---|
| 709 | if (stochasticOperator != null) {
|
---|
| 710 | stochasticOperator.RandomParameter.ActualName = "GlobalRandom";
|
---|
| 711 | stochasticOperator.RandomParameter.Hidden = true;
|
---|
| 712 | }
|
---|
| 713 | }
|
---|
| 714 |
|
---|
| 715 | private void ParameterizeStochasticOperatorForLayer(IOperator @operator) {
|
---|
| 716 | var stochasticOperator = @operator as IStochasticOperator;
|
---|
| 717 | if (stochasticOperator != null) {
|
---|
| 718 | stochasticOperator.RandomParameter.ActualName = "LocalRandom";
|
---|
| 719 | stochasticOperator.RandomParameter.Hidden = true;
|
---|
| 720 | }
|
---|
| 721 | }
|
---|
| 722 |
|
---|
[11578] | 723 | #endregion
|
---|
| 724 |
|
---|
| 725 | #region Updates
|
---|
[12993] | 726 | private void UpdateAnalyzers() {
|
---|
| 727 | Analyzer.Operators.Clear();
|
---|
| 728 | LayerAnalyzer.Operators.Clear();
|
---|
| 729 |
|
---|
| 730 | Analyzer.Operators.Add(qualityAnalyzer, qualityAnalyzer.EnabledByDefault);
|
---|
[12996] | 731 | Analyzer.Operators.Add(ageAnalyzer, ageAnalyzer.EnabledByDefault);
|
---|
| 732 | Analyzer.Operators.Add(ageDistributionAnalyzer, ageDistributionAnalyzer.EnabledByDefault);
|
---|
[14173] | 733 | Analyzer.Operators.Add(selectionPressureAnalyzer, false);
|
---|
[13402] | 734 | selectionPressureAnalyzer.ValueParameter.Depth = 1; // Adding analyzer sets depth to 2
|
---|
| 735 | Analyzer.Operators.Add(currentSuccessRatioAnalyzer, false);
|
---|
| 736 | currentSuccessRatioAnalyzer.ValueParameter.Depth = 1; // Adding analyzer sets depth to 2
|
---|
[12996] | 737 | LayerAnalyzer.Operators.Add(layerQualityAnalyzer, false);
|
---|
| 738 | LayerAnalyzer.Operators.Add(layerAgeAnalyzer, false);
|
---|
| 739 | LayerAnalyzer.Operators.Add(layerAgeDistributionAnalyzer, false);
|
---|
[13402] | 740 | LayerAnalyzer.Operators.Add(layerSelectionPressureAnalyzer, false);
|
---|
| 741 | layerSelectionPressureAnalyzer.ValueParameter.Depth = 0; // Adding layer-analyzer sets depth to 1
|
---|
[12993] | 742 |
|
---|
[13402] | 743 |
|
---|
[12548] | 744 | if (Problem != null) {
|
---|
[12993] | 745 | foreach (var analyzer in Problem.Operators.OfType<IAnalyzer>()) {
|
---|
| 746 | Analyzer.Operators.Add(analyzer, analyzer.EnabledByDefault);
|
---|
[12996] | 747 | LayerAnalyzer.Operators.Add((IAnalyzer)analyzer.Clone(), false);
|
---|
[12993] | 748 | }
|
---|
[12548] | 749 | }
|
---|
[12531] | 750 | }
|
---|
[11578] | 751 | private void UpdateCrossovers() {
|
---|
| 752 | var oldCrossover = CrossoverParameter.Value;
|
---|
| 753 | var defaultCrossover = Problem.Operators.OfType<ICrossover>().FirstOrDefault();
|
---|
| 754 | CrossoverParameter.ValidValues.Clear();
|
---|
| 755 | foreach (var crossover in Problem.Operators.OfType<ICrossover>().OrderBy(c => c.Name)) {
|
---|
| 756 | ParameterizeStochasticOperatorForLayer(crossover);
|
---|
| 757 | CrossoverParameter.ValidValues.Add(crossover);
|
---|
| 758 | }
|
---|
| 759 | if (oldCrossover != null) {
|
---|
| 760 | var crossover = CrossoverParameter.ValidValues.FirstOrDefault(c => c.GetType() == oldCrossover.GetType());
|
---|
[11678] | 761 | if (crossover != null)
|
---|
| 762 | CrossoverParameter.Value = crossover;
|
---|
| 763 | else
|
---|
| 764 | oldCrossover = null;
|
---|
[11578] | 765 | }
|
---|
| 766 | if (oldCrossover == null && defaultCrossover != null)
|
---|
| 767 | CrossoverParameter.Value = defaultCrossover;
|
---|
| 768 | }
|
---|
| 769 | private void UpdateMutators() {
|
---|
[15238] | 770 | IManipulator oldMutator = MutatorParameter.Value;
|
---|
[11578] | 771 | MutatorParameter.ValidValues.Clear();
|
---|
[15238] | 772 | IManipulator defaultMutator = Problem.Operators.OfType<IManipulator>().FirstOrDefault();
|
---|
| 773 |
|
---|
| 774 | foreach (IManipulator mutator in Problem.Operators.OfType<IManipulator>().OrderBy(x => x.Name)) {
|
---|
[11578] | 775 | ParameterizeStochasticOperatorForLayer(mutator);
|
---|
| 776 | MutatorParameter.ValidValues.Add(mutator);
|
---|
| 777 | }
|
---|
[15238] | 778 |
|
---|
[11578] | 779 | if (oldMutator != null) {
|
---|
[15238] | 780 | IManipulator mutator = MutatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMutator.GetType());
|
---|
| 781 | if (mutator != null) MutatorParameter.Value = mutator;
|
---|
| 782 | else oldMutator = null;
|
---|
[11578] | 783 | }
|
---|
[15238] | 784 |
|
---|
| 785 | if (oldMutator == null && defaultMutator != null)
|
---|
| 786 | MutatorParameter.Value = defaultMutator;
|
---|
[11578] | 787 | }
|
---|
[12993] | 788 | private void UpdateTerminators() {
|
---|
| 789 | var newTerminators = new Dictionary<ITerminator, bool> {
|
---|
| 790 | {generationsTerminator, !Terminators.Operators.Contains(generationsTerminator) || Terminators.Operators.ItemChecked(generationsTerminator)},
|
---|
| 791 | {evaluationsTerminator, Terminators.Operators.Contains(evaluationsTerminator) && Terminators.Operators.ItemChecked(evaluationsTerminator)},
|
---|
| 792 | {qualityTerminator, Terminators.Operators.Contains(qualityTerminator) && Terminators.Operators.ItemChecked(qualityTerminator) },
|
---|
| 793 | {executionTimeTerminator, Terminators.Operators.Contains(executionTimeTerminator) && Terminators.Operators.ItemChecked(executionTimeTerminator)}
|
---|
| 794 | };
|
---|
| 795 | if (Problem != null) {
|
---|
| 796 | foreach (var terminator in Problem.Operators.OfType<ITerminator>())
|
---|
| 797 | newTerminators.Add(terminator, !Terminators.Operators.Contains(terminator) || Terminators.Operators.ItemChecked(terminator));
|
---|
| 798 | }
|
---|
| 799 |
|
---|
| 800 | Terminators.Operators.Clear();
|
---|
| 801 |
|
---|
| 802 | foreach (var newTerminator in newTerminators)
|
---|
| 803 | Terminators.Operators.Add(newTerminator.Key, newTerminator.Value);
|
---|
| 804 | }
|
---|
[11578] | 805 | #endregion
|
---|
[11567] | 806 | }
|
---|
[13402] | 807 | }
|
---|