Changeset 11620 for branches/ALPS
- Timestamp:
- 12/02/14 13:20:44 (10 years ago)
- Location:
- branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3
- Files:
-
- 2 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/AgeDistributionAnalyzer.cs
r11617 r11620 31 31 32 32 namespace HeuristicLab.Algorithms.ALPS { 33 // Based on QualityDi versityAnalyzer34 [Item("AgeDi versityAnalyzer", "Analyzes the distribution of the ages in that it adds a Histogram of them into the result collection.")]33 // Based on QualityDistributionAnalyzer 34 [Item("AgeDistributionAnalyzer", "Analyzes the distribution of the ages in that it adds a Histogram of them into the result collection.")] 35 35 [StorableClass] 36 public sealed class AgeDi versityAnalyzer : SingleSuccessorOperator, IAnalyzer, IIterationBasedOperator {36 public sealed class AgeDistributionAnalyzer : SingleSuccessorOperator, IAnalyzer, IIterationBasedOperator { 37 37 38 38 #region Parameter Properties … … 69 69 70 70 [StorableConstructor] 71 private AgeDi versityAnalyzer(bool deserializing)71 private AgeDistributionAnalyzer(bool deserializing) 72 72 : base(deserializing) { } 73 private AgeDi versityAnalyzer(AgeDiversityAnalyzer original, Cloner cloner)73 private AgeDistributionAnalyzer(AgeDistributionAnalyzer original, Cloner cloner) 74 74 : base(original, cloner) { } 75 75 public override IDeepCloneable Clone(Cloner cloner) { 76 return new AgeDi versityAnalyzer(this, cloner);76 return new AgeDistributionAnalyzer(this, cloner); 77 77 } 78 public AgeDi versityAnalyzer()78 public AgeDistributionAnalyzer() 79 79 : base() { 80 80 Parameters.Add(new ScopeTreeLookupParameter<IntValue>("Age", "The value which represents the age of a solution.")); -
branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/AlpsGeneticAlgorithm.cs
r11609 r11620 21 21 22 22 using System; 23 using System.Collections; 24 using System.Collections.Generic; 23 25 using System.Linq; 24 26 using HeuristicLab.Analysis; … … 359 361 ParameterizeSelectors(); 360 362 } 363 private void AgeGapParameter_ValueChanged(object sender, EventArgs e) { 364 AgeGap.ValueChanged += AgeGap_ValueChanged; 365 RecalculateAgeLimits(); 366 } 367 private void AgeGap_ValueChanged(object sender, EventArgs e) { 368 RecalculateAgeLimits(); 369 } 370 private void AgingSchemeParameter_ValueChanged(object sender, EventArgs e) { 371 AgingScheme.ValueChanged += AgingScheme_ValueChanged; 372 RecalculateAgeLimits(); 373 } 374 private void AgingScheme_ValueChanged(object sender, EventArgs e) { 375 RecalculateAgeLimits(); 376 } 377 private void NumberOfLayersParameter_ValueChanged(object sender, EventArgs e) { 378 NumberOfLayers.ValueChanged += NumberOfLayers_ValueChanged; 379 RecalculateAgeLimits(); 380 } 381 private void NumberOfLayers_ValueChanged(object sender, EventArgs e) { 382 RecalculateAgeLimits(); 383 } 361 384 #endregion 362 385 … … 369 392 if (Problem != null) 370 393 Problem.Evaluator.QualityParameter.ActualNameChanged += Evaluator_QualityParameter_ActualNameChanged; 394 AgeGapParameter.ValueChanged += AgeGapParameter_ValueChanged; 395 AgeGap.ValueChanged += AgeGap_ValueChanged; 396 AgingSchemeParameter.ValueChanged += AgingSchemeParameter_ValueChanged; 397 AgingScheme.ValueChanged += AgingScheme_ValueChanged; 398 NumberOfLayersParameter.ValueChanged += NumberOfLayersParameter_ValueChanged; 399 NumberOfLayers.ValueChanged += NumberOfLayers_ValueChanged; 371 400 } 372 401 private void ParameterizeSolutionsCreator() { … … 450 479 } 451 480 } 452 453 481 #endregion 454 482 … … 497 525 } 498 526 #endregion 527 528 private void RecalculateAgeLimits() { 529 IEnumerable<int> scheme; 530 switch (AgingScheme.Value) { 531 case AgingSchemes.Linear: scheme = LinearAgingScheme(); break; 532 case AgingSchemes.Fibonacci: scheme = FibonacciAgingScheme(); break; 533 case AgingSchemes.Polynomial: scheme = PolynomialAgingScheme(2); break; 534 case AgingSchemes.Exponential: scheme = ExponentialAgingScheme(2); break; 535 default: throw new NotSupportedException("Aging Scheme " + AgingScheme.Value + " is not supported."); 536 } 537 538 int ageGap = AgeGap.Value; 539 AgeLimits = new IntArray(scheme.Select(a => a * ageGap).Take(NumberOfLayers.Value).ToArray()); 540 } 541 542 // 1 2 3 4 5 6 7 543 private static IEnumerable<int> LinearAgingScheme() { 544 for (int i = 0; ; i++) 545 yield return i + 1; 546 } 547 // 1 2 3 5 8 13 21 548 private static IEnumerable<int> FibonacciAgingScheme() { 549 for (int i = 1, next = 2, temp; ; temp = next, next = i + next, i = temp) 550 yield return i; 551 } 552 // (n^2): 1 2 4 9 16 25 36 553 private static IEnumerable<int> PolynomialAgingScheme(double exp) { 554 yield return 1; 555 yield return 2; 556 for (int i = 2; ; i++) 557 yield return (int)Math.Pow(i, exp); 558 559 } 560 // 1 2 4 8 16 32 64 561 private static IEnumerable<int> ExponentialAgingScheme(double @base) { 562 for (int i = 0; ; i++) 563 yield return (int)Math.Pow(@base, i); 564 } 499 565 } 500 566 } -
branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/HeuristicLab.Algorithms.ALPS-3.3.csproj
r11617 r11620 78 78 </ItemGroup> 79 79 <ItemGroup> 80 <Compile Include="AgeDi versityAnalyzer.cs" />80 <Compile Include="AgeDistributionAnalyzer.cs" /> 81 81 <Compile Include="AgingScheme.cs" /> 82 82 <Compile Include="AlpsGeneticAlgorithm.cs" />
Note: See TracChangeset
for help on using the changeset viewer.