source: branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/EldersSelector.cs @ 11586

Last change on this file since 11586 was 11586, checked in by pfleck, 5 years ago

#2269 Implemented LayerUpdator.

  • Added First/LastSubScopeProcessor.
  • Added two Calculators because ExpressionCalculator does not support required features yet.
  • Added some wiring.
  • Small bugfixes and refactorings.
File size: 2.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2014 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.Collections.Generic;
23using System.Linq;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Data;
27using HeuristicLab.Parameters;
28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
29using HeuristicLab.Selection;
30
31namespace HeuristicLab.Algorithms.ALPS {
32
33  [Item("EldersSelector", "Select all individuals which are to old for their current layer.")]
34  [StorableClass]
35  public sealed class EldersSelector : SingleObjectiveSelector {
36
37    private ILookupParameter<IntArray> AgeLimitsParameter {
38      get { return (ILookupParameter<IntArray>)Parameters["AgeLimits"]; }
39    }
40    private ILookupParameter<IntValue> NumberOfLayersParameter {
41      get { return (ILookupParameter<IntValue>)Parameters["NumberOfLayers"]; }
42    }
43    private ILookupParameter<IntValue> LayerParameter {
44      get { return (ILookupParameter<IntValue>)Parameters["Layer"]; }
45    }
46
47    [StorableConstructor]
48    private EldersSelector(bool deserializing)
49      : base(deserializing) { }
50    private EldersSelector(EldersSelector original, Cloner cloner)
51      : base(original, cloner) { }
52    public override IDeepCloneable Clone(Cloner cloner) {
53      return new EldersSelector(this, cloner);
54    }
55    public EldersSelector()
56      : base() {
57      Parameters.Add(new LookupParameter<IntArray>("AgeLimits"));
58      Parameters.Add(new LookupParameter<IntValue>("NumberOfLayers"));
59      Parameters.Add(new LookupParameter<IntValue>("Layer"));
60    }
61
62    protected override IScope[] Select(List<IScope> scopes) {
63      var ageLimits = AgeLimitsParameter.ActualValue;
64      int numberOfLayers = NumberOfLayersParameter.ActualValue.Value;
65      int layer = LayerParameter.ActualValue.Value;
66
67      if (layer >= numberOfLayers) // is max layer?
68        return new IScope[0];
69
70      int limit = ageLimits[layer];
71      var elders =
72        from scope in scopes
73        let age = ((IntValue)scope.Variables["Age"].Value).Value
74        where age > limit
75        select scope;
76
77      return elders.ToArray();
78    }
79  }
80}
Note: See TracBrowser for help on using the repository browser.