Changeset 12993 for branches/ALPS
- Timestamp:
- 10/09/15 14:37:18 (9 years ago)
- Location:
- branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3
- Files:
-
- 1 deleted
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/AlpsGeneticAlgorithm.cs
r12992 r12993 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using HeuristicLab.Analysis; 26 using HeuristicLab.Collections; 25 27 using HeuristicLab.Common; 26 28 using HeuristicLab.Core; … … 39 41 [Creatable("Algorithms")] 40 42 [StorableClass] 41 public sealed class AlpsGeneticAlgorithm : Alps { 43 public sealed class AlpsGeneticAlgorithm : 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 42 56 #region Parameter Properties 57 private IValueParameter<IntValue> SeedParameter { 58 get { return (IValueParameter<IntValue>)Parameters["Seed"]; } 59 } 60 private IValueParameter<BoolValue> SetSeedRandomlyParameter { 61 get { return (IValueParameter<BoolValue>)Parameters["SetSeedRandomly"]; } 62 } 63 64 private IFixedValueParameter<MultiAnalyzer> AnalyzerParameter { 65 get { return (IFixedValueParameter<MultiAnalyzer>)Parameters["Analyzer"]; } 66 } 67 private IFixedValueParameter<MultiAnalyzer> LayerAnalyzerParameter { 68 get { return (IFixedValueParameter<MultiAnalyzer>)Parameters["LayerAnalyzer"]; } 69 } 70 71 private IValueParameter<IntValue> NumberOfLayersParameter { 72 get { return (IValueParameter<IntValue>)Parameters["NumberOfLayers"]; } 73 } 43 74 private IValueParameter<IntValue> PopulationSizeParameter { 44 75 get { return (IValueParameter<IntValue>)Parameters["PopulationSize"]; } 45 76 } 77 46 78 public IConstrainedValueParameter<ISelector> SelectorParameter { 47 79 get { return (IConstrainedValueParameter<ISelector>)Parameters["Selector"]; } … … 50 82 get { return (IConstrainedValueParameter<ICrossover>)Parameters["Crossover"]; } 51 83 } 84 public IConstrainedValueParameter<IManipulator> MutatorParameter { 85 get { return (IConstrainedValueParameter<IManipulator>)Parameters["Mutator"]; } 86 } 52 87 private IValueParameter<PercentValue> MutationProbabilityParameter { 53 88 get { return (IValueParameter<PercentValue>)Parameters["MutationProbability"]; } 54 89 } 55 public IConstrainedValueParameter<IManipulator> MutatorParameter {56 get { return (IConstrainedValueParameter<IManipulator>)Parameters["Mutator"]; }57 }58 90 private IValueParameter<IntValue> ElitesParameter { 59 91 get { return (IValueParameter<IntValue>)Parameters["Elites"]; } … … 65 97 get { return (IValueParameter<BoolValue>)Parameters["PlusSelection"]; } 66 98 } 99 100 private IValueParameter<EnumValue<AgingScheme>> AgingSchemeParameter { 101 get { return (IValueParameter<EnumValue<AgingScheme>>)Parameters["AgingScheme"]; } 102 } 103 private IValueParameter<IntValue> AgeGapParameter { 104 get { return (IValueParameter<IntValue>)Parameters["AgeGap"]; } 105 } 106 private IValueParameter<EnumValue<AgeInheritance>> AgeInheritanceParameter { 107 get { return (IValueParameter<EnumValue<AgeInheritance>>)Parameters["AgeInheritance"]; } 108 } 109 private IValueParameter<ReductionOperation> AgeInheritanceReductionParameter { 110 get { return (IValueParameter<ReductionOperation>)Parameters["AgeInheritanceReduction"]; } 111 } 112 private IValueParameter<IntArray> AgeLimitsParameter { 113 get { return (IValueParameter<IntArray>)Parameters["AgeLimits"]; } 114 } 115 116 private IValueParameter<IntValue> MatingPoolRangeParameter { 117 get { return (IValueParameter<IntValue>)Parameters["MatingPoolRange"]; } 118 } 119 private IValueParameter<PercentValue> MatingPoolSelectionPercentageParameter { 120 get { return (IValueLookupParameter<PercentValue>)Parameters["MatingPoolSelectionPercentage"]; } 121 } 122 123 private IValueParameter<MultiTerminator> TerminatorParameter { 124 get { return (IValueParameter<MultiTerminator>)Parameters["Terminator"]; } 125 } 67 126 #endregion 68 127 69 128 #region Properties 129 public IntValue Seed { 130 get { return SeedParameter.Value; } 131 set { SeedParameter.Value = value; } 132 } 133 public BoolValue SetSeedRandomly { 134 get { return SetSeedRandomlyParameter.Value; } 135 set { SetSeedRandomlyParameter.Value = value; } 136 } 137 138 public MultiAnalyzer Analyzer { 139 get { return AnalyzerParameter.Value; } 140 } 141 public MultiAnalyzer LayerAnalyzer { 142 get { return LayerAnalyzerParameter.Value; } 143 } 144 145 public IntValue NumberOfLayers { 146 get { return NumberOfLayersParameter.Value; } 147 set { NumberOfLayersParameter.Value = value; } 148 } 70 149 public IntValue PopulationSize { 71 150 get { return PopulationSizeParameter.Value; } 72 151 set { PopulationSizeParameter.Value = value; } 73 152 } 153 154 public ISelector Selector { 155 get { return SelectorParameter.Value; } 156 set { SelectorParameter.Value = value; } 157 } 158 public ICrossover Crossover { 159 get { return CrossoverParameter.Value; } 160 set { CrossoverParameter.Value = value; } 161 } 162 public IManipulator Mutator { 163 get { return MutatorParameter.Value; } 164 set { MutatorParameter.Value = value; } 165 } 166 public PercentValue MutationProbability { 167 get { return MutationProbabilityParameter.Value; } 168 set { MutationProbabilityParameter.Value = value; } 169 } 170 public IntValue Elites { 171 get { return ElitesParameter.Value; } 172 set { ElitesParameter.Value = value; } 173 } 174 public bool ReevaluteElites { 175 get { return ReevaluateElitesParameter.Value.Value; } 176 set { ReevaluateElitesParameter.Value.Value = value; } 177 } 178 public bool PlusSelection { 179 get { return PlusSelectionParameter.Value.Value; } 180 set { PlusSelectionParameter.Value.Value = value; } 181 } 182 183 public EnumValue<AgingScheme> AgingScheme { 184 get { return AgingSchemeParameter.Value; } 185 set { AgingSchemeParameter.Value = value; } 186 } 187 public IntValue AgeGap { 188 get { return AgeGapParameter.Value; } 189 set { AgeGapParameter.Value = value; } 190 } 191 public EnumValue<AgeInheritance> AgeInheritance { 192 get { return AgeInheritanceParameter.Value; } 193 set { AgeInheritanceParameter.Value = value; } 194 } 195 private ReductionOperation AgeInheritanceReduction { 196 get { return AgeInheritanceReductionParameter.Value; } 197 set { AgeInheritanceReductionParameter.Value = value; } 198 } 199 public IntArray AgeLimits { 200 get { return AgeLimitsParameter.Value; } 201 set { AgeLimitsParameter.Value = value; } 202 } 203 204 public IntValue MatingPoolRange { 205 get { return MatingPoolRangeParameter.Value; } 206 set { MatingPoolRangeParameter.Value = value; } 207 } 208 public PercentValue MatingPoolSelectionPercentage { 209 get { return MatingPoolSelectionPercentageParameter.Value; } 210 set { MatingPoolSelectionPercentageParameter.Value = value; } 211 } 212 213 public MultiTerminator Terminators { 214 get { return TerminatorParameter.Value; } 215 } 216 74 217 public int MaximumGenerations { 75 218 get { return generationsTerminator.Threshold.Value; } 76 219 set { generationsTerminator.Threshold.Value = value; } 77 220 } 78 public ISelector Selector { 79 get { return SelectorParameter.Value; } 80 set { SelectorParameter.Value = value; } 81 } 82 public ICrossover Crossover { 83 get { return CrossoverParameter.Value; } 84 set { CrossoverParameter.Value = value; } 85 } 86 public PercentValue MutationProbability { 87 get { return MutationProbabilityParameter.Value; } 88 set { MutationProbabilityParameter.Value = value; } 89 } 90 public IManipulator Mutator { 91 get { return MutatorParameter.Value; } 92 set { MutatorParameter.Value = value; } 93 } 94 public IntValue Elites { 95 get { return ElitesParameter.Value; } 96 set { ElitesParameter.Value = value; } 97 } 98 public bool ReevaluteElites { 99 get { return ReevaluateElitesParameter.Value.Value; } 100 set { ReevaluateElitesParameter.Value.Value = value; } 101 } 102 public bool PlusSelection { 103 get { return PlusSelectionParameter.Value.Value; } 104 set { PlusSelectionParameter.Value.Value = value; } 105 } 106 221 #endregion 222 223 #region Helper Properties 224 private RandomCreator GlobalRandomCreator { 225 get { return (RandomCreator)OperatorGraph.InitialOperator; } 226 } 227 private SolutionsCreator SolutionsCreator { 228 get { return OperatorGraph.Iterate().OfType<SolutionsCreator>().First(); } 229 } 107 230 private AlpsGeneticAlgorithmMainLoop MainLoop { 108 231 get { return OperatorGraph.Iterate().OfType<AlpsGeneticAlgorithmMainLoop>().First(); } … … 110 233 #endregion 111 234 235 #region Preconfigured Analyzers 236 [Storable] 237 private BestAverageWorstQualityAnalyzer qualityAnalyzer; 238 [Storable] 239 private BestAverageWorstQualityAnalyzer layerQualityAnalyzer; 240 #endregion 241 242 #region Preconfigured Terminators 112 243 [Storable] 113 244 private ComparisonTerminator<IntValue> generationsTerminator; 245 [Storable] 246 private ComparisonTerminator<IntValue> evaluationsTerminator; 247 [Storable] 248 private SingleObjectiveQualityTerminator qualityTerminator; 249 [Storable] 250 private ExecutionTimeTerminator executionTimeTerminator; 251 #endregion 114 252 115 253 [StorableConstructor] … … 122 260 private AlpsGeneticAlgorithm(AlpsGeneticAlgorithm original, Cloner cloner) 123 261 : base(original, cloner) { 262 qualityAnalyzer = cloner.Clone(original.qualityAnalyzer); 263 layerQualityAnalyzer = cloner.Clone(original.layerQualityAnalyzer); 124 264 generationsTerminator = cloner.Clone(original.generationsTerminator); 265 evaluationsTerminator = cloner.Clone(original.evaluationsTerminator); 266 qualityTerminator = cloner.Clone(original.qualityTerminator); 267 executionTimeTerminator = cloner.Clone(original.executionTimeTerminator); 125 268 Initialize(); 126 269 } … … 130 273 public AlpsGeneticAlgorithm() 131 274 : base() { 275 #region Add parameters 276 Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0))); 277 Parameters.Add(new ValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true))); 278 279 Parameters.Add(new FixedValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze the islands.", new MultiAnalyzer())); 280 Parameters.Add(new FixedValueParameter<MultiAnalyzer>("LayerAnalyzer", "The operator used to analyze each layer.", new MultiAnalyzer())); 281 282 Parameters.Add(new ValueParameter<IntValue>("NumberOfLayers", "The number of layers.", new IntValue(10))); 132 283 Parameters.Add(new ValueParameter<IntValue>("PopulationSize", "The size of the population of solutions each layer.", new IntValue(100))); 284 133 285 Parameters.Add(new ConstrainedValueParameter<ISelector>("Selector", "The operator used to select solutions for reproduction.")); 134 286 Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions.")); 287 Parameters.Add(new OptionalConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions.")); 135 288 Parameters.Add(new ValueParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution.", new PercentValue(0.05))); 136 Parameters.Add(new OptionalConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions."));137 289 Parameters.Add(new ValueParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.", new IntValue(1))); 138 290 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 }); 139 291 Parameters.Add(new ValueParameter<BoolValue>("PlusSelection", "Include the parents in the selection of the invividuals for the next generation.", new BoolValue(false)) { Hidden = true }); 140 292 293 Parameters.Add(new ValueParameter<EnumValue<AgingScheme>>("AgingScheme", "The aging scheme for setting the age-limits for the layers.", new EnumValue<AgingScheme>(ALPS.AgingScheme.Polynomial))); 294 Parameters.Add(new ValueParameter<IntValue>("AgeGap", "The frequency of reseeding the lowest layer and scaling factor for the age-limits for the layers", new IntValue(20))); 295 Parameters.Add(new ValueParameter<EnumValue<AgeInheritance>>("AgeInheritance", "The operator for determining the age of an offspring based the parents' age.", new EnumValue<AgeInheritance>(ALPS.AgeInheritance.Older))); 296 Parameters.Add(new ValueParameter<ReductionOperation>("AgeInheritanceReduction") { Hidden = true }); 297 Parameters.Add(new ValueParameter<IntArray>("AgeLimits", new IntArray(new int[0])) { Hidden = true }); 298 299 Parameters.Add(new ValueParameter<IntValue>("MatingPoolRange", "The range of layers used for creating a mating pool. (1 = current + previous layer)", new IntValue(1)) { Hidden = true }); 300 Parameters.Add(new ValueParameter<PercentValue>("MatingPoolSelectionPercentage", "Percentage of the previous layers used for creating a mating pool.", new PercentValue(1.0, restrictToUnitInterval: true)) { Hidden = true }); 301 302 Parameters.Add(new ValueParameter<MultiTerminator>("Terminator", "The termination criteria which sould be checked.", new MultiTerminator())); 303 #endregion 304 305 #region Create operators 141 306 var globalRandomCreator = new RandomCreator(); 142 307 var layer0Creator = new SubScopesCreator() { Name = "Create Layer Zero" }; … … 152 317 var resultsCollector = new ResultsCollector(); 153 318 var mainLoop = new AlpsGeneticAlgorithmMainLoop(); 154 319 #endregion 320 321 #region Create and parameterize operator graph 155 322 OperatorGraph.InitialOperator = globalRandomCreator; 156 323 … … 195 362 resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Evaluated Solutions", null, "EvaluatedSolutions")); 196 363 resultsCollector.Successor = mainLoop; 197 364 #endregion 365 366 #region Set selectors 198 367 foreach (var selector in ApplicationManager.Manager.GetInstances<ISelector>().Where(s => !(s is IMultiObjectiveSelector)).OrderBy(s => Name)) 199 368 SelectorParameter.ValidValues.Add(selector); 200 var tournamentSelector = SelectorParameter.ValidValues.OfType<TournamentSelector>().FirstOrDefault(); 201 if (tournamentSelector != null) { 202 tournamentSelector.GroupSizeParameter.Value = new IntValue(4); 203 SelectorParameter.Value = tournamentSelector; 204 } 205 369 var defaultSelector = SelectorParameter.ValidValues.OfType<GeneralizedRankSelector>().FirstOrDefault(); 370 if (defaultSelector != null) { 371 defaultSelector.PressureParameter.Value = new DoubleValue(4); 372 SelectorParameter.Value = defaultSelector; 373 } 374 #endregion 375 376 #region Create analyzers 377 qualityAnalyzer = new BestAverageWorstQualityAnalyzer(); 378 layerQualityAnalyzer = new BestAverageWorstQualityAnalyzer(); 379 #endregion 380 381 #region Create terminators 206 382 generationsTerminator = new ComparisonTerminator<IntValue>("Generations", ComparisonType.Less, new IntValue(1000)) { Name = "Generations" }; 383 evaluationsTerminator = new ComparisonTerminator<IntValue>("EvaluatedSolutions", ComparisonType.Less, new IntValue(int.MaxValue)) { Name = "Evaluations" }; 384 qualityTerminator = new SingleObjectiveQualityTerminator() { Name = "Quality" }; 385 executionTimeTerminator = new ExecutionTimeTerminator(this, new TimeSpanValue(TimeSpan.FromMinutes(5))); 386 #endregion 387 388 #region Parameterize 389 ParameterizeAnalyzers(); 390 UpdateAnalyzers(); 207 391 208 392 ParameterizeSelectors(); … … 210 394 UpdateTerminators(); 211 395 396 ParameterizeAgeLimits(); 397 ParameterizeAgeInheritanceReduction(); 398 #endregion 399 212 400 Initialize(); 213 401 } 214 402 215 403 #region Events 404 public override void Prepare() { 405 if (Problem != null) 406 base.Prepare(); 407 } 216 408 protected override void OnProblemChanged() { 217 409 base.OnProblemChanged(); 410 ParameterizeStochasticOperator(Problem.SolutionCreator); 411 ParameterizeStochasticOperatorForLayer(Problem.Evaluator); 412 foreach (var @operator in Problem.Operators.OfType<IOperator>()) 413 ParameterizeStochasticOperator(@operator); 414 415 ParameterizeIterationBasedOperators(); 416 218 417 ParameterizeSolutionsCreator(); 219 418 ParameterizeMainLoop(); 419 ParameterizeAnalyzers(); 220 420 ParameterizeSelectors(); 221 ParameterizeIterationBasedOperators(); 421 ParameterizeTerminators(); 422 423 Problem.Evaluator.QualityParameter.ActualNameChanged += Evaluator_QualityParameter_ActualNameChanged; 424 425 UpdateAnalyzers(); 222 426 UpdateCrossovers(); 223 427 UpdateMutators(); 224 428 UpdateTerminators(); 225 429 } 430 431 protected override void RegisterProblemEvents() { 432 base.RegisterProblemEvents(); 433 var maximizationParameter = (IValueParameter<BoolValue>)Problem.MaximizationParameter; 434 if (maximizationParameter != null) maximizationParameter.ValueChanged += new EventHandler(MaximizationParameter_ValueChanged); 435 } 436 protected override void DeregisterProblemEvents() { 437 var maximizationParameter = (IValueParameter<BoolValue>)Problem.MaximizationParameter; 438 if (maximizationParameter != null) maximizationParameter.ValueChanged -= new EventHandler(MaximizationParameter_ValueChanged); 439 base.DeregisterProblemEvents(); 440 } 441 226 442 protected override void Problem_SolutionCreatorChanged(object sender, EventArgs e) { 227 443 base.Problem_SolutionCreatorChanged(sender, e); 444 ParameterizeStochasticOperator(Problem.SolutionCreator); 445 ParameterizeStochasticOperatorForLayer(Problem.Evaluator); 446 447 Problem.Evaluator.QualityParameter.ActualNameChanged += Evaluator_QualityParameter_ActualNameChanged; 448 228 449 ParameterizeSolutionsCreator(); 450 ParameterizeAnalyzers(); 229 451 } 230 452 protected override void Problem_EvaluatorChanged(object sender, EventArgs e) { 231 453 base.Problem_EvaluatorChanged(sender, e); 454 foreach (var @operator in Problem.Operators.OfType<IOperator>()) 455 ParameterizeStochasticOperator(@operator); 456 457 UpdateAnalyzers(); 458 232 459 ParameterizeSolutionsCreator(); 233 460 ParameterizeMainLoop(); … … 241 468 UpdateTerminators(); 242 469 } 243 protected override void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) { 244 base.Evaluator_QualityParameter_ActualNameChanged(sender, e); 470 private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) { 245 471 ParameterizeMainLoop(); 472 ParameterizeAnalyzers(); 246 473 ParameterizeSelectors(); 474 } 475 private void MaximizationParameter_ValueChanged(object sender, EventArgs e) { 476 ParameterizeTerminators(); 477 } 478 private void QualityAnalyzer_CurrentBestQualityParameter_NameChanged(object sender, EventArgs e) { 479 ParameterizeTerminators(); 480 } 481 482 private void AgeGapParameter_ValueChanged(object sender, EventArgs e) { 483 AgeGap.ValueChanged += AgeGap_ValueChanged; 484 ParameterizeAgeLimits(); 485 } 486 private void AgeGap_ValueChanged(object sender, EventArgs e) { 487 ParameterizeAgeLimits(); 488 } 489 private void AgingSchemeParameter_ValueChanged(object sender, EventArgs e) { 490 AgingScheme.ValueChanged += AgingScheme_ValueChanged; 491 ParameterizeAgeLimits(); 492 } 493 private void AgingScheme_ValueChanged(object sender, EventArgs e) { 494 ParameterizeAgeLimits(); 495 } 496 private void NumberOfLayersParameter_ValueChanged(object sender, EventArgs e) { 497 NumberOfLayers.ValueChanged += NumberOfLayers_ValueChanged; 498 ParameterizeAgeLimits(); 499 } 500 private void NumberOfLayers_ValueChanged(object sender, EventArgs e) { 501 ParameterizeAgeLimits(); 502 } 503 private void AgeInheritanceParameter_ValueChanged(object sender, EventArgs e) { 504 AgeInheritance.ValueChanged += AgeInheritance_ValueChanged; 505 ParameterizeAgeInheritanceReduction(); 506 } 507 private void AgeInheritance_ValueChanged(object sender, EventArgs e) { 508 ParameterizeAgeInheritanceReduction(); 509 } 510 511 private void AnalyzerOperators_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<IAnalyzer>> e) { 512 foreach (var analyzer in e.Items) { 513 foreach (var parameter in analyzer.Value.Parameters.OfType<IScopeTreeLookupParameter>()) { 514 parameter.Depth = 2; 515 } 516 } 517 } 518 private void LayerAnalyzerOperators_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<IAnalyzer>> e) { 519 foreach (var analyzer in e.Items) { 520 IParameter resultParameter; 521 if (analyzer.Value.Parameters.TryGetValue("Results", out resultParameter)) { 522 var lookupParameter = resultParameter as ILookupParameter; 523 if (lookupParameter != null) 524 lookupParameter.ActualName = "LayerResults"; 525 } 526 foreach (var parameter in analyzer.Value.Parameters.OfType<IScopeTreeLookupParameter>()) { 527 parameter.Depth = 1; 528 } 529 } 247 530 } 248 531 #endregion … … 250 533 #region Parameterization 251 534 private void Initialize() { 535 if (Problem != null) 536 Problem.Evaluator.QualityParameter.ActualNameChanged += Evaluator_QualityParameter_ActualNameChanged; 537 538 NumberOfLayersParameter.ValueChanged += NumberOfLayersParameter_ValueChanged; 539 NumberOfLayers.ValueChanged += NumberOfLayers_ValueChanged; 540 541 Analyzer.Operators.ItemsAdded += AnalyzerOperators_ItemsAdded; 542 LayerAnalyzer.Operators.ItemsAdded += LayerAnalyzerOperators_ItemsAdded; 543 544 AgeGapParameter.ValueChanged += AgeGapParameter_ValueChanged; 545 AgeGap.ValueChanged += AgeGap_ValueChanged; 546 AgingSchemeParameter.ValueChanged += AgingSchemeParameter_ValueChanged; 547 AgingScheme.ValueChanged += AgingScheme_ValueChanged; 548 AgeInheritanceParameter.ValueChanged += AgeInheritanceParameter_ValueChanged; 549 AgeInheritance.ValueChanged += AgeInheritance_ValueChanged; 550 551 qualityAnalyzer.CurrentBestQualityParameter.NameChanged += new EventHandler(QualityAnalyzer_CurrentBestQualityParameter_NameChanged); 252 552 } 253 553 private void ParameterizeSolutionsCreator() { 554 SolutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name; 555 SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name; 254 556 MainLoop.LayerUpdator.SolutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name; 255 557 MainLoop.LayerUpdator.SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name; … … 263 565 MainLoop.LayerUpdator.SolutionsCreator.NumberOfSolutionsParameter.ActualName = PopulationSizeParameter.Name; 264 566 } 567 private void ParameterizeAnalyzers() { 568 qualityAnalyzer.ResultsParameter.ActualName = "Results"; 569 qualityAnalyzer.ResultsParameter.Hidden = true; 570 qualityAnalyzer.QualityParameter.Depth = 2; 571 layerQualityAnalyzer.ResultsParameter.ActualName = "Results"; 572 layerQualityAnalyzer.ResultsParameter.Hidden = true; 573 layerQualityAnalyzer.QualityParameter.Depth = 1; 574 if (Problem != null) { 575 qualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name; 576 qualityAnalyzer.MaximizationParameter.Hidden = true; 577 qualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName; 578 qualityAnalyzer.QualityParameter.Hidden = true; 579 qualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name; 580 qualityAnalyzer.BestKnownQualityParameter.Hidden = true; 581 layerQualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name; 582 layerQualityAnalyzer.MaximizationParameter.Hidden = true; 583 layerQualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName; 584 layerQualityAnalyzer.QualityParameter.Hidden = true; 585 layerQualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name; 586 layerQualityAnalyzer.BestKnownQualityParameter.Hidden = true; 587 } 588 } 265 589 private void ParameterizeSelectors() { 266 590 foreach (var selector in SelectorParameter.ValidValues) { … … 279 603 } 280 604 } 605 } 606 private void ParameterizeTerminators() { 607 qualityTerminator.Parameterize(qualityAnalyzer.CurrentBestQualityParameter, Problem); 281 608 } 282 609 private void ParameterizeIterationBasedOperators() { … … 290 617 } 291 618 } 292 293 protected override ReductionOperations GetAgeInheritanceReduction(AgeInheritance ageInheritance) { 619 private void ParameterizeAgeInheritanceReduction() { 620 AgeInheritanceReduction.Value = GetAgeInheritanceReduction(AgeInheritance.Value); 621 } 622 private void ParameterizeAgeLimits() { 623 var scheme = AgingScheme.Value; 624 int ageGap = AgeGap.Value; 625 int numberOfLayers = NumberOfLayers.Value; 626 AgeLimits = scheme.CalculateAgeLimits(ageGap, numberOfLayers); 627 } 628 629 private void ParameterizeStochasticOperator(IOperator @operator) { 630 var stochasticOperator = @operator as IStochasticOperator; 631 if (stochasticOperator != null) { 632 stochasticOperator.RandomParameter.ActualName = "GlobalRandom"; 633 stochasticOperator.RandomParameter.Hidden = true; 634 } 635 } 636 637 private void ParameterizeStochasticOperatorForLayer(IOperator @operator) { 638 var stochasticOperator = @operator as IStochasticOperator; 639 if (stochasticOperator != null) { 640 stochasticOperator.RandomParameter.ActualName = "LocalRandom"; 641 stochasticOperator.RandomParameter.Hidden = true; 642 } 643 } 644 645 private ReductionOperations GetAgeInheritanceReduction(AgeInheritance ageInheritance) { 294 646 switch (ageInheritance) { 295 647 case ALPS.AgeInheritance.Older: return ReductionOperations.Max; … … 302 654 303 655 #region Updates 656 private void UpdateAnalyzers() { 657 Analyzer.Operators.Clear(); 658 LayerAnalyzer.Operators.Clear(); 659 660 Analyzer.Operators.Add(qualityAnalyzer, qualityAnalyzer.EnabledByDefault); 661 LayerAnalyzer.Operators.Add(layerQualityAnalyzer, layerQualityAnalyzer.EnabledByDefault); 662 663 if (Problem != null) { 664 foreach (var analyzer in Problem.Operators.OfType<IAnalyzer>()) { 665 Analyzer.Operators.Add(analyzer, analyzer.EnabledByDefault); 666 } 667 } 668 } 669 private void UpdateCrossovers() { 670 var oldCrossover = CrossoverParameter.Value; 671 var defaultCrossover = Problem.Operators.OfType<ICrossover>().FirstOrDefault(); 672 CrossoverParameter.ValidValues.Clear(); 673 foreach (var crossover in Problem.Operators.OfType<ICrossover>().OrderBy(c => c.Name)) { 674 ParameterizeStochasticOperatorForLayer(crossover); 675 CrossoverParameter.ValidValues.Add(crossover); 676 } 677 if (oldCrossover != null) { 678 var crossover = CrossoverParameter.ValidValues.FirstOrDefault(c => c.GetType() == oldCrossover.GetType()); 679 if (crossover != null) 680 CrossoverParameter.Value = crossover; 681 else 682 oldCrossover = null; 683 } 684 if (oldCrossover == null && defaultCrossover != null) 685 CrossoverParameter.Value = defaultCrossover; 686 } 687 private void UpdateMutators() { 688 var oldMutator = MutatorParameter.Value; 689 MutatorParameter.ValidValues.Clear(); 690 foreach (var mutator in Problem.Operators.OfType<IManipulator>().OrderBy(m => m.Name)) { 691 ParameterizeStochasticOperatorForLayer(mutator); 692 MutatorParameter.ValidValues.Add(mutator); 693 } 694 if (oldMutator != null) { 695 var mutator = MutatorParameter.ValidValues.FirstOrDefault(m => m.GetType() == oldMutator.GetType()); 696 if (mutator != null) 697 MutatorParameter.Value = mutator; 698 } 699 } 304 700 private void UpdateTerminators() { 305 701 var newTerminators = new Dictionary<ITerminator, bool> { … … 319 715 Terminators.Operators.Add(newTerminator.Key, newTerminator.Value); 320 716 } 321 private void UpdateCrossovers() {322 var oldCrossover = CrossoverParameter.Value;323 var defaultCrossover = Problem.Operators.OfType<ICrossover>().FirstOrDefault();324 CrossoverParameter.ValidValues.Clear();325 foreach (var crossover in Problem.Operators.OfType<ICrossover>().OrderBy(c => c.Name)) {326 ParameterizeStochasticOperatorForLayer(crossover);327 CrossoverParameter.ValidValues.Add(crossover);328 }329 if (oldCrossover != null) {330 var crossover = CrossoverParameter.ValidValues.FirstOrDefault(c => c.GetType() == oldCrossover.GetType());331 if (crossover != null)332 CrossoverParameter.Value = crossover;333 else334 oldCrossover = null;335 }336 if (oldCrossover == null && defaultCrossover != null)337 CrossoverParameter.Value = defaultCrossover;338 }339 private void UpdateMutators() {340 var oldMutator = MutatorParameter.Value;341 MutatorParameter.ValidValues.Clear();342 foreach (var mutator in Problem.Operators.OfType<IManipulator>().OrderBy(m => m.Name)) {343 ParameterizeStochasticOperatorForLayer(mutator);344 MutatorParameter.ValidValues.Add(mutator);345 }346 if (oldMutator != null) {347 var mutator = MutatorParameter.ValidValues.FirstOrDefault(m => m.GetType() == oldMutator.GetType());348 if (mutator != null)349 MutatorParameter.Value = mutator;350 }351 }352 717 #endregion 353 718 } -
branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/HeuristicLab.Algorithms.ALPS-3.3.csproj
r12992 r12993 133 133 <ItemGroup> 134 134 <Compile Include="AgeInheritance.cs" /> 135 <Compile Include="Alps.cs" />136 135 <Compile Include="Analyzers\EvaluatedSolutionsHistoryAnalyzer.cs" /> 137 136 <Compile Include="Analyzers\OldestAverageYoungestAgeAnalyzer.cs" />
Note: See TracChangeset
for help on using the changeset viewer.