Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 12018 was 12018, checked in by pfleck, 9 years ago

#2269

  • merged trunk after 3.3.11 release
  • updated copyright and plugin version in ALPS plugin
  • removed old ALPS samples based on an userdefined alg
File size: 3.0 KB
RevLine 
[11585]1#region License Information
2/* HeuristicLab
[12018]3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[11585]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]
[11586]35  public sealed class EldersSelector : SingleObjectiveSelector {
[11585]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    }
[11586]43    private ILookupParameter<IntValue> LayerParameter {
44      get { return (ILookupParameter<IntValue>)Parameters["Layer"]; }
45    }
[11585]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"));
[11586]58      Parameters.Add(new LookupParameter<IntValue>("NumberOfLayers"));
59      Parameters.Add(new LookupParameter<IntValue>("Layer"));
[11585]60    }
61
62    protected override IScope[] Select(List<IScope> scopes) {
63      var ageLimits = AgeLimitsParameter.ActualValue;
64      int numberOfLayers = NumberOfLayersParameter.ActualValue.Value;
[11586]65      int layer = LayerParameter.ActualValue.Value;
[11585]66
[11609]67      if (layer >= numberOfLayers - 1) // is max layer?
[11585]68        return new IScope[0];
69
70      int limit = ageLimits[layer];
[11609]71      var eldersQuery =
[11585]72        from scope in scopes
[11586]73        let age = ((IntValue)scope.Variables["Age"].Value).Value
[11585]74        where age > limit
75        select scope;
76
[11609]77      var elders = eldersQuery.ToArray();
78
79      if (!CopySelected.Value)
80        foreach (var elder in elders)
81          scopes.Remove(elder);
82
83      return elders;
[11585]84    }
85  }
86}
Note: See TracBrowser for help on using the repository browser.