[11580] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[14185] | 3 | * Copyright (C) 2002-2016 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;
|
---|
| 29 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
[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.")]
|
---|
[11585] | 35 | [StorableClass]
|
---|
[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]
|
---|
[13402] | 136 | private AlpsOffspringSelectionGeneticAlgorithmMainLoop(bool deserializing)
|
---|
[11580] | 137 | : base(deserializing) { }
|
---|
[13402] | 138 | private AlpsOffspringSelectionGeneticAlgorithmMainLoop(AlpsOffspringSelectionGeneticAlgorithmMainLoop original, Cloner cloner)
|
---|
[11580] | 139 | : base(original, cloner) { }
|
---|
| 140 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
[13402] | 141 | return new AlpsOffspringSelectionGeneticAlgorithmMainLoop(this, cloner);
|
---|
[11580] | 142 | }
|
---|
[13402] | 143 | public AlpsOffspringSelectionGeneticAlgorithmMainLoop()
|
---|
[11580] | 144 | : base() {
|
---|
[13124] | 145 | Parameters.Add(new ValueLookupParameter<IRandom>("GlobalRandom", "A pseudo random number generator."));
|
---|
| 146 | Parameters.Add(new ValueLookupParameter<IRandom>("LocalRandom", "A pseudo random number generator."));
|
---|
| 147 |
|
---|
| 148 | 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."));
|
---|
| 149 | Parameters.Add(new ValueLookupParameter<IntValue>("EvaluatedSolutions", "The number of times solutions have been evaluated."));
|
---|
[12045] | 150 | Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution."));
|
---|
[13124] | 151 | Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
|
---|
[11580] | 152 |
|
---|
[13128] | 153 | Parameters.Add(new ValueLookupParameter<IOperator>("Analyzer", "The operator used to analyze all individuals from all layers combined."));
|
---|
[13124] | 154 | Parameters.Add(new ValueLookupParameter<IOperator>("LayerAnalyzer", "The operator used to analyze each layer."));
|
---|
| 155 |
|
---|
| 156 | Parameters.Add(new ValueLookupParameter<IntValue>("NumberOfLayers", "The number of layers."));
|
---|
[13206] | 157 | Parameters.Add(new ValueLookupParameter<IntValue>("PopulationSize", "The size of the population of solutions in each layer."));
|
---|
[13124] | 158 | Parameters.Add(new LookupParameter<IntValue>("CurrentPopulationSize", "The current size of the population."));
|
---|
| 159 |
|
---|
| 160 | Parameters.Add(new ValueLookupParameter<IOperator>("Selector", "The operator used to select solutions for reproduction."));
|
---|
| 161 | Parameters.Add(new ValueLookupParameter<IOperator>("Crossover", "The operator used to cross solutions."));
|
---|
| 162 | Parameters.Add(new ValueLookupParameter<IOperator>("Mutator", "The operator used to mutate solutions."));
|
---|
| 163 | Parameters.Add(new ValueLookupParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution."));
|
---|
| 164 | Parameters.Add(new ValueLookupParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation."));
|
---|
| 165 | Parameters.Add(new ValueLookupParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)"));
|
---|
| 166 |
|
---|
[13402] | 167 | Parameters.Add(new ValueLookupParameter<DoubleValue>("SuccessRatio", "The ratio of successful to total children that should be achieved."));
|
---|
| 168 | 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]."));
|
---|
| 169 | Parameters.Add(new ValueLookupParameter<DoubleValue>("MaximumSelectionPressure", "The maximum selection pressure that terminates the algorithm."));
|
---|
| 170 | 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."));
|
---|
| 171 | 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."));
|
---|
| 172 |
|
---|
[13124] | 173 | Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Age", "The age of individuals."));
|
---|
[13127] | 174 | Parameters.Add(new ValueLookupParameter<IntValue>("AgeGap", "The frequency of reseeding the lowest layer and scaling factor for the age-limits for the layers."));
|
---|
[13124] | 175 | 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] | 176 | Parameters.Add(new ValueLookupParameter<IntArray>("AgeLimits", "The maximum age an individual is allowed to reach in a certain layer."));
|
---|
[13124] | 177 |
|
---|
| 178 | Parameters.Add(new ValueLookupParameter<IntValue>("MatingPoolRange", "The range of sub - populations used for creating a mating pool. (1 = current + previous sub-population)"));
|
---|
[13127] | 179 | Parameters.Add(new ValueLookupParameter<BoolValue>("ReduceToPopulationSize", "Reduce the CurrentPopulationSize after elder migration to PopulationSize"));
|
---|
[13124] | 180 |
|
---|
[13127] | 181 | Parameters.Add(new ValueLookupParameter<IOperator>("Terminator", "The termination criteria that defines if the algorithm should continue or stop"));
|
---|
[13124] | 182 |
|
---|
[13127] | 183 |
|
---|
[11580] | 184 | var variableCreator = new VariableCreator() { Name = "Initialize" };
|
---|
| 185 | var initLayerAnalyzerProcessor = new SubScopesProcessor();
|
---|
[11590] | 186 | var layerVariableCreator = new VariableCreator() { Name = "Initialize Layer" };
|
---|
[11580] | 187 | var initLayerAnalyzerPlaceholder = new Placeholder() { Name = "LayerAnalyzer (Placeholder)" };
|
---|
[13402] | 188 | var layerResultCollector = new ResultsCollector() { Name = "Collect layer results" };
|
---|
[11609] | 189 | var initAnalyzerPlaceholder = new Placeholder() { Name = "Analyzer (Placeholder)" };
|
---|
| 190 | var resultsCollector = new ResultsCollector();
|
---|
[11583] | 191 | var matingPoolCreator = new MatingPoolCreator() { Name = "Create Mating Pools" };
|
---|
[13113] | 192 | var matingPoolProcessor = new UniformSubScopesProcessor() { Name = "Process Mating Pools" };
|
---|
[11590] | 193 | var initializeLayer = new Assigner() { Name = "Reset LayerEvaluatedSolutions" };
|
---|
[13402] | 194 | var mainOperator = new AlpsOffspringSelectionGeneticAlgorithmMainOperator();
|
---|
[11583] | 195 | var generationsIcrementor = new IntCounter() { Name = "Increment Generations" };
|
---|
| 196 | var evaluatedSolutionsReducer = new DataReducer() { Name = "Increment EvaluatedSolutions" };
|
---|
[13111] | 197 | var eldersEmigrator = CreateEldersEmigrator();
|
---|
| 198 | var layerOpener = CreateLayerOpener();
|
---|
| 199 | var layerReseeder = CreateReseeder();
|
---|
[12992] | 200 | var layerAnalyzerProcessor = new UniformSubScopesProcessor();
|
---|
[12197] | 201 | var layerAnalyzerPlaceholder = new Placeholder() { Name = "LayerAnalyzer (Placeholder)" };
|
---|
[11580] | 202 | var analyzerPlaceholder = new Placeholder() { Name = "Analyzer (Placeholder)" };
|
---|
[12531] | 203 | var termination = new TerminationOperator();
|
---|
[11580] | 204 |
|
---|
| 205 | OperatorGraph.InitialOperator = variableCreator;
|
---|
| 206 |
|
---|
| 207 | variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Generations", new IntValue(0)));
|
---|
[11586] | 208 | variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("OpenLayers", new IntValue(1)));
|
---|
[11609] | 209 | variableCreator.Successor = initLayerAnalyzerProcessor;
|
---|
[11580] | 210 |
|
---|
[11590] | 211 | initLayerAnalyzerProcessor.Operators.Add(layerVariableCreator);
|
---|
[11609] | 212 | initLayerAnalyzerProcessor.Successor = initAnalyzerPlaceholder;
|
---|
[11580] | 213 |
|
---|
[13127] | 214 | layerVariableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Layer", new IntValue(0)));
|
---|
[12071] | 215 | layerVariableCreator.CollectedValues.Add(new ValueParameter<ResultCollection>("LayerResults"));
|
---|
[13402] | 216 | layerVariableCreator.CollectedValues.Add(new ValueParameter<DoubleValue>("SelectionPressure", new DoubleValue(0)));
|
---|
| 217 | layerVariableCreator.CollectedValues.Add(new ValueParameter<DoubleValue>("CurrentSuccessRatio", new DoubleValue(0)));
|
---|
[11590] | 218 | layerVariableCreator.Successor = initLayerAnalyzerPlaceholder;
|
---|
| 219 |
|
---|
[11580] | 220 | initLayerAnalyzerPlaceholder.OperatorParameter.ActualName = LayerAnalyzerParameter.Name;
|
---|
[13402] | 221 | initLayerAnalyzerPlaceholder.Successor = layerResultCollector;
|
---|
[11580] | 222 |
|
---|
[13402] | 223 | layerResultCollector.ResultsParameter.ActualName = "LayerResults";
|
---|
| 224 | layerResultCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Selection Pressure", "Displays the rising selection pressure during a generation.", "SelectionPressure"));
|
---|
| 225 | 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"));
|
---|
| 226 | layerResultCollector.Successor = null;
|
---|
| 227 |
|
---|
[11609] | 228 | initAnalyzerPlaceholder.OperatorParameter.ActualName = AnalyzerParameter.Name;
|
---|
| 229 | initAnalyzerPlaceholder.Successor = resultsCollector;
|
---|
| 230 |
|
---|
| 231 | resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Generations"));
|
---|
[13124] | 232 | resultsCollector.CollectedValues.Add(new ScopeTreeLookupParameter<ResultCollection>("LayerResults", "Result set for each Layer", "LayerResults"));
|
---|
[11609] | 233 | resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("OpenLayers"));
|
---|
| 234 | resultsCollector.CopyValue = new BoolValue(false);
|
---|
[13031] | 235 | resultsCollector.Successor = matingPoolCreator;
|
---|
[11609] | 236 |
|
---|
[13124] | 237 | matingPoolCreator.MatingPoolRangeParameter.Value = null;
|
---|
| 238 | matingPoolCreator.MatingPoolRangeParameter.ActualName = MatingPoolRangeParameter.Name;
|
---|
[11580] | 239 | matingPoolCreator.Successor = matingPoolProcessor;
|
---|
| 240 |
|
---|
| 241 | matingPoolProcessor.Parallel.Value = true;
|
---|
[11590] | 242 | matingPoolProcessor.Operator = initializeLayer;
|
---|
[11583] | 243 | matingPoolProcessor.Successor = generationsIcrementor;
|
---|
[11580] | 244 |
|
---|
[11590] | 245 | initializeLayer.LeftSideParameter.ActualName = "LayerEvaluatedSolutions";
|
---|
| 246 | initializeLayer.RightSideParameter.Value = new IntValue(0);
|
---|
| 247 | initializeLayer.Successor = mainOperator;
|
---|
| 248 |
|
---|
[13124] | 249 | mainOperator.RandomParameter.ActualName = LocalRandomParameter.Name;
|
---|
| 250 | mainOperator.EvaluatorParameter.ActualName = EvaluatorParameter.Name;
|
---|
| 251 | mainOperator.EvaluatedSolutionsParameter.ActualName = "LayerEvaluatedSolutions";
|
---|
| 252 | mainOperator.QualityParameter.ActualName = QualityParameter.Name;
|
---|
| 253 | mainOperator.MaximizationParameter.ActualName = MaximizationParameter.Name;
|
---|
| 254 | mainOperator.PopulationSizeParameter.ActualName = PopulationSizeParameter.Name;
|
---|
| 255 | mainOperator.SelectorParameter.ActualName = SelectorParameter.Name;
|
---|
| 256 | mainOperator.CrossoverParameter.ActualName = CrossoverParameter.Name;
|
---|
| 257 | mainOperator.MutatorParameter.ActualName = MutatorParameter.ActualName;
|
---|
| 258 | mainOperator.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
|
---|
| 259 | mainOperator.ElitesParameter.ActualName = ElitesParameter.Name;
|
---|
| 260 | mainOperator.ReevaluateElitesParameter.ActualName = ReevaluateElitesParameter.Name;
|
---|
[13402] | 261 | mainOperator.ComparisonFactorParameter.ActualName = ComparisonFactorParameter.Name;
|
---|
| 262 | mainOperator.SuccessRatioParameter.ActualName = SuccessRatioParameter.Name;
|
---|
| 263 | mainOperator.CurrentSuccessRatioParameter.ActualName = "CurrentSuccessRatio";
|
---|
| 264 | mainOperator.SelectionPressureParameter.ActualName = "SelectionPressure";
|
---|
| 265 | mainOperator.MaximumSelectionPressureParameter.ActualName = MaximumSelectionPressureParameter.Name;
|
---|
| 266 | mainOperator.OffspringSelectionBeforeMutationParameter.ActualName = OffspringSelectionBeforeMutationParameter.Name;
|
---|
| 267 | mainOperator.FillPopulationWithParentsParameter.ActualName = FillPopulationWithParentsParameter.Name;
|
---|
[13124] | 268 | mainOperator.AgeParameter.ActualName = AgeParameter.Name;
|
---|
| 269 | mainOperator.AgeInheritanceParameter.ActualName = AgeInheritanceParameter.Name;
|
---|
| 270 | mainOperator.AgeIncrementParameter.Value = new DoubleValue(1.0);
|
---|
| 271 | mainOperator.Successor = null;
|
---|
| 272 |
|
---|
[11583] | 273 | generationsIcrementor.ValueParameter.ActualName = "Generations";
|
---|
| 274 | generationsIcrementor.Increment = new IntValue(1);
|
---|
| 275 | generationsIcrementor.Successor = evaluatedSolutionsReducer;
|
---|
| 276 |
|
---|
[11676] | 277 | evaluatedSolutionsReducer.ParameterToReduce.ActualName = "LayerEvaluatedSolutions";
|
---|
[13124] | 278 | evaluatedSolutionsReducer.TargetParameter.ActualName = EvaluatedSolutionsParameter.Name;
|
---|
[11583] | 279 | evaluatedSolutionsReducer.ReductionOperation.Value = new ReductionOperation(ReductionOperations.Sum);
|
---|
| 280 | evaluatedSolutionsReducer.TargetOperation.Value = new ReductionOperation(ReductionOperations.Sum);
|
---|
| 281 | evaluatedSolutionsReducer.Successor = eldersEmigrator;
|
---|
| 282 |
|
---|
[13095] | 283 | eldersEmigrator.Successor = layerOpener;
|
---|
[11580] | 284 |
|
---|
[13095] | 285 | layerOpener.Successor = layerReseeder;
|
---|
[11580] | 286 |
|
---|
[13095] | 287 | layerReseeder.Successor = layerAnalyzerProcessor;
|
---|
| 288 |
|
---|
[12197] | 289 | layerAnalyzerProcessor.Operator = layerAnalyzerPlaceholder;
|
---|
| 290 | layerAnalyzerProcessor.Successor = analyzerPlaceholder;
|
---|
[11580] | 291 |
|
---|
[12197] | 292 | layerAnalyzerPlaceholder.OperatorParameter.ActualName = LayerAnalyzerParameter.Name;
|
---|
[11580] | 293 |
|
---|
| 294 | analyzerPlaceholder.OperatorParameter.ActualName = AnalyzerParameter.Name;
|
---|
[12531] | 295 | analyzerPlaceholder.Successor = termination;
|
---|
[11580] | 296 |
|
---|
[13127] | 297 | termination.TerminatorParameter.ActualName = TerminatorParameter.Name;
|
---|
[13031] | 298 | termination.ContinueBranch = matingPoolCreator;
|
---|
[11583] | 299 | }
|
---|
[13111] | 300 |
|
---|
[13124] | 301 | private CombinedOperator CreateEldersEmigrator() {
|
---|
[13111] | 302 | var eldersEmigrator = new CombinedOperator() { Name = "Emigrate Elders" };
|
---|
| 303 | var selectorProsessor = new UniformSubScopesProcessor();
|
---|
| 304 | var eldersSelector = new EldersSelector();
|
---|
[13206] | 305 | var shiftToRightMigrator = new UnidirectionalRingMigrator() { Name = "Shift elders to next layer" };
|
---|
[13111] | 306 | var mergingProsessor = new UniformSubScopesProcessor();
|
---|
| 307 | var mergingReducer = new MergingReducer();
|
---|
| 308 | var subScopesCounter = new SubScopesCounter();
|
---|
[13117] | 309 | var reduceToPopulationSizeBranch = new ConditionalBranch() { Name = "ReduceToPopulationSize?" };
|
---|
[13124] | 310 | var countCalculator = new ExpressionCalculator() { Name = "CurrentPopulationSize = Min(CurrentPopulationSize, PopulationSize)" };
|
---|
[13111] | 311 | var bestSelector = new BestSelector();
|
---|
| 312 | var rightReducer = new RightReducer();
|
---|
| 313 |
|
---|
| 314 | eldersEmigrator.OperatorGraph.InitialOperator = selectorProsessor;
|
---|
| 315 |
|
---|
| 316 | selectorProsessor.Operator = eldersSelector;
|
---|
| 317 | selectorProsessor.Successor = shiftToRightMigrator;
|
---|
| 318 |
|
---|
[13127] | 319 | eldersSelector.AgeParameter.ActualName = AgeParameter.Name;
|
---|
| 320 | eldersSelector.AgeLimitsParameter.ActualName = AgeLimitsParameter.Name;
|
---|
| 321 | eldersSelector.NumberOfLayersParameter.ActualName = NumberOfLayersParameter.Name;
|
---|
| 322 | eldersSelector.LayerParameter.ActualName = "Layer";
|
---|
| 323 | eldersSelector.Successor = null;
|
---|
| 324 |
|
---|
[13111] | 325 | shiftToRightMigrator.ClockwiseMigrationParameter.Value = new BoolValue(true);
|
---|
| 326 | shiftToRightMigrator.Successor = mergingProsessor;
|
---|
| 327 |
|
---|
| 328 | mergingProsessor.Operator = mergingReducer;
|
---|
| 329 |
|
---|
| 330 | mergingReducer.Successor = subScopesCounter;
|
---|
| 331 |
|
---|
[13124] | 332 | subScopesCounter.ValueParameter.ActualName = CurrentPopulationSizeParameter.Name;
|
---|
[13111] | 333 | subScopesCounter.AccumulateParameter.Value = new BoolValue(false);
|
---|
[13117] | 334 | subScopesCounter.Successor = reduceToPopulationSizeBranch;
|
---|
[13111] | 335 |
|
---|
[13124] | 336 | reduceToPopulationSizeBranch.ConditionParameter.ActualName = ReduceToPopulationSizeParameter.Name;
|
---|
[13117] | 337 | reduceToPopulationSizeBranch.TrueBranch = countCalculator;
|
---|
| 338 |
|
---|
[13124] | 339 | countCalculator.CollectedValues.Add(new LookupParameter<IntValue>(PopulationSizeParameter.Name));
|
---|
| 340 | countCalculator.CollectedValues.Add(new LookupParameter<IntValue>(CurrentPopulationSizeParameter.Name));
|
---|
| 341 | countCalculator.ExpressionParameter.Value = new StringValue("CurrentPopulationSize PopulationSize CurrentPopulationSize PopulationSize < if toint");
|
---|
| 342 | countCalculator.ExpressionResultParameter.ActualName = CurrentPopulationSizeParameter.Name;
|
---|
[13111] | 343 | countCalculator.Successor = bestSelector;
|
---|
| 344 |
|
---|
[13124] | 345 | bestSelector.NumberOfSelectedSubScopesParameter.ActualName = CurrentPopulationSizeParameter.Name;
|
---|
[13111] | 346 | bestSelector.CopySelected = new BoolValue(false);
|
---|
| 347 | bestSelector.Successor = rightReducer;
|
---|
| 348 |
|
---|
| 349 | return eldersEmigrator;
|
---|
| 350 | }
|
---|
| 351 |
|
---|
[13124] | 352 | private CombinedOperator CreateLayerOpener() {
|
---|
[13111] | 353 | var layerOpener = new CombinedOperator() { Name = "Open new Layer if needed" };
|
---|
| 354 | var maxLayerReached = new Comparator() { Name = "MaxLayersReached = OpenLayers >= NumberOfLayers" };
|
---|
| 355 | var maxLayerReachedBranch = new ConditionalBranch() { Name = "MaxLayersReached?" };
|
---|
| 356 | var openNewLayerCalculator = new ExpressionCalculator() { Name = "OpenNewLayer = Generations >= AgeLimits[OpenLayers - 1]" };
|
---|
| 357 | var openNewLayerBranch = new ConditionalBranch() { Name = "OpenNewLayer?" };
|
---|
[13206] | 358 | var layerCreator = new LastLayerCloner() { Name = "Create Layer" };
|
---|
[13124] | 359 | var updateLayerNumber = new Assigner() { Name = "Layer = OpenLayers" };
|
---|
| 360 | var historyWiper = new ResultsHistoryWiper() { Name = "Clear History in Results" };
|
---|
[13402] | 361 | var createChildrenViaCrossover = new AlpsOffspringSelectionGeneticAlgorithmMainOperator();
|
---|
[13111] | 362 | var incrEvaluatedSolutionsForNewLayer = new SubScopesCounter() { Name = "Update EvaluatedSolutions" };
|
---|
| 363 | var incrOpenLayers = new IntCounter() { Name = "Incr. OpenLayers" };
|
---|
| 364 | var newLayerResultsCollector = new ResultsCollector() { Name = "Collect new Layer Results" };
|
---|
| 365 |
|
---|
| 366 | layerOpener.OperatorGraph.InitialOperator = maxLayerReached;
|
---|
| 367 |
|
---|
| 368 | maxLayerReached.LeftSideParameter.ActualName = "OpenLayers";
|
---|
[13124] | 369 | maxLayerReached.RightSideParameter.ActualName = NumberOfLayersParameter.Name;
|
---|
[13111] | 370 | maxLayerReached.ResultParameter.ActualName = "MaxLayerReached";
|
---|
| 371 | maxLayerReached.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
|
---|
| 372 | maxLayerReached.Successor = maxLayerReachedBranch;
|
---|
| 373 |
|
---|
| 374 | maxLayerReachedBranch.ConditionParameter.ActualName = "MaxLayerReached";
|
---|
| 375 | maxLayerReachedBranch.FalseBranch = openNewLayerCalculator;
|
---|
| 376 |
|
---|
[13124] | 377 | openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntArray>(AgeLimitsParameter.Name));
|
---|
[13111] | 378 | openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntValue>("Generations"));
|
---|
[13124] | 379 | openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntValue>(NumberOfLayersParameter.Name));
|
---|
[13111] | 380 | openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntValue>("OpenLayers"));
|
---|
| 381 | openNewLayerCalculator.ExpressionResultParameter.ActualName = "OpenNewLayer";
|
---|
| 382 | openNewLayerCalculator.ExpressionParameter.Value = new StringValue("Generations 1 + AgeLimits OpenLayers 1 - [] >");
|
---|
| 383 | openNewLayerCalculator.Successor = openNewLayerBranch;
|
---|
| 384 |
|
---|
| 385 | openNewLayerBranch.ConditionParameter.ActualName = "OpenNewLayer";
|
---|
| 386 | openNewLayerBranch.TrueBranch = layerCreator;
|
---|
| 387 |
|
---|
[13206] | 388 | layerCreator.NewLayerOperator = updateLayerNumber;
|
---|
[13111] | 389 | layerCreator.Successor = incrOpenLayers;
|
---|
| 390 |
|
---|
[13124] | 391 | updateLayerNumber.LeftSideParameter.ActualName = "Layer";
|
---|
| 392 | updateLayerNumber.RightSideParameter.ActualName = "OpenLayers";
|
---|
| 393 | updateLayerNumber.Successor = historyWiper;
|
---|
| 394 |
|
---|
| 395 | historyWiper.ResultsParameter.ActualName = "LayerResults";
|
---|
| 396 | historyWiper.Successor = createChildrenViaCrossover;
|
---|
| 397 |
|
---|
| 398 | // Maybe use only crossover and no elitism instead of "default operator"
|
---|
| 399 | createChildrenViaCrossover.RandomParameter.ActualName = LocalRandomParameter.Name;
|
---|
| 400 | createChildrenViaCrossover.EvaluatorParameter.ActualName = EvaluatorParameter.Name;
|
---|
| 401 | createChildrenViaCrossover.EvaluatedSolutionsParameter.ActualName = "LayerEvaluatedSolutions";
|
---|
| 402 | createChildrenViaCrossover.QualityParameter.ActualName = QualityParameter.Name;
|
---|
| 403 | createChildrenViaCrossover.MaximizationParameter.ActualName = MaximizationParameter.Name;
|
---|
| 404 | createChildrenViaCrossover.PopulationSizeParameter.ActualName = PopulationSizeParameter.Name;
|
---|
| 405 | createChildrenViaCrossover.SelectorParameter.ActualName = SelectorParameter.Name;
|
---|
| 406 | createChildrenViaCrossover.CrossoverParameter.ActualName = CrossoverParameter.Name;
|
---|
[13402] | 407 | createChildrenViaCrossover.MutatorParameter.ActualName = MutatorParameter.ActualName;
|
---|
[13124] | 408 | createChildrenViaCrossover.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
|
---|
| 409 | createChildrenViaCrossover.ElitesParameter.ActualName = ElitesParameter.Name;
|
---|
| 410 | createChildrenViaCrossover.ReevaluateElitesParameter.ActualName = ReevaluateElitesParameter.Name;
|
---|
[13402] | 411 | createChildrenViaCrossover.ComparisonFactorParameter.ActualName = ComparisonFactorParameter.Name;
|
---|
| 412 | createChildrenViaCrossover.SuccessRatioParameter.ActualName = SuccessRatioParameter.Name;
|
---|
| 413 | createChildrenViaCrossover.CurrentSuccessRatioParameter.ActualName = "CurrentSuccessRatio";
|
---|
| 414 | createChildrenViaCrossover.SelectionPressureParameter.ActualName = "SelectionPressure";
|
---|
| 415 | createChildrenViaCrossover.MaximumSelectionPressureParameter.ActualName = MaximumSelectionPressureParameter.Name;
|
---|
| 416 | createChildrenViaCrossover.OffspringSelectionBeforeMutationParameter.ActualName = OffspringSelectionBeforeMutationParameter.Name;
|
---|
| 417 | createChildrenViaCrossover.FillPopulationWithParentsParameter.ActualName = FillPopulationWithParentsParameter.Name;
|
---|
[13124] | 418 | createChildrenViaCrossover.AgeParameter.ActualName = AgeParameter.Name;
|
---|
| 419 | createChildrenViaCrossover.AgeInheritanceParameter.ActualName = AgeInheritanceParameter.Name;
|
---|
| 420 | createChildrenViaCrossover.AgeIncrementParameter.Value = new DoubleValue(0.0);
|
---|
[13111] | 421 | createChildrenViaCrossover.Successor = incrEvaluatedSolutionsForNewLayer;
|
---|
| 422 |
|
---|
[13124] | 423 | incrEvaluatedSolutionsForNewLayer.ValueParameter.ActualName = EvaluatedSolutionsParameter.Name;
|
---|
[13111] | 424 | incrEvaluatedSolutionsForNewLayer.AccumulateParameter.Value = new BoolValue(true);
|
---|
| 425 |
|
---|
| 426 | incrOpenLayers.ValueParameter.ActualName = "OpenLayers";
|
---|
| 427 | incrOpenLayers.Increment = new IntValue(1);
|
---|
| 428 | incrOpenLayers.Successor = newLayerResultsCollector;
|
---|
| 429 |
|
---|
| 430 | newLayerResultsCollector.CollectedValues.Add(new ScopeTreeLookupParameter<ResultCollection>("LayerResults", "Result set for each layer", "LayerResults"));
|
---|
| 431 | newLayerResultsCollector.CopyValue = new BoolValue(false);
|
---|
| 432 | newLayerResultsCollector.Successor = null;
|
---|
| 433 |
|
---|
| 434 | return layerOpener;
|
---|
| 435 | }
|
---|
| 436 |
|
---|
[13124] | 437 | private CombinedOperator CreateReseeder() {
|
---|
[13111] | 438 | var reseeder = new CombinedOperator() { Name = "Reseed Layer Zero if needed" };
|
---|
| 439 | var reseedingController = new ReseedingController() { Name = "Reseeding needed (Generation % AgeGap == 0)?" };
|
---|
| 440 | var removeIndividuals = new SubScopesRemover();
|
---|
| 441 | var createIndividuals = new SolutionsCreator();
|
---|
| 442 | var initializeAgeProsessor = new UniformSubScopesProcessor();
|
---|
| 443 | var initializeAge = new VariableCreator() { Name = "Initialize Age" };
|
---|
| 444 | var incrEvaluatedSolutionsAfterReseeding = new SubScopesCounter() { Name = "Update EvaluatedSolutions" };
|
---|
| 445 |
|
---|
| 446 | reseeder.OperatorGraph.InitialOperator = reseedingController;
|
---|
| 447 |
|
---|
[13127] | 448 | reseedingController.GenerationsParameter.ActualName = "Generations";
|
---|
| 449 | reseedingController.AgeGapParameter.ActualName = AgeGapParameter.Name;
|
---|
[13111] | 450 | reseedingController.FirstLayerOperator = removeIndividuals;
|
---|
[13127] | 451 | reseedingController.Successor = null;
|
---|
[13111] | 452 |
|
---|
| 453 | removeIndividuals.Successor = createIndividuals;
|
---|
| 454 |
|
---|
[13124] | 455 | createIndividuals.NumberOfSolutionsParameter.ActualName = PopulationSizeParameter.Name;
|
---|
[13111] | 456 | createIndividuals.Successor = initializeAgeProsessor;
|
---|
| 457 |
|
---|
| 458 | initializeAgeProsessor.Operator = initializeAge;
|
---|
| 459 | initializeAgeProsessor.Successor = incrEvaluatedSolutionsAfterReseeding;
|
---|
| 460 |
|
---|
[13124] | 461 | initializeAge.CollectedValues.Add(new ValueParameter<DoubleValue>(AgeParameter.Name, new DoubleValue(0)));
|
---|
[13111] | 462 |
|
---|
[13124] | 463 | incrEvaluatedSolutionsAfterReseeding.ValueParameter.ActualName = EvaluatedSolutionsParameter.Name;
|
---|
[13111] | 464 | incrEvaluatedSolutionsAfterReseeding.AccumulateParameter.Value = new BoolValue(true);
|
---|
| 465 |
|
---|
| 466 | return reseeder;
|
---|
| 467 | }
|
---|
[11580] | 468 | }
|
---|
| 469 | } |
---|