[11580] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[16565] | 3 | * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[11580] | 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using HeuristicLab.Common;
|
---|
| 23 | using HeuristicLab.Core;
|
---|
| 24 | using HeuristicLab.Data;
|
---|
| 25 | using HeuristicLab.Operators;
|
---|
| 26 | using HeuristicLab.Optimization;
|
---|
| 27 | using HeuristicLab.Optimization.Operators;
|
---|
| 28 | using HeuristicLab.Parameters;
|
---|
[16565] | 29 | using HEAL.Attic;
|
---|
[13111] | 30 | using HeuristicLab.Selection;
|
---|
[11580] | 31 |
|
---|
| 32 | namespace HeuristicLab.Algorithms.ALPS {
|
---|
| 33 |
|
---|
[13402] | 34 | [Item("AlpsOffspringSelectionGeneticAlgorithmMainLoop", "An ALPS offspring selection genetic algorithm main loop operator.")]
|
---|
[16565] | 35 | [StorableType("C8DF9B75-7008-405D-B38A-15C1C22110B0")]
|
---|
[13402] | 36 | public sealed class AlpsOffspringSelectionGeneticAlgorithmMainLoop : AlgorithmOperator {
|
---|
[11580] | 37 | #region Parameter Properties
|
---|
[13124] | 38 | public IValueLookupParameter<IRandom> GlobalRandomParameter {
|
---|
| 39 | get { return (IValueLookupParameter<IRandom>)Parameters["GlobalRandom"]; }
|
---|
[12045] | 40 | }
|
---|
[13124] | 41 | public IValueLookupParameter<IRandom> LocalRandomParameter {
|
---|
| 42 | get { return (IValueLookupParameter<IRandom>)Parameters["LocalRandom"]; }
|
---|
[12045] | 43 | }
|
---|
[13124] | 44 |
|
---|
| 45 | public IValueLookupParameter<IOperator> EvaluatorParameter {
|
---|
| 46 | get { return (IValueLookupParameter<IOperator>)Parameters["Evaluator"]; }
|
---|
| 47 | }
|
---|
| 48 | public IValueLookupParameter<IntValue> EvaluatedSolutionsParameter {
|
---|
| 49 | get { return (IValueLookupParameter<IntValue>)Parameters["EvaluatedSolutions"]; }
|
---|
| 50 | }
|
---|
| 51 | public IScopeTreeLookupParameter<DoubleValue> QualityParameter {
|
---|
| 52 | get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
|
---|
| 53 | }
|
---|
| 54 | public IValueLookupParameter<BoolValue> MaximizationParameter {
|
---|
| 55 | get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
|
---|
| 56 | }
|
---|
| 57 |
|
---|
[11580] | 58 | public ILookupParameter<IOperator> AnalyzerParameter {
|
---|
| 59 | get { return (ILookupParameter<IOperator>)Parameters["Analyzer"]; }
|
---|
| 60 | }
|
---|
| 61 | public ILookupParameter<IOperator> LayerAnalyzerParameter {
|
---|
| 62 | get { return (ILookupParameter<IOperator>)Parameters["LayerAnalyzer"]; }
|
---|
| 63 | }
|
---|
| 64 |
|
---|
[13124] | 65 | public IValueLookupParameter<IntValue> NumberOfLayersParameter {
|
---|
| 66 | get { return (IValueLookupParameter<IntValue>)Parameters["NumberOfLayers"]; }
|
---|
[11583] | 67 | }
|
---|
[13124] | 68 | public IValueLookupParameter<IntValue> PopulationSizeParameter {
|
---|
| 69 | get { return (IValueLookupParameter<IntValue>)Parameters["PopulationSize"]; }
|
---|
| 70 | }
|
---|
| 71 | public ILookupParameter<IntValue> CurrentPopulationSizeParameter {
|
---|
| 72 | get { return (ILookupParameter<IntValue>)Parameters["CurrentPopulationSize"]; }
|
---|
| 73 | }
|
---|
[11583] | 74 |
|
---|
[13124] | 75 | public IValueLookupParameter<IOperator> SelectorParameter {
|
---|
| 76 | get { return (IValueLookupParameter<IOperator>)Parameters["Selector"]; }
|
---|
| 77 | }
|
---|
| 78 | public IValueLookupParameter<IOperator> CrossoverParameter {
|
---|
| 79 | get { return (IValueLookupParameter<IOperator>)Parameters["Crossover"]; }
|
---|
| 80 | }
|
---|
| 81 | public IValueLookupParameter<IOperator> MutatorParameter {
|
---|
| 82 | get { return (IValueLookupParameter<IOperator>)Parameters["Mutator"]; }
|
---|
| 83 | }
|
---|
| 84 | public IValueLookupParameter<PercentValue> MutationProbabilityParameter {
|
---|
| 85 | get { return (IValueLookupParameter<PercentValue>)Parameters["MutationProbability"]; }
|
---|
| 86 | }
|
---|
| 87 | public IValueLookupParameter<IntValue> ElitesParameter {
|
---|
| 88 | get { return (IValueLookupParameter<IntValue>)Parameters["Elites"]; }
|
---|
| 89 | }
|
---|
| 90 | public IValueLookupParameter<BoolValue> ReevaluateElitesParameter {
|
---|
| 91 | get { return (IValueLookupParameter<BoolValue>)Parameters["ReevaluateElites"]; }
|
---|
| 92 | }
|
---|
[13402] | 93 |
|
---|
| 94 | public IValueLookupParameter<DoubleValue> SuccessRatioParameter {
|
---|
| 95 | get { return (IValueLookupParameter<DoubleValue>)Parameters["SuccessRatio"]; }
|
---|
[13124] | 96 | }
|
---|
[13402] | 97 | public ILookupParameter<DoubleValue> ComparisonFactorParameter {
|
---|
| 98 | get { return (ILookupParameter<DoubleValue>)Parameters["ComparisonFactor"]; }
|
---|
| 99 | }
|
---|
| 100 | public IValueLookupParameter<DoubleValue> MaximumSelectionPressureParameter {
|
---|
| 101 | get { return (IValueLookupParameter<DoubleValue>)Parameters["MaximumSelectionPressure"]; }
|
---|
| 102 | }
|
---|
| 103 | public IValueLookupParameter<BoolValue> OffspringSelectionBeforeMutationParameter {
|
---|
| 104 | get { return (IValueLookupParameter<BoolValue>)Parameters["OffspringSelectionBeforeMutation"]; }
|
---|
| 105 | }
|
---|
| 106 | public IValueLookupParameter<BoolValue> FillPopulationWithParentsParameter {
|
---|
| 107 | get { return (IValueLookupParameter<BoolValue>)Parameters["FillPopulationWithParents"]; }
|
---|
| 108 | }
|
---|
[13124] | 109 |
|
---|
| 110 | public IScopeTreeLookupParameter<DoubleValue> AgeParameter {
|
---|
| 111 | get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["Age"]; }
|
---|
| 112 | }
|
---|
[13127] | 113 | public IValueLookupParameter<IntValue> AgeGapParameter {
|
---|
| 114 | get { return (IValueLookupParameter<IntValue>)Parameters["AgeGap"]; }
|
---|
| 115 | }
|
---|
[13124] | 116 | public IValueLookupParameter<DoubleValue> AgeInheritanceParameter {
|
---|
| 117 | get { return (IValueLookupParameter<DoubleValue>)Parameters["AgeInheritance"]; }
|
---|
| 118 | }
|
---|
| 119 | public IValueLookupParameter<IntArray> AgeLimitsParameter {
|
---|
| 120 | get { return (IValueLookupParameter<IntArray>)Parameters["AgeLimits"]; }
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | public IValueLookupParameter<IntValue> MatingPoolRangeParameter {
|
---|
| 124 | get { return (IValueLookupParameter<IntValue>)Parameters["MatingPoolRange"]; }
|
---|
| 125 | }
|
---|
| 126 | public IValueLookupParameter<BoolValue> ReduceToPopulationSizeParameter {
|
---|
| 127 | get { return (IValueLookupParameter<BoolValue>)Parameters["ReduceToPopulationSize"]; }
|
---|
| 128 | }
|
---|
[13127] | 129 |
|
---|
| 130 | public IValueLookupParameter<IOperator> TerminatorParameter {
|
---|
| 131 | get { return (IValueLookupParameter<IOperator>)Parameters["Terminator"]; }
|
---|
| 132 | }
|
---|
[13124] | 133 | #endregion
|
---|
| 134 |
|
---|
[11580] | 135 | [StorableConstructor]
|
---|
[16565] | 136 | private AlpsOffspringSelectionGeneticAlgorithmMainLoop(StorableConstructorFlag _) : base(_) { }
|
---|
[13402] | 137 | private AlpsOffspringSelectionGeneticAlgorithmMainLoop(AlpsOffspringSelectionGeneticAlgorithmMainLoop original, Cloner cloner)
|
---|
[11580] | 138 | : base(original, cloner) { }
|
---|
| 139 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
[13402] | 140 | return new AlpsOffspringSelectionGeneticAlgorithmMainLoop(this, cloner);
|
---|
[11580] | 141 | }
|
---|
[13402] | 142 | public AlpsOffspringSelectionGeneticAlgorithmMainLoop()
|
---|
[11580] | 143 | : base() {
|
---|
[13124] | 144 | Parameters.Add(new ValueLookupParameter<IRandom>("GlobalRandom", "A pseudo random number generator."));
|
---|
| 145 | Parameters.Add(new ValueLookupParameter<IRandom>("LocalRandom", "A pseudo random number generator."));
|
---|
| 146 |
|
---|
| 147 | Parameters.Add(new ValueLookupParameter<IOperator>("Evaluator", "The operator used to evaluate solutions. This operator is executed in parallel, if an engine is used which supports parallelization."));
|
---|
| 148 | Parameters.Add(new ValueLookupParameter<IntValue>("EvaluatedSolutions", "The number of times solutions have been evaluated."));
|
---|
[12045] | 149 | Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution."));
|
---|
[13124] | 150 | Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
|
---|
[11580] | 151 |
|
---|
[13128] | 152 | Parameters.Add(new ValueLookupParameter<IOperator>("Analyzer", "The operator used to analyze all individuals from all layers combined."));
|
---|
[13124] | 153 | Parameters.Add(new ValueLookupParameter<IOperator>("LayerAnalyzer", "The operator used to analyze each layer."));
|
---|
| 154 |
|
---|
| 155 | Parameters.Add(new ValueLookupParameter<IntValue>("NumberOfLayers", "The number of layers."));
|
---|
[13206] | 156 | Parameters.Add(new ValueLookupParameter<IntValue>("PopulationSize", "The size of the population of solutions in each layer."));
|
---|
[13124] | 157 | Parameters.Add(new LookupParameter<IntValue>("CurrentPopulationSize", "The current size of the population."));
|
---|
| 158 |
|
---|
| 159 | Parameters.Add(new ValueLookupParameter<IOperator>("Selector", "The operator used to select solutions for reproduction."));
|
---|
| 160 | Parameters.Add(new ValueLookupParameter<IOperator>("Crossover", "The operator used to cross solutions."));
|
---|
| 161 | Parameters.Add(new ValueLookupParameter<IOperator>("Mutator", "The operator used to mutate solutions."));
|
---|
| 162 | Parameters.Add(new ValueLookupParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution."));
|
---|
| 163 | Parameters.Add(new ValueLookupParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation."));
|
---|
| 164 | Parameters.Add(new ValueLookupParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)"));
|
---|
| 165 |
|
---|
[13402] | 166 | Parameters.Add(new ValueLookupParameter<DoubleValue>("SuccessRatio", "The ratio of successful to total children that should be achieved."));
|
---|
| 167 | Parameters.Add(new ValueLookupParameter<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]."));
|
---|
| 168 | Parameters.Add(new ValueLookupParameter<DoubleValue>("MaximumSelectionPressure", "The maximum selection pressure that terminates the algorithm."));
|
---|
| 169 | Parameters.Add(new ValueLookupParameter<BoolValue>("OffspringSelectionBeforeMutation", "True if the offspring selection step should be applied before mutation, false if it should be applied after mutation."));
|
---|
| 170 | Parameters.Add(new ValueLookupParameter<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."));
|
---|
| 171 |
|
---|
[13124] | 172 | Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Age", "The age of individuals."));
|
---|
[13127] | 173 | Parameters.Add(new ValueLookupParameter<IntValue>("AgeGap", "The frequency of reseeding the lowest layer and scaling factor for the age-limits for the layers."));
|
---|
[13124] | 174 | Parameters.Add(new ValueLookupParameter<DoubleValue>("AgeInheritance", "A weight that determines the age of a child after crossover based on the older (1.0) and younger (0.0) parent."));
|
---|
[13206] | 175 | Parameters.Add(new ValueLookupParameter<IntArray>("AgeLimits", "The maximum age an individual is allowed to reach in a certain layer."));
|
---|
[13124] | 176 |
|
---|
| 177 | Parameters.Add(new ValueLookupParameter<IntValue>("MatingPoolRange", "The range of sub - populations used for creating a mating pool. (1 = current + previous sub-population)"));
|
---|
[13127] | 178 | Parameters.Add(new ValueLookupParameter<BoolValue>("ReduceToPopulationSize", "Reduce the CurrentPopulationSize after elder migration to PopulationSize"));
|
---|
[13124] | 179 |
|
---|
[13127] | 180 | Parameters.Add(new ValueLookupParameter<IOperator>("Terminator", "The termination criteria that defines if the algorithm should continue or stop"));
|
---|
[13124] | 181 |
|
---|
[13127] | 182 |
|
---|
[11580] | 183 | var variableCreator = new VariableCreator() { Name = "Initialize" };
|
---|
| 184 | var initLayerAnalyzerProcessor = new SubScopesProcessor();
|
---|
[11590] | 185 | var layerVariableCreator = new VariableCreator() { Name = "Initialize Layer" };
|
---|
[11580] | 186 | var initLayerAnalyzerPlaceholder = new Placeholder() { Name = "LayerAnalyzer (Placeholder)" };
|
---|
[13402] | 187 | var layerResultCollector = new ResultsCollector() { Name = "Collect layer results" };
|
---|
[11609] | 188 | var initAnalyzerPlaceholder = new Placeholder() { Name = "Analyzer (Placeholder)" };
|
---|
| 189 | var resultsCollector = new ResultsCollector();
|
---|
[11583] | 190 | var matingPoolCreator = new MatingPoolCreator() { Name = "Create Mating Pools" };
|
---|
[13113] | 191 | var matingPoolProcessor = new UniformSubScopesProcessor() { Name = "Process Mating Pools" };
|
---|
[11590] | 192 | var initializeLayer = new Assigner() { Name = "Reset LayerEvaluatedSolutions" };
|
---|
[13402] | 193 | var mainOperator = new AlpsOffspringSelectionGeneticAlgorithmMainOperator();
|
---|
[11583] | 194 | var generationsIcrementor = new IntCounter() { Name = "Increment Generations" };
|
---|
| 195 | var evaluatedSolutionsReducer = new DataReducer() { Name = "Increment EvaluatedSolutions" };
|
---|
[13111] | 196 | var eldersEmigrator = CreateEldersEmigrator();
|
---|
| 197 | var layerOpener = CreateLayerOpener();
|
---|
| 198 | var layerReseeder = CreateReseeder();
|
---|
[12992] | 199 | var layerAnalyzerProcessor = new UniformSubScopesProcessor();
|
---|
[12197] | 200 | var layerAnalyzerPlaceholder = new Placeholder() { Name = "LayerAnalyzer (Placeholder)" };
|
---|
[11580] | 201 | var analyzerPlaceholder = new Placeholder() { Name = "Analyzer (Placeholder)" };
|
---|
[12531] | 202 | var termination = new TerminationOperator();
|
---|
[11580] | 203 |
|
---|
| 204 | OperatorGraph.InitialOperator = variableCreator;
|
---|
| 205 |
|
---|
| 206 | variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Generations", new IntValue(0)));
|
---|
[11586] | 207 | variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("OpenLayers", new IntValue(1)));
|
---|
[11609] | 208 | variableCreator.Successor = initLayerAnalyzerProcessor;
|
---|
[11580] | 209 |
|
---|
[11590] | 210 | initLayerAnalyzerProcessor.Operators.Add(layerVariableCreator);
|
---|
[11609] | 211 | initLayerAnalyzerProcessor.Successor = initAnalyzerPlaceholder;
|
---|
[11580] | 212 |
|
---|
[13127] | 213 | layerVariableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Layer", new IntValue(0)));
|
---|
[12071] | 214 | layerVariableCreator.CollectedValues.Add(new ValueParameter<ResultCollection>("LayerResults"));
|
---|
[13402] | 215 | layerVariableCreator.CollectedValues.Add(new ValueParameter<DoubleValue>("SelectionPressure", new DoubleValue(0)));
|
---|
| 216 | layerVariableCreator.CollectedValues.Add(new ValueParameter<DoubleValue>("CurrentSuccessRatio", new DoubleValue(0)));
|
---|
[11590] | 217 | layerVariableCreator.Successor = initLayerAnalyzerPlaceholder;
|
---|
| 218 |
|
---|
[11580] | 219 | initLayerAnalyzerPlaceholder.OperatorParameter.ActualName = LayerAnalyzerParameter.Name;
|
---|
[13402] | 220 | initLayerAnalyzerPlaceholder.Successor = layerResultCollector;
|
---|
[11580] | 221 |
|
---|
[13402] | 222 | layerResultCollector.ResultsParameter.ActualName = "LayerResults";
|
---|
| 223 | layerResultCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Selection Pressure", "Displays the rising selection pressure during a generation.", "SelectionPressure"));
|
---|
| 224 | layerResultCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Success Ratio", "Indicates how many successful children were already found during a generation (relative to the population size).", "CurrentSuccessRatio"));
|
---|
| 225 | layerResultCollector.Successor = null;
|
---|
| 226 |
|
---|
[11609] | 227 | initAnalyzerPlaceholder.OperatorParameter.ActualName = AnalyzerParameter.Name;
|
---|
| 228 | initAnalyzerPlaceholder.Successor = resultsCollector;
|
---|
| 229 |
|
---|
| 230 | resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Generations"));
|
---|
[13124] | 231 | resultsCollector.CollectedValues.Add(new ScopeTreeLookupParameter<ResultCollection>("LayerResults", "Result set for each Layer", "LayerResults"));
|
---|
[11609] | 232 | resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("OpenLayers"));
|
---|
| 233 | resultsCollector.CopyValue = new BoolValue(false);
|
---|
[13031] | 234 | resultsCollector.Successor = matingPoolCreator;
|
---|
[11609] | 235 |
|
---|
[13124] | 236 | matingPoolCreator.MatingPoolRangeParameter.Value = null;
|
---|
| 237 | matingPoolCreator.MatingPoolRangeParameter.ActualName = MatingPoolRangeParameter.Name;
|
---|
[11580] | 238 | matingPoolCreator.Successor = matingPoolProcessor;
|
---|
| 239 |
|
---|
| 240 | matingPoolProcessor.Parallel.Value = true;
|
---|
[11590] | 241 | matingPoolProcessor.Operator = initializeLayer;
|
---|
[11583] | 242 | matingPoolProcessor.Successor = generationsIcrementor;
|
---|
[11580] | 243 |
|
---|
[11590] | 244 | initializeLayer.LeftSideParameter.ActualName = "LayerEvaluatedSolutions";
|
---|
| 245 | initializeLayer.RightSideParameter.Value = new IntValue(0);
|
---|
| 246 | initializeLayer.Successor = mainOperator;
|
---|
| 247 |
|
---|
[13124] | 248 | mainOperator.RandomParameter.ActualName = LocalRandomParameter.Name;
|
---|
| 249 | mainOperator.EvaluatorParameter.ActualName = EvaluatorParameter.Name;
|
---|
| 250 | mainOperator.EvaluatedSolutionsParameter.ActualName = "LayerEvaluatedSolutions";
|
---|
| 251 | mainOperator.QualityParameter.ActualName = QualityParameter.Name;
|
---|
| 252 | mainOperator.MaximizationParameter.ActualName = MaximizationParameter.Name;
|
---|
| 253 | mainOperator.PopulationSizeParameter.ActualName = PopulationSizeParameter.Name;
|
---|
| 254 | mainOperator.SelectorParameter.ActualName = SelectorParameter.Name;
|
---|
| 255 | mainOperator.CrossoverParameter.ActualName = CrossoverParameter.Name;
|
---|
| 256 | mainOperator.MutatorParameter.ActualName = MutatorParameter.ActualName;
|
---|
| 257 | mainOperator.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
|
---|
| 258 | mainOperator.ElitesParameter.ActualName = ElitesParameter.Name;
|
---|
| 259 | mainOperator.ReevaluateElitesParameter.ActualName = ReevaluateElitesParameter.Name;
|
---|
[13402] | 260 | mainOperator.ComparisonFactorParameter.ActualName = ComparisonFactorParameter.Name;
|
---|
| 261 | mainOperator.SuccessRatioParameter.ActualName = SuccessRatioParameter.Name;
|
---|
| 262 | mainOperator.CurrentSuccessRatioParameter.ActualName = "CurrentSuccessRatio";
|
---|
| 263 | mainOperator.SelectionPressureParameter.ActualName = "SelectionPressure";
|
---|
| 264 | mainOperator.MaximumSelectionPressureParameter.ActualName = MaximumSelectionPressureParameter.Name;
|
---|
| 265 | mainOperator.OffspringSelectionBeforeMutationParameter.ActualName = OffspringSelectionBeforeMutationParameter.Name;
|
---|
| 266 | mainOperator.FillPopulationWithParentsParameter.ActualName = FillPopulationWithParentsParameter.Name;
|
---|
[13124] | 267 | mainOperator.AgeParameter.ActualName = AgeParameter.Name;
|
---|
| 268 | mainOperator.AgeInheritanceParameter.ActualName = AgeInheritanceParameter.Name;
|
---|
| 269 | mainOperator.AgeIncrementParameter.Value = new DoubleValue(1.0);
|
---|
| 270 | mainOperator.Successor = null;
|
---|
| 271 |
|
---|
[11583] | 272 | generationsIcrementor.ValueParameter.ActualName = "Generations";
|
---|
| 273 | generationsIcrementor.Increment = new IntValue(1);
|
---|
| 274 | generationsIcrementor.Successor = evaluatedSolutionsReducer;
|
---|
| 275 |
|
---|
[11676] | 276 | evaluatedSolutionsReducer.ParameterToReduce.ActualName = "LayerEvaluatedSolutions";
|
---|
[13124] | 277 | evaluatedSolutionsReducer.TargetParameter.ActualName = EvaluatedSolutionsParameter.Name;
|
---|
[11583] | 278 | evaluatedSolutionsReducer.ReductionOperation.Value = new ReductionOperation(ReductionOperations.Sum);
|
---|
| 279 | evaluatedSolutionsReducer.TargetOperation.Value = new ReductionOperation(ReductionOperations.Sum);
|
---|
| 280 | evaluatedSolutionsReducer.Successor = eldersEmigrator;
|
---|
| 281 |
|
---|
[13095] | 282 | eldersEmigrator.Successor = layerOpener;
|
---|
[11580] | 283 |
|
---|
[13095] | 284 | layerOpener.Successor = layerReseeder;
|
---|
[11580] | 285 |
|
---|
[13095] | 286 | layerReseeder.Successor = layerAnalyzerProcessor;
|
---|
| 287 |
|
---|
[12197] | 288 | layerAnalyzerProcessor.Operator = layerAnalyzerPlaceholder;
|
---|
| 289 | layerAnalyzerProcessor.Successor = analyzerPlaceholder;
|
---|
[11580] | 290 |
|
---|
[12197] | 291 | layerAnalyzerPlaceholder.OperatorParameter.ActualName = LayerAnalyzerParameter.Name;
|
---|
[11580] | 292 |
|
---|
| 293 | analyzerPlaceholder.OperatorParameter.ActualName = AnalyzerParameter.Name;
|
---|
[12531] | 294 | analyzerPlaceholder.Successor = termination;
|
---|
[11580] | 295 |
|
---|
[13127] | 296 | termination.TerminatorParameter.ActualName = TerminatorParameter.Name;
|
---|
[13031] | 297 | termination.ContinueBranch = matingPoolCreator;
|
---|
[11583] | 298 | }
|
---|
[13111] | 299 |
|
---|
[13124] | 300 | private CombinedOperator CreateEldersEmigrator() {
|
---|
[13111] | 301 | var eldersEmigrator = new CombinedOperator() { Name = "Emigrate Elders" };
|
---|
| 302 | var selectorProsessor = new UniformSubScopesProcessor();
|
---|
| 303 | var eldersSelector = new EldersSelector();
|
---|
[13206] | 304 | var shiftToRightMigrator = new UnidirectionalRingMigrator() { Name = "Shift elders to next layer" };
|
---|
[13111] | 305 | var mergingProsessor = new UniformSubScopesProcessor();
|
---|
| 306 | var mergingReducer = new MergingReducer();
|
---|
| 307 | var subScopesCounter = new SubScopesCounter();
|
---|
[13117] | 308 | var reduceToPopulationSizeBranch = new ConditionalBranch() { Name = "ReduceToPopulationSize?" };
|
---|
[13124] | 309 | var countCalculator = new ExpressionCalculator() { Name = "CurrentPopulationSize = Min(CurrentPopulationSize, PopulationSize)" };
|
---|
[13111] | 310 | var bestSelector = new BestSelector();
|
---|
| 311 | var rightReducer = new RightReducer();
|
---|
| 312 |
|
---|
| 313 | eldersEmigrator.OperatorGraph.InitialOperator = selectorProsessor;
|
---|
| 314 |
|
---|
| 315 | selectorProsessor.Operator = eldersSelector;
|
---|
| 316 | selectorProsessor.Successor = shiftToRightMigrator;
|
---|
| 317 |
|
---|
[13127] | 318 | eldersSelector.AgeParameter.ActualName = AgeParameter.Name;
|
---|
| 319 | eldersSelector.AgeLimitsParameter.ActualName = AgeLimitsParameter.Name;
|
---|
| 320 | eldersSelector.NumberOfLayersParameter.ActualName = NumberOfLayersParameter.Name;
|
---|
| 321 | eldersSelector.LayerParameter.ActualName = "Layer";
|
---|
| 322 | eldersSelector.Successor = null;
|
---|
| 323 |
|
---|
[13111] | 324 | shiftToRightMigrator.ClockwiseMigrationParameter.Value = new BoolValue(true);
|
---|
| 325 | shiftToRightMigrator.Successor = mergingProsessor;
|
---|
| 326 |
|
---|
| 327 | mergingProsessor.Operator = mergingReducer;
|
---|
| 328 |
|
---|
| 329 | mergingReducer.Successor = subScopesCounter;
|
---|
| 330 |
|
---|
[13124] | 331 | subScopesCounter.ValueParameter.ActualName = CurrentPopulationSizeParameter.Name;
|
---|
[13111] | 332 | subScopesCounter.AccumulateParameter.Value = new BoolValue(false);
|
---|
[13117] | 333 | subScopesCounter.Successor = reduceToPopulationSizeBranch;
|
---|
[13111] | 334 |
|
---|
[13124] | 335 | reduceToPopulationSizeBranch.ConditionParameter.ActualName = ReduceToPopulationSizeParameter.Name;
|
---|
[13117] | 336 | reduceToPopulationSizeBranch.TrueBranch = countCalculator;
|
---|
| 337 |
|
---|
[13124] | 338 | countCalculator.CollectedValues.Add(new LookupParameter<IntValue>(PopulationSizeParameter.Name));
|
---|
| 339 | countCalculator.CollectedValues.Add(new LookupParameter<IntValue>(CurrentPopulationSizeParameter.Name));
|
---|
| 340 | countCalculator.ExpressionParameter.Value = new StringValue("CurrentPopulationSize PopulationSize CurrentPopulationSize PopulationSize < if toint");
|
---|
| 341 | countCalculator.ExpressionResultParameter.ActualName = CurrentPopulationSizeParameter.Name;
|
---|
[13111] | 342 | countCalculator.Successor = bestSelector;
|
---|
| 343 |
|
---|
[13124] | 344 | bestSelector.NumberOfSelectedSubScopesParameter.ActualName = CurrentPopulationSizeParameter.Name;
|
---|
[13111] | 345 | bestSelector.CopySelected = new BoolValue(false);
|
---|
| 346 | bestSelector.Successor = rightReducer;
|
---|
| 347 |
|
---|
| 348 | return eldersEmigrator;
|
---|
| 349 | }
|
---|
| 350 |
|
---|
[13124] | 351 | private CombinedOperator CreateLayerOpener() {
|
---|
[13111] | 352 | var layerOpener = new CombinedOperator() { Name = "Open new Layer if needed" };
|
---|
| 353 | var maxLayerReached = new Comparator() { Name = "MaxLayersReached = OpenLayers >= NumberOfLayers" };
|
---|
| 354 | var maxLayerReachedBranch = new ConditionalBranch() { Name = "MaxLayersReached?" };
|
---|
| 355 | var openNewLayerCalculator = new ExpressionCalculator() { Name = "OpenNewLayer = Generations >= AgeLimits[OpenLayers - 1]" };
|
---|
| 356 | var openNewLayerBranch = new ConditionalBranch() { Name = "OpenNewLayer?" };
|
---|
[13206] | 357 | var layerCreator = new LastLayerCloner() { Name = "Create Layer" };
|
---|
[13124] | 358 | var updateLayerNumber = new Assigner() { Name = "Layer = OpenLayers" };
|
---|
| 359 | var historyWiper = new ResultsHistoryWiper() { Name = "Clear History in Results" };
|
---|
[13402] | 360 | var createChildrenViaCrossover = new AlpsOffspringSelectionGeneticAlgorithmMainOperator();
|
---|
[13111] | 361 | var incrEvaluatedSolutionsForNewLayer = new SubScopesCounter() { Name = "Update EvaluatedSolutions" };
|
---|
| 362 | var incrOpenLayers = new IntCounter() { Name = "Incr. OpenLayers" };
|
---|
| 363 | var newLayerResultsCollector = new ResultsCollector() { Name = "Collect new Layer Results" };
|
---|
| 364 |
|
---|
| 365 | layerOpener.OperatorGraph.InitialOperator = maxLayerReached;
|
---|
| 366 |
|
---|
| 367 | maxLayerReached.LeftSideParameter.ActualName = "OpenLayers";
|
---|
[13124] | 368 | maxLayerReached.RightSideParameter.ActualName = NumberOfLayersParameter.Name;
|
---|
[13111] | 369 | maxLayerReached.ResultParameter.ActualName = "MaxLayerReached";
|
---|
| 370 | maxLayerReached.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
|
---|
| 371 | maxLayerReached.Successor = maxLayerReachedBranch;
|
---|
| 372 |
|
---|
| 373 | maxLayerReachedBranch.ConditionParameter.ActualName = "MaxLayerReached";
|
---|
| 374 | maxLayerReachedBranch.FalseBranch = openNewLayerCalculator;
|
---|
| 375 |
|
---|
[13124] | 376 | openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntArray>(AgeLimitsParameter.Name));
|
---|
[13111] | 377 | openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntValue>("Generations"));
|
---|
[13124] | 378 | openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntValue>(NumberOfLayersParameter.Name));
|
---|
[13111] | 379 | openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntValue>("OpenLayers"));
|
---|
| 380 | openNewLayerCalculator.ExpressionResultParameter.ActualName = "OpenNewLayer";
|
---|
| 381 | openNewLayerCalculator.ExpressionParameter.Value = new StringValue("Generations 1 + AgeLimits OpenLayers 1 - [] >");
|
---|
| 382 | openNewLayerCalculator.Successor = openNewLayerBranch;
|
---|
| 383 |
|
---|
| 384 | openNewLayerBranch.ConditionParameter.ActualName = "OpenNewLayer";
|
---|
| 385 | openNewLayerBranch.TrueBranch = layerCreator;
|
---|
| 386 |
|
---|
[13206] | 387 | layerCreator.NewLayerOperator = updateLayerNumber;
|
---|
[13111] | 388 | layerCreator.Successor = incrOpenLayers;
|
---|
| 389 |
|
---|
[13124] | 390 | updateLayerNumber.LeftSideParameter.ActualName = "Layer";
|
---|
| 391 | updateLayerNumber.RightSideParameter.ActualName = "OpenLayers";
|
---|
| 392 | updateLayerNumber.Successor = historyWiper;
|
---|
| 393 |
|
---|
| 394 | historyWiper.ResultsParameter.ActualName = "LayerResults";
|
---|
| 395 | historyWiper.Successor = createChildrenViaCrossover;
|
---|
| 396 |
|
---|
| 397 | // Maybe use only crossover and no elitism instead of "default operator"
|
---|
| 398 | createChildrenViaCrossover.RandomParameter.ActualName = LocalRandomParameter.Name;
|
---|
| 399 | createChildrenViaCrossover.EvaluatorParameter.ActualName = EvaluatorParameter.Name;
|
---|
| 400 | createChildrenViaCrossover.EvaluatedSolutionsParameter.ActualName = "LayerEvaluatedSolutions";
|
---|
| 401 | createChildrenViaCrossover.QualityParameter.ActualName = QualityParameter.Name;
|
---|
| 402 | createChildrenViaCrossover.MaximizationParameter.ActualName = MaximizationParameter.Name;
|
---|
| 403 | createChildrenViaCrossover.PopulationSizeParameter.ActualName = PopulationSizeParameter.Name;
|
---|
| 404 | createChildrenViaCrossover.SelectorParameter.ActualName = SelectorParameter.Name;
|
---|
| 405 | createChildrenViaCrossover.CrossoverParameter.ActualName = CrossoverParameter.Name;
|
---|
[13402] | 406 | createChildrenViaCrossover.MutatorParameter.ActualName = MutatorParameter.ActualName;
|
---|
[13124] | 407 | createChildrenViaCrossover.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
|
---|
| 408 | createChildrenViaCrossover.ElitesParameter.ActualName = ElitesParameter.Name;
|
---|
| 409 | createChildrenViaCrossover.ReevaluateElitesParameter.ActualName = ReevaluateElitesParameter.Name;
|
---|
[13402] | 410 | createChildrenViaCrossover.ComparisonFactorParameter.ActualName = ComparisonFactorParameter.Name;
|
---|
| 411 | createChildrenViaCrossover.SuccessRatioParameter.ActualName = SuccessRatioParameter.Name;
|
---|
| 412 | createChildrenViaCrossover.CurrentSuccessRatioParameter.ActualName = "CurrentSuccessRatio";
|
---|
| 413 | createChildrenViaCrossover.SelectionPressureParameter.ActualName = "SelectionPressure";
|
---|
| 414 | createChildrenViaCrossover.MaximumSelectionPressureParameter.ActualName = MaximumSelectionPressureParameter.Name;
|
---|
| 415 | createChildrenViaCrossover.OffspringSelectionBeforeMutationParameter.ActualName = OffspringSelectionBeforeMutationParameter.Name;
|
---|
| 416 | createChildrenViaCrossover.FillPopulationWithParentsParameter.ActualName = FillPopulationWithParentsParameter.Name;
|
---|
[13124] | 417 | createChildrenViaCrossover.AgeParameter.ActualName = AgeParameter.Name;
|
---|
| 418 | createChildrenViaCrossover.AgeInheritanceParameter.ActualName = AgeInheritanceParameter.Name;
|
---|
| 419 | createChildrenViaCrossover.AgeIncrementParameter.Value = new DoubleValue(0.0);
|
---|
[13111] | 420 | createChildrenViaCrossover.Successor = incrEvaluatedSolutionsForNewLayer;
|
---|
| 421 |
|
---|
[13124] | 422 | incrEvaluatedSolutionsForNewLayer.ValueParameter.ActualName = EvaluatedSolutionsParameter.Name;
|
---|
[13111] | 423 | incrEvaluatedSolutionsForNewLayer.AccumulateParameter.Value = new BoolValue(true);
|
---|
| 424 |
|
---|
| 425 | incrOpenLayers.ValueParameter.ActualName = "OpenLayers";
|
---|
| 426 | incrOpenLayers.Increment = new IntValue(1);
|
---|
| 427 | incrOpenLayers.Successor = newLayerResultsCollector;
|
---|
| 428 |
|
---|
| 429 | newLayerResultsCollector.CollectedValues.Add(new ScopeTreeLookupParameter<ResultCollection>("LayerResults", "Result set for each layer", "LayerResults"));
|
---|
| 430 | newLayerResultsCollector.CopyValue = new BoolValue(false);
|
---|
| 431 | newLayerResultsCollector.Successor = null;
|
---|
| 432 |
|
---|
| 433 | return layerOpener;
|
---|
| 434 | }
|
---|
| 435 |
|
---|
[13124] | 436 | private CombinedOperator CreateReseeder() {
|
---|
[13111] | 437 | var reseeder = new CombinedOperator() { Name = "Reseed Layer Zero if needed" };
|
---|
| 438 | var reseedingController = new ReseedingController() { Name = "Reseeding needed (Generation % AgeGap == 0)?" };
|
---|
| 439 | var removeIndividuals = new SubScopesRemover();
|
---|
| 440 | var createIndividuals = new SolutionsCreator();
|
---|
| 441 | var initializeAgeProsessor = new UniformSubScopesProcessor();
|
---|
| 442 | var initializeAge = new VariableCreator() { Name = "Initialize Age" };
|
---|
| 443 | var incrEvaluatedSolutionsAfterReseeding = new SubScopesCounter() { Name = "Update EvaluatedSolutions" };
|
---|
| 444 |
|
---|
| 445 | reseeder.OperatorGraph.InitialOperator = reseedingController;
|
---|
| 446 |
|
---|
[13127] | 447 | reseedingController.GenerationsParameter.ActualName = "Generations";
|
---|
| 448 | reseedingController.AgeGapParameter.ActualName = AgeGapParameter.Name;
|
---|
[13111] | 449 | reseedingController.FirstLayerOperator = removeIndividuals;
|
---|
[13127] | 450 | reseedingController.Successor = null;
|
---|
[13111] | 451 |
|
---|
| 452 | removeIndividuals.Successor = createIndividuals;
|
---|
| 453 |
|
---|
[13124] | 454 | createIndividuals.NumberOfSolutionsParameter.ActualName = PopulationSizeParameter.Name;
|
---|
[13111] | 455 | createIndividuals.Successor = initializeAgeProsessor;
|
---|
| 456 |
|
---|
| 457 | initializeAgeProsessor.Operator = initializeAge;
|
---|
| 458 | initializeAgeProsessor.Successor = incrEvaluatedSolutionsAfterReseeding;
|
---|
| 459 |
|
---|
[13124] | 460 | initializeAge.CollectedValues.Add(new ValueParameter<DoubleValue>(AgeParameter.Name, new DoubleValue(0)));
|
---|
[13111] | 461 |
|
---|
[13124] | 462 | incrEvaluatedSolutionsAfterReseeding.ValueParameter.ActualName = EvaluatedSolutionsParameter.Name;
|
---|
[13111] | 463 | incrEvaluatedSolutionsAfterReseeding.AccumulateParameter.Value = new BoolValue(true);
|
---|
| 464 |
|
---|
| 465 | return reseeder;
|
---|
| 466 | }
|
---|
[11580] | 467 | }
|
---|
| 468 | } |
---|