[8313] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2012 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;
|
---|
| 24 | using HeuristicLab.Analysis;
|
---|
| 25 | using HeuristicLab.Common;
|
---|
| 26 | using HeuristicLab.Core;
|
---|
| 27 | using HeuristicLab.Data;
|
---|
| 28 | using HeuristicLab.Operators;
|
---|
| 29 | using HeuristicLab.Optimization;
|
---|
| 30 | using HeuristicLab.Optimization.Operators;
|
---|
| 31 | using HeuristicLab.Parameters;
|
---|
| 32 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 33 | using HeuristicLab.PluginInfrastructure;
|
---|
| 34 | using HeuristicLab.Random;
|
---|
| 35 |
|
---|
| 36 | namespace HeuristicLab.Algorithms.RAPGA {
|
---|
| 37 | /// <summary>
|
---|
| 38 | /// A relevant alleles preserving genetic algorithm.
|
---|
| 39 | /// </summary>
|
---|
| 40 | [Item("RAPGA", "A relevant alleles preserving genetic algorithm.")]
|
---|
| 41 | [Creatable("Algorithms")]
|
---|
| 42 | [StorableClass]
|
---|
| 43 | public sealed class RAPGA : HeuristicOptimizationEngineAlgorithm, IStorableContent {
|
---|
| 44 | public string Filename { get; set; }
|
---|
| 45 |
|
---|
| 46 | #region Problem Properties
|
---|
| 47 | public override Type ProblemType {
|
---|
| 48 | get { return typeof(ISingleObjectiveHeuristicOptimizationProblem); }
|
---|
| 49 | }
|
---|
| 50 | public new ISingleObjectiveHeuristicOptimizationProblem Problem {
|
---|
| 51 | get { return (ISingleObjectiveHeuristicOptimizationProblem)base.Problem; }
|
---|
| 52 | set { base.Problem = value; }
|
---|
| 53 | }
|
---|
| 54 | #endregion
|
---|
| 55 |
|
---|
| 56 | #region Parameter Properties
|
---|
| 57 | private ValueParameter<IntValue> SeedParameter {
|
---|
| 58 | get { return (ValueParameter<IntValue>)Parameters["Seed"]; }
|
---|
| 59 | }
|
---|
| 60 | private ValueParameter<BoolValue> SetSeedRandomlyParameter {
|
---|
| 61 | get { return (ValueParameter<BoolValue>)Parameters["SetSeedRandomly"]; }
|
---|
| 62 | }
|
---|
| 63 | private ValueParameter<IntValue> PopulationSizeParameter {
|
---|
| 64 | get { return (ValueParameter<IntValue>)Parameters["PopulationSize"]; }
|
---|
| 65 | }
|
---|
[8330] | 66 | private IValueParameter<IntValue> MinimumPopulationSizeParameter {
|
---|
| 67 | get { return (IValueParameter<IntValue>)Parameters["MinimumPopulationSize"]; }
|
---|
[8349] | 68 | }
|
---|
[8330] | 69 | private IValueParameter<IntValue> MaximumPopulationSizeParameter {
|
---|
[8349] | 70 | get { return (IValueParameter<IntValue>)Parameters["MaximumPopulationSize"]; }
|
---|
[8330] | 71 | }
|
---|
| 72 | private IValueParameter<DoubleValue> ComparisonFactorParameter {
|
---|
| 73 | get { return (IValueParameter<DoubleValue>)Parameters["ComparisonFactor"]; }
|
---|
| 74 | }
|
---|
| 75 | private IValueParameter<IntValue> EffortParameter {
|
---|
| 76 | get { return (IValueParameter<IntValue>)Parameters["Effort"]; }
|
---|
| 77 | }
|
---|
[8377] | 78 | private IValueParameter<IntValue> BatchSizeParameter {
|
---|
| 79 | get { return (IValueParameter<IntValue>)Parameters["BatchSize"]; }
|
---|
| 80 | }
|
---|
[8313] | 81 | public IConstrainedValueParameter<ISelector> SelectorParameter {
|
---|
| 82 | get { return (IConstrainedValueParameter<ISelector>)Parameters["Selector"]; }
|
---|
| 83 | }
|
---|
| 84 | public IConstrainedValueParameter<ICrossover> CrossoverParameter {
|
---|
| 85 | get { return (IConstrainedValueParameter<ICrossover>)Parameters["Crossover"]; }
|
---|
| 86 | }
|
---|
| 87 | private ValueParameter<PercentValue> MutationProbabilityParameter {
|
---|
| 88 | get { return (ValueParameter<PercentValue>)Parameters["MutationProbability"]; }
|
---|
| 89 | }
|
---|
| 90 | public IConstrainedValueParameter<IManipulator> MutatorParameter {
|
---|
| 91 | get { return (IConstrainedValueParameter<IManipulator>)Parameters["Mutator"]; }
|
---|
| 92 | }
|
---|
| 93 | private ValueParameter<IntValue> ElitesParameter {
|
---|
| 94 | get { return (ValueParameter<IntValue>)Parameters["Elites"]; }
|
---|
| 95 | }
|
---|
| 96 | private ValueParameter<MultiAnalyzer> AnalyzerParameter {
|
---|
| 97 | get { return (ValueParameter<MultiAnalyzer>)Parameters["Analyzer"]; }
|
---|
| 98 | }
|
---|
| 99 | private ValueParameter<IntValue> MaximumGenerationsParameter {
|
---|
| 100 | get { return (ValueParameter<IntValue>)Parameters["MaximumGenerations"]; }
|
---|
| 101 | }
|
---|
[8349] | 102 | public IConstrainedValueParameter<ISolutionSimilarityCalculator> SimilarityCalculatorParameter {
|
---|
| 103 | get { return (IConstrainedValueParameter<ISolutionSimilarityCalculator>)Parameters["SimilarityCalculator"]; }
|
---|
| 104 | }
|
---|
[8313] | 105 | #endregion
|
---|
| 106 |
|
---|
| 107 | #region Properties
|
---|
| 108 | public IntValue Seed {
|
---|
| 109 | get { return SeedParameter.Value; }
|
---|
| 110 | set { SeedParameter.Value = value; }
|
---|
| 111 | }
|
---|
| 112 | public BoolValue SetSeedRandomly {
|
---|
| 113 | get { return SetSeedRandomlyParameter.Value; }
|
---|
| 114 | set { SetSeedRandomlyParameter.Value = value; }
|
---|
| 115 | }
|
---|
| 116 | public IntValue PopulationSize {
|
---|
| 117 | get { return PopulationSizeParameter.Value; }
|
---|
| 118 | set { PopulationSizeParameter.Value = value; }
|
---|
| 119 | }
|
---|
[8330] | 120 | public IntValue MinimumPopulationSize {
|
---|
| 121 | get { return MinimumPopulationSizeParameter.Value; }
|
---|
| 122 | set { MinimumPopulationSizeParameter.Value = value; }
|
---|
| 123 | }
|
---|
| 124 | public IntValue MaximumPopulationSize {
|
---|
| 125 | get { return MaximumPopulationSizeParameter.Value; }
|
---|
| 126 | set { MaximumPopulationSizeParameter.Value = value; }
|
---|
| 127 | }
|
---|
| 128 | public DoubleValue ComparisonFactor {
|
---|
| 129 | get { return ComparisonFactorParameter.Value; }
|
---|
| 130 | set { ComparisonFactorParameter.Value = value; }
|
---|
| 131 | }
|
---|
| 132 | public IntValue Effort {
|
---|
| 133 | get { return EffortParameter.Value; }
|
---|
| 134 | set { EffortParameter.Value = value; }
|
---|
| 135 | }
|
---|
[8377] | 136 | public IntValue BatchSize {
|
---|
| 137 | get { return BatchSizeParameter.Value; }
|
---|
| 138 | set { BatchSizeParameter.Value = value; }
|
---|
| 139 | }
|
---|
[8313] | 140 | public ISelector Selector {
|
---|
| 141 | get { return SelectorParameter.Value; }
|
---|
| 142 | set { SelectorParameter.Value = value; }
|
---|
| 143 | }
|
---|
| 144 | public ICrossover Crossover {
|
---|
| 145 | get { return CrossoverParameter.Value; }
|
---|
| 146 | set { CrossoverParameter.Value = value; }
|
---|
| 147 | }
|
---|
| 148 | public PercentValue MutationProbability {
|
---|
| 149 | get { return MutationProbabilityParameter.Value; }
|
---|
| 150 | set { MutationProbabilityParameter.Value = value; }
|
---|
| 151 | }
|
---|
| 152 | public IManipulator Mutator {
|
---|
| 153 | get { return MutatorParameter.Value; }
|
---|
| 154 | set { MutatorParameter.Value = value; }
|
---|
| 155 | }
|
---|
| 156 | public IntValue Elites {
|
---|
| 157 | get { return ElitesParameter.Value; }
|
---|
| 158 | set { ElitesParameter.Value = value; }
|
---|
| 159 | }
|
---|
| 160 | public MultiAnalyzer Analyzer {
|
---|
| 161 | get { return AnalyzerParameter.Value; }
|
---|
| 162 | set { AnalyzerParameter.Value = value; }
|
---|
| 163 | }
|
---|
| 164 | public IntValue MaximumGenerations {
|
---|
| 165 | get { return MaximumGenerationsParameter.Value; }
|
---|
| 166 | set { MaximumGenerationsParameter.Value = value; }
|
---|
| 167 | }
|
---|
[8349] | 168 | public ISolutionSimilarityCalculator SimilarityCalculator {
|
---|
| 169 | get { return SimilarityCalculatorParameter.Value; }
|
---|
| 170 | set { SimilarityCalculatorParameter.Value = value; }
|
---|
| 171 | }
|
---|
[8313] | 172 | private RandomCreator RandomCreator {
|
---|
| 173 | get { return (RandomCreator)OperatorGraph.InitialOperator; }
|
---|
| 174 | }
|
---|
| 175 | private SolutionsCreator SolutionsCreator {
|
---|
| 176 | get { return (SolutionsCreator)RandomCreator.Successor; }
|
---|
| 177 | }
|
---|
| 178 | private RAPGAMainLoop RAPGAMainLoop {
|
---|
| 179 | get { return FindMainLoop(SolutionsCreator.Successor); }
|
---|
| 180 | }
|
---|
| 181 | [Storable]
|
---|
| 182 | private BestAverageWorstQualityAnalyzer qualityAnalyzer;
|
---|
[8377] | 183 | [Storable]
|
---|
| 184 | private PopulationSizeAnalyzer populationSizeAnalyzer;
|
---|
[8378] | 185 | [Storable]
|
---|
| 186 | private OffspringSuccessAnalyzer offspringSuccessAnalyzer;
|
---|
[8313] | 187 | #endregion
|
---|
| 188 |
|
---|
| 189 | [StorableConstructor]
|
---|
| 190 | private RAPGA(bool deserializing) : base(deserializing) { }
|
---|
| 191 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 192 | private void AfterDeserialization() { Initialize(); }
|
---|
| 193 | private RAPGA(RAPGA original, Cloner cloner)
|
---|
| 194 | : base(original, cloner) {
|
---|
| 195 | qualityAnalyzer = cloner.Clone(original.qualityAnalyzer);
|
---|
[8377] | 196 | populationSizeAnalyzer = cloner.Clone(original.populationSizeAnalyzer);
|
---|
[8378] | 197 | offspringSuccessAnalyzer = cloner.Clone(original.offspringSuccessAnalyzer);
|
---|
[8313] | 198 | Initialize();
|
---|
| 199 | }
|
---|
| 200 | public RAPGA()
|
---|
| 201 | : base() {
|
---|
| 202 | Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
|
---|
| 203 | Parameters.Add(new ValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
|
---|
[8359] | 204 | Parameters.Add(new ValueParameter<IntValue>("PopulationSize", "The size of the population of solutions.", new IntValue(100)));
|
---|
[8330] | 205 | Parameters.Add(new ValueParameter<IntValue>("MinimumPopulationSize", "The minimum size of the population of solutions.", new IntValue(2)));
|
---|
[8377] | 206 | Parameters.Add(new ValueParameter<IntValue>("MaximumPopulationSize", "The maximum size of the population of solutions.", new IntValue(300)));
|
---|
[8330] | 207 | Parameters.Add(new ValueParameter<DoubleValue>("ComparisonFactor", "The comparison factor.", new DoubleValue(0.0)));
|
---|
[8377] | 208 | Parameters.Add(new ValueParameter<IntValue>("Effort", "The maximum number of offspring created in each generation.", new IntValue(1000)));
|
---|
| 209 | Parameters.Add(new ValueParameter<IntValue>("BatchSize", "The number of children that should be created during one iteration of the offspring creation process.", new IntValue(10)));
|
---|
[8313] | 210 | Parameters.Add(new ConstrainedValueParameter<ISelector>("Selector", "The operator used to select solutions for reproduction."));
|
---|
| 211 | Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions."));
|
---|
| 212 | Parameters.Add(new ValueParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution.", new PercentValue(0.05)));
|
---|
| 213 | Parameters.Add(new OptionalConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions."));
|
---|
| 214 | Parameters.Add(new ValueParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.", new IntValue(1)));
|
---|
| 215 | Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze each generation.", new MultiAnalyzer()));
|
---|
| 216 | Parameters.Add(new ValueParameter<IntValue>("MaximumGenerations", "The maximum number of generations which should be processed.", new IntValue(1000)));
|
---|
[8349] | 217 | Parameters.Add(new ConstrainedValueParameter<ISolutionSimilarityCalculator>("SimilarityCalculator", "The operator used to calculate the similarity between two solutions."));
|
---|
[8313] | 218 |
|
---|
| 219 | RandomCreator randomCreator = new RandomCreator();
|
---|
| 220 | SolutionsCreator solutionsCreator = new SolutionsCreator();
|
---|
| 221 | SubScopesCounter subScopesCounter = new SubScopesCounter();
|
---|
| 222 | ResultsCollector resultsCollector = new ResultsCollector();
|
---|
| 223 | RAPGAMainLoop mainLoop = new RAPGAMainLoop();
|
---|
| 224 | OperatorGraph.InitialOperator = randomCreator;
|
---|
| 225 |
|
---|
| 226 | randomCreator.RandomParameter.ActualName = "Random";
|
---|
| 227 | randomCreator.SeedParameter.ActualName = SeedParameter.Name;
|
---|
| 228 | randomCreator.SeedParameter.Value = null;
|
---|
| 229 | randomCreator.SetSeedRandomlyParameter.ActualName = SetSeedRandomlyParameter.Name;
|
---|
| 230 | randomCreator.SetSeedRandomlyParameter.Value = null;
|
---|
| 231 | randomCreator.Successor = solutionsCreator;
|
---|
| 232 |
|
---|
| 233 | solutionsCreator.NumberOfSolutionsParameter.ActualName = PopulationSizeParameter.Name;
|
---|
| 234 | solutionsCreator.Successor = subScopesCounter;
|
---|
| 235 |
|
---|
| 236 | subScopesCounter.Name = "Initialize EvaluatedSolutions";
|
---|
| 237 | subScopesCounter.ValueParameter.ActualName = "EvaluatedSolutions";
|
---|
| 238 | subScopesCounter.Successor = resultsCollector;
|
---|
| 239 |
|
---|
| 240 | resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Evaluated Solutions", null, "EvaluatedSolutions"));
|
---|
| 241 | resultsCollector.ResultsParameter.ActualName = "Results";
|
---|
| 242 | resultsCollector.Successor = mainLoop;
|
---|
| 243 |
|
---|
| 244 | mainLoop.SelectorParameter.ActualName = SelectorParameter.Name;
|
---|
| 245 | mainLoop.CrossoverParameter.ActualName = CrossoverParameter.Name;
|
---|
| 246 | mainLoop.ElitesParameter.ActualName = ElitesParameter.Name;
|
---|
| 247 | mainLoop.MaximumGenerationsParameter.ActualName = MaximumGenerationsParameter.Name;
|
---|
| 248 | mainLoop.MutatorParameter.ActualName = MutatorParameter.Name;
|
---|
| 249 | mainLoop.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
|
---|
| 250 | mainLoop.RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
|
---|
| 251 | mainLoop.AnalyzerParameter.ActualName = AnalyzerParameter.Name;
|
---|
| 252 | mainLoop.EvaluatedSolutionsParameter.ActualName = "EvaluatedSolutions";
|
---|
| 253 | mainLoop.PopulationSizeParameter.ActualName = PopulationSizeParameter.Name;
|
---|
| 254 | mainLoop.ResultsParameter.ActualName = "Results";
|
---|
| 255 |
|
---|
| 256 | foreach (ISelector selector in ApplicationManager.Manager.GetInstances<ISelector>().Where(x => !(x is IMultiObjectiveSelector)).OrderBy(x => x.Name))
|
---|
| 257 | SelectorParameter.ValidValues.Add(selector);
|
---|
| 258 | ISelector proportionalSelector = SelectorParameter.ValidValues.FirstOrDefault(x => x.GetType().Name.Equals("ProportionalSelector"));
|
---|
| 259 | if (proportionalSelector != null) SelectorParameter.Value = proportionalSelector;
|
---|
| 260 | ParameterizeSelectors();
|
---|
| 261 |
|
---|
| 262 | qualityAnalyzer = new BestAverageWorstQualityAnalyzer();
|
---|
[8377] | 263 | populationSizeAnalyzer = new PopulationSizeAnalyzer();
|
---|
[8378] | 264 | offspringSuccessAnalyzer = new OffspringSuccessAnalyzer();
|
---|
[8313] | 265 | ParameterizeAnalyzers();
|
---|
| 266 | UpdateAnalyzers();
|
---|
| 267 |
|
---|
| 268 | Initialize();
|
---|
| 269 | }
|
---|
| 270 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 271 | return new RAPGA(this, cloner);
|
---|
| 272 | }
|
---|
| 273 |
|
---|
| 274 | public override void Prepare() {
|
---|
[8349] | 275 | if (Problem != null && SimilarityCalculator != null) base.Prepare();
|
---|
[8313] | 276 | }
|
---|
| 277 |
|
---|
| 278 | #region Events
|
---|
| 279 | protected override void OnProblemChanged() {
|
---|
| 280 | ParameterizeStochasticOperator(Problem.SolutionCreator);
|
---|
| 281 | ParameterizeStochasticOperator(Problem.Evaluator);
|
---|
| 282 | foreach (IOperator op in Problem.Operators.OfType<IOperator>()) ParameterizeStochasticOperator(op);
|
---|
| 283 | ParameterizeSolutionsCreator();
|
---|
| 284 | ParameterizeSelectors();
|
---|
| 285 | ParameterizeAnalyzers();
|
---|
| 286 | ParameterizeIterationBasedOperators();
|
---|
| 287 | UpdateCrossovers();
|
---|
| 288 | UpdateMutators();
|
---|
| 289 | UpdateAnalyzers();
|
---|
[8349] | 290 | UpdateSimilarityCalculators();
|
---|
| 291 | ParameterizeRAPGAMainLoop();
|
---|
[8313] | 292 | Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
|
---|
| 293 | base.OnProblemChanged();
|
---|
| 294 | }
|
---|
| 295 |
|
---|
| 296 | protected override void Problem_SolutionCreatorChanged(object sender, EventArgs e) {
|
---|
| 297 | ParameterizeStochasticOperator(Problem.SolutionCreator);
|
---|
| 298 | ParameterizeSolutionsCreator();
|
---|
| 299 | base.Problem_SolutionCreatorChanged(sender, e);
|
---|
| 300 | }
|
---|
| 301 | protected override void Problem_EvaluatorChanged(object sender, EventArgs e) {
|
---|
| 302 | ParameterizeStochasticOperator(Problem.Evaluator);
|
---|
| 303 | ParameterizeSolutionsCreator();
|
---|
[8349] | 304 | ParameterizeRAPGAMainLoop();
|
---|
[8313] | 305 | ParameterizeSelectors();
|
---|
| 306 | ParameterizeAnalyzers();
|
---|
| 307 | Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
|
---|
| 308 | base.Problem_EvaluatorChanged(sender, e);
|
---|
| 309 | }
|
---|
| 310 | protected override void Problem_OperatorsChanged(object sender, EventArgs e) {
|
---|
[8349] | 311 | foreach (IOperator op in Problem.Operators.OfType<IOperator>()) ParameterizeStochasticOperator(op);
|
---|
[8313] | 312 | ParameterizeIterationBasedOperators();
|
---|
| 313 | UpdateCrossovers();
|
---|
| 314 | UpdateMutators();
|
---|
| 315 | UpdateAnalyzers();
|
---|
[8349] | 316 | UpdateSimilarityCalculators();
|
---|
| 317 | ParameterizeRAPGAMainLoop();
|
---|
[8313] | 318 | base.Problem_OperatorsChanged(sender, e);
|
---|
| 319 | }
|
---|
[8377] | 320 | void BatchSizeParameter_ValueChanged(object sender, EventArgs e) {
|
---|
| 321 | BatchSize.ValueChanged += new EventHandler(BatchSize_ValueChanged);
|
---|
[8359] | 322 | ParameterizeSelectors();
|
---|
| 323 | }
|
---|
[8377] | 324 | void BatchSize_ValueChanged(object sender, EventArgs e) {
|
---|
[8359] | 325 | ParameterizeSelectors();
|
---|
| 326 | }
|
---|
[8313] | 327 | private void ElitesParameter_ValueChanged(object sender, EventArgs e) {
|
---|
| 328 | Elites.ValueChanged += new EventHandler(Elites_ValueChanged);
|
---|
| 329 | ParameterizeSelectors();
|
---|
| 330 | }
|
---|
| 331 | private void Elites_ValueChanged(object sender, EventArgs e) {
|
---|
| 332 | ParameterizeSelectors();
|
---|
| 333 | }
|
---|
| 334 |
|
---|
| 335 | private void PopulationSizeParameter_ValueChanged(object sender, EventArgs e) {
|
---|
| 336 | PopulationSize.ValueChanged += new EventHandler(PopulationSize_ValueChanged);
|
---|
| 337 | ParameterizeSelectors();
|
---|
| 338 | }
|
---|
| 339 | private void PopulationSize_ValueChanged(object sender, EventArgs e) {
|
---|
| 340 | ParameterizeSelectors();
|
---|
| 341 | }
|
---|
| 342 | private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
|
---|
[8349] | 343 | ParameterizeRAPGAMainLoop();
|
---|
[8313] | 344 | ParameterizeSelectors();
|
---|
| 345 | ParameterizeAnalyzers();
|
---|
| 346 | }
|
---|
| 347 | #endregion
|
---|
| 348 |
|
---|
| 349 | #region Helpers
|
---|
| 350 | private void Initialize() {
|
---|
| 351 | PopulationSizeParameter.ValueChanged += new EventHandler(PopulationSizeParameter_ValueChanged);
|
---|
| 352 | PopulationSize.ValueChanged += new EventHandler(PopulationSize_ValueChanged);
|
---|
| 353 | ElitesParameter.ValueChanged += new EventHandler(ElitesParameter_ValueChanged);
|
---|
| 354 | Elites.ValueChanged += new EventHandler(Elites_ValueChanged);
|
---|
[8377] | 355 | BatchSizeParameter.ValueChanged += new EventHandler(BatchSizeParameter_ValueChanged);
|
---|
| 356 | BatchSize.ValueChanged += new EventHandler(BatchSize_ValueChanged);
|
---|
[8313] | 357 | if (Problem != null) {
|
---|
| 358 | Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
|
---|
| 359 | }
|
---|
| 360 | }
|
---|
| 361 |
|
---|
| 362 | private void ParameterizeSolutionsCreator() {
|
---|
| 363 | SolutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
|
---|
| 364 | SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name;
|
---|
| 365 | }
|
---|
[8349] | 366 | private void ParameterizeRAPGAMainLoop() {
|
---|
[8313] | 367 | RAPGAMainLoop.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
|
---|
| 368 | RAPGAMainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
|
---|
| 369 | RAPGAMainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
[8349] | 370 | foreach (ISimilarityBasedOperator op in RAPGAMainLoop.OperatorGraph.Operators.OfType<ISimilarityBasedOperator>())
|
---|
| 371 | op.SimilarityCalculator = SimilarityCalculator;
|
---|
[8313] | 372 | }
|
---|
| 373 | private void ParameterizeStochasticOperator(IOperator op) {
|
---|
| 374 | IStochasticOperator stochasticOp = op as IStochasticOperator;
|
---|
| 375 | if (stochasticOp != null) {
|
---|
| 376 | stochasticOp.RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
|
---|
| 377 | stochasticOp.RandomParameter.Hidden = true;
|
---|
| 378 | }
|
---|
| 379 | }
|
---|
| 380 | private void ParameterizeSelectors() {
|
---|
| 381 | foreach (ISelector selector in SelectorParameter.ValidValues) {
|
---|
| 382 | selector.CopySelected = new BoolValue(true);
|
---|
[8377] | 383 | selector.NumberOfSelectedSubScopesParameter.Value = new IntValue(2 * BatchSize.Value);
|
---|
[8313] | 384 | selector.NumberOfSelectedSubScopesParameter.Hidden = true;
|
---|
| 385 | ParameterizeStochasticOperator(selector);
|
---|
| 386 | }
|
---|
| 387 | if (Problem != null) {
|
---|
| 388 | foreach (ISingleObjectiveSelector selector in SelectorParameter.ValidValues.OfType<ISingleObjectiveSelector>()) {
|
---|
| 389 | selector.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
|
---|
| 390 | selector.MaximizationParameter.Hidden = true;
|
---|
| 391 | selector.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
| 392 | selector.QualityParameter.Hidden = true;
|
---|
| 393 | }
|
---|
| 394 | }
|
---|
| 395 | }
|
---|
| 396 | private void ParameterizeAnalyzers() {
|
---|
| 397 | qualityAnalyzer.ResultsParameter.ActualName = "Results";
|
---|
| 398 | qualityAnalyzer.ResultsParameter.Hidden = true;
|
---|
[8377] | 399 | populationSizeAnalyzer.ResultsParameter.ActualName = "Results";
|
---|
| 400 | populationSizeAnalyzer.ResultsParameter.Hidden = true;
|
---|
[8378] | 401 | offspringSuccessAnalyzer.ResultsParameter.ActualName = "Results";
|
---|
| 402 | offspringSuccessAnalyzer.ResultsParameter.Hidden = true;
|
---|
[8313] | 403 | if (Problem != null) {
|
---|
| 404 | qualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
|
---|
| 405 | qualityAnalyzer.MaximizationParameter.Hidden = true;
|
---|
| 406 | qualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
| 407 | qualityAnalyzer.QualityParameter.Depth = 1;
|
---|
| 408 | qualityAnalyzer.QualityParameter.Hidden = true;
|
---|
| 409 | qualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
|
---|
| 410 | qualityAnalyzer.BestKnownQualityParameter.Hidden = true;
|
---|
| 411 | }
|
---|
| 412 | }
|
---|
| 413 | private void ParameterizeIterationBasedOperators() {
|
---|
| 414 | if (Problem != null) {
|
---|
| 415 | foreach (IIterationBasedOperator op in Problem.Operators.OfType<IIterationBasedOperator>()) {
|
---|
| 416 | op.IterationsParameter.ActualName = "Generations";
|
---|
| 417 | op.IterationsParameter.Hidden = true;
|
---|
| 418 | op.MaximumIterationsParameter.ActualName = "MaximumGenerations";
|
---|
| 419 | op.MaximumIterationsParameter.Hidden = true;
|
---|
| 420 | }
|
---|
| 421 | }
|
---|
| 422 | }
|
---|
| 423 | private void UpdateCrossovers() {
|
---|
| 424 | ICrossover oldCrossover = CrossoverParameter.Value;
|
---|
| 425 | CrossoverParameter.ValidValues.Clear();
|
---|
| 426 | ICrossover defaultCrossover = Problem.Operators.OfType<ICrossover>().FirstOrDefault();
|
---|
| 427 |
|
---|
| 428 | foreach (ICrossover crossover in Problem.Operators.OfType<ICrossover>().OrderBy(x => x.Name))
|
---|
| 429 | CrossoverParameter.ValidValues.Add(crossover);
|
---|
| 430 |
|
---|
| 431 | if (oldCrossover != null) {
|
---|
| 432 | ICrossover crossover = CrossoverParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldCrossover.GetType());
|
---|
| 433 | if (crossover != null) CrossoverParameter.Value = crossover;
|
---|
| 434 | else oldCrossover = null;
|
---|
| 435 | }
|
---|
| 436 | if (oldCrossover == null && defaultCrossover != null)
|
---|
| 437 | CrossoverParameter.Value = defaultCrossover;
|
---|
| 438 | }
|
---|
| 439 | private void UpdateMutators() {
|
---|
| 440 | IManipulator oldMutator = MutatorParameter.Value;
|
---|
| 441 | MutatorParameter.ValidValues.Clear();
|
---|
| 442 | foreach (IManipulator mutator in Problem.Operators.OfType<IManipulator>().OrderBy(x => x.Name))
|
---|
| 443 | MutatorParameter.ValidValues.Add(mutator);
|
---|
| 444 | if (oldMutator != null) {
|
---|
| 445 | IManipulator mutator = MutatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMutator.GetType());
|
---|
| 446 | if (mutator != null) MutatorParameter.Value = mutator;
|
---|
| 447 | }
|
---|
| 448 | }
|
---|
| 449 | private void UpdateAnalyzers() {
|
---|
| 450 | Analyzer.Operators.Clear();
|
---|
| 451 | if (Problem != null) {
|
---|
| 452 | foreach (IAnalyzer analyzer in Problem.Operators.OfType<IAnalyzer>()) {
|
---|
| 453 | foreach (IScopeTreeLookupParameter param in analyzer.Parameters.OfType<IScopeTreeLookupParameter>())
|
---|
| 454 | param.Depth = 1;
|
---|
| 455 | Analyzer.Operators.Add(analyzer, analyzer.EnabledByDefault);
|
---|
| 456 | }
|
---|
| 457 | }
|
---|
| 458 | Analyzer.Operators.Add(qualityAnalyzer, qualityAnalyzer.EnabledByDefault);
|
---|
[8377] | 459 | Analyzer.Operators.Add(populationSizeAnalyzer, populationSizeAnalyzer.EnabledByDefault);
|
---|
[8378] | 460 | Analyzer.Operators.Add(offspringSuccessAnalyzer, offspringSuccessAnalyzer.EnabledByDefault);
|
---|
[8313] | 461 | }
|
---|
[8349] | 462 | private void UpdateSimilarityCalculators() {
|
---|
| 463 | ISolutionSimilarityCalculator oldSimilarityCalculator = SimilarityCalculatorParameter.Value;
|
---|
| 464 | SimilarityCalculatorParameter.ValidValues.Clear();
|
---|
| 465 | ISolutionSimilarityCalculator defaultSimilarityCalculator = Problem.Operators.OfType<ISolutionSimilarityCalculator>().FirstOrDefault();
|
---|
| 466 |
|
---|
| 467 | foreach (ISolutionSimilarityCalculator similarityCalculator in Problem.Operators.OfType<ISolutionSimilarityCalculator>())
|
---|
| 468 | SimilarityCalculatorParameter.ValidValues.Add(similarityCalculator);
|
---|
| 469 |
|
---|
| 470 | if (oldSimilarityCalculator != null) {
|
---|
| 471 | ISolutionSimilarityCalculator similarityCalculator = SimilarityCalculatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldSimilarityCalculator.GetType());
|
---|
| 472 | if (similarityCalculator != null) SimilarityCalculatorParameter.Value = similarityCalculator;
|
---|
| 473 | else oldSimilarityCalculator = null;
|
---|
| 474 | }
|
---|
| 475 | if (oldSimilarityCalculator == null && defaultSimilarityCalculator != null)
|
---|
| 476 | SimilarityCalculatorParameter.Value = defaultSimilarityCalculator;
|
---|
| 477 | }
|
---|
[8313] | 478 | private RAPGAMainLoop FindMainLoop(IOperator start) {
|
---|
| 479 | IOperator mainLoop = start;
|
---|
| 480 | while (mainLoop != null && !(mainLoop is RAPGAMainLoop))
|
---|
| 481 | mainLoop = ((SingleSuccessorOperator)mainLoop).Successor;
|
---|
| 482 | if (mainLoop == null) return null;
|
---|
| 483 | else return (RAPGAMainLoop)mainLoop;
|
---|
| 484 | }
|
---|
| 485 | #endregion
|
---|
| 486 | }
|
---|
| 487 | }
|
---|