[3378] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2010 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;
|
---|
| 23 | using System.Linq;
|
---|
[3650] | 24 | using HeuristicLab.Analysis;
|
---|
[4068] | 25 | using HeuristicLab.Common;
|
---|
[3378] | 26 | using HeuristicLab.Core;
|
---|
| 27 | using HeuristicLab.Data;
|
---|
| 28 | using HeuristicLab.Optimization;
|
---|
| 29 | using HeuristicLab.Optimization.Operators;
|
---|
| 30 | using HeuristicLab.Parameters;
|
---|
| 31 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 32 | using HeuristicLab.PluginInfrastructure;
|
---|
| 33 | using HeuristicLab.Random;
|
---|
| 34 |
|
---|
| 35 | namespace HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm {
|
---|
| 36 | /// <summary>
|
---|
| 37 | /// An offspring selection genetic algorithm.
|
---|
| 38 | /// </summary>
|
---|
[3379] | 39 | [Item("Offspring Selection Genetic Algorithm", "An offspring selection genetic algorithm (Affenzeller, M. et al. 2009. Genetic Algorithms and Genetic Programming - Modern Concepts and Practical Applications. CRC Press).")]
|
---|
[3378] | 40 | [Creatable("Algorithms")]
|
---|
| 41 | [StorableClass]
|
---|
[4437] | 42 | public sealed class OffspringSelectionGeneticAlgorithm : EngineAlgorithm, IStorableContent {
|
---|
| 43 | public string Filename { get; set; }
|
---|
| 44 |
|
---|
[3378] | 45 | #region Problem Properties
|
---|
| 46 | public override Type ProblemType {
|
---|
| 47 | get { return typeof(ISingleObjectiveProblem); }
|
---|
| 48 | }
|
---|
| 49 | public new ISingleObjectiveProblem Problem {
|
---|
| 50 | get { return (ISingleObjectiveProblem)base.Problem; }
|
---|
| 51 | set { base.Problem = value; }
|
---|
| 52 | }
|
---|
| 53 | #endregion
|
---|
| 54 |
|
---|
| 55 | #region Parameter Properties
|
---|
| 56 | private ValueParameter<IntValue> SeedParameter {
|
---|
| 57 | get { return (ValueParameter<IntValue>)Parameters["Seed"]; }
|
---|
| 58 | }
|
---|
| 59 | private ValueParameter<BoolValue> SetSeedRandomlyParameter {
|
---|
| 60 | get { return (ValueParameter<BoolValue>)Parameters["SetSeedRandomly"]; }
|
---|
| 61 | }
|
---|
| 62 | private ValueParameter<IntValue> PopulationSizeParameter {
|
---|
| 63 | get { return (ValueParameter<IntValue>)Parameters["PopulationSize"]; }
|
---|
| 64 | }
|
---|
| 65 | private ConstrainedValueParameter<ISelector> SelectorParameter {
|
---|
| 66 | get { return (ConstrainedValueParameter<ISelector>)Parameters["Selector"]; }
|
---|
| 67 | }
|
---|
| 68 | private ConstrainedValueParameter<ICrossover> CrossoverParameter {
|
---|
| 69 | get { return (ConstrainedValueParameter<ICrossover>)Parameters["Crossover"]; }
|
---|
| 70 | }
|
---|
| 71 | private ValueParameter<PercentValue> MutationProbabilityParameter {
|
---|
| 72 | get { return (ValueParameter<PercentValue>)Parameters["MutationProbability"]; }
|
---|
| 73 | }
|
---|
| 74 | private OptionalConstrainedValueParameter<IManipulator> MutatorParameter {
|
---|
| 75 | get { return (OptionalConstrainedValueParameter<IManipulator>)Parameters["Mutator"]; }
|
---|
| 76 | }
|
---|
| 77 | private ValueParameter<IntValue> ElitesParameter {
|
---|
| 78 | get { return (ValueParameter<IntValue>)Parameters["Elites"]; }
|
---|
| 79 | }
|
---|
| 80 | private ValueParameter<IntValue> MaximumGenerationsParameter {
|
---|
| 81 | get { return (ValueParameter<IntValue>)Parameters["MaximumGenerations"]; }
|
---|
| 82 | }
|
---|
[3379] | 83 | private ValueLookupParameter<DoubleValue> SuccessRatioParameter {
|
---|
| 84 | get { return (ValueLookupParameter<DoubleValue>)Parameters["SuccessRatio"]; }
|
---|
| 85 | }
|
---|
| 86 | private ValueLookupParameter<DoubleValue> ComparisonFactorLowerBoundParameter {
|
---|
| 87 | get { return (ValueLookupParameter<DoubleValue>)Parameters["ComparisonFactorLowerBound"]; }
|
---|
| 88 | }
|
---|
| 89 | private ValueLookupParameter<DoubleValue> ComparisonFactorUpperBoundParameter {
|
---|
| 90 | get { return (ValueLookupParameter<DoubleValue>)Parameters["ComparisonFactorUpperBound"]; }
|
---|
| 91 | }
|
---|
[3426] | 92 | private OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier> ComparisonFactorModifierParameter {
|
---|
| 93 | get { return (OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier>)Parameters["ComparisonFactorModifier"]; }
|
---|
[3379] | 94 | }
|
---|
| 95 | private ValueLookupParameter<DoubleValue> MaximumSelectionPressureParameter {
|
---|
| 96 | get { return (ValueLookupParameter<DoubleValue>)Parameters["MaximumSelectionPressure"]; }
|
---|
| 97 | }
|
---|
| 98 | private ValueLookupParameter<BoolValue> OffspringSelectionBeforeMutationParameter {
|
---|
| 99 | get { return (ValueLookupParameter<BoolValue>)Parameters["OffspringSelectionBeforeMutation"]; }
|
---|
| 100 | }
|
---|
[3510] | 101 | private ValueLookupParameter<IntValue> SelectedParentsParameter {
|
---|
| 102 | get { return (ValueLookupParameter<IntValue>)Parameters["SelectedParents"]; }
|
---|
| 103 | }
|
---|
[3658] | 104 | private ValueParameter<MultiAnalyzer> AnalyzerParameter {
|
---|
| 105 | get { return (ValueParameter<MultiAnalyzer>)Parameters["Analyzer"]; }
|
---|
[3650] | 106 | }
|
---|
[3891] | 107 | private ValueParameter<IntValue> MaximumEvaluatedSolutionsParameter {
|
---|
| 108 | get { return (ValueParameter<IntValue>)Parameters["MaximumEvaluatedSolutions"]; }
|
---|
| 109 | }
|
---|
[3378] | 110 | #endregion
|
---|
| 111 |
|
---|
| 112 | #region Properties
|
---|
| 113 | public IntValue Seed {
|
---|
| 114 | get { return SeedParameter.Value; }
|
---|
| 115 | set { SeedParameter.Value = value; }
|
---|
| 116 | }
|
---|
| 117 | public BoolValue SetSeedRandomly {
|
---|
| 118 | get { return SetSeedRandomlyParameter.Value; }
|
---|
| 119 | set { SetSeedRandomlyParameter.Value = value; }
|
---|
| 120 | }
|
---|
| 121 | public IntValue PopulationSize {
|
---|
| 122 | get { return PopulationSizeParameter.Value; }
|
---|
| 123 | set { PopulationSizeParameter.Value = value; }
|
---|
| 124 | }
|
---|
| 125 | public ISelector Selector {
|
---|
| 126 | get { return SelectorParameter.Value; }
|
---|
| 127 | set { SelectorParameter.Value = value; }
|
---|
| 128 | }
|
---|
| 129 | public ICrossover Crossover {
|
---|
| 130 | get { return CrossoverParameter.Value; }
|
---|
| 131 | set { CrossoverParameter.Value = value; }
|
---|
| 132 | }
|
---|
| 133 | public PercentValue MutationProbability {
|
---|
| 134 | get { return MutationProbabilityParameter.Value; }
|
---|
| 135 | set { MutationProbabilityParameter.Value = value; }
|
---|
| 136 | }
|
---|
| 137 | public IManipulator Mutator {
|
---|
| 138 | get { return MutatorParameter.Value; }
|
---|
| 139 | set { MutatorParameter.Value = value; }
|
---|
| 140 | }
|
---|
| 141 | public IntValue Elites {
|
---|
| 142 | get { return ElitesParameter.Value; }
|
---|
| 143 | set { ElitesParameter.Value = value; }
|
---|
| 144 | }
|
---|
| 145 | public IntValue MaximumGenerations {
|
---|
| 146 | get { return MaximumGenerationsParameter.Value; }
|
---|
| 147 | set { MaximumGenerationsParameter.Value = value; }
|
---|
| 148 | }
|
---|
[3510] | 149 | public DoubleValue SuccessRatio {
|
---|
[3379] | 150 | get { return SuccessRatioParameter.Value; }
|
---|
| 151 | set { SuccessRatioParameter.Value = value; }
|
---|
| 152 | }
|
---|
[3510] | 153 | public DoubleValue ComparisonFactorLowerBound {
|
---|
[3379] | 154 | get { return ComparisonFactorLowerBoundParameter.Value; }
|
---|
| 155 | set { ComparisonFactorLowerBoundParameter.Value = value; }
|
---|
| 156 | }
|
---|
[3510] | 157 | public DoubleValue ComparisonFactorUpperBound {
|
---|
[3379] | 158 | get { return ComparisonFactorUpperBoundParameter.Value; }
|
---|
| 159 | set { ComparisonFactorUpperBoundParameter.Value = value; }
|
---|
| 160 | }
|
---|
[3510] | 161 | public IDiscreteDoubleValueModifier ComparisonFactorModifier {
|
---|
[3379] | 162 | get { return ComparisonFactorModifierParameter.Value; }
|
---|
| 163 | set { ComparisonFactorModifierParameter.Value = value; }
|
---|
| 164 | }
|
---|
[3510] | 165 | public DoubleValue MaximumSelectionPressure {
|
---|
[3379] | 166 | get { return MaximumSelectionPressureParameter.Value; }
|
---|
| 167 | set { MaximumSelectionPressureParameter.Value = value; }
|
---|
| 168 | }
|
---|
[3510] | 169 | public BoolValue OffspringSelectionBeforeMutation {
|
---|
[3379] | 170 | get { return OffspringSelectionBeforeMutationParameter.Value; }
|
---|
| 171 | set { OffspringSelectionBeforeMutationParameter.Value = value; }
|
---|
| 172 | }
|
---|
[3510] | 173 | public IntValue SelectedParents {
|
---|
| 174 | get { return SelectedParentsParameter.Value; }
|
---|
| 175 | set { SelectedParentsParameter.Value = value; }
|
---|
| 176 | }
|
---|
[3658] | 177 | public MultiAnalyzer Analyzer {
|
---|
[3650] | 178 | get { return AnalyzerParameter.Value; }
|
---|
| 179 | set { AnalyzerParameter.Value = value; }
|
---|
| 180 | }
|
---|
[3891] | 181 | public IntValue MaximumEvaluatedSolutions {
|
---|
| 182 | get { return MaximumEvaluatedSolutionsParameter.Value; }
|
---|
| 183 | set { MaximumEvaluatedSolutionsParameter.Value = value; }
|
---|
| 184 | }
|
---|
[3378] | 185 | private RandomCreator RandomCreator {
|
---|
| 186 | get { return (RandomCreator)OperatorGraph.InitialOperator; }
|
---|
| 187 | }
|
---|
| 188 | private SolutionsCreator SolutionsCreator {
|
---|
| 189 | get { return (SolutionsCreator)RandomCreator.Successor; }
|
---|
| 190 | }
|
---|
| 191 | private OffspringSelectionGeneticAlgorithmMainLoop MainLoop {
|
---|
| 192 | get { return (OffspringSelectionGeneticAlgorithmMainLoop)SolutionsCreator.Successor; }
|
---|
| 193 | }
|
---|
[3689] | 194 | [Storable]
|
---|
[3672] | 195 | private BestAverageWorstQualityAnalyzer qualityAnalyzer;
|
---|
[3689] | 196 | [Storable]
|
---|
[3672] | 197 | private ValueAnalyzer selectionPressureAnalyzer;
|
---|
[3378] | 198 | #endregion
|
---|
| 199 |
|
---|
[3379] | 200 | [StorableConstructor]
|
---|
| 201 | private OffspringSelectionGeneticAlgorithm(bool deserializing) : base(deserializing) { }
|
---|
[4722] | 202 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 203 | private void AfterDeserialization() {
|
---|
| 204 | Initialize();
|
---|
| 205 | }
|
---|
| 206 | private OffspringSelectionGeneticAlgorithm(OffspringSelectionGeneticAlgorithm original, Cloner cloner)
|
---|
| 207 | : base(original, cloner) {
|
---|
| 208 | qualityAnalyzer = cloner.Clone(original.qualityAnalyzer);
|
---|
| 209 | selectionPressureAnalyzer = cloner.Clone(original.selectionPressureAnalyzer);
|
---|
| 210 | Initialize();
|
---|
| 211 | }
|
---|
| 212 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 213 | return new OffspringSelectionGeneticAlgorithm(this, cloner);
|
---|
| 214 | }
|
---|
[3378] | 215 | public OffspringSelectionGeneticAlgorithm()
|
---|
| 216 | : base() {
|
---|
| 217 | Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
|
---|
| 218 | Parameters.Add(new ValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
|
---|
| 219 | Parameters.Add(new ValueParameter<IntValue>("PopulationSize", "The size of the population of solutions.", new IntValue(100)));
|
---|
| 220 | Parameters.Add(new ConstrainedValueParameter<ISelector>("Selector", "The operator used to select solutions for reproduction."));
|
---|
| 221 | Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions."));
|
---|
| 222 | Parameters.Add(new ValueParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution.", new PercentValue(0.05)));
|
---|
| 223 | Parameters.Add(new OptionalConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions."));
|
---|
| 224 | Parameters.Add(new ValueParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.", new IntValue(1)));
|
---|
| 225 | Parameters.Add(new ValueParameter<IntValue>("MaximumGenerations", "The maximum number of generations which should be processed.", new IntValue(1000)));
|
---|
[3379] | 226 | Parameters.Add(new ValueLookupParameter<DoubleValue>("SuccessRatio", "The ratio of successful to total children that should be achieved.", new DoubleValue(1)));
|
---|
| 227 | Parameters.Add(new ValueLookupParameter<DoubleValue>("ComparisonFactorLowerBound", "The lower bound of the comparison factor (start).", new DoubleValue(0)));
|
---|
| 228 | Parameters.Add(new ValueLookupParameter<DoubleValue>("ComparisonFactorUpperBound", "The upper bound of the comparison factor (end).", new DoubleValue(1)));
|
---|
[3426] | 229 | Parameters.Add(new OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier>("ComparisonFactorModifier", "The operator used to modify the comparison factor.", new ItemSet<IDiscreteDoubleValueModifier>(new IDiscreteDoubleValueModifier[] { new LinearDiscreteDoubleValueModifier() }), new LinearDiscreteDoubleValueModifier()));
|
---|
[3379] | 230 | Parameters.Add(new ValueLookupParameter<DoubleValue>("MaximumSelectionPressure", "The maximum selection pressure that terminates the algorithm.", new DoubleValue(100)));
|
---|
| 231 | 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.", new BoolValue(false)));
|
---|
[3735] | 232 | Parameters.Add(new ValueLookupParameter<IntValue>("SelectedParents", "How much parents should be selected each time the offspring selection step is performed until the population is filled. This parameter should be about the same or twice the size of PopulationSize for smaller problems, and less for large problems.", new IntValue(200)));
|
---|
[3658] | 233 | Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze each generation.", new MultiAnalyzer()));
|
---|
[3891] | 234 | Parameters.Add(new ValueParameter<IntValue>("MaximumEvaluatedSolutions", "The maximum number of evaluated solutions (approximately).", new IntValue(int.MaxValue)));
|
---|
| 235 |
|
---|
[3378] | 236 | RandomCreator randomCreator = new RandomCreator();
|
---|
| 237 | SolutionsCreator solutionsCreator = new SolutionsCreator();
|
---|
| 238 | OffspringSelectionGeneticAlgorithmMainLoop mainLoop = new OffspringSelectionGeneticAlgorithmMainLoop();
|
---|
| 239 | OperatorGraph.InitialOperator = randomCreator;
|
---|
| 240 |
|
---|
| 241 | randomCreator.RandomParameter.ActualName = "Random";
|
---|
| 242 | randomCreator.SeedParameter.ActualName = SeedParameter.Name;
|
---|
| 243 | randomCreator.SeedParameter.Value = null;
|
---|
| 244 | randomCreator.SetSeedRandomlyParameter.ActualName = SetSeedRandomlyParameter.Name;
|
---|
| 245 | randomCreator.SetSeedRandomlyParameter.Value = null;
|
---|
| 246 | randomCreator.Successor = solutionsCreator;
|
---|
| 247 |
|
---|
| 248 | solutionsCreator.NumberOfSolutionsParameter.ActualName = PopulationSizeParameter.Name;
|
---|
| 249 | solutionsCreator.Successor = mainLoop;
|
---|
| 250 |
|
---|
[3744] | 251 | mainLoop.AnalyzerParameter.ActualName = AnalyzerParameter.Name;
|
---|
| 252 | mainLoop.ComparisonFactorModifierParameter.ActualName = ComparisonFactorModifierParameter.Name;
|
---|
| 253 | mainLoop.ComparisonFactorParameter.ActualName = "ComparisonFactor";
|
---|
| 254 | mainLoop.ComparisonFactorStartParameter.ActualName = ComparisonFactorLowerBoundParameter.Name;
|
---|
[3378] | 255 | mainLoop.CrossoverParameter.ActualName = CrossoverParameter.Name;
|
---|
| 256 | mainLoop.ElitesParameter.ActualName = ElitesParameter.Name;
|
---|
| 257 | mainLoop.MaximumGenerationsParameter.ActualName = MaximumGenerationsParameter.Name;
|
---|
[3744] | 258 | mainLoop.MaximumSelectionPressureParameter.ActualName = MaximumSelectionPressureParameter.Name;
|
---|
| 259 | mainLoop.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
|
---|
[3378] | 260 | mainLoop.MutatorParameter.ActualName = MutatorParameter.Name;
|
---|
[3744] | 261 | mainLoop.OffspringSelectionBeforeMutationParameter.ActualName = OffspringSelectionBeforeMutationParameter.Name;
|
---|
[3378] | 262 | mainLoop.RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
|
---|
| 263 | mainLoop.ResultsParameter.ActualName = "Results";
|
---|
[3744] | 264 | mainLoop.SelectorParameter.ActualName = SelectorParameter.Name;
|
---|
| 265 | mainLoop.SuccessRatioParameter.ActualName = SuccessRatioParameter.Name;
|
---|
[3378] | 266 |
|
---|
[3689] | 267 | foreach (ISelector selector in ApplicationManager.Manager.GetInstances<ISelector>().Where(x => !(x is IMultiObjectiveSelector)).OrderBy(x => x.Name))
|
---|
| 268 | SelectorParameter.ValidValues.Add(selector);
|
---|
| 269 | ISelector proportionalSelector = SelectorParameter.ValidValues.FirstOrDefault(x => x.GetType().Name.Equals("ProportionalSelector"));
|
---|
| 270 | if (proportionalSelector != null) SelectorParameter.Value = proportionalSelector;
|
---|
| 271 | ParameterizeSelectors();
|
---|
| 272 |
|
---|
| 273 | foreach (IDiscreteDoubleValueModifier modifier in ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>().OrderBy(x => x.Name))
|
---|
| 274 | ComparisonFactorModifierParameter.ValidValues.Add(modifier);
|
---|
| 275 | IDiscreteDoubleValueModifier linearModifier = ComparisonFactorModifierParameter.ValidValues.FirstOrDefault(x => x.GetType().Name.Equals("LinearDiscreteDoubleValueModifier"));
|
---|
| 276 | if (linearModifier != null) ComparisonFactorModifierParameter.Value = linearModifier;
|
---|
| 277 | ParameterizeComparisonFactorModifiers();
|
---|
| 278 |
|
---|
| 279 | qualityAnalyzer = new BestAverageWorstQualityAnalyzer();
|
---|
| 280 | selectionPressureAnalyzer = new ValueAnalyzer();
|
---|
| 281 | ParameterizeAnalyzers();
|
---|
| 282 | UpdateAnalyzers();
|
---|
| 283 |
|
---|
[3378] | 284 | Initialize();
|
---|
| 285 | }
|
---|
| 286 |
|
---|
| 287 |
|
---|
[4722] | 288 |
|
---|
[3378] | 289 | public override void Prepare() {
|
---|
| 290 | if (Problem != null) base.Prepare();
|
---|
| 291 | }
|
---|
| 292 |
|
---|
| 293 | #region Events
|
---|
| 294 | protected override void OnProblemChanged() {
|
---|
| 295 | ParameterizeStochasticOperator(Problem.SolutionCreator);
|
---|
| 296 | ParameterizeStochasticOperator(Problem.Evaluator);
|
---|
| 297 | foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
|
---|
| 298 | ParameterizeSolutionsCreator();
|
---|
[3379] | 299 | ParameterizMainLoop();
|
---|
[3378] | 300 | ParameterizeSelectors();
|
---|
[3650] | 301 | ParameterizeAnalyzers();
|
---|
[3750] | 302 | ParameterizeIterationBasedOperators();
|
---|
[3378] | 303 | UpdateCrossovers();
|
---|
| 304 | UpdateMutators();
|
---|
[3650] | 305 | UpdateAnalyzers();
|
---|
[3378] | 306 | Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
|
---|
| 307 | base.OnProblemChanged();
|
---|
| 308 | }
|
---|
| 309 |
|
---|
| 310 | protected override void Problem_SolutionCreatorChanged(object sender, EventArgs e) {
|
---|
| 311 | ParameterizeStochasticOperator(Problem.SolutionCreator);
|
---|
| 312 | ParameterizeSolutionsCreator();
|
---|
| 313 | base.Problem_SolutionCreatorChanged(sender, e);
|
---|
| 314 | }
|
---|
| 315 | protected override void Problem_EvaluatorChanged(object sender, EventArgs e) {
|
---|
| 316 | ParameterizeStochasticOperator(Problem.Evaluator);
|
---|
| 317 | ParameterizeSolutionsCreator();
|
---|
[3379] | 318 | ParameterizMainLoop();
|
---|
[3378] | 319 | ParameterizeSelectors();
|
---|
[3650] | 320 | ParameterizeAnalyzers();
|
---|
[3378] | 321 | Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
|
---|
| 322 | base.Problem_EvaluatorChanged(sender, e);
|
---|
| 323 | }
|
---|
| 324 | protected override void Problem_OperatorsChanged(object sender, EventArgs e) {
|
---|
| 325 | foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
|
---|
[3750] | 326 | ParameterizeIterationBasedOperators();
|
---|
[3378] | 327 | UpdateCrossovers();
|
---|
| 328 | UpdateMutators();
|
---|
[3650] | 329 | UpdateAnalyzers();
|
---|
[3378] | 330 | base.Problem_OperatorsChanged(sender, e);
|
---|
| 331 | }
|
---|
| 332 | private void ElitesParameter_ValueChanged(object sender, EventArgs e) {
|
---|
| 333 | Elites.ValueChanged += new EventHandler(Elites_ValueChanged);
|
---|
| 334 | ParameterizeSelectors();
|
---|
| 335 | }
|
---|
| 336 | private void Elites_ValueChanged(object sender, EventArgs e) {
|
---|
| 337 | ParameterizeSelectors();
|
---|
| 338 | }
|
---|
| 339 | private void PopulationSizeParameter_ValueChanged(object sender, EventArgs e) {
|
---|
| 340 | PopulationSize.ValueChanged += new EventHandler(PopulationSize_ValueChanged);
|
---|
| 341 | ParameterizeSelectors();
|
---|
| 342 | }
|
---|
| 343 | private void PopulationSize_ValueChanged(object sender, EventArgs e) {
|
---|
| 344 | ParameterizeSelectors();
|
---|
| 345 | }
|
---|
| 346 | private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
|
---|
[3379] | 347 | ParameterizMainLoop();
|
---|
[3378] | 348 | ParameterizeSelectors();
|
---|
[3650] | 349 | ParameterizeAnalyzers();
|
---|
[3378] | 350 | }
|
---|
| 351 | #endregion
|
---|
| 352 |
|
---|
| 353 | #region Helpers
|
---|
| 354 | private void Initialize() {
|
---|
| 355 | PopulationSizeParameter.ValueChanged += new EventHandler(PopulationSizeParameter_ValueChanged);
|
---|
| 356 | PopulationSize.ValueChanged += new EventHandler(PopulationSize_ValueChanged);
|
---|
| 357 | ElitesParameter.ValueChanged += new EventHandler(ElitesParameter_ValueChanged);
|
---|
| 358 | Elites.ValueChanged += new EventHandler(Elites_ValueChanged);
|
---|
| 359 | if (Problem != null) {
|
---|
| 360 | Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
|
---|
| 361 | }
|
---|
| 362 | }
|
---|
| 363 | private void ParameterizeSolutionsCreator() {
|
---|
| 364 | SolutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
|
---|
| 365 | SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name;
|
---|
| 366 | }
|
---|
[3379] | 367 | private void ParameterizMainLoop() {
|
---|
[3378] | 368 | MainLoop.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
|
---|
| 369 | MainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
|
---|
| 370 | MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
| 371 | }
|
---|
| 372 | private void ParameterizeStochasticOperator(IOperator op) {
|
---|
| 373 | if (op is IStochasticOperator)
|
---|
| 374 | ((IStochasticOperator)op).RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
|
---|
| 375 | }
|
---|
| 376 | private void ParameterizeSelectors() {
|
---|
[3689] | 377 | foreach (ISelector selector in SelectorParameter.ValidValues) {
|
---|
[3378] | 378 | selector.CopySelected = new BoolValue(true);
|
---|
[3510] | 379 | selector.NumberOfSelectedSubScopesParameter.Value = null;
|
---|
| 380 | selector.NumberOfSelectedSubScopesParameter.ActualName = SelectedParentsParameter.Name;
|
---|
[3378] | 381 | ParameterizeStochasticOperator(selector);
|
---|
| 382 | }
|
---|
| 383 | if (Problem != null) {
|
---|
[3689] | 384 | foreach (ISingleObjectiveSelector selector in SelectorParameter.ValidValues.OfType<ISingleObjectiveSelector>()) {
|
---|
[3378] | 385 | selector.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
|
---|
| 386 | selector.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
| 387 | }
|
---|
| 388 | }
|
---|
| 389 | }
|
---|
[3650] | 390 | private void ParameterizeAnalyzers() {
|
---|
[3672] | 391 | qualityAnalyzer.ResultsParameter.ActualName = "Results";
|
---|
| 392 | selectionPressureAnalyzer.Name = "SelectionPressure Analyzer";
|
---|
| 393 | selectionPressureAnalyzer.ResultsParameter.ActualName = "Results";
|
---|
| 394 | selectionPressureAnalyzer.ValueParameter.ActualName = "SelectionPressure";
|
---|
| 395 | selectionPressureAnalyzer.ValueParameter.Depth = 0;
|
---|
| 396 | selectionPressureAnalyzer.ValuesParameter.ActualName = "Selection Pressure History";
|
---|
[3650] | 397 | if (Problem != null) {
|
---|
[3672] | 398 | qualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
|
---|
| 399 | qualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
| 400 | qualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
|
---|
[3650] | 401 | }
|
---|
| 402 | }
|
---|
[3379] | 403 | private void ParameterizeComparisonFactorModifiers() {
|
---|
[3689] | 404 | foreach (IDiscreteDoubleValueModifier modifier in ComparisonFactorModifierParameter.ValidValues) {
|
---|
[3413] | 405 | modifier.IndexParameter.ActualName = "Generations";
|
---|
[3379] | 406 | modifier.EndIndexParameter.ActualName = MaximumGenerationsParameter.Name;
|
---|
| 407 | modifier.EndValueParameter.ActualName = ComparisonFactorUpperBoundParameter.Name;
|
---|
| 408 | modifier.StartIndexParameter.Value = new IntValue(0);
|
---|
| 409 | modifier.StartValueParameter.ActualName = ComparisonFactorLowerBoundParameter.Name;
|
---|
[3413] | 410 | modifier.ValueParameter.ActualName = "ComparisonFactor";
|
---|
[3379] | 411 | }
|
---|
| 412 | }
|
---|
[3750] | 413 | private void ParameterizeIterationBasedOperators() {
|
---|
| 414 | if (Problem != null) {
|
---|
| 415 | foreach (IIterationBasedOperator op in Problem.Operators.OfType<IIterationBasedOperator>()) {
|
---|
| 416 | op.IterationsParameter.ActualName = "Generations";
|
---|
| 417 | op.MaximumIterationsParameter.ActualName = MaximumGenerationsParameter.Name;
|
---|
| 418 | }
|
---|
| 419 | }
|
---|
| 420 | }
|
---|
[3378] | 421 | private void UpdateCrossovers() {
|
---|
| 422 | ICrossover oldCrossover = CrossoverParameter.Value;
|
---|
| 423 | CrossoverParameter.ValidValues.Clear();
|
---|
| 424 | foreach (ICrossover crossover in Problem.Operators.OfType<ICrossover>().OrderBy(x => x.Name))
|
---|
| 425 | CrossoverParameter.ValidValues.Add(crossover);
|
---|
| 426 | if (oldCrossover != null) {
|
---|
| 427 | ICrossover crossover = CrossoverParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldCrossover.GetType());
|
---|
| 428 | if (crossover != null) CrossoverParameter.Value = crossover;
|
---|
| 429 | }
|
---|
| 430 | }
|
---|
| 431 | private void UpdateMutators() {
|
---|
| 432 | IManipulator oldMutator = MutatorParameter.Value;
|
---|
| 433 | MutatorParameter.ValidValues.Clear();
|
---|
| 434 | foreach (IManipulator mutator in Problem.Operators.OfType<IManipulator>().OrderBy(x => x.Name))
|
---|
| 435 | MutatorParameter.ValidValues.Add(mutator);
|
---|
| 436 | if (oldMutator != null) {
|
---|
| 437 | IManipulator mutator = MutatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMutator.GetType());
|
---|
| 438 | if (mutator != null) MutatorParameter.Value = mutator;
|
---|
| 439 | }
|
---|
| 440 | }
|
---|
[3650] | 441 | private void UpdateAnalyzers() {
|
---|
| 442 | Analyzer.Operators.Clear();
|
---|
| 443 | if (Problem != null) {
|
---|
[3816] | 444 | foreach (IAnalyzer analyzer in Problem.Operators.OfType<IAnalyzer>()) {
|
---|
[3672] | 445 | foreach (IScopeTreeLookupParameter param in analyzer.Parameters.OfType<IScopeTreeLookupParameter>())
|
---|
| 446 | param.Depth = 1;
|
---|
[3650] | 447 | Analyzer.Operators.Add(analyzer);
|
---|
[3672] | 448 | }
|
---|
[3650] | 449 | }
|
---|
[3799] | 450 | Analyzer.Operators.Add(qualityAnalyzer);
|
---|
| 451 | Analyzer.Operators.Add(selectionPressureAnalyzer);
|
---|
[3650] | 452 | }
|
---|
[3378] | 453 | #endregion
|
---|
| 454 | }
|
---|
| 455 | }
|
---|