Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3057_DynamicALPS/TestProblems/oesr-alps-master/HeuristicLab.Algorithms.OESRALPS/AgingScheme.cs @ 17717

Last change on this file since 17717 was 17479, checked in by kyang, 5 years ago

#3057

  1. upload the latest version of ALPS with SMS-EMOA
  2. upload the related dynamic test problems (dynamic, single-objective symbolic regression), written by David Daninel.
File size: 3.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 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
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using HeuristicLab.Data;
26using HEAL.Attic;
27
28namespace HeuristicLab.Algorithms.OESRALPS {
29    /// <summary>
30    /// Defines the growth of age limits for the layers.
31    /// </summary>
32    /// [Guid("")]
33    [StorableType("929B3D03-A85A-4162-8D32-09E3576B7286")]
34  public enum AgingScheme {
35    Linear,
36    Fibonacci,
37    Polynomial,
38    Exponential
39  }
40
41  /// <summary>
42  /// Helper for calculating the age limits for a AgingScheme and a given AgeGap.
43  /// </summary>
44  public static class AgingSchemeCalculator {
45    public static IntArray CalculateAgeLimits(this AgingScheme scheme, int ageGap, int numberOfLayers) {
46      IEnumerable<int> schemeGenerator;
47      switch (scheme) {
48        case AgingScheme.Linear: schemeGenerator = LinearAgingScheme(); break;
49        case AgingScheme.Fibonacci: schemeGenerator = FibonacciAgingScheme(); break;
50        case AgingScheme.Polynomial: schemeGenerator = PolynomialAgingScheme(2); break;
51        case AgingScheme.Exponential: schemeGenerator = ExponentialAgingScheme(2); break;
52        default: throw new NotSupportedException("Aging Scheme " + scheme + " is not supported.");
53      }
54
55      return new IntArray(schemeGenerator.Select(a => a * ageGap).Take(numberOfLayers).ToArray());
56    }
57
58    #region Scheme definitions
59    // 1 2 3 4 5 6 7 ...
60    private static IEnumerable<int> LinearAgingScheme() {
61      for (int i = 0; ; i++)
62        yield return i + 1;
63    }
64    // 1 2 3 5 8 13 21 ...
65    private static IEnumerable<int> FibonacciAgingScheme() {
66      for (int i = 1, next = 2, temp; ; temp = next, next = i + next, i = temp)
67        yield return i;
68    }
69    // (n^2): 1 2 4 9 16 25 36 ...
70    private static IEnumerable<int> PolynomialAgingScheme(double exp) {
71      yield return 1;
72      yield return 2;
73      for (int i = 2; ; i++)
74        yield return (int)Math.Pow(i, exp);
75    }
76    // 1 2 4 8 16 32 64 ...
77    private static IEnumerable<int> ExponentialAgingScheme(double @base) {
78      for (int i = 0; ; i++)
79        yield return (int)Math.Pow(@base, i);
80    }
81    #endregion
82  }
83}
Note: See TracBrowser for help on using the repository browser.