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 |
|
---|
22 | using System.Collections.Generic;
|
---|
23 | using System.Linq;
|
---|
24 | using HeuristicLab.Common;
|
---|
25 | using HeuristicLab.Core;
|
---|
26 | using HeuristicLab.Data;
|
---|
27 | using HeuristicLab.Parameters;
|
---|
28 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
29 | using HeuristicLab.Selection;
|
---|
30 |
|
---|
31 | namespace 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 | } |
---|