[12119] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
[12534] | 23 | using System.Collections.Generic;
|
---|
[12120] | 24 | using System.Linq;
|
---|
[12119] | 25 | using HeuristicLab.Common;
|
---|
| 26 | using HeuristicLab.Core;
|
---|
| 27 | using HeuristicLab.Data;
|
---|
[12120] | 28 | using HeuristicLab.Operators;
|
---|
[12119] | 29 | using HeuristicLab.Optimization;
|
---|
[12120] | 30 | using HeuristicLab.Optimization.Operators;
|
---|
[12119] | 31 | using HeuristicLab.Parameters;
|
---|
| 32 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
[12120] | 33 | using HeuristicLab.PluginInfrastructure;
|
---|
| 34 | using HeuristicLab.Random;
|
---|
| 35 | using HeuristicLab.Selection;
|
---|
[12119] | 36 |
|
---|
| 37 | namespace HeuristicLab.Algorithms.ALPS.SteadyState {
|
---|
| 38 | [Item("ALPS Steady-State Genetic Algorithm", "A genetic algorithmn with a steady-state age-layered population structure")]
|
---|
| 39 | [Creatable("Algorithms")]
|
---|
| 40 | [StorableClass]
|
---|
[12571] | 41 | public sealed class AlpsSsGeneticAlgorithm : Alps {
|
---|
[12119] | 42 | #region Parameter Properties
|
---|
[12153] | 43 | private IValueParameter<IntValue> LayerSizeParameter {
|
---|
| 44 | get { return (IValueParameter<IntValue>)Parameters["LayerSize"]; }
|
---|
[12120] | 45 | }
|
---|
| 46 | public IConstrainedValueParameter<ISelector> SelectorParameter {
|
---|
| 47 | get { return (IConstrainedValueParameter<ISelector>)Parameters["Selector"]; }
|
---|
| 48 | }
|
---|
| 49 | public IConstrainedValueParameter<ICrossover> CrossoverParameter {
|
---|
| 50 | get { return (IConstrainedValueParameter<ICrossover>)Parameters["Crossover"]; }
|
---|
| 51 | }
|
---|
| 52 | private IValueParameter<PercentValue> MutationProbabilityParameter {
|
---|
| 53 | get { return (IValueParameter<PercentValue>)Parameters["MutationProbability"]; }
|
---|
| 54 | }
|
---|
| 55 | public IConstrainedValueParameter<IManipulator> MutatorParameter {
|
---|
| 56 | get { return (IConstrainedValueParameter<IManipulator>)Parameters["Mutator"]; }
|
---|
| 57 | }
|
---|
| 58 | private IValueParameter<IntValue> ElitesParameter {
|
---|
| 59 | get { return (IValueParameter<IntValue>)Parameters["Elites"]; }
|
---|
| 60 | }
|
---|
| 61 | private IFixedValueParameter<BoolValue> ReevaluateElitesParameter {
|
---|
| 62 | get { return (IFixedValueParameter<BoolValue>)Parameters["ReevaluateElites"]; }
|
---|
| 63 | }
|
---|
[12192] | 64 | private IValueParameter<IntValue> BatchSizeParameter {
|
---|
| 65 | get { return (IValueParameter<IntValue>)Parameters["BatchSize"]; }
|
---|
| 66 | }
|
---|
[12119] | 67 | #endregion
|
---|
| 68 |
|
---|
| 69 | #region Properties
|
---|
[12153] | 70 | public IntValue LayerSize {
|
---|
| 71 | get { return LayerSizeParameter.Value; }
|
---|
| 72 | set { LayerSizeParameter.Value = value; }
|
---|
[12120] | 73 | }
|
---|
[12534] | 74 | public int MaximumIterations {
|
---|
| 75 | get { return iterationsTerminator.Threshold.Value; }
|
---|
| 76 | set { iterationsTerminator.Threshold.Value = value; }
|
---|
[12120] | 77 | }
|
---|
| 78 |
|
---|
| 79 | public ISelector Selector {
|
---|
| 80 | get { return SelectorParameter.Value; }
|
---|
| 81 | set { SelectorParameter.Value = value; }
|
---|
| 82 | }
|
---|
| 83 | public ICrossover Crossover {
|
---|
| 84 | get { return CrossoverParameter.Value; }
|
---|
| 85 | set { CrossoverParameter.Value = value; }
|
---|
| 86 | }
|
---|
| 87 | public PercentValue MutationProbability {
|
---|
| 88 | get { return MutationProbabilityParameter.Value; }
|
---|
| 89 | set { MutationProbabilityParameter.Value = value; }
|
---|
| 90 | }
|
---|
| 91 | public IManipulator Mutator {
|
---|
| 92 | get { return MutatorParameter.Value; }
|
---|
| 93 | set { MutatorParameter.Value = value; }
|
---|
| 94 | }
|
---|
| 95 | public IntValue Elites {
|
---|
| 96 | get { return ElitesParameter.Value; }
|
---|
| 97 | set { ElitesParameter.Value = value; }
|
---|
| 98 | }
|
---|
| 99 | public bool ReevaluteElites {
|
---|
| 100 | get { return ReevaluateElitesParameter.Value.Value; }
|
---|
| 101 | set { ReevaluateElitesParameter.Value.Value = value; }
|
---|
| 102 | }
|
---|
[12119] | 103 | #endregion
|
---|
| 104 |
|
---|
[12138] | 105 | private AlpsSsGeneticAlgorithmMainLoop MainLoop {
|
---|
| 106 | get { return OperatorGraph.Iterate().OfType<AlpsSsGeneticAlgorithmMainLoop>().First(); }
|
---|
| 107 | }
|
---|
| 108 |
|
---|
[12534] | 109 | [Storable]
|
---|
| 110 | private ComparisonTerminator<IntValue> iterationsTerminator;
|
---|
| 111 |
|
---|
[12119] | 112 | [StorableConstructor]
|
---|
| 113 | private AlpsSsGeneticAlgorithm(bool deserializing)
|
---|
| 114 | : base(deserializing) { }
|
---|
[12571] | 115 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 116 | private void AfterDeserialization() {
|
---|
| 117 | Initialize();
|
---|
| 118 | }
|
---|
[12119] | 119 | private AlpsSsGeneticAlgorithm(AlpsSsGeneticAlgorithm original, Cloner cloner)
|
---|
| 120 | : base(original, cloner) {
|
---|
[12534] | 121 | iterationsTerminator = cloner.Clone(original.iterationsTerminator);
|
---|
[12119] | 122 | Initialize();
|
---|
| 123 | }
|
---|
| 124 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 125 | return new AlpsSsGeneticAlgorithm(this, cloner);
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 | public AlpsSsGeneticAlgorithm()
|
---|
| 129 | : base() {
|
---|
[12153] | 130 | Parameters.Add(new ValueParameter<IntValue>("LayerSize", "The size of the population of solutions each layer.", new IntValue(100)));
|
---|
[12120] | 131 | Parameters.Add(new ConstrainedValueParameter<ISelector>("Selector", "The operator used to select solutions for reproduction."));
|
---|
| 132 | Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions."));
|
---|
| 133 | Parameters.Add(new ValueParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution.", new PercentValue(0.05)));
|
---|
| 134 | Parameters.Add(new OptionalConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions."));
|
---|
| 135 | Parameters.Add(new ValueParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.", new IntValue(1)));
|
---|
| 136 | 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 });
|
---|
[12192] | 137 | Parameters.Add(new ValueParameter<IntValue>("BatchSize", "Number of inner iterations before updates and analyzers are fired.", new IntValue(100)) { Hidden = true });
|
---|
[12119] | 138 |
|
---|
[12120] | 139 | var randomCreator = new RandomCreator();
|
---|
[12220] | 140 | var workingScopeCreator = new NamedSubScopesCreator() { Name = "Create Working- and Layers-Scope" };
|
---|
[12157] | 141 | var layersProcessor = new NamedSubScopeProcessor() { Name = "Process Layers-Scope" };
|
---|
[12220] | 142 | var layerCreator = new SubScopesCreator() { Name = "Create Layers" };
|
---|
| 143 | var layerProcessor = new UniformSubScopesProcessor();
|
---|
[12153] | 144 | var layerVariableCreator = new VariableCreator() { Name = "Initialize Layer" };
|
---|
[12159] | 145 | var layerNumberCreator = new ScopeIndexAssigner() { Name = "Create Layer Number" };
|
---|
[12153] | 146 | var layerSolutionsCreator = new SolutionsCreator();
|
---|
[12120] | 147 | var initializeAgeProcessor = new UniformSubScopesProcessor();
|
---|
| 148 | var initializeAge = new VariableCreator() { Name = "Initialize Age" };
|
---|
[12270] | 149 | var initializeLocalEvaluatedSolutions = new ExpressionCalculator() { Name = "Initialize local EvaluatedSolutions" };
|
---|
| 150 | var initializeEvaluatedSolutions = new Assigner() { Name = "Initialize EvaluatedSolutions" };
|
---|
[12153] | 151 | var initializePopulationSize = new Assigner() { Name = "Initialize PopulationSize" };
|
---|
[12120] | 152 | var resultsCollector = new ResultsCollector();
|
---|
| 153 | var mainLoop = new AlpsSsGeneticAlgorithmMainLoop();
|
---|
[12119] | 154 |
|
---|
[12120] | 155 | OperatorGraph.InitialOperator = randomCreator;
|
---|
| 156 |
|
---|
| 157 | randomCreator.SeedParameter.Value = null;
|
---|
| 158 | randomCreator.SetSeedRandomlyParameter.Value = null;
|
---|
[12153] | 159 | randomCreator.Successor = workingScopeCreator;
|
---|
[12120] | 160 |
|
---|
[12270] | 161 | workingScopeCreator.NamesParameter.Value = new StringArray(new[] { "WorkingScope", "LayersScope", });
|
---|
[12153] | 162 | workingScopeCreator.Successor = layersProcessor;
|
---|
[12120] | 163 |
|
---|
[12220] | 164 | layersProcessor.TargetScopeParameter.ActualName = "LayersScope";
|
---|
[12157] | 165 | layersProcessor.Operator = layerCreator;
|
---|
[12270] | 166 | layersProcessor.Successor = initializeLocalEvaluatedSolutions;
|
---|
[12120] | 167 |
|
---|
[12153] | 168 | layerCreator.NumberOfSubScopesParameter.ActualName = "NumberOfLayers";
|
---|
| 169 | layerCreator.NumberOfSubScopesParameter.Value = null;
|
---|
| 170 | layerCreator.Successor = layerProcessor;
|
---|
[12120] | 171 |
|
---|
[12153] | 172 | layerProcessor.Operator = layerVariableCreator;
|
---|
[12120] | 173 |
|
---|
[12153] | 174 | layerVariableCreator.CollectedValues.Add(new ValueParameter<ResultCollection>("LayerResults"));
|
---|
[12159] | 175 | layerVariableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Layer"));
|
---|
| 176 | layerVariableCreator.Successor = layerNumberCreator;
|
---|
[12153] | 177 |
|
---|
[12159] | 178 | layerNumberCreator.ValueParameter.ActualName = "Layer";
|
---|
| 179 | layerNumberCreator.Successor = layerSolutionsCreator;
|
---|
| 180 |
|
---|
[12153] | 181 | layerSolutionsCreator.NumberOfSolutionsParameter.ActualName = LayerSizeParameter.Name;
|
---|
| 182 | layerSolutionsCreator.Successor = initializeAgeProcessor;
|
---|
| 183 |
|
---|
[12120] | 184 | initializeAgeProcessor.Operator = initializeAge;
|
---|
| 185 |
|
---|
[12138] | 186 | initializeAge.CollectedValues.Add(new ValueParameter<IntValue>("EvalsCreated", new IntValue(1)));
|
---|
[12153] | 187 | initializeAge.CollectedValues.Add(new ValueParameter<IntValue>("LastMove", new IntValue(1)));
|
---|
[12120] | 188 |
|
---|
[12270] | 189 | initializeLocalEvaluatedSolutions.ExpressionResultParameter.ActualName = "LocalEvaluatedSolutions";
|
---|
| 190 | initializeLocalEvaluatedSolutions.ExpressionParameter.Value = new StringValue("LayerSize NumberOfLayers * toint");
|
---|
| 191 | initializeLocalEvaluatedSolutions.CollectedValues.Add(new LookupParameter<IntValue>("LayerSize"));
|
---|
| 192 | initializeLocalEvaluatedSolutions.CollectedValues.Add(new LookupParameter<IntValue>("NumberOfLayers"));
|
---|
| 193 | initializeLocalEvaluatedSolutions.Successor = initializeEvaluatedSolutions;
|
---|
[12120] | 194 |
|
---|
[12270] | 195 | initializeEvaluatedSolutions.LeftSideParameter.ActualName = "EvaluatedSolutions";
|
---|
| 196 | initializeEvaluatedSolutions.RightSideParameter.ActualName = "LocalEvaluatedSolutions";
|
---|
| 197 | initializeEvaluatedSolutions.Successor = initializePopulationSize;
|
---|
[12192] | 198 |
|
---|
[12153] | 199 | initializePopulationSize.LeftSideParameter.ActualName = "PopulationSize";
|
---|
| 200 | initializePopulationSize.RightSideParameter.ActualName = "EvaluatedSolutions";
|
---|
| 201 | initializePopulationSize.Successor = resultsCollector;
|
---|
[12136] | 202 |
|
---|
[12270] | 203 | resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("EvaluatedSolutions"));
|
---|
[12220] | 204 | resultsCollector.CollectedValues.Add(new ScopeTreeLookupParameter<ResultCollection>("LayerResults", "Result set for each layer", "LayerResults", 2));
|
---|
[12120] | 205 | resultsCollector.Successor = mainLoop;
|
---|
| 206 |
|
---|
| 207 | foreach (var selector in ApplicationManager.Manager.GetInstances<ISelector>().Where(s => !(s is IMultiObjectiveSelector)).OrderBy(s => Name))
|
---|
| 208 | SelectorParameter.ValidValues.Add(selector);
|
---|
| 209 | var tournamentSelector = SelectorParameter.ValidValues.OfType<TournamentSelector>().FirstOrDefault();
|
---|
| 210 | if (tournamentSelector != null) {
|
---|
[12220] | 211 | tournamentSelector.GroupSizeParameter.Value = new IntValue(4);
|
---|
[12120] | 212 | SelectorParameter.Value = tournamentSelector;
|
---|
| 213 | }
|
---|
| 214 |
|
---|
[12549] | 215 | iterationsTerminator = new ComparisonTerminator<IntValue>("Iterations", ComparisonType.Less, new IntValue(1000)) { Name = "Iterations" };
|
---|
| 216 |
|
---|
[12120] | 217 | ParameterizeSelectors();
|
---|
[12549] | 218 | UpdateTerminators();
|
---|
| 219 |
|
---|
[12119] | 220 | Initialize();
|
---|
| 221 | }
|
---|
| 222 |
|
---|
| 223 | #region Events
|
---|
[12120] | 224 | protected override void OnProblemChanged() {
|
---|
| 225 | base.OnProblemChanged();
|
---|
| 226 | ParameterizeSolutionsCreator();
|
---|
| 227 | ParameterizeMainLoop();
|
---|
| 228 | ParameterizeSelectors();
|
---|
| 229 | ParameterizeIterationBasedOperators();
|
---|
| 230 | UpdateCrossovers();
|
---|
| 231 | UpdateMutators();
|
---|
[12549] | 232 | UpdateTerminators();
|
---|
[12120] | 233 | }
|
---|
| 234 | protected override void Problem_SolutionCreatorChanged(object sender, EventArgs e) {
|
---|
| 235 | base.Problem_SolutionCreatorChanged(sender, e);
|
---|
| 236 | ParameterizeSolutionsCreator();
|
---|
| 237 | }
|
---|
| 238 | protected override void Problem_EvaluatorChanged(object sender, EventArgs e) {
|
---|
| 239 | base.Problem_EvaluatorChanged(sender, e);
|
---|
| 240 | ParameterizeSolutionsCreator();
|
---|
| 241 | ParameterizeMainLoop();
|
---|
| 242 | ParameterizeSelectors();
|
---|
| 243 | }
|
---|
| 244 | protected override void Problem_OperatorsChanged(object sender, EventArgs e) {
|
---|
| 245 | base.Problem_OperatorsChanged(sender, e);
|
---|
| 246 | ParameterizeIterationBasedOperators();
|
---|
| 247 | UpdateCrossovers();
|
---|
| 248 | UpdateMutators();
|
---|
[12549] | 249 | UpdateTerminators();
|
---|
[12120] | 250 | }
|
---|
| 251 | protected override void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
|
---|
| 252 | base.Evaluator_QualityParameter_ActualNameChanged(sender, e);
|
---|
| 253 | ParameterizeMainLoop();
|
---|
| 254 | ParameterizeSelectors();
|
---|
| 255 | }
|
---|
[12119] | 256 | #endregion
|
---|
| 257 |
|
---|
| 258 | #region Parameterization
|
---|
| 259 | private void Initialize() {
|
---|
| 260 | }
|
---|
[12120] | 261 | private void ParameterizeSolutionsCreator() {
|
---|
| 262 | }
|
---|
| 263 | private void ParameterizeMainLoop() {
|
---|
[12138] | 264 | MainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
|
---|
| 265 | MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
[12120] | 266 | }
|
---|
| 267 | private void ParameterizeSelectors() {
|
---|
| 268 | foreach (var selector in SelectorParameter.ValidValues) {
|
---|
| 269 | selector.CopySelected = new BoolValue(true);
|
---|
[12138] | 270 | selector.NumberOfSelectedSubScopesParameter.Value = new IntValue(2);
|
---|
[12120] | 271 | selector.NumberOfSelectedSubScopesParameter.Hidden = true;
|
---|
| 272 | ParameterizeStochasticOperatorForLayer(selector);
|
---|
| 273 | }
|
---|
| 274 | if (Problem != null) {
|
---|
| 275 | foreach (var selector in SelectorParameter.ValidValues.OfType<ISingleObjectiveSelector>()) {
|
---|
| 276 | selector.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
|
---|
| 277 | selector.MaximizationParameter.Hidden = true;
|
---|
| 278 | selector.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
| 279 | selector.QualityParameter.Hidden = true;
|
---|
| 280 | }
|
---|
| 281 | }
|
---|
| 282 | }
|
---|
| 283 | private void ParameterizeIterationBasedOperators() {
|
---|
| 284 | if (Problem != null) {
|
---|
| 285 | foreach (var @operator in Problem.Operators.OfType<IIterationBasedOperator>()) {
|
---|
[12136] | 286 | @operator.IterationsParameter.ActualName = "Iteration";
|
---|
[12120] | 287 | @operator.IterationsParameter.Hidden = true;
|
---|
[12534] | 288 | @operator.MaximumIterationsParameter.ActualName = iterationsTerminator.ThresholdParameter.Name;
|
---|
[12120] | 289 | @operator.MaximumIterationsParameter.Hidden = true;
|
---|
| 290 | }
|
---|
| 291 | }
|
---|
| 292 | }
|
---|
| 293 |
|
---|
[12271] | 294 | protected override ReductionOperations GetAgeInheritanceReduction(AgeInheritance ageInheritance) {
|
---|
| 295 | switch (ageInheritance) {
|
---|
| 296 | case ALPS.AgeInheritance.Older: return ReductionOperations.Min;
|
---|
| 297 | case ALPS.AgeInheritance.Agerage: return ReductionOperations.Avg;
|
---|
| 298 | case ALPS.AgeInheritance.Younger: return ReductionOperations.Max;
|
---|
| 299 | default: throw new NotSupportedException("AgeInheritance " + ageInheritance + " is not supported.");
|
---|
| 300 | }
|
---|
| 301 | }
|
---|
| 302 |
|
---|
[12138] | 303 | protected override void ParameterizeStochasticOperator(IOperator @operator) {
|
---|
| 304 | var stochasticOperator = @operator as IStochasticOperator;
|
---|
| 305 | if (stochasticOperator != null) {
|
---|
| 306 | stochasticOperator.RandomParameter.ActualName = "Random";
|
---|
| 307 | stochasticOperator.RandomParameter.Hidden = true;
|
---|
| 308 | }
|
---|
| 309 | }
|
---|
[12120] | 310 | protected override void ParameterizeStochasticOperatorForLayer(IOperator @operator) {
|
---|
| 311 | var stochasticOperator = @operator as IStochasticOperator;
|
---|
| 312 | if (stochasticOperator != null) {
|
---|
[12138] | 313 | stochasticOperator.RandomParameter.ActualName = "Random";
|
---|
[12120] | 314 | stochasticOperator.RandomParameter.Hidden = true;
|
---|
| 315 | }
|
---|
| 316 | }
|
---|
[12119] | 317 | #endregion
|
---|
| 318 |
|
---|
| 319 | #region Updates
|
---|
[12549] | 320 |
|
---|
| 321 | private void UpdateTerminators() {
|
---|
[12534] | 322 | var newTerminators = new Dictionary<ITerminator, bool> {
|
---|
| 323 | {iterationsTerminator, !Terminators.Operators.Contains(iterationsTerminator) || Terminators.Operators.ItemChecked(iterationsTerminator)},
|
---|
[12549] | 324 | {evaluationsTerminator, Terminators.Operators.Contains(evaluationsTerminator) && Terminators.Operators.ItemChecked(evaluationsTerminator)},
|
---|
| 325 | {qualityTerminator, Terminators.Operators.Contains(qualityTerminator) && Terminators.Operators.ItemChecked(qualityTerminator) },
|
---|
| 326 | {executionTimeTerminator, Terminators.Operators.Contains(executionTimeTerminator) && Terminators.Operators.ItemChecked(executionTimeTerminator)}
|
---|
[12534] | 327 | };
|
---|
[12549] | 328 | if (Problem != null) {
|
---|
| 329 | foreach (var terminator in Problem.Operators.OfType<ITerminator>())
|
---|
| 330 | newTerminators.Add(terminator, !Terminators.Operators.Contains(terminator) || Terminators.Operators.ItemChecked(terminator));
|
---|
| 331 | }
|
---|
[12534] | 332 |
|
---|
[12549] | 333 | Terminators.Operators.Clear();
|
---|
[12534] | 334 |
|
---|
| 335 | foreach (var newTerminator in newTerminators)
|
---|
[12549] | 336 | Terminators.Operators.Add(newTerminator.Key, newTerminator.Value);
|
---|
[12534] | 337 | }
|
---|
[12120] | 338 | private void UpdateCrossovers() {
|
---|
| 339 | var oldCrossover = CrossoverParameter.Value;
|
---|
| 340 | var defaultCrossover = Problem.Operators.OfType<ICrossover>().FirstOrDefault();
|
---|
| 341 | CrossoverParameter.ValidValues.Clear();
|
---|
| 342 | foreach (var crossover in Problem.Operators.OfType<ICrossover>().OrderBy(c => c.Name)) {
|
---|
| 343 | ParameterizeStochasticOperatorForLayer(crossover);
|
---|
| 344 | CrossoverParameter.ValidValues.Add(crossover);
|
---|
| 345 | }
|
---|
| 346 | if (oldCrossover != null) {
|
---|
| 347 | var crossover = CrossoverParameter.ValidValues.FirstOrDefault(c => c.GetType() == oldCrossover.GetType());
|
---|
| 348 | if (crossover != null)
|
---|
| 349 | CrossoverParameter.Value = crossover;
|
---|
| 350 | else
|
---|
| 351 | oldCrossover = null;
|
---|
| 352 | }
|
---|
| 353 | if (oldCrossover == null && defaultCrossover != null)
|
---|
| 354 | CrossoverParameter.Value = defaultCrossover;
|
---|
| 355 | }
|
---|
| 356 | private void UpdateMutators() {
|
---|
| 357 | var oldMutator = MutatorParameter.Value;
|
---|
| 358 | MutatorParameter.ValidValues.Clear();
|
---|
| 359 | foreach (var mutator in Problem.Operators.OfType<IManipulator>().OrderBy(m => m.Name)) {
|
---|
| 360 | ParameterizeStochasticOperatorForLayer(mutator);
|
---|
| 361 | MutatorParameter.ValidValues.Add(mutator);
|
---|
| 362 | }
|
---|
| 363 | if (oldMutator != null) {
|
---|
| 364 | var mutator = MutatorParameter.ValidValues.FirstOrDefault(m => m.GetType() == oldMutator.GetType());
|
---|
| 365 | if (mutator != null)
|
---|
| 366 | MutatorParameter.Value = mutator;
|
---|
| 367 | }
|
---|
| 368 | }
|
---|
[12119] | 369 | #endregion
|
---|
| 370 | }
|
---|
| 371 | } |
---|