Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 11585 was 11585, checked in by pfleck, 10 years ago

#2269 Implemented EldersEmigrator.

  • Implemented EldersSelector and ShiftToRightMigrator.
File size: 2.6 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 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
44    [StorableConstructor]
45    private EldersSelector(bool deserializing)
46      : base(deserializing) { }
47    private EldersSelector(EldersSelector original, Cloner cloner)
48      : base(original, cloner) { }
49    public override IDeepCloneable Clone(Cloner cloner) {
50      return new EldersSelector(this, cloner);
51    }
52    public EldersSelector()
53      : base() {
54      Parameters.Add(new LookupParameter<IntArray>("AgeLimits"));
55    }
56
57    protected override IScope[] Select(List<IScope> scopes) {
58      var ageLimits = AgeLimitsParameter.ActualValue;
59      int numberOfLayers = NumberOfLayersParameter.ActualValue.Value;
60
61      int layer = ((IntValue)CurrentScope.Variables["Layer"]).Value;
62
63      if (layer >= numberOfLayers)
64        return new IScope[0];
65
66      int limit = ageLimits[layer];
67      var elders =
68        from scope in scopes
69        let age = ((IntValue)scope.Variables["Age"]).Value
70        where age > limit
71        select scope;
72
73      return elders.ToArray();
74    }
75  }
76}
Note: See TracBrowser for help on using the repository browser.