Changeset 11620


Ignore:
Timestamp:
12/02/14 13:20:44 (8 years ago)
Author:
pfleck
Message:

#2269

  • Implemented automatic calculation of the age limits based on ALPS' parameter.
  • Renamed AgeDiversityAnalyzer to AgeDistributionAnalyzer.
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  
    3131
    3232namespace HeuristicLab.Algorithms.ALPS {
    33   // Based on QualityDiversityAnalyzer
    34   [Item("AgeDiversityAnalyzer", "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.")]
    3535  [StorableClass]
    36   public sealed class AgeDiversityAnalyzer : SingleSuccessorOperator, IAnalyzer, IIterationBasedOperator {
     36  public sealed class AgeDistributionAnalyzer : SingleSuccessorOperator, IAnalyzer, IIterationBasedOperator {
    3737
    3838    #region Parameter Properties
     
    6969
    7070    [StorableConstructor]
    71     private AgeDiversityAnalyzer(bool deserializing)
     71    private AgeDistributionAnalyzer(bool deserializing)
    7272      : base(deserializing) { }
    73     private AgeDiversityAnalyzer(AgeDiversityAnalyzer original, Cloner cloner)
     73    private AgeDistributionAnalyzer(AgeDistributionAnalyzer original, Cloner cloner)
    7474      : base(original, cloner) { }
    7575    public override IDeepCloneable Clone(Cloner cloner) {
    76       return new AgeDiversityAnalyzer(this, cloner);
     76      return new AgeDistributionAnalyzer(this, cloner);
    7777    }
    78     public AgeDiversityAnalyzer()
     78    public AgeDistributionAnalyzer()
    7979      : base() {
    8080      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  
    2121
    2222using System;
     23using System.Collections;
     24using System.Collections.Generic;
    2325using System.Linq;
    2426using HeuristicLab.Analysis;
     
    359361      ParameterizeSelectors();
    360362    }
     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    }
    361384    #endregion
    362385
     
    369392      if (Problem != null)
    370393        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;
    371400    }
    372401    private void ParameterizeSolutionsCreator() {
     
    450479      }
    451480    }
    452 
    453481    #endregion
    454482
     
    497525    }
    498526    #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    }
    499565  }
    500566}
  • branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/HeuristicLab.Algorithms.ALPS-3.3.csproj

    r11617 r11620  
    7878  </ItemGroup>
    7979  <ItemGroup>
    80     <Compile Include="AgeDiversityAnalyzer.cs" />
     80    <Compile Include="AgeDistributionAnalyzer.cs" />
    8181    <Compile Include="AgingScheme.cs" />
    8282    <Compile Include="AlpsGeneticAlgorithm.cs" />
Note: See TracChangeset for help on using the changeset viewer.