Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/LayerSorter.cs @ 12570

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

#2269

  • Added missing Hook.
  • Sealed some classes.
File size: 2.2 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 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 HeuristicLab.Common;
23using HeuristicLab.Core;
24using HeuristicLab.Data;
25using HeuristicLab.Operators;
26using HeuristicLab.Parameters;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28
29namespace HeuristicLab.Algorithms.ALPS {
30  [Item("LayerSorter", "")]
31  [StorableClass]
32  public sealed class LayerSorter : SingleSuccessorOperator {
33    private IScopeTreeLookupParameter<IntValue> LayerParameter {
34      get { return (IScopeTreeLookupParameter<IntValue>)Parameters["Layer"]; }
35    }
36
37    [StorableConstructor]
38    private LayerSorter(bool deserializing)
39      : base(deserializing) { }
40    private LayerSorter(LayerSorter original, Cloner cloner)
41      : base(original, cloner) { }
42    public override IDeepCloneable Clone(Cloner cloner) {
43      return new LayerSorter(this, cloner);
44    }
45    public LayerSorter()
46      : base() {
47      Parameters.Add(new ScopeTreeLookupParameter<IntValue>("Layer"));
48    }
49
50    public override IOperation Apply() {
51      var layers = ExecutionContext.Scope.SubScopes;
52      layers.Sort(SortLayers);
53
54      return base.Apply();
55    }
56
57    private int SortLayers(IScope x, IScope y) {
58      var lx = (IntValue)x.Variables["Layer"].Value;
59      var ly = (IntValue)y.Variables["Layer"].Value;
60
61      return lx.Value.CompareTo(ly.Value);
62    }
63  }
64}
Note: See TracBrowser for help on using the repository browser.